Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/nto/Message.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__Message_HPP__
00002 #define __J2K__Message_HPP__
00003 
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <errno.h>
00006 #include <sys/neutrino.h>
00007 #include <sys/dispatch.h>
00008 
00009 #ifndef __FRED_MSG_DATA_T__
00010 #define __FRED_MSG_DATA_T__
00011 
00012 enum MsgQueryInfo_t
00013 {
00014 ///////////////////////////////////////////////////////////////////////////////////////////////////
00015 //   Query Request   __OR__   Status State                                                       //
00016 ///////////////////////////////////////////////////////////////////////////////////////////////////
00017   MQI_PING          = 0x0000,   // Ping the server:  Server exist ?!
00018   MQI_STATUS        = 0x0001,   // Retrieve status:  Get current server status. 
00019   MQI_GET           = 0x0002,   // Get an element:   Return some element from current storage
00020   MQI_PUT           = 0x0004,   // Put an element:   Store some element in current storage
00021   MQI_CLEAR         = 0x0008,   // Clear element:    Clear element from current storage
00022   MQI_QUIT          = 0x0010,   // Quit Request:     Caller should quit
00023   MQI_ADD_CONSUMER  = 0x0020,   // Add one consumer slot
00024   MQI_ADD_PRODUCER  = 0x0040,   // Add one producer slot
00025   MQI_IS_EXPIRED    = 0x0080,   // Does my request is expired ?  __OR__  You are expired
00026   MQI_IS_EMPTY      = 0x0100,   // Does the buffer is empty ?    __OR__  Buffer is empty
00027   MQI_IS_FULL       = 0x0200,   // Does the buffer is filled ?   __OR__  Buffer is full
00028   MQI_EXIST         = 0x0400,   // Do you exist ?                __OR__  Server exist
00029   MQI_SUICIDE       = 0x0800,   // Should I suicide ?            __OR__  Please suicide !
00030   MQI_TIMEOUT       = 0x0D90,   // MQI_IS_EXPIRED | MQI_EXIST | MQI_SUICIDE | MQI_QUIT;
00031   MQI_CONSUMER      = 0x0402,   // MQI_EXIST | MQI_GET
00032   MQI_PRODUCER      = 0x0404    // MQI_EXIST | MQI_PUT
00033 ///////////////////////////////////////////////////////////////////////////////////////////////////
00034 };
00035 
00036 /* We specify the header as being at least a pulse */
00037 typedef struct _pulse    msg_header_t;
00038 
00039 /* Our real data comes after the header */
00040 typedef struct _fred_msg_data_t
00041 {
00042   msg_header_t  hdr;
00043   int           request;
00044   int           status;
00045   int           index;
00046   int           number;
00047   void*         data;
00048   pthread_t     pid;
00049 } fred_msg_data_t;
00050 
00051 #endif // __FRED_MSG_DATA_T__
00052 
00053 class Message 
00054 {
00055 protected:
00056   fred_msg_data_t  msg;
00057 
00058 public:
00059   Message( int number0 = -1, int request0 = 0, int status0 = 0, int index0 = 0, void* data0 = NULL );
00060 
00061   Message( const Message& src );
00062   const Message& operator= ( const Message& src );
00063 
00064   // Reset with default message
00065   inline void reset();
00066    
00067   // Copy a message content from the source
00068   inline void copy( const Message* src );
00069 
00070   virtual ~Message();
00071 
00072   // Normal Message handling
00073   void handleHeader();
00074 
00075   // Check for Kernel Message
00076   int checkHeader( int rcvid );
00077 
00078   inline int isIO();
00079   inline int receive( int channel );
00080   inline int send( int fd, Message* rm );
00081   inline void reply( int rcvid );
00082   inline void reply( int rcvid, int number, int state = EOK );
00083 
00084   // Message functions:
00085   inline fred_msg_data_t  getMessage();
00086   inline void*            getMessageAddr();
00087   inline size_t           getMessageSize();
00088   inline int              getNumber();
00089   inline void             setNumber( int nb );
00090   inline int              getRequest();
00091   inline void             setRequest( int r );
00092   inline int              getStatus();
00093   inline void             setStatus( int s );
00094   inline int              getIndex();
00095   inline void             setIndex( int i );
00096   inline void*            getData();
00097   inline void             setData( void* ptr );
00098 
00099   inline pthread_t        getPThread();
00100   inline void             setPThread( pthread_t tid );
00101 
00102   // Header functions:
00103   inline msg_header_t     getHeader();
00104   inline int              getHeaderCode();
00105   inline int              getHeaderScoid();
00106 
00107   // Query recognition:
00108   inline BOOL  Message::isStatus();
00109   inline BOOL  Message::isGet();
00110   inline BOOL  Message::isPut();
00111   inline BOOL  Message::isClear();
00112   inline BOOL  Message::isQuit();
00113   inline BOOL  Message::isAddConsumer();
00114   inline BOOL  Message::isAddProducer();
00115   inline BOOL  Message::isExpired();
00116   inline BOOL  Message::isEmpty();
00117   inline BOOL  Message::isFull();
00118   inline BOOL  Message::isExist();
00119   inline BOOL  Message::isSuicide();
00120   inline BOOL  Message::isTimeout();
00121   inline BOOL  Message::isConsumer();
00122   inline BOOL  Message::isProducer();
00123 
00124 
00125   void print()
00126   {
00127     printf( "===================================== \n" );
00128     printf( "Message: \n" );
00129     printf( "===================================== \n" );
00130 
00131     printf( " - Request: [%d]  ", msg.request );
00132     printInfo( msg.request );
00133 
00134     printf( " - Status:  [%d]  ", msg.status  );
00135     printInfo( msg.status  );
00136 
00137     printf( " - Index:   [%d] \n", msg.index   );
00138     printf( " - Number:  [%d] \n", msg.number  );
00139 
00140     printf( "===================================== \n" );
00141     fflush( stdout );
00142   }
00143 
00144   void printInfo( int info )
00145   {
00146     register int backup = msg.status;
00147 
00148     msg.status = info;
00149     if ( isStatus()        ) { printf( " STATUS      " ); }
00150     if ( isGet()           ) { printf( " GET         " ); }
00151     if ( isPut()           ) { printf( " PUT         " ); }
00152     if ( isClear()         ) { printf( " CLEAR       " ); }
00153     if ( isQuit()          ) { printf( " QUIT        " ); }
00154     if ( isAddConsumer()   ) { printf( " ADD_CONSUMER " ); }
00155     if ( isAddProducer()   ) { printf( " ADD_PRODUCER " ); }
00156     if ( isExpired()       ) { printf( " EXPIRED     " ); }
00157     if ( isEmpty()         ) { printf( " EMPTY       " ); }
00158     if ( isFull()          ) { printf( " FULL        " ); }
00159     if ( isExist()         ) { printf( " EXIST       " ); }
00160     if ( isSuicide()       ) { printf( " SUICIDE     " ); }
00161     if ( isTimeout()       ) { printf( " TIMEOUT     " ); }
00162     if ( isConsumer()      ) { printf( " CONSUMER    " ); }
00163     if ( isProducer()      ) { printf( " PRODUCER    " ); }
00164 
00165     msg.status = backup;
00166     printf( "\n" );
00167     fflush( stdout );
00168   }
00169 };
00170 
00171 #include <j2k/nto/Message.inl>
00172 
00173 #endif // End of Message.hpp

Generated on Sun Oct 14 18:46:35 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001