Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

system.hh

00001 /*
00002 *  Name:      system.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Base operating system
00005 *  Date:      $Date: 2003/08/08 23:30:34 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_SYSTEM_SYSTEM__
00027 #define _MPCL_SYSTEM_SYSTEM__
00028 
00029 #include <cstdlib>
00030 #include <vector>
00031 #include "../text/string.hh"
00032 #include "defs.hh"
00033 
00034 
00036 namespace mpcl
00037 {
00038 
00040   namespace system
00041   {
00042 
00043     using std::string;
00044     using std::vector;
00045     using text::TString;
00046 
00048     class ISystem
00049     {
00050     
00051       public:
00052 
00058         enum ELogLevel
00059         {
00060           eEmerg   , 
00061           eAlert   , 
00062           eCrit    , 
00063           eErr     , 
00064           eWarning , 
00065           eNotice  , 
00066           eInfo    , 
00067           eDebug     
00068         };
00069 
00076         enum ELogFacility
00077         {
00078           eAuthPriv ,  
00079           eCron     ,  
00080           eDaemon   ,  
00081           eKern     ,  
00082           eLocal0   ,  
00083           eLocal1   ,  
00084           eLocal2   ,  
00085           eLocal3   ,  
00086           eLocal4   ,  
00087           eLocal5   ,  
00088           eLocal6   ,  
00089           eLocal7   ,  
00090           eLpr      ,  
00091           eMail     ,  
00092           eNews     ,  
00093           eUser     ,  
00094           eUucp        
00095         };
00096         
00098         class TMachineDependent
00099         {
00100             
00101           protected:
00102             
00104             enum EEndianness
00105             {
00106               eLittleEndian , 
00107               eBigEndian      
00108             };
00109 
00111             EEndianness   eEndianType;
00112 
00113 
00114           public:
00115             
00116             //
00117             //  C O N S T R U C T O R S
00118             //
00119             
00121             TMachineDependent (void);
00122             
00124             virtual ~TMachineDependent (void) {}
00125             
00126             
00127           public:
00128             
00129             //
00130             //  S E L E C T O R S
00131             //
00132             
00137             bool isBigEndian (void) const
00138             {
00139               return ( eEndianType == eBigEndian );
00140             }
00141             
00146             bool isLittleEndian (void) const
00147             {
00148               return ( eEndianType == eLittleEndian );
00149             }
00150             
00161             long int getEndianIndependentLongInt ( EEndianness          eENDIAN_TYPE      ,
00162                                                    const unsigned char* pkucSOURCE_BUFFER ,
00163                                                    std::size_t          zLENGTH           ) const;
00164             
00165         };  // class TMachineDependent
00166         
00168         class TLittleEndianBuffer : private TMachineDependent
00169         {
00170       
00171           private:
00172       
00174             const unsigned char*   pkucBuffer;
00175             
00177             std::size_t            zLength;
00178             
00179       
00180           public:
00181             
00182             //
00183             //  C O N S T R U C T O R S
00184             //
00185             
00191             TLittleEndianBuffer ( const unsigned char* pkucSOURCE_BUFFER ,
00192                                   std::size_t          zLENGTH           ) :
00193               pkucBuffer (pkucSOURCE_BUFFER)                               ,
00194               zLength    (zLENGTH)                                         {}
00195             
00196             
00197           public:
00198             
00199             //
00200             //  S E L E C T O R S
00201             //
00202             
00204             virtual operator long int (void) const
00205             {
00206               return getEndianIndependentLongInt (eLittleEndian, pkucBuffer, zLength);
00207             }
00208 
00209         };  // class TLittleEndianBuffer
00210         
00212         class TBigEndianBuffer : private TMachineDependent
00213         {
00214       
00215           private:
00216             
00218             const unsigned char*   pkucBuffer;
00219             
00221             std::size_t            zLength;      
00222             
00223             
00224           public:
00225             
00226             //
00227             //  C O N S T R U C T O R S
00228             //
00229             
00235             TBigEndianBuffer ( const unsigned char* pkucSOURCE_BUFFER ,
00236                                std::size_t          zLENGTH           ) :
00237               pkucBuffer (pkucSOURCE_BUFFER)                            ,
00238               zLength    (zLENGTH)                                      {}
00239 
00240 
00241           public:
00242       
00243             //
00244             //  S E L E C T O R S
00245             //
00246       
00248             virtual operator long int (void) const
00249             {
00250               return getEndianIndependentLongInt (eBigEndian, pkucBuffer, zLength);
00251             }
00252       
00253         };  // class TBigEndianBuffer
00254 
00255 
00256       public:
00257 
00258         //
00259         //  C O N S T R U C T O R S
00260         //
00261 
00263         virtual ~ISystem (void) {}
00264         
00265 
00266       public:
00267 
00268         //
00269         //  S E L E C T O R S
00270         //
00271 
00276         virtual TString getCurrentDirectory (void) const = 0;
00277 
00282         virtual char getDirectorySeparator (void) const = 0;
00283 
00289         virtual std::size_t getFileSize (const char* pkcFILE_NAME) const = 0;
00290 
00300         virtual vector<TString> getPathItems (const string& rkySOURCE_PATH_COLLECTION) const;
00301 
00306         virtual char getPathSeparator (void) const = 0;
00307 
00312         virtual int getProcessId (void) const = 0;
00313 
00320         virtual void sleep (std::size_t zSECONDS, std::size_t zNANOSECONDS = 0) const = 0;
00321 
00333         virtual void writeLogEntry ( const string& rkyMESSAGE          ,
00334                                      ELogLevel     eLEVEL    = eNotice ,
00335                                      ELogFacility  eFACILITY = eUser   ) const = 0;
00336 
00344         virtual void yield (void) const = 0;
00345 
00346     };  // class ISystem
00347 
00348   }  // namespace system
00349 
00350 }  // namespace mpcl
00351 
00352 
00353 #endif  // not _MPCL_SYSTEM_SYSTEM__

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18