示例#1
0
文件: reg.c 项目: Evanglie/libipc
MSG_PTR x_ipc_msgCreate(MSG_DATA_PTR msgData)
{
  MSG_PTR msg;
  
  msg = NEW(MSG_TYPE);
  msg->direct = FALSE;
  msg->parsedFormats = FALSE;
  msg->msgData = msgData;
  msg->hndList = x_ipc_listCreate();
  msg->tapList = NULL;  
  msg->excepList = NULL;  
  msg->directList = NULL;  
#ifdef NMP_IPC
  msg->priority = DEFAULT_PRIORITY;
  msg->limit    = MAX_INT;
  msg->notifyHandlerChange = FALSE;
#endif
  
  /* 11-Jun-91: fedor: Blah! storing the parse string should 
     not be done here - but didnt want to mess with msgData for now ! */
  msg->msgFormatStr = NULL;
  msg->resFormatStr = NULL;
  
  LOCK_CM_MUTEX;
  ADD_MESSAGE(msgData->name, msg);
  UNLOCK_CM_MUTEX;
  return msg;
}
示例#2
0
LIST_PTR x_ipc_listDBCreate(const char* file, int line)
{ 
#ifdef UNUSED_PRAGMA
#pragma unused(file, line)
#endif
  return x_ipc_listCreate();
}
示例#3
0
static FORMAT_PTR Enum_Format(Format_Parse_Ptr parser, BOOLEAN *error)
{ 
  TokenPtr Token;
  FORMAT_PTR Form, subform;
  LIST_PTR format_list;
  int num_formats, i, maxVal;
  
  num_formats = 0;
  Token = NextToken(parser);
  if (Token->Type == COLON_TOK) {
    Token = NextToken(parser);
    if (Token->Type != INT_TOK) {
      *error = TRUE;
      ParserError(Token, parser, "an integer");
      return NULL;
    } else {
      maxVal = Token->value.num;
    }
  } else {
    format_list = x_ipc_listCreate();
    do {
      if (num_formats > 0) Token = NextToken(parser);
      if (Token->Type != STR_TOK) {
	*error = TRUE;
	ParserError(Token, parser, "a string");
	return NULL;
      } else {
	Form = new_n_formatter(Token->value.str);
	/* More efficient for Lisp if all enum format names are upper case */
	LOCK_M_MUTEX;
	if (IS_LISP_MODULE()) {
	  upcase(Form->formatter.name);
	}
	UNLOCK_M_MUTEX;
	x_ipc_listInsertItem((char *)Form, format_list);
	num_formats++;
      }
      Token = NextToken(parser);
    } while (Token->Type == COMMA_TOK);
    UngetToken(parser, Token);
    maxVal = num_formats - 1;
  }
  
  Form = new_a_formatter(EnumFMT, num_formats+2);
  Form->formatter.a[1].i = maxVal;
  if (num_formats > 0) {
    /* Index from high to low since "format_list" 
       has formatters in reverse order */
    subform = (FORMAT_PTR)x_ipc_listFirst(format_list);
    for(i=num_formats;i>0;i--) {
      Form->formatter.a[i+1].f = subform;
      subform = (FORMAT_PTR)x_ipc_listNext(format_list);
    }
    x_ipc_listFree(&format_list);
  }
  return Form;
}
示例#4
0
LIST_PTR x_ipc_listMake2(const void *item1, const void *item2)
{
  LIST_PTR list;
  
  list = x_ipc_listCreate();
  x_ipc_listInsertItem(item2, list);
  x_ipc_listInsertItem(item1, list);
  
  return list;
}
示例#5
0
LIST_PTR x_ipc_listMake1(const void *item)
{
  LIST_PTR list;
  
  list = x_ipc_listCreate();
  
  x_ipc_listInsertItem(item, list);
  
  return list;
}
示例#6
0
void x_ipc_dataMsgInitialize(void)
{
  LOCK_M_MUTEX;
  GET_M_GLOBAL(DMFree) = 0;
  GET_M_GLOBAL(DMTotal) = 0;
  GET_M_GLOBAL(DMmin) = 2000000000;
  GET_M_GLOBAL(DMmax) = -1;
  
  GET_M_GLOBAL(dataMsgBufferList) = x_ipc_listCreate();
  UNLOCK_M_MUTEX;
}
示例#7
0
LIST_PTR x_ipc_listCopy(LIST_PTR list)
{
  LIST_PTR newList;
  
  LOCK_LIST_MUTEX;
  newList = x_ipc_listCreate();
  
  (void)x_ipc_listIterateFromLast((LIST_ITER_FN)x_ipc_listCopyInsert, 
			    (char *)newList, list);
  
  UNLOCK_LIST_MUTEX;
  return newList;
}
示例#8
0
static FORMAT_PTR Struct_Format(Format_Parse_Ptr parser, BOOLEAN *error)
{ 
  FORMAT_PTR Form, subform;
  LIST_PTR format_list;
  int num_formats, i;
  
  format_list = x_ipc_listCreate();
  num_formats = 0;
  
  if (parser->TokenList->Type != RBRACE_TOK) {
    while (1) {
      x_ipc_listInsertItem((char *)Parse(parser, TRUE, error), format_list);
      num_formats++;
      if (parser->TokenList->Type == COMMA_TOK) {
	(void)NextToken(parser);
      } else if (parser->TokenList->Type == RBRACE_TOK) {
	break;
      } else {
	*error = TRUE;
	ParserError(NextToken(parser), parser, "','");
	return NULL;
      }
    }
  }
  
  Form = new_a_formatter(StructFMT, num_formats+1);
  /* Index from high to low since "format_list" 
     has formatters in reverse order */
  subform = (FORMAT_PTR)x_ipc_listFirst(format_list);
  for(i=num_formats;i>0;i--) {
    Form->formatter.a[i].f = subform;
    subform = (FORMAT_PTR)x_ipc_listNext(format_list);
  }
  
  x_ipc_listFree(&format_list);
  return Form;
}
示例#9
0
文件: reg.c 项目: Evanglie/libipc
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;
}
示例#10
0
void x_ipcRefInitialize(void)
{
  LOCK_CM_MUTEX;
  GET_C_GLOBAL(x_ipcRefFreeList) = x_ipc_listCreate();
  UNLOCK_CM_MUTEX;
}
示例#11
0
void x_ipc_globalMInit(void)
{
#if defined(VXWORKS)
  if (x_ipc_gM == NULL) {
    if (taskVarAdd(0, (int *)&x_ipc_gM) != OK) {
      printErr("taskVarAdd failed\n");
    }
  }
#endif
  
  if (mGlobalp() && GET_C_GLOBAL(valid)) {
    /* Already initialized, nothing to do. */
    return;
  } else if (x_ipc_isValidServerConnection()) {
    /* Already running, shut down and reinitialize. */
    LOCK_CM_MUTEX;
    SHUTDOWN_SOCKET(GET_C_GLOBAL(serverRead));
    if (GET_C_GLOBAL(serverRead) != GET_C_GLOBAL(serverWrite))
      SHUTDOWN_SOCKET(GET_C_GLOBAL(serverWrite));
    UNLOCK_CM_MUTEX;
    x_ipc_globalMInvalidate();
    x_ipc_globalMFree();
  } else if (mGlobalp()){
    /* Was initialized, but the current values are not valid. */
    /* Free some memory and reinitialize. */
    x_ipc_globalMFree();
  } 
  /* Never created or has been freed, set the global pointer. */
#if defined(VXWORKS)
  x_ipc_gM = (GM_TYPE *)x_ipcMalloc(sizeof(GM_TYPE));
  bzero((void *)x_ipc_gM,sizeof(GM_TYPE));
#else
  x_ipc_gM_ptr = &x_ipc_gM;
#endif

#ifdef THREADED
  initMutex(&GET_M_GLOBAL(mutex));
#endif

  GET_M_GLOBAL(currentContext) = 
    (X_IPC_CONTEXT_PTR)x_ipcMalloc(sizeof(X_IPC_CONTEXT_TYPE));

#ifdef THREADED
  initMutex(&GET_C_GLOBAL(mutex));
  LOCK_CM_MUTEX;
  initMutex(&GET_M_GLOBAL(selectMutex));
  initPing(&GET_M_GLOBAL(ping));
  initMutex(&GET_C_GLOBAL(ioMutex));
  initMutex(&listMutex);
#endif
  
#if defined(VXWORKS) || defined(NMP_IPC)
  GET_M_GLOBAL(enableDistributedResponses) = TRUE;
#else
  GET_M_GLOBAL(enableDistributedResponses) = FALSE;
#endif
  
  GET_C_GLOBAL(willListen) = -1;
  GET_C_GLOBAL(valid) = FALSE;
  
  GET_M_GLOBAL(byteOrder) = BYTE_ORDER;
  GET_M_GLOBAL(alignment) = (ALIGNMENT_TYPE)ALIGN;
  
  GET_C_GLOBAL(serverRead) = NO_SERVER_GLOBAL;
  GET_C_GLOBAL(serverWrite) = NO_SERVER_GLOBAL;
  GET_C_GLOBAL(directDefault) = FALSE;
  
  GET_M_GLOBAL(pipeBroken) = FALSE;
  
  GET_M_GLOBAL(bufferToAlloc) = NULL;
  
  /* not done */
  GET_M_GLOBAL(byteFormat) = NULL;
  GET_M_GLOBAL(charFormat) = NULL;
  GET_M_GLOBAL(doubleFormat) = NULL;
  GET_M_GLOBAL(floatFormat) = NULL;
  GET_M_GLOBAL(intFormat) = NULL;
  GET_M_GLOBAL(longFormat) = NULL;
  GET_M_GLOBAL(shortFormat) = NULL;
  
  GET_M_GLOBAL(classFormatTable) = NULL;
  GET_M_GLOBAL(formatNamesTable) = NULL;
  GET_C_GLOBAL(handlerTable) = NULL;
  GET_C_GLOBAL(messageTable) = NULL;
  GET_C_GLOBAL(resourceTable) = NULL;
  GET_C_GLOBAL(hndIdTable) = NULL;
  GET_C_GLOBAL(msgIdTable) = NULL;
  GET_M_GLOBAL(listCellFreeListGlobal) = NULL;
  GET_M_GLOBAL(dataMsgBufferList) = NULL;
  GET_M_GLOBAL(listFreeListGlobal) = NULL;
  GET_C_GLOBAL(moduleConnectionTable) = NULL;
  GET_C_GLOBAL(pendingReplies) = NULL;
  initMsgQueue(&GET_C_GLOBAL(msgQueue));
  GET_C_GLOBAL(queryNotificationList) = NULL;
  GET_C_GLOBAL(connectNotifyList) = NULL;
  GET_C_GLOBAL(disconnectNotifyList) = NULL;
  GET_C_GLOBAL(changeNotifyList) = NULL;
  GET_C_GLOBAL(x_ipcRefFreeList) = NULL;
  /* GET_M_GLOBAL(x_ipcDefaultTimeGlobal) = {NoTime, {NoInterval, 0}}; */
  /* 16-Jan-93 */
  /* GET_M_GLOBAL(versionGlobal);*/
#if defined(DBMALLOC)
  GET_M_GLOBAL(x_ipcMallocMemHnd) = debug_malloc;
#elif defined(__TURBOC__)
  GET_M_GLOBAL(x_ipcMallocMemHnd) = farmalloc;
#else
  GET_M_GLOBAL(x_ipcMallocMemHnd) = malloc;
#endif
  GET_M_GLOBAL(modNameGlobal) = NULL;
  GET_C_GLOBAL(servHostGlobal) = NULL;
  
  FD_ZERO(&(GET_C_GLOBAL(x_ipcConnectionListGlobal)));
  FD_ZERO(&(GET_C_GLOBAL(x_ipcListenMaskGlobal)));
  
#ifdef LISP
  GET_M_GLOBAL(lispFlagGlobal) = '\0';
  GET_M_GLOBAL(lispRefSaveGlobal) = NULL;
#ifdef CLISP
  GET_M_GLOBAL(lispBufferSizeGlobal) = lispbuffersize;
  GET_M_GLOBAL(lispDecodeMsgGlobal) = lispdecode;
  GET_M_GLOBAL(lispEncodeMsgGlobal) = lispencode;
  GET_M_GLOBAL(lispExitGlobal) = lispexit;
#else /* !CLISP */
  GET_M_GLOBAL(lispBufferSizeGlobal) = NULL;
  GET_M_GLOBAL(lispDecodeMsgGlobal) = NULL;
  GET_M_GLOBAL(lispEncodeMsgGlobal) = NULL;
  GET_M_GLOBAL(lispExitGlobal) = NULL;
#endif /* !CLISP */
#ifdef NMP_IPC
  GET_M_GLOBAL(lispQueryResponseGlobal) = NULL;
#endif
#endif /* LISP */

  GET_M_GLOBAL(DMFree) = 0;
  GET_M_GLOBAL(DMTotal) =0;
  GET_M_GLOBAL(DMmin) = 0;
  GET_M_GLOBAL(DMmax) = 0;;
  GET_M_GLOBAL(directFlagGlobal) = 0;
  GET_M_GLOBAL(expectedWaitGlobal) = FALSE;
  GET_M_GLOBAL(freeMemRetryAmount) = 0;
  
  /* not done - only used in behaviors.c does not change */
  GET_M_GLOBAL(inconsistentConstraintsGlobal)[0] = (PLAN_FIRST+DELAY_PLANNING);
  GET_M_GLOBAL(inconsistentConstraintsGlobal)[1] = 0;
  
  GET_M_GLOBAL(mallocMemRetryAmount) = 1;
  GET_C_GLOBAL(parentRefGlobal) = -1; 
  GET_C_GLOBAL(sendMessageRefGlobal) = 1;
  GET_C_GLOBAL(listenPortNum) = 0;
  GET_C_GLOBAL(listenPort) = NO_FD;
  GET_C_GLOBAL(listenSocket) = NO_FD;
  GET_M_GLOBAL(totalMemRequest) = 0;
  GET_M_GLOBAL(totalMemBytes) = 0;
  
  GET_M_GLOBAL(indentGlobal) = 0;
  GET_M_GLOBAL(dPrintBYTE_FN) = NULL;
  GET_M_GLOBAL(dPrintUBYTE_FN) = NULL;
  GET_M_GLOBAL(dPrintCHAR_FN) = NULL;
  GET_M_GLOBAL(dPrintDOUBLE_FN) = NULL;
  GET_M_GLOBAL(dPrintFLOAT_FN) = NULL;
  GET_M_GLOBAL(dPrintFORMAT_FN) = NULL;
  GET_M_GLOBAL(dPrintINT_FN) = NULL;
  GET_M_GLOBAL(dPrintBOOLEAN_FN) = NULL;
  GET_M_GLOBAL(dPrintLONG_FN) = NULL;
#ifndef NMP_IPC
  GET_M_GLOBAL(dPrintMAP_FN) = NULL;
#endif
  GET_M_GLOBAL(dPrintSHORT_FN) = NULL;
  GET_M_GLOBAL(dPrintSTR_FN) = NULL;
  GET_M_GLOBAL(dPrintX_IPC_FN) = NULL;
  GET_M_GLOBAL(dPrintTWOBYTE_FN) = NULL;
  GET_M_GLOBAL(dPrintUINT_FN) = NULL;
  GET_M_GLOBAL(dPrintUSHORT_FN) = NULL;
  GET_M_GLOBAL(dPrintULONG_FN) = NULL;

  GET_M_GLOBAL(Message_Ignore_Set) = NULL;
  
  GET_M_GLOBAL(x_ipcExitHnd) = NULL;
  GET_M_GLOBAL(x_ipcFreeMemoryHnd) = NULL;
  
  GET_M_GLOBAL(logList)[0] = NULL;
  GET_M_GLOBAL(logList)[1] = NULL;
  GET_M_GLOBAL(logList)[2] = NULL;
  
  GET_M_GLOBAL(Found_Key) = NULL;/***/
  
  GET_C_GLOBAL(tappedMsgs) = NULL;
  GET_C_GLOBAL(broadcastMsgs) = NULL;
  GET_C_GLOBAL(maxConnection) = 0;

  GET_M_GLOBAL(requiredResources) = x_ipc_strListCreate();
  GET_M_GLOBAL(moduleList) = NULL;

#ifdef NMP_IPC
  GET_M_GLOBAL(timerList) = x_ipc_listCreate();
#endif

#ifdef LISPWORKS_FFI_HACK
  GET_C_GLOBAL(execHndState).state = ExecHnd_Idle;
#endif
  UNLOCK_CM_MUTEX;
}