00001 /*---------------------------------------------------------------------------- 00002 Name: CallbackServerUnparsed.h 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Include this header in your client code if you want to establish 00006 a client side callback server. 00007 We will call the update() method when messages arrive. 00008 The received message key and QoS is not parsed, we need another 00009 layer doing XML parsing with expat. 00010 This library is thread safe, multiple client callback servers may 00011 be established in parallel. 00012 Author: "Marcel Ruff" <xmlBlaster@marcelruff.info> 00013 Date: 05/2003 00014 See: http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.html 00015 -----------------------------------------------------------------------------*/ 00016 #ifndef XMLBLASTER_CallbackServerUnparsed_H 00017 #define XMLBLASTER_CallbackServerUnparsed_H 00018 00019 #ifdef __cplusplus 00020 #ifndef XMLBLASTER_C_COMPILE_AS_CPP /* 'g++ -DXMLBLASTER_C_COMPILE_AS_CPP ...' allows to compile the lib as C++ code */ 00021 extern "C" { 00022 #endif 00023 #endif 00024 00025 #include <util/msgUtil.h> 00026 #include <util/Properties.h> 00027 #include "socket/xmlBlasterSocket.h" 00028 00029 #define DEFAULT_CALLBACK_SERVER_PORT 7611 00030 00031 /* Forward declarations */ 00032 struct SocketDataHolder; 00033 struct CallbackServerUnparsedStruct; 00034 typedef struct CallbackServerUnparsedStruct CallbackServerUnparsed; 00035 00036 /* Define function pointers */ 00037 00048 typedef bool (* UseThisSocket)(CallbackServerUnparsed *cb, int socketToUse, int socketToUseUdp); 00049 00050 typedef int (* InitCallbackServer)(CallbackServerUnparsed *cb); 00051 00055 typedef bool (* IsListening)(CallbackServerUnparsed *cb); 00056 00073 typedef void (*UpdateCbFp)(MsgUnitArr *msg, void *userData, XmlBlasterException *xmlBlasterException, void/*SocketDataHolder*/ *socketDataHolder); 00074 00075 typedef void (* ShutdownCallbackServerRaw)(CallbackServerUnparsed *cb); 00076 00077 typedef void ( * CallbackServerUnparsedSendResponse)(CallbackServerUnparsed *cb, void/*SocketDataHolder*/ *socketDataHolder, MsgUnitArr *msgUnitArr); 00078 typedef void ( * CallbackServerUnparsedSendXmlBlasterException)(CallbackServerUnparsed *cb, void/*SocketDataHolder*/ *socketDataHolder, XmlBlasterException *exception); 00079 typedef void ( * CallbackServerUnparsedDoRespond)(bool success, CallbackServerUnparsed *cb, void/*SocketDataHolder*/ *socketDataHolder, MsgUnitArr *msgUnitArrP, XmlBlasterException *exception); 00080 00081 #define MAX_RESPONSE_LISTENER_SIZE 100 00082 00083 typedef void (* ResponseFp)(MsgRequestInfo *msgRequestInfoP, void /*SocketDataHolder*/ *socketDataHolder); /* using void * to avoid including the socket specific header */ 00084 00085 typedef struct ResponseListenerStruct { 00086 MsgRequestInfo *msgRequestInfoP; 00087 /*void *userP; 00088 const char *requestId;*/ 00089 ResponseFp responseEventFp; 00090 } ResponseListener; 00091 00092 typedef bool ( * AddResponseListener)(CallbackServerUnparsed *cb, MsgRequestInfo *msgRequestInfoP, ResponseFp responseEventFp); 00093 typedef ResponseListener * ( * RemoveResponseListener)(CallbackServerUnparsed *cb, const char *requestId); 00094 00095 typedef void ( * CallbackServerUnparsedLogging)(void *logUserP, XMLBLASTER_LOG_LEVEL currLevel, XMLBLASTER_LOG_LEVEL level, const char *location, const char *fmt, ...); 00096 00107 struct CallbackServerUnparsedStruct { 00108 Properties *props; 00109 bool stopListenLoop; 00110 int listenSocket; 00111 int acceptSocket; 00112 int socketUdp; 00113 char * hostCB; 00114 int portCB; 00115 bool reusingConnectionSocket; 00116 XMLBLASTER_LOG_LEVEL logLevel; 00117 CallbackServerUnparsedLogging log; 00118 void *logUserP; 00119 /* 00120 * Is created by the client and used to validate callback messages in update. 00121 * This is sent on connect in ConnectQos. 00122 * (Is different from the xmlBlaster secret session ID) 00123 char secretSessionId[MAX_SECRETSESSIONID_LEN]; 00124 */ 00125 InitCallbackServer runCallbackServer; 00126 IsListening isListening; 00127 ShutdownCallbackServerRaw shutdown; 00128 UpdateCbFp updateCb; 00129 void *updateCbUserData; 00130 UseThisSocket useThisSocket; 00131 ResponseListener responseListener[MAX_RESPONSE_LISTENER_SIZE]; 00132 AddResponseListener addResponseListener; 00133 RemoveResponseListener removeResponseListener; 00134 bool isShutdown; 00135 CallbackServerUnparsedSendResponse sendResponse; 00136 CallbackServerUnparsedSendXmlBlasterException sendXmlBlasterException; 00137 CallbackServerUnparsedDoRespond sendResponseOrException; 00138 pthread_mutex_t listenMutex; 00139 00140 /* Socket write access: */ 00141 XmlBlasterWriteToSocketFuncHolder writeToSocket; 00144 /* Socket read access: */ 00145 XmlBlasterReadFromSocketFuncHolder readFromSocket; 00146 }; 00147 00151 typedef struct ListenLoopArgsStruct { 00152 CallbackServerUnparsed* cb; 00153 bool udp; 00154 } ListenLoopArgs; 00155 00169 extern CallbackServerUnparsed *getCallbackServerUnparsed(int argc, const char* const* argv, 00170 UpdateCbFp updateCb, void *userData); 00171 00176 extern void freeCallbackServerUnparsed(CallbackServerUnparsed **callbackData); 00177 00181 extern const char *callbackServerRawUsage(); 00182 00187 typedef void * (*cbFp)(void *); 00188 00189 00190 #ifdef __cplusplus 00191 #ifndef XMLBLASTER_C_COMPILE_AS_CPP 00192 } 00193 #endif 00194 #endif 00195 00196 #endif /* XMLBLASTER_CallbackServerUnparsed_H */ 00197