cMsg.h

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------*
00002  *
00003  *  Copyright (c) 2004        Southeastern Universities Research Association, *
00004  *                            Thomas Jefferson National Accelerator Facility  *
00005  *                                                                            *
00006  *    This software was developed under a United States Government license    *
00007  *    described in the NOTICE file included as part of this distribution.     *
00008  *                                                                            *
00009  *    E.Wolin, 14-Jul-2004, Jefferson Lab                                     *
00010  *                                                                            *
00011  *    Authors: Elliott Wolin                                                  *
00012  *             wolin@jlab.org                    Jefferson Lab, MS-6B         *
00013  *             Phone: (757) 269-7365             12000 Jefferson Ave.         *
00014  *             Fax:   (757) 269-5800             Newport News, VA 23606       *
00015  *                                                                            *
00016  *             Carl Timmer                                                    *
00017  *             timmer@jlab.org                   Jefferson Lab, MS-6B         *
00018  *             Phone: (757) 269-5130             12000 Jefferson Ave.         *
00019  *             Fax:   (757) 269-5800             Newport News, VA 23606       *
00020  *                                                                            *
00021  * Description:                                                               *
00022  *                                                                            *
00023  *  Defines cMsg API and return codes                                         *
00024  *                                                                            *
00025  *                                                                            *
00026  *----------------------------------------------------------------------------*/
00027  
00098 #ifndef _cMsg_h
00099 #define _cMsg_h
00100 
00101 
00102 /* required includes */
00103 #include <time.h>
00104 #ifndef _cMsgConstants_h
00105 #include "cMsgConstants.h"
00106 #endif
00107 
00108 #ifndef VXWORKS
00109 #include <inttypes.h>
00110 #endif
00111 
00113 typedef void *cMsgSubscribeConfig;
00114 
00116 typedef void (cMsgShutdownHandler) (void *userArg);
00117 
00119 typedef void (cMsgCallbackFunc) (void *msg, void *userArg);
00120 
00121 /* function prototypes */
00122 #ifdef __cplusplus
00123 extern "C" {
00124 #endif
00125 
00126 #ifdef Darwin
00127 #define CLOCK_REALTIME 0
00128 void clock_gettime(int dummy, struct timespec *t1);
00129 #endif
00130 
00131 #ifdef VXWORKS
00132   char *strdup(const char *s1);
00133   int   strcasecmp(const char *s1, const char *s2);
00134   int   strncasecmp(const char *s1, const char *s2, size_t n);
00135 #endif
00136 
00137 
00138   /* basic functions */
00139   int   cMsgConnect           (const char *myUDL, const char *myName, const char *myDescription,
00140                                void **domainId);
00141   int   cMsgSend              (void *domainId, void *msg);
00142   int   cMsgSyncSend          (void *domainId, void *msg, const struct timespec *timeout, int *response);
00143   int   cMsgFlush             (void *domainId, const struct timespec *timeout);
00144   int   cMsgSubscribe         (void *domainId, const char *subject, const char *type, cMsgCallbackFunc *callback,
00145                                void *userArg, cMsgSubscribeConfig *config, void **handle);
00146   int   cMsgUnSubscribe       (void *domainId, void *handle);
00147   int   cMsgSendAndGet        (void *domainId, void *sendMsg, const struct timespec *timeout, void **replyMsg);
00148   int   cMsgSubscribeAndGet   (void *domainId, const char *subject, const char *type,
00149                                const struct timespec *timeout, void **replyMsg);
00150   int   cMsgMonitor           (void *domainId, const char *command, void **replyMsg);
00151   int   cMsgReceiveStart      (void *domainId);
00152   int   cMsgReceiveStop       (void *domainId);
00153   int   cMsgDisconnect        (void **domainId);
00154   int   cMsgSetShutdownHandler(void *domainId, cMsgShutdownHandler *handler, void *userArg);
00155   int   cMsgShutdownClients   (void *domainId, const char *client, int flag);
00156   int   cMsgShutdownServers   (void *domainId, const char *server, int flag);
00157   char *cMsgPerror            (int errorCode);
00158   
00159   
00160   /* message access functions */
00161   int    cMsgFreeMessage          (void **vmsg);
00162   void  *cMsgCreateMessage        (void);
00163   void  *cMsgCreateNewMessage     (const void *vmsg);
00164   void  *cMsgCopyMessage          (const void *vmsg);
00165   int    cMsgInitMessage          (void *vmsg);
00166   void  *cMsgCreateResponseMessage(const void *vmsg);
00167   void  *cMsgCreateNullResponseMessage(const void *vmsg);
00168   int    cMsgWasSent              (const void *vmsg, int *hasBeenSent);
00169   
00170   int    cMsgGetVersion           (const void *vmsg, int *version);
00171   int    cMsgGetGetRequest        (const void *vmsg, int *getRequest);
00172   
00173   int    cMsgSetGetResponse       (      void *vmsg, int  getReponse);
00174   int    cMsgGetGetResponse       (const void *vmsg, int *getReponse);
00175   
00176   int    cMsgSetNullGetResponse   (      void *vmsg, int  nullGetResponse);
00177   int    cMsgGetNullGetResponse   (const void *vmsg, int *nullGetResponse);
00178     
00179   int    cMsgGetDomain            (const void *vmsg, const char **domain);
00180   
00181   int    cMsgSetSubject           (      void *vmsg, const char  *subject);
00182   int    cMsgGetSubject           (const void *vmsg, const char **subject);
00183   
00184   int    cMsgSetType              (      void *vmsg, const char  *type);
00185   int    cMsgGetType              (const void *vmsg, const char **type);
00186   
00187   int    cMsgSetText              (      void *vmsg, const char  *text);
00188   int    cMsgGetText              (const void *vmsg, const char **text);
00189   
00190   int    cMsgSetUserInt           (      void *vmsg, int  userInt);
00191   int    cMsgGetUserInt           (const void *vmsg, int *userInt);
00192   
00193   int    cMsgSetUserTime          (      void *vmsg, const struct timespec *userTime);
00194   int    cMsgGetUserTime          (const void *vmsg, struct timespec *userTime);
00195   
00196   int    cMsgGetSender            (const void *vmsg, const char  **sender);
00197   int    cMsgGetSenderHost        (const void *vmsg, const char  **senderHost);
00198   int    cMsgGetSenderTime        (const void *vmsg, struct timespec *senderTime);
00199   
00200   int    cMsgGetReceiver          (const void *vmsg, const char  **receiver);
00201   int    cMsgGetReceiverHost      (const void *vmsg, const char  **receiverHost);
00202   int    cMsgGetReceiverTime      (const void *vmsg, struct timespec *receiverTime);
00203   
00204   int    cMsgSetByteArrayLength   (      void *vmsg, int  length);
00205   int    cMsgGetByteArrayLength   (const void *vmsg, int *length);
00206   
00207   int    cMsgSetByteArrayOffset   (      void *vmsg, int  offset);
00208   int    cMsgGetByteArrayOffset   (const void *vmsg, int *offset);
00209   
00210   int    cMsgSetByteArrayEndian   (      void *vmsg, int endian);
00211   int    cMsgGetByteArrayEndian   (const void *vmsg, int *endian);
00212   int    cMsgNeedToSwap           (const void *vmsg, int *swap);
00213   
00214   int    cMsgSetByteArray         (      void *vmsg, char  *array);
00215   int    cMsgGetByteArray         (const void *vmsg, char **array);
00216   
00217   int    cMsgSetByteArrayAndLimits(      void *vmsg, char *array, int offset, int length);
00218   int    cMsgCopyByteArray        (      void *vmsg, char *array, int offset, int length);
00219   /* message context stuff */
00220   int    cMsgGetSubscriptionDomain (const void *vmsg, const char **domain);
00221   int    cMsgGetSubscriptionSubject(const void *vmsg, const char **subject);
00222   int    cMsgGetSubscriptionType   (const void *vmsg, const char **type);
00223   int    cMsgGetSubscriptionUDL    (const void *vmsg, const char **udl);
00224   int    cMsgGetSubscriptionCueSize(const void *vmsg, int   *size);
00225   int    cMsgSetReliableSend       (      void *vmsg, int boolean);
00226   int    cMsgGetReliableSend       (      void *vmsg, int *boolean);
00227   /*  misc. */
00228   int    cMsgToString              (      void *vmsg, char **string, int binary);
00229   
00230   /* ***************************************** */
00231   /* compound payload stuff - 65 user routines */
00232   /* ***************************************** */
00233   int    cMsgAddSenderToHistory      (void *vmsg, char *name);
00234   
00235   int    cMsgPayloadGet              (const void *vmsg, char **names,  int *types,  int len);
00236   int    cMsgPayloadGetInfo          (const void *vmsg, char ***names, int **types, int *len);
00237   int    cMsgPayloadGetCount         (const void *vmsg, int *count);
00238   int    cMsgPayloadContainsName     (const void *vmsg, const char *name);
00239   int    cMsgPayloadGetType          (const void *vmsg, const char *name, int *type);
00240   int    cMsgPayloadRemove           (      void *vmsg, const char *name);
00241   int    cMsgPayloadCopy             (const void *vmsgFrom, void *vmsgTo);
00242 
00243   int    cMsgPayloadUpdateText       (const void *vmsg);
00244   int    cMsgPayloadGetFieldText     (const void *vmsg, const char *name, const char **val);
00245   void   cMsgPayloadPrint            (const void *vmsg);
00246   
00247 const char *cMsgPayloadFieldDescription(const void *vmsg, const char *name);
00248   
00249   /* users should NOT have access to these 3 routines */
00250   int    cMsgPayloadSetFromText             (      void *vmsg, const char *text);
00251   int    cMsgPayloadSetSystemFieldsFromText (      void *vmsg, const char *text);
00252   int    cMsgPayloadSetAllFieldsFromText    (void *vmsg, const char *text);
00253 
00254   void   cMsgPayloadWipeout          (      void *vmsg);
00255   void   cMsgPayloadClear            (      void *vmsg);
00256   int    cMsgHasPayload              (const void *vmsg, int *hasPayload);
00257  
00258   int    cMsgGetBinary               (const void *vmsg, const char *name, const char **val, int *len, int *endian);
00259 
00260   int    cMsgGetMessage              (const void *vmsg, const char *name, const void **val);
00261   int    cMsgGetMessageArray         (const void *vmsg, const char *name, const void ***val, int *len);
00262   
00263   int    cMsgGetString               (const void *vmsg, const char *name, const char **val);
00264   int    cMsgGetStringArray          (const void *vmsg, const char *name, const char ***array, int *len);
00265   
00266   int    cMsgGetFloat                (const void *vmsg, const char *name, float  *val);
00267   int    cMsgGetFloatArray           (const void *vmsg, const char *name, const float  **vals, int *len);
00268   int    cMsgGetDouble               (const void *vmsg, const char *name, double *val);
00269   int    cMsgGetDoubleArray          (const void *vmsg, const char *name, const double **vals, int *len);
00270   
00271   int    cMsgGetInt8                 (const void *vmsg, const char *name, int8_t   *val);
00272   int    cMsgGetInt16                (const void *vmsg, const char *name, int16_t  *val);
00273   int    cMsgGetInt32                (const void *vmsg, const char *name, int32_t  *val);
00274   int    cMsgGetInt64                (const void *vmsg, const char *name, int64_t  *val);
00275   int    cMsgGetUint8                (const void *vmsg, const char *name, uint8_t  *val);
00276   int    cMsgGetUint16               (const void *vmsg, const char *name, uint16_t *val);
00277   int    cMsgGetUint32               (const void *vmsg, const char *name, uint32_t *val);
00278   int    cMsgGetUint64               (const void *vmsg, const char *name, uint64_t *val);
00279   
00280   int    cMsgGetInt8Array            (const void *vmsg, const char *name, const int8_t   **vals, int *len);
00281   int    cMsgGetInt16Array           (const void *vmsg, const char *name, const int16_t  **vals, int *len);
00282   int    cMsgGetInt32Array           (const void *vmsg, const char *name, const int32_t  **vals, int *len);
00283   int    cMsgGetInt64Array           (const void *vmsg, const char *name, const int64_t  **vals, int *len);
00284   int    cMsgGetUint8Array           (const void *vmsg, const char *name, const uint8_t  **vals, int *len);
00285   int    cMsgGetUint16Array          (const void *vmsg, const char *name, const uint16_t **vals, int *len);
00286   int    cMsgGetUint32Array          (const void *vmsg, const char *name, const uint32_t **vals, int *len);
00287   int    cMsgGetUint64Array          (const void *vmsg, const char *name, const uint64_t **vals, int *len);
00288 
00289   int    cMsgAddInt8                 (      void *vmsg, const char *name, int8_t   val);
00290   int    cMsgAddInt16                (      void *vmsg, const char *name, int16_t  val);
00291   int    cMsgAddInt32                (      void *vmsg, const char *name, int32_t  val);
00292   int    cMsgAddInt64                (      void *vmsg, const char *name, int64_t  val);
00293   int    cMsgAddUint8                (      void *vmsg, const char *name, uint8_t  val);
00294   int    cMsgAddUint16               (      void *vmsg, const char *name, uint16_t val);
00295   int    cMsgAddUint32               (      void *vmsg, const char *name, uint32_t val);
00296   int    cMsgAddUint64               (      void *vmsg, const char *name, uint64_t val);
00297 
00298   int    cMsgAddInt8Array            (      void *vmsg, const char *name, const int8_t   vals[], int len);
00299   int    cMsgAddInt16Array           (      void *vmsg, const char *name, const int16_t  vals[], int len);
00300   int    cMsgAddInt32Array           (      void *vmsg, const char *name, const int32_t  vals[], int len);
00301   int    cMsgAddInt64Array           (      void *vmsg, const char *name, const int64_t  vals[], int len);
00302   int    cMsgAddUint8Array           (      void *vmsg, const char *name, const uint8_t  vals[], int len);
00303   int    cMsgAddUint16Array          (      void *vmsg, const char *name, const uint16_t vals[], int len);
00304   int    cMsgAddUint32Array          (      void *vmsg, const char *name, const uint32_t vals[], int len);
00305   int    cMsgAddUint64Array          (      void *vmsg, const char *name, const uint64_t vals[], int len);
00306 
00307   int    cMsgAddString               (      void *vmsg, const char *name, const char *val);
00308   int    cMsgAddStringArray          (      void *vmsg, const char *name, const char **vals, int len);
00309 
00310   int    cMsgAddFloat                (      void *vmsg, const char *name, float  val);
00311   int    cMsgAddDouble               (      void *vmsg, const char *name, double val);
00312   int    cMsgAddFloatArray           (      void *vmsg, const char *name, const float vals[],  int len);
00313   int    cMsgAddDoubleArray          (      void *vmsg, const char *name, const double vals[], int len);
00314 
00315   int    cMsgAddBinary               (      void *vmsg, const char *name, const char *src, int size, int endian);
00316   int    cMsgAddMessage              (      void *vmsg, const char *name, const void *vmessage);
00317   int    cMsgAddMessageArray         (      void *vmsg, const char *name, const void *vmessage[], int len);
00318 
00319   char   *cMsgFloatChars(float f);
00320   char   *cMsgDoubleChars(double d);
00321 
00322 
00323   /* system and domain info access functions */
00324   int cMsgGetUDL         (void *domainId, char **udl);
00325   int cMsgGetName        (void *domainId, char **name);
00326   int cMsgGetDescription (void *domainId, char **description);
00327   int cMsgGetConnectState(void *domainId,  int *connectState);
00328   int cMsgGetReceiveState(void *domainId,  int *receiveState);
00329 
00330   
00331   /* subscribe configuration functions */
00332   cMsgSubscribeConfig *cMsgSubscribeConfigCreate(void);
00333   int cMsgSubscribeConfigDestroy       (cMsgSubscribeConfig *config);
00334   
00335   int cMsgSubscribeSetMaxCueSize       (cMsgSubscribeConfig *config, int  size);
00336   int cMsgSubscribeGetMaxCueSize       (cMsgSubscribeConfig *config, int *size);
00337   
00338   int cMsgSubscribeSetSkipSize         (cMsgSubscribeConfig *config, int  size);
00339   int cMsgSubscribeGetSkipSize         (cMsgSubscribeConfig *config, int *size);
00340   
00341   int cMsgSubscribeSetMaySkip          (cMsgSubscribeConfig *config, int  maySkip);
00342   int cMsgSubscribeGetMaySkip          (cMsgSubscribeConfig *config, int *maySkip);
00343   
00344   int cMsgSubscribeSetMustSerialize    (cMsgSubscribeConfig *config, int  serialize);
00345   int cMsgSubscribeGetMustSerialize    (cMsgSubscribeConfig *config, int *serialize);
00346   
00347   int cMsgSubscribeSetMaxThreads       (cMsgSubscribeConfig *config, int  threads);
00348   int cMsgSubscribeGetMaxThreads       (cMsgSubscribeConfig *config, int *threads);
00349   
00350   int cMsgSubscribeSetMessagesPerThread(cMsgSubscribeConfig *config, int  mpt);
00351   int cMsgSubscribeGetMessagesPerThread(cMsgSubscribeConfig *config, int *mpt);
00352 
00353   int cMsgSubscribeSetStackSize        (cMsgSubscribeConfig *config, size_t size);
00354   int cMsgSubscribeGetStackSize        (cMsgSubscribeConfig *config, size_t *size);
00355 
00356 
00357   /* for debugging */
00358   int cMsgSetDebugLevel(int level);
00359 
00360 
00361 #ifdef __cplusplus
00362 }
00363 #endif
00364 
00365 
00366 #endif /* _cMsg_h */

Generated on Wed Feb 6 13:37:49 2008 for cMsg Messaging System by  doxygen 1.3.9.1