IPC_RETURN_TYPE IPC_queryNotify (const char *msgName, unsigned int length, BYTE_ARRAY content, HANDLER_TYPE handler, void *clientData) { MSG_PTR msg; void *queryData; IPC_VARCONTENT_TYPE vc; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_msgFind(msgName); if (msg == NULL) { RETURN_ERROR(IPC_Message_Not_Defined); } else if (ipcDataToSend(msg->msgData->msgFormat, msgName, length, content, &queryData, &vc) != IPC_OK) { PASS_ON_ERROR(); } else { return ipcReturnValue(x_ipc_queryNotifySend(msg, msgName, queryData, (REPLY_HANDLER_FN)handler, clientData)); } } }
IPC_RETURN_TYPE IPC_publish (const char *msgName, unsigned int length, BYTE_ARRAY content) { MSG_PTR msg; CONST_FORMAT_PTR format; void *dataToSend; IPC_VARCONTENT_TYPE vc; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_msgFind(msgName); if (!msg) { RETURN_ERROR(IPC_Message_Not_Defined); } else { format = msg->msgData->msgFormat; if (ipcDataToSend(format, msgName, length, content, &dataToSend, &vc) != IPC_OK) { PASS_ON_ERROR(); } else { return ipcReturnValue(x_ipcBroadcast(msgName, dataToSend)); } } } }
IPC_RETURN_TYPE _IPC_subscribe (const char *msgName, const char *hndName, HANDLER_TYPE handler, void *clientData, int autoUnmarshall) { HND_KEY_TYPE hndKey; HND_PTR hnd; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { x_ipcRegisterHandler(msgName, hndName, handler); /* Set the client data */ hndKey.num = 0; hndKey.str = hndName; LOCK_CM_MUTEX; hnd = GET_HANDLER(&hndKey); UNLOCK_CM_MUTEX; hnd->autoUnmarshall = autoUnmarshall; if (hnd->isRegistered && hnd->clientData != NO_CLIENT_DATA) { X_IPC_MOD_WARNING1("Resetting client data for handler %s\n", hndName); } hnd->isRegistered = TRUE; hnd->clientData = clientData; return IPC_OK; } }
IPC_RETURN_TYPE IPC_defineMsg (const char *msgName, unsigned int length, const char *formatString) { char msgFormat[20]; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } if (length != (unsigned int)IPC_VARIABLE_LENGTH && formatString != NULL && length != (unsigned int)x_ipc_dataStructureSize(ParseFormatString(formatString))) { RETURN_ERROR(IPC_Mismatched_Formatter); } else { if (length == IPC_VARIABLE_LENGTH) { sprintf(msgFormat, "{int, <byte:1>}"); } else if (length == 0) { msgFormat[0] = '\0'; } else { sprintf(msgFormat, "[byte:%d]", length); } x_ipcRegisterMessage(msgName, BroadcastClass, msgFormat, formatString); return IPC_OK; } }
IPC_RETURN_TYPE IPC_respond (MSG_INSTANCE msgInstance, const char *msgName, unsigned int length, BYTE_ARRAY content) { MSG_PTR msg; void *replyData; IPC_VARCONTENT_TYPE vc; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!msgInstance) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_msgFind(msgName); if (!msg) { RETURN_ERROR(IPC_Message_Not_Defined); } else if (ipcDataToSend(msg->msgData->msgFormat, msgName, length, content, &replyData, &vc) != IPC_OK) { PASS_ON_ERROR(); } else { return ipcReturnValue(x_ipc_sendResponse(msgInstance, msg, (char *)replyData, ReplyClass, NULL, msgInstance->responseSd)); } } }
IPC_RETURN_TYPE IPC_listen (unsigned int timeoutMSecs) { #ifndef IPC_ALLOW_DISCONNECTED_EVENT_HANDLING if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } #endif return ipcReturnValue(x_ipcHandleMessage(timeoutMSecs)); }
IPC_RETURN_TYPE _IPC_unsubscribe (const char *msgName, const char *hndName) { if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { x_ipcDeregisterHandler(msgName, hndName); return IPC_OK; } }
int IPC_isMsgDefined (const char *msgName) { if (!msgName || strlen(msgName) == 0) { ipcSetError(IPC_Null_Argument); return FALSE; } else if (!X_IPC_CONNECTED()) { ipcSetError(IPC_Not_Connected); return FALSE; } else { return x_ipcMessageRegistered(msgName); } }
int IPC_isModuleConnected (const char *moduleName) { if (!moduleName || strlen(moduleName) == 0) { ipcSetError(IPC_Null_Argument); return -1; } else if (!X_IPC_CONNECTED()) { ipcSetError(IPC_Not_Connected); return -1; } else { int retVal; x_ipcQuery(IPC_MODULE_CONNECTED_QUERY, &moduleName, &retVal); return retVal; } }
IPC_RETURN_TYPE IPC_unsubscribeHandlerChange (const char *msgName, CHANGE_HANDLE_TYPE handler) { if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { removeChange(msgName, handler); return IPC_OK; } }
IPC_RETURN_TYPE IPC_unsubscribeDisconnect (CONNECT_HANDLE_TYPE handler) { if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { LOCK_CM_MUTEX; removeConnect(GET_C_GLOBAL(disconnectNotifyList), IPC_DISCONNECT_NOTIFY_MSG, handler); UNLOCK_CM_MUTEX; return IPC_OK; } }
IPC_RETURN_TYPE IPC_setCapacity (int capacity) { if (capacity < 1) { RETURN_ERROR(IPC_Argument_Out_Of_Range); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { LOCK_M_MUTEX; x_ipcRegisterResource(GET_M_GLOBAL(modNameGlobal), capacity); UNLOCK_M_MUTEX; return IPC_OK; } }
/* TNgo, 5/22/97, added another variable to this function so that it can be called by IPC_connectModule */ IPC_RETURN_TYPE _IPC_connect (const char *taskName, const char *serverName, BOOLEAN willListen) { const char *serverHost; char *colon = NULL; int i, serverPort; struct timeval wait; /* Added by Bob Goode/Tam Ngo, 5/21/97, for WINSOCK option. */ #ifdef OS2 sock_init(); #elif defined(_WINSOCK_) startWinsock(); #endif /* Winsock DLL loading */ if (ipcVerbosity > IPC_Silent) { printf("NMP IPC Version %d.%d.%d (%s)\n", IPC_VERSION_MAJOR, IPC_VERSION_MINOR, IPC_VERSION_MICRO, IPC_VERSION_DATE); } /* Modified by TNgo, 5/22/97 */ serverHost = ((serverName != NULL && strlen(serverName) > 0) ? serverName : x_ipcServerMachine()); for (i=0; i<MAX_RECONNECT_TRIES; i++) { if (i > 0 && ipcVerbosity > IPC_Silent) printf(" Trying again %s to connect with the central server on %s\n", taskName, serverHost); IPC_initialize(); x_ipcWillListen(willListen); x_ipcConnectModule(taskName, serverHost); if (X_IPC_CONNECTED()) { x_ipcWaitUntilReady(); if (ipcVerbosity > IPC_Silent) { colon = (serverHost ? (char *)index((char *)serverHost, ':') : NULL); serverPort = (colon == NULL ? SERVER_PORT : atoi(colon+1)); X_IPC_MOD_WARNING1("... IPC Connected on port %d\n", serverPort); } return IPC_OK; } else { /* Need to do this, rather than sleep, because of SIGALRM's */ wait.tv_sec = RECONNECT_WAIT; wait.tv_usec = 0; select(0, 0, 0, 0, &wait); } } /* At this point, we've been unable to connect */ RETURN_ERROR(IPC_Not_Connected); }
IPC_RETURN_TYPE IPC_subscribeDisconnect (CONNECT_HANDLE_TYPE handler, void *clientData) { if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { LOCK_CM_MUTEX; insertConnect(&GET_C_GLOBAL(disconnectNotifyList), IPC_DISCONNECT_NOTIFY_MSG, (X_IPC_HND_FN)ipcDisconnectHandler, handler, clientData); UNLOCK_CM_MUTEX; return IPC_OK; } }
IPC_RETURN_TYPE IPC_setMsgQueueLength (const char *msgName, int queueLength) { MSG_PTR msg; if (queueLength < 1) { RETURN_ERROR(IPC_Argument_Out_Of_Range); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_findOrRegisterMessage(msgName); msg->limit = queueLength; LOCK_M_MUTEX; x_ipcLimitPendingMessages(msgName, GET_M_GLOBAL(modNameGlobal), queueLength); UNLOCK_M_MUTEX; return IPC_OK; } }
IPC_RETURN_TYPE IPC_subscribeHandlerChange (const char *msgName, CHANGE_HANDLE_TYPE handler, void *clientData) { MSG_PTR msg; if (!msgName || strlen(msgName) == 0) { RETURN_ERROR(IPC_Null_Argument); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_msgFind2(msgName, NULL); if (!msg) { RETURN_ERROR(IPC_Message_Not_Defined); } else { insertChange(msgName, handler, clientData); return IPC_OK; } } }
IPC_RETURN_TYPE IPC_setMsgPriority (const char *msgName, int priority) { SET_MSG_PRIORITY_TYPE setMsgData; MSG_PTR msg; if (priority < 0) { RETURN_ERROR(IPC_Argument_Out_Of_Range); } else if (!X_IPC_CONNECTED()) { RETURN_ERROR(IPC_Not_Connected); } else { msg = x_ipc_findOrRegisterMessage(msgName); msg->priority = priority; setMsgData.msgName = (char*)msgName; setMsgData.priority = priority; return ipcReturnValue(x_ipcInform(IPC_SET_MSG_PRIORITY_INFORM, &setMsgData)); } }
int IPC_numHandlers (const char *msgName) { DIRECT_MSG_TYPE directInfo; X_IPC_RETURN_VALUE_TYPE status; int num; if (!msgName || strlen(msgName) == 0) { ipcSetError(IPC_Null_Argument); return -1; } else if (!X_IPC_CONNECTED()) { ipcSetError(IPC_Not_Connected); return -1; } else { status = x_ipcQueryCentral(X_IPC_DIRECT_MSG_QUERY, (void *)&msgName, (void *)&directInfo); if (status == Success) { num = directInfo.numHandlers; x_ipcFreeReply(X_IPC_DIRECT_MSG_QUERY, &directInfo); } else { num = 0; } return num; } }
/* Returns TRUE (1) if the module is currently connected to the IPC server */ int IPC_isConnected (void) { return X_IPC_CONNECTED(); }