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; } }
void _x_ipcWatchVar(const char *varName, const char *format, X_IPC_HND_FN watchFn) { #ifdef UNUSED_PRAGMA #pragma unused(format) #endif char *watchMsgName; watchMsgName = (char *)x_ipcMalloc(1+strlen(varName)+strlen(VAR_WATCH_PREFIX)); strcpy(watchMsgName,VAR_WATCH_PREFIX); strcat(watchMsgName,varName); /* Check to see if already registered */ LOCK_CM_MUTEX; HND_KEY_TYPE hndKey; hndKey.num = 0; hndKey.str = watchMsgName; HND_PTR watchMsgHnd = GET_HANDLER(&hndKey); UNLOCK_CM_MUTEX; if (watchMsgHnd == NULL || watchMsgHnd->msg == NULL) { /* Register the tap messages and handler */ x_ipcRegisterHandler(watchMsgName,watchMsgName,watchFn); x_ipcLimitPendingMessages(watchMsgName, GET_M_GLOBAL(modNameGlobal), 1); } x_ipcFree(watchMsgName); }
HND_PTR x_ipc_selfRegisterHnd(int sd, MODULE_PTR hndOrg, HND_DATA_PTR hndData, X_IPC_HND_FN hndProc) { int32 localId; MSG_PTR msg; HND_PTR hnd; HND_KEY_TYPE hndKey; msg = x_ipc_findOrRegisterMessage(hndData->msgName); hndKey.num = sd; hndKey.str = hndData->hndName; LOCK_CM_MUTEX; hnd = GET_HANDLER(&hndKey); UNLOCK_CM_MUTEX; if (!hnd) { hnd = NEW(HND_TYPE); hnd->sd = sd; hnd->localId = 0; hnd->msg = NULL; hnd->hndProc = hndProc; hnd->hndOrg = hndOrg; hnd->hndData = hndData; hnd->msgList = x_ipc_listCreate(); hnd->resource = NULL; hnd->hndLanguage = C_LANGUAGE; /* The default */ #ifdef NMP_IPC hnd->clientData = NO_CLIENT_DATA; hnd->isRegistered = TRUE; #endif LOCK_CM_MUTEX; ADD_HANDLER(&hndKey, hnd); localId = x_ipc_idTableInsert((char *)hnd, GET_C_GLOBAL(hndIdTable)); UNLOCK_CM_MUTEX; hnd->localId = localId; if (hndProc) hnd->hndData->refId = localId; } else { LOCK_M_MUTEX; if (!IS_LISP_MODULE() && hndProc != hnd->hndProc) { /* 24-Jun-91: fedor: the warning is not meaningful for lisp because each re-register will cause a pointer change - lisp functions are not at static locations like c */ X_IPC_MOD_WARNING1("\nWARNING: Procedure change ignored for existing handler %s.\n", hnd->hndData->hndName); } UNLOCK_M_MUTEX; } /* 3-Sep-90: fedor: NULL forces initial module cache of a message. */ hnd->msg = NULL; if (!x_ipc_listMemberItem((char *)hnd, msg->hndList)) x_ipc_listInsertItem((char *)hnd, msg->hndList); if (!x_ipc_listMemberItem((char *)msg, hnd->msgList)) x_ipc_listInsertItem((char *)msg, hnd->msgList); return hnd; }