Esempio n. 1
0
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));
      }
    }
  }
}
Esempio n. 2
0
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));
    }
  }
}
Esempio n. 3
0
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));
    }
  }
}
Esempio n. 4
0
IPC_RETURN_TYPE IPC_dispatch (void)
{
  while (IPC_listen(IPC_WAIT_FOREVER) != IPC_Error) {};
  /* If control reaches here, IPC_listen returned IPC_Error */
  PASS_ON_ERROR();
}
Esempio n. 5
0
IPC_RETURN_TYPE _IPC_queryResponse (const char *msgName, 
				    unsigned int length, BYTE_ARRAY content,
				    BYTE_ARRAY *replyHandle,
				    FORMATTER_PTR *replyFormatterPtr,
				    const char **responseMsgNamePtr,
				    unsigned int timeoutMsecs)
{
  unsigned long quitTime = WAITFOREVER, now;
  QUERY_REPLY_TYPE queryReplyData;
  QUERY_NOTIFICATION_PTR queryNotif;
  IPC_RETURN_TYPE retVal = IPC_OK;

  queryReplyData.handled = FALSE;
  queryReplyData.data = NULL;
  queryReplyData.formatter = (FORMATTER_PTR)NULL;
  queryReplyData.msgName = NULL;

  if (timeoutMsecs != IPC_WAIT_FOREVER) {
    /* When to timeout */
    now = x_ipc_timeInMsecs();
    quitTime = timeoutMsecs + now;
  }

  /* Send the query, and set up a handler to catch the result and
     squirrel away the response data in "queryReplyData" */
  if (IPC_queryNotify(msgName, length, content, queryReplyHandler, 
		      &queryReplyData) == IPC_Error) {
    PASS_ON_ERROR();
  } else {
    /* Check if completed, because in threaded IPC, another thread could
       have handled the notification already */
    if (!queryReplyData.handled) {
      while ((retVal = IPC_listen(timeoutMsecs)) == IPC_OK &&
	     !queryReplyData.handled) {
	/* Handled a message, but not the one we are waiting for.
	   If still have time, reset the timeout and try again */
	if (timeoutMsecs != IPC_WAIT_FOREVER) {
	  now = x_ipc_timeInMsecs();
	  if (quitTime < now) {
	    retVal = IPC_Timeout;
	    break;
	  } else {
	    timeoutMsecs = quitTime - now;
	  }
	}
      }
    }
    if (retVal != IPC_OK) {
      /* Clean up */

      LOCK_CM_MUTEX;
      queryNotif = 
	((QUERY_NOTIFICATION_PTR)
	 x_ipc_listMemReturnItem((LIST_ITER_FN)testQueryReplyData,
				 (char *)&queryReplyData,
				 GET_C_GLOBAL(queryNotificationList)));
      x_ipc_listDeleteItem((void *)queryNotif,
			   GET_C_GLOBAL(queryNotificationList));
      UNLOCK_CM_MUTEX;
      x_ipcRefFree(queryNotif->ref);
      x_ipcFree((void *)queryNotif);
    }

    *replyHandle = queryReplyData.data;
    if (replyFormatterPtr) *replyFormatterPtr = queryReplyData.formatter;
    if (responseMsgNamePtr) *responseMsgNamePtr = queryReplyData.msgName;

    return retVal;
  }
}