示例#1
0
static void setVarHnd(DISPATCH_PTR dispatch, void *varValue)
{
  GLOBAL_VAR_PTR var=NULL;
  const char *msgName = dispatch->msg->msgData->name;
  const char *varName;
  char *watchMsgName;
  
  varName = &(msgName[strlen(VAR_SET_PREFIX)]);
  
  var = (GLOBAL_VAR_PTR) x_ipc_hashTableFind(varName, GET_S_GLOBAL(varTable));
  if (var == NULL) {
    /* handle the error here. */
  } else {
    /* Free the old data if it exists */
    if (var->value != NULL)
      x_ipcFreeData(msgName,var->value);
    /* Store the pointer to the new data */
    var->value = varValue;
  }
  /* Need to do a x_ipcSuccess, if a command. */
  /*  centralSuccess(dispatch);*/
  /* Broadcast the result. */
  
  watchMsgName = (char *)x_ipcMalloc(1+strlen(varName)+strlen(VAR_WATCH_PREFIX));
  strcpy(watchMsgName,VAR_WATCH_PREFIX);
  strcat(watchMsgName,varName);

  centralBroadcast(watchMsgName,var->value);
  x_ipcFree(watchMsgName);
}
示例#2
0
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;
}
示例#3
0
static CONST_FORMAT_PTR x_ipc_formatterRecv(int sd)
{
  DATA_MSG_PTR dataMsg = NULL;
  CONST_FORMAT_PTR *pointerToFormat;
  CONST_FORMAT_PTR format;
  NAMED_FORMAT_PTR formatFormat;
  
  LOCK_M_MUTEX;
  formatFormat = (NAMED_FORMAT_PTR)
    x_ipc_hashTableFind("format", GET_M_GLOBAL(formatNamesTable));
  UNLOCK_M_MUTEX;
  if (!formatFormat) {
    X_IPC_MOD_ERROR("ERROR: x_ipc_formatterRecv: no formatFormat");
  }
  
  switch(x_ipc_dataMsgRecv(sd, &dataMsg, 0, NULL, 0)){
  case StatOK:
    pointerToFormat = (CONST_FORMAT_PTR *)
      x_ipc_dataMsgDecodeMsg(formatFormat->format, dataMsg, FALSE);
    x_ipc_dataMsgFree(dataMsg);
    format = *pointerToFormat;
    x_ipcFree((void *)pointerToFormat);
    return(format);
  case StatError:
    X_IPC_MOD_ERROR("ERROR: foramatterRecv: x_ipc_dataMsgRecv: StatError:");
    /*NOTREACHED*/
    break;
  case StatEOF:
    X_IPC_MOD_ERROR("ERROR: foramatterRecv: x_ipc_dataMsgRecv: StatEOF:");
    /*NOTREACHED*/
    break;
  case StatSendEOF:    
  case StatSendError:    
  case StatRecvEOF:    
  case StatRecvError:    
    X_IPC_MOD_ERROR("ERROR: foramatterRecv: x_ipc_dataMsgRecv: Unexpected error \n");
    break;
#ifndef TEST_CASE_COVERAGE
  default:
    X_IPC_MOD_ERROR("ERROR: foramatterRecv: x_ipc_dataMsgRecv: UNKNOWN:");
    /*NOTREACHED*/
#endif
  }
  return ( CONST_FORMAT_PTR) NULL;
}
示例#4
0
static void getVarHnd(DISPATCH_PTR dispatch, void *empty)
{
#ifdef UNUSED_PRAGMA
#pragma unused(empty)
#endif
  
  GLOBAL_VAR_PTR var=NULL;
  const char *msgName;
  const char *varName;
  
  msgName = dispatch->msg->msgData->name;
  varName = &(msgName[strlen(VAR_SET_PREFIX)]);
  var = (GLOBAL_VAR_PTR) x_ipc_hashTableFind(varName, GET_S_GLOBAL(varTable));
  if (var == NULL) {
    /* handle the error here. */
  } else {
    centralReply(dispatch, (char *)var->value);
  }
}
示例#5
0
static void formatterSend(int sd, CONST_FORMAT_PTR form)
{
  DATA_MSG_PTR dataMsg;
  NAMED_FORMAT_PTR formatFormat;
  
  formatFormat = 
    (NAMED_FORMAT_PTR)x_ipc_hashTableFind("format", 
				    GET_M_GLOBAL(formatNamesTable));
  
  if (!formatFormat) {
    X_IPC_ERROR("ERROR: formatterSend: no formatFormat");
  }
  dataMsg = x_ipc_dataMsgCreate(0, 0, 0, 0, 0, formatFormat->format, (void *)&form, 
			  (FORMAT_PTR)NULL, (void *)NULL);
  
  (void)x_ipc_dataMsgSend(sd, dataMsg);
  
  x_ipc_dataMsgFree(dataMsg);
}
示例#6
0
static void getSetVarHnd(DISPATCH_PTR dispatch, void *varValue)
{
  GLOBAL_VAR_PTR var=NULL;
  const char *msgName;
  const char *varName;
  
  msgName = dispatch->msg->msgData->name;
  varName = &(msgName[strlen(VAR_GET_SET_PREFIX)]);
  var = (GLOBAL_VAR_PTR) x_ipc_hashTableFind(varName, GET_S_GLOBAL(varTable));
  if (var == NULL) {
    /* handle the error here. */
  } else {
    /* Free the old data if it exists */
    if (var->value != NULL) {
      centralReply(dispatch, (char *)var->value);
      x_ipcFreeData(msgName,var->value);
    }
    /* Store the pointer to the new data */
    var->value = varValue;
  }
}
示例#7
0
文件: reg.c 项目: Evanglie/libipc
/******************************************************************************
 *
 * FUNCTION: int32 x_ipc_deregisterHnd(sd, hndData)
 *
 * DESCRIPTION: Deregister the given handler for the given message, for
 *              the given module (as indicated by the socket descriptor sd).
 *
 * INPUTS: int32 sd; Socket descriptor of the module that registere the handler 
 *         HND_DATA_PTR hndData; Name of message and handler pair.
 *
 * OUTPUTS: int32: returns FALSE if the handler is not currently registered.
 *
 * NOTES: Just remove the handler from the message's hndList.  Do not actually
 *        delete it, since other things depend on having the handler around.
 *
 *****************************************************************************/
