void x_ipc_msgInfoMsgInitialize(void) { int32 refId; MSG_DATA_PTR msgData; LOCK_CM_MUTEX; LOCK_IO_MUTEX; if (x_ipc_readNBytes(GET_C_GLOBAL(serverRead), (char *)&refId, sizeof(int32)) != StatOK) { GET_C_GLOBAL(serverRead) = NO_SERVER_GLOBAL; GET_C_GLOBAL(serverWrite) = NO_SERVER_GLOBAL; X_IPC_MOD_ERROR("ERROR: Socket connection broken or access denied to central server\n"); UNLOCK_IO_MUTEX; UNLOCK_CM_MUTEX; return; } NET_INT_TO_INT(refId); msgData = NEW(MSG_DATA_TYPE); msgData->refId = refId; msgData->name = strdup(X_IPC_MSG_INFO_QUERY); msgData->msg_class = QueryClass; msgData->msgFormat = (FORMAT_PTR)x_ipc_formatterRecv(GET_C_GLOBAL(serverRead)); msgData->resFormat = (FORMAT_PTR)x_ipc_formatterRecv(GET_C_GLOBAL(serverRead)); UNLOCK_IO_MUTEX; UNLOCK_CM_MUTEX; (void)x_ipc_msgCreate(msgData); }
/****************************************************************************** * * FUNCTION: void x_ipc_globalMInvalidate(void) * * DESCRIPTION: * Indicate that the module data structures are invalid and need to be * reinitialized. This is used when the server goes down. * *****************************************************************************/ void x_ipc_globalMInvalidate(void) { if (mGlobalp()) { LOCK_CM_MUTEX; GET_C_GLOBAL(serverRead) = NO_SERVER_GLOBAL; GET_C_GLOBAL(serverWrite) = NO_SERVER_GLOBAL; GET_C_GLOBAL(valid) = FALSE; UNLOCK_CM_MUTEX; } }
int32 x_ipc_nextSendMessageRef(void) { int32 result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(sendMessageRefGlobal); GET_C_GLOBAL(sendMessageRefGlobal)++; UNLOCK_CM_MUTEX; return result; }
void x_ipc_hndDelete(HND_PTR hnd) { HND_KEY_TYPE hndKey; LIST_PTR msgList; LIST_ELEM_PTR listTmp; MODULE_PTR module; MSG_PTR msg; if (hnd) { if (hnd->hndLanguage == UNKNOWN_LANGUAGE) return; hnd->hndLanguage = UNKNOWN_LANGUAGE; hnd->msg = NULL; msgList = hnd->msgList; hnd->msgList = NULL; /* to revent recursion of free's */ x_ipc_listTestDeleteItemAll((LIST_ITER_FN) x_ipc_removeHndFromMsg, (char *)hnd, msgList); x_ipc_listFree(&msgList); LOCK_CM_MUTEX; (void)x_ipc_idTableRemove(hnd->localId, GET_C_GLOBAL(hndIdTable)); /* Need to remove from the module list. */ if (GET_M_GLOBAL(moduleList) != NULL) { for (listTmp = GET_M_GLOBAL(moduleList)->first; (listTmp != NULL); listTmp = listTmp->next ) { module = (MODULE_PTR)(listTmp->item); x_ipc_listDeleteItemAll(hnd,module->hndList); } } if (hnd->hndData) { hndKey.num = hnd->sd; hndKey.str = hnd->hndData->hndName; x_ipc_hashTableRemove((char *)&hndKey, GET_C_GLOBAL(handlerTable)); msg = GET_MESSAGE(hnd->hndData->msgName); if (msg) x_ipc_removeHndFromMsg(hnd, msg); x_ipcFree((char *)hnd->hndData->msgName); hnd->hndData->msgName = NULL; x_ipcFree((char *)hnd->hndData->hndName); hnd->hndData->hndName = NULL; x_ipcFree((char *)hnd->hndData); hnd->hndData = NULL; } UNLOCK_CM_MUTEX; hnd->hndData = NULL; x_ipcFree((char *)hnd); } }
X_IPC_RETURN_VALUE_TYPE centralBroadcast(const char *name, const void *data) { MSG_PTR msg; msg = x_ipc_msgFind(name); if (msg == NULL) return MsgUndefined; x_ipc_checkMessageClass(msg, BroadcastClass); if ((GET_C_GLOBAL(broadcastMsgs) == NULL) || (x_ipc_strListMemberItem(name, GET_C_GLOBAL(broadcastMsgs)))) return centralSendMessage((X_IPC_REF_PTR)NULL, msg, (char *)data, (char *)NULL); else return Success; }
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 { if (!GET_C_GLOBAL(willListen)) X_IPC_MOD_WARNING1("WARNING: Subscribing to %s, " "but have connected no-listen\n", msgName); x_ipcRegisterHandler(msgName, hndName, (X_IPC_HND_FN)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 && hnd->clientData != clientData) { X_IPC_MOD_WARNING1("Resetting client data for handler %s\n", hndName); } hnd->isRegistered = TRUE; hnd->clientData = clientData; return IPC_OK; } }
static void x_ipc_tappedMsgVarHnd(X_IPC_REF_PTR Ref, STR_LIST_PTR tapped) { #ifdef UNUSED_PRAGMA #pragma unused(Ref) #endif MSG_PTR msg; LOCK_CM_MUTEX; x_ipc_strListFree(&GET_C_GLOBAL(tappedMsgs),TRUE); GET_C_GLOBAL(tappedMsgs) = tapped; STR_LIST_ITERATE(tapped, string, { LOCK_CM_MUTEX; msg = GET_MESSAGE(string); UNLOCK_CM_MUTEX; if (msg != NULL) { msg->direct = FALSE; }});
IPC_RETURN_TYPE IPC_subscribeFD (int fd, FD_HANDLER_TYPE handler, void *clientData) { if (!GET_C_GLOBAL(willListen)) X_IPC_MOD_WARNING1("WARNING: Subscribing to port %d, " "but have connected no-listen\n", fd); x_ipcAddEventHandler(fd, (X_IPC_FD_HND_FN)handler, clientData); return IPC_OK; }
/****************************************************************************** * * FUNCTION: int x_ipcGetMaxConnection(void) * * DESCRIPTION: * Returns the largest connection number ever used. * *****************************************************************************/ int x_ipcGetMaxConnection(void) { int result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(maxConnection); UNLOCK_CM_MUTEX; return result; }
/****************************************************************************** * * FUNCTION: int x_ipcGetConnections(void) * * DESCRIPTION: * Returns set file descriptors open for accepting new connections. * *****************************************************************************/ fd_set *x_ipcGetAcceptFds(void) { fd_set * result; LOCK_CM_MUTEX; result = &GET_C_GLOBAL(x_ipcListenMaskGlobal); UNLOCK_CM_MUTEX; return result; }
/****************************************************************************** * * FUNCTION: int x_ipcGetConnections(void) * * DESCRIPTION: * Returns set of open file descriptors. * *****************************************************************************/ fd_set *x_ipcGetConnections(void) { fd_set * result; LOCK_CM_MUTEX; result = &GET_C_GLOBAL(x_ipcConnectionListGlobal); UNLOCK_CM_MUTEX; return result; }
int execHndState_tmpResponse(void) { int result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).tmpResponse; UNLOCK_CM_MUTEX; return result; }
X_IPC_REF_PTR execHndState_x_ipcRef(void) { X_IPC_REF_PTR result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).x_ipcRef; UNLOCK_CM_MUTEX; return result; }
void *execHndState_clientData(void) { void *result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).clientData; UNLOCK_CM_MUTEX; return result; }
EXECHND_STATE_ENUM execHndState_state(void) { EXECHND_STATE_ENUM result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).state; UNLOCK_CM_MUTEX; return result; }
MSG_PTR execHndState_msg(void) { MSG_PTR result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).msg; UNLOCK_CM_MUTEX; return result; }
CONNECTION_PTR execHndState_connection(void) { void *result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).clientData; UNLOCK_CM_MUTEX; return result; }
int execHndState_tmpParentRef(void) { int result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).tmpParentRef; UNLOCK_CM_MUTEX; return result; }
const char *execHndState_hndName(void) { const char *result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(execHndState).hndName; UNLOCK_CM_MUTEX; return result; }
void *x_ipcReferenceData(X_IPC_REF_PTR ref) { int32 refId, sd; MSG_PTR msg; char *msgData; X_IPC_REF_PTR waitRef; X_IPC_RETURN_VALUE_TYPE returnValue; msg = x_ipc_msgFind(X_IPC_REF_DATA_QUERY); if (msg == NULL) return NULL; if (!ref->msg) { if (!ref->name) { /* 17-Jun-91: fedor: start enforcing correct refs */ X_IPC_MOD_ERROR1("ERROR: x_ipcReferenceData: Badly Formed Reference: %d\n", ref->refId); return NULL; } ref->msg = x_ipc_msgFind(ref->name); if (ref->msg == NULL) return NULL; } /* 17-Jun-91: fedor: check if any message form */ if (!ref->msg->msgData->msgFormat) return NULL; refId = x_ipc_nextSendMessageRef(); returnValue = x_ipc_sendMessage((X_IPC_REF_PTR)NULL, msg, (char *)&ref->refId, (char *)NULL, refId); if (returnValue != Success) { X_IPC_MOD_ERROR("ERROR: x_ipcReferenceData: x_ipc_sendMessage Failed.\n"); return NULL; } waitRef = x_ipcRefCreate(ref->msg, ref->name, refId); msgData = (char *)x_ipcMalloc((unsigned)x_ipc_dataStructureSize(ref->msg->msgData->msgFormat)); LOCK_CM_MUTEX; sd = GET_C_GLOBAL(serverRead); UNLOCK_CM_MUTEX; returnValue = x_ipc_waitForReplyFrom(waitRef, msgData, TRUE, WAITFOREVER, sd); x_ipcRefFree(waitRef); if (returnValue == NullReply) { /* 17-Jun-91: fedor: if NullReply then nothing else was malloced. */ x_ipcFree(msgData); return NULL; } else return msgData; }
/****************************************************************************** * * FUNCTION: int32 x_ipcGetServer(void) * * DESCRIPTION: * Returns the connection number for connection to central, or -1. * *****************************************************************************/ int x_ipcGetServer(void) { if (mGlobalp()) { int result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(serverRead); UNLOCK_CM_MUTEX; return result; } else return -1; }
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; } }
/****************************************************************************** * * FUNCTION: BOOLEAN x_ipc_isValidServerConnection(void) * * DESCRIPTION: * Returns TRUE if the connection to the server is valid. * *****************************************************************************/ BOOLEAN x_ipc_isValidServerConnection(void) { if (!mGlobalp()) { return FALSE; } else { BOOLEAN result; LOCK_CM_MUTEX; result = GET_C_GLOBAL(serverWrite) != NO_SERVER_GLOBAL; UNLOCK_CM_MUTEX; return result; } }
static FORMAT_PTR Named_Format(Format_Parse_Ptr parser, TokenPtr Token) { NAMED_FORMAT_PTR namedFormat; FORMAT_PTR format; if (parser->formatStack == NULL) { parser->formatStack = x_ipc_strListCreate(); } if (x_ipc_strListMemberItem(Token->value.str, parser->formatStack)) { /* found a recursive definition. just return pointer */ return new_n_formatter(Token->value.str); } x_ipc_strListPush(strdup(Token->value.str), parser->formatStack); LOCK_M_MUTEX; namedFormat = (NAMED_FORMAT_PTR)x_ipc_hashTableFind(Token->value.str, GET_M_GLOBAL(formatNamesTable)); UNLOCK_M_MUTEX; if (!namedFormat) { #ifdef NMP_IPC if (GET_C_GLOBAL(serverRead) != CENTRAL_SERVER_ID) { if (x_ipcQueryCentral(X_IPC_NAMED_FORM_QUERY, &Token->value.str, &format) != Success || !format) { X_IPC_MOD_WARNING2("Warning: Named Format %s is not registered\n%s\n", Token->value.str, parser->ParseString); format = new_f_formatter(BadFormatFMT, NULL); } } else #endif { X_IPC_MOD_WARNING2("Warning: Named Format %s is not registered\n%s\n", Token->value.str, parser->ParseString); format = new_f_formatter(BadFormatFMT, NULL); } } else { /* Need to use the named formatter -- parse it now */ if (!namedFormat->parsed) { namedFormat->format = (FORMAT_PTR)ParseFormatString(namedFormat->definition); namedFormat->parsed = TRUE; } format = copyFormatter(namedFormat->format); } x_ipcFree((void *)x_ipc_strListPopItem(parser->formatStack)); return format; }
X_IPC_RETURN_VALUE_TYPE centralSendResponse(DISPATCH_PTR dispatch, MSG_PTR msg, void *resData, X_IPC_MSG_CLASS_TYPE resClass, void *resClassData, int sd) { #ifdef UNUSED_PRAGMA #pragma unused(resClassData, sd) #endif int32 intent; DATA_MSG_PTR dataMsg; if (msg) { intent = msg->msgData->refId; } else { intent = -1; if (dispatch) { if (!dispatch->msg) dispatch->msg = x_ipc_msgFind(dispatch->msg->msgData->name); msg = dispatch->msg; } } dataMsg = x_ipc_dataMsgCreate(GET_C_GLOBAL(parentRefGlobal), intent, (int32)resClass, 0, 0, dispatch->msg->msgData->resFormat, resData, (FORMAT_PTR)NULL, (char *)NULL); if (dataMsg == NULL) return Failure; /* RTG - must set datastruct to be null so message does not get decoded * into the same memory location. We also have to copy the message * buffer if it is the same as the original data structure because * the original data structure can change, if the message is queued. */ if (dataMsg->msgData == resData) { /* Need to copy the data, in case the messages gets queued. */ char *newCopy = NULL; newCopy = (char *)x_ipcMalloc(dataMsg->msgTotal); BCOPY(dataMsg->msgData, newCopy,dataMsg->msgTotal); dataMsg->msgData = newCopy; dataMsg->dataStruct = NULL; } else dataMsg->dataStruct = NULL; recvMessageBuild(GET_S_GLOBAL(x_ipcServerModGlobal), dataMsg); x_ipc_dataMsgFree(dataMsg); return Success; }
void x_ipcRefFree(X_IPC_REF_PTR x_ipcRef) { if (x_ipcRef) { x_ipcRef->refId = 0; x_ipcRef->msg = NULL; x_ipcFree((char *)x_ipcRef->name); x_ipcRef->name = NULL; LOCK_CM_MUTEX; x_ipc_listInsertItemFirst((char *)x_ipcRef, GET_C_GLOBAL(x_ipcRefFreeList)); UNLOCK_CM_MUTEX; } }
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; } }
X_IPC_REF_PTR x_ipcRefCreate(MSG_PTR msg, const char *name, int32 refId) { X_IPC_REF_PTR x_ipcRef; int32 length; LOCK_CM_MUTEX; if (!x_ipc_listLength(GET_C_GLOBAL(x_ipcRefFreeList))) x_ipcRef = NEW(X_IPC_REF_TYPE); else x_ipcRef = (X_IPC_REF_PTR)x_ipc_listPopItem(GET_C_GLOBAL(x_ipcRefFreeList)); UNLOCK_CM_MUTEX; x_ipcRef->refId = refId; x_ipcRef->msg = msg; if (!name) { x_ipcRef->name = NULL; } else { char *namePtr; length = strlen(name); namePtr = (char *)x_ipcMalloc((unsigned)(length+1)); BCOPY(name, namePtr, length); namePtr[length] = '\0'; x_ipcRef->name = namePtr; } x_ipcRef->responseSd = NO_FD; #ifdef NMP_IPC x_ipcRef->responded = FALSE; x_ipcRef->dataLength = 0; #endif x_ipcRef->encoding.byteOrder = GET_M_GLOBAL(byteOrder); x_ipcRef->encoding.alignment = GET_M_GLOBAL(alignment); return x_ipcRef; }
void x_ipcRegisterResource(const char *resName, int32 capacity) { ADD_RES_FORM_TYPE addResForm; addResForm.capacity = capacity; addResForm.resName = resName; (void)x_ipcInform(X_IPC_REGISTER_RESOURCE_INFORM, (void *)&addResForm); LOCK_CM_MUTEX; if(GET_C_GLOBAL(directDefault)) { /* Make the default module direct. */ x_ipcDirectResource(resName); } UNLOCK_CM_MUTEX; }
static void ipcDisconnectHandler (MSG_INSTANCE ref, char **moduleNamePtr) { CONNECT_DATA_PTR disconnectData; LIST_PTR list; LOCK_CM_MUTEX; list = GET_C_GLOBAL(disconnectNotifyList); UNLOCK_CM_MUTEX; for (disconnectData = (CONNECT_DATA_PTR)x_ipc_listFirst(list); disconnectData; disconnectData = (CONNECT_DATA_PTR)x_ipc_listNext(list)) { (disconnectData->handler)(*moduleNamePtr, disconnectData->clientData); } x_ipcFreeData(IPC_msgInstanceName(ref), moduleNamePtr); /* ??? */ }