int32 x_ipc_deregisterHnd(int sd, HND_DATA_PTR hndData)
{
  HND_PTR hnd;
  MSG_PTR msg;
  HND_KEY_TYPE hndKey;
  
  msg = x_ipc_findOrRegisterMessage(hndData->msgName);
  
  hndKey.num = sd;
  hndKey.str = hndData->hndName;
  
  LOCK_CM_MUTEX;
  hnd = (HND_PTR)x_ipc_hashTableFind((char *)&hndKey, GET_C_GLOBAL(handlerTable));
  UNLOCK_CM_MUTEX;
  if (hnd) {
    x_ipc_removeHndFromMsg(hnd, msg);
    x_ipc_listDeleteItem((char *)msg, hnd->msgList);
    hnd->isRegistered = FALSE;
  } 
  return (hnd != NULL);
}
示例#8
0
X_IPC_RETURN_VALUE_TYPE x_ipc_sendMessage(X_IPC_REF_PTR ref, MSG_PTR msg,
					  void *msgData, void *classData,
					  int32 preallocatedRefId)
{
  int32 refId, savedRef, i, sd;
  DATA_MSG_PTR msgDataMsg;
  X_IPC_MSG_CLASS_TYPE msg_class;
  CLASS_FORM_PTR classForm;
  CONST_FORMAT_PTR classFormat;
  X_IPC_RETURN_STATUS_TYPE result;
  DIRECT_MSG_HANDLER_PTR direct;
  CONNECTION_PTR connection;
  
  classFormat = NULL;
  
  if (!msg) {
    X_IPC_MOD_ERROR("ERROR: x_ipc_sendMessage: NULL msg.\n");
  }
  
  if (!x_ipc_isValidServerConnection()) {
    X_IPC_MOD_ERROR("ERROR: Must be connected to the server to send a message");
    return Failure;
  }
  
  /* save the message ref to use in case x_ipc_msgFind triggers 
     a recursive call to x_ipc_sendMessage */
  
  LOCK_CM_MUTEX;
  savedRef = (preallocatedRefId != NO_REF ? preallocatedRefId
	      : x_ipc_nextSendMessageRef());
  
  msg_class = msg->msgData->msg_class;
  classForm = GET_CLASS_FORMAT(&msg_class);
  
  if (classForm)
    classFormat = classForm->format;
  
  refId = (ref ? ref->refId : NO_REF);
  
  /* RTG For now, only do direct if no logging. */
  msgDataMsg = x_ipc_dataMsgCreate(GET_C_GLOBAL(parentRefGlobal), -1,
				   (int32)msg_class, refId, savedRef,
				   msg->msgData->msgFormat, msgData,
				   (FORMAT_PTR)classFormat, classData);
  UNLOCK_CM_MUTEX;
  if (msgDataMsg == NULL) {
    X_IPC_MOD_ERROR1("Unable to send message %s, probably a bad format\n",
		msg->msgData->name);
    return Failure;
  }
  if (!msg->direct || !msg->directList || msg->directList->numHandlers == 0) {
    msgDataMsg->intent = msg->msgData->refId;
    LOCK_CM_MUTEX;
    sd = GET_C_GLOBAL(serverWrite);
    UNLOCK_CM_MUTEX;
    result = x_ipc_dataMsgSend(sd, msgDataMsg);
  } else {
    /* Send in reverse order (to match what happens within central) */
    for (i=msg->directList->numHandlers-1, result=StatOK;
	 i>=0 && result == StatOK; i--) {
      direct = &(msg->directList->handlers[i]);
      if (direct->readSd >= 0) {
	msgDataMsg->intent = direct->intent;
	result = x_ipc_dataMsgSend(direct->writeSd, msgDataMsg);
	if (result == StatError && errno == EPIPE) {
	  fprintf(stderr, "Need to close %d\n", direct->writeSd);
	  LOCK_CM_MUTEX;
	  connection = (CONNECTION_PTR)x_ipc_hashTableFind((void *)&direct->writeSd,
							   GET_C_GLOBAL(moduleConnectionTable));
	  UNLOCK_CM_MUTEX;
	  if (connection) {
	    x_ipcHandleClosedConnection(direct->writeSd, connection);
	    result = StatOK;
	  }
	}
      }
    }
  }

  x_ipc_dataMsgFree(msgDataMsg);
  
  if (result != StatOK) 
    return Failure;
  return Success;
}