Пример #1
0
/******************************************************************************
 *
 * FUNCTION: void x_ipc_globalMFree(void)
 *
 * DESCRIPTION: 
 * Free memory that x_ipc allocates in the module.
 *
 *****************************************************************************/
void x_ipc_globalMFree(void)
{
  if (mGlobalp()) {
    LOCK_M_MUTEX;
    x_ipc_listFreeAllItems((LIST_FREE_FN)x_ipcFree, 
		     GET_M_GLOBAL(dataMsgBufferList));
    x_ipc_listFree(&(GET_M_GLOBAL(dataMsgBufferList)));
    GET_M_GLOBAL(dataMsgBufferList) = NULL;
    x_ipc_listFree(&(GET_M_GLOBAL(Message_Ignore_Set)));
    GET_M_GLOBAL(Message_Ignore_Set) = NULL;
    
    x_ipc_hashTableFree(&GET_M_GLOBAL(classFormatTable),
		  (HASH_ITER_FN)x_ipc_classEntryFree, NULL);
    x_ipc_hashTableFree(&GET_M_GLOBAL(formatNamesTable),
		  (HASH_ITER_FN)x_ipc_formatFreeEntry, NULL);
    x_ipc_hashTableFree(&GET_M_GLOBAL(externalFdTable),x_ipc_hashItemsFree, NULL);
    
    if (GET_M_GLOBAL(logList)[0]) {
      x_ipcFree((char *)(GET_M_GLOBAL(logList)[0])->theFile);
      x_ipcFree((char *)GET_M_GLOBAL(logList)[0]);
    }
    GET_M_GLOBAL(logList)[0] = NULL;
    if (GET_M_GLOBAL(logList)[1]) {
      x_ipcFree((char *)(GET_M_GLOBAL(logList)[1])->theFile);
      x_ipcFree((char *)GET_M_GLOBAL(logList)[1]);
    }
    GET_M_GLOBAL(logList)[1] = NULL;

    x_ipc_freeContext(&GET_M_GLOBAL(currentContext));

    x_ipc_listCleanup();
    
    x_ipc_strListFree(&GET_M_GLOBAL(requiredResources), TRUE);

    x_ipcFree((char *)GET_M_GLOBAL(modNameGlobal));

    if (GET_M_GLOBAL(byteFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(byteFormat));
    if (GET_M_GLOBAL(charFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(charFormat));
    if (GET_M_GLOBAL(shortFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(shortFormat));
    if (GET_M_GLOBAL(intFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(intFormat));
    if (GET_M_GLOBAL(longFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(longFormat));
    if (GET_M_GLOBAL(floatFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(floatFormat));
    if (GET_M_GLOBAL(doubleFormat)) x_ipc_freeFormatter(&GET_M_GLOBAL(doubleFormat));

    x_ipc_listFreeAllItems((LIST_FREE_FN)x_ipcFree, GET_M_GLOBAL(timerList));
    x_ipc_listFree(&(GET_M_GLOBAL(timerList)));

#if defined(VXWORKS)
    x_ipcFree((char *)x_ipc_gM);
    x_ipc_gM = NULL;
#else
    x_ipc_globalMInit();
    x_ipcFree((char *)GET_M_GLOBAL(currentContext));
    bzero((char *)&x_ipc_gM,sizeof(x_ipc_gM));
    x_ipc_gM_ptr = NULL;
#endif
    UNLOCK_M_MUTEX;
  }
}
Пример #2
0
/******************************************************************************
 *
 * 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;
  }
}
Пример #3
0
/******************************************************************************
 *
 * 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;
}
Пример #4
0
void x_ipcStats(FILE *stream)
{
  if (!mGlobalp())
    return;
  
  LOCK_M_MUTEX;
  fprintf(stream,"Cumulative Memory Usage:\n  Requests: %ld (%ld bytes)\n", 
	  GET_M_GLOBAL(totalMemRequest), GET_M_GLOBAL(totalMemBytes));
  UNLOCK_M_MUTEX;
  x_ipc_dataMsgDisplayStats(stream);
  fflush(stream);
}
Пример #5
0
void IPC_perror (const char *msg)
{
#ifdef VXWORKS
  LOCK_M_MUTEX;
  fprintf(stderr, "%s: ", (mGlobalp() ? GET_M_GLOBAL(modNameGlobal) : "???"));
  UNLOCK_M_MUTEX;
#endif
  if (msg && strlen(msg) > 0) {
    fprintf(stderr, "%s: ", msg);
  }
  fprintf(stderr, "%s\n", ipcErrorStrings[IPC_errno]);
}
Пример #6
0
/******************************************************************************
 *
 * 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;
  }
}
Пример #7
0
/******************************************************************************
 *
 * FUNCTION: X_IPC_REF_PTR x_ipcRootNode(void)
 *
 * DESCRIPTION: Return a reference to the root node of the task tree
 *
 *****************************************************************************/
X_IPC_REF_PTR x_ipcRootNode(void)
{
  if (mGlobalp()) {
    X_IPC_REF_PTR result;

    LOCK_M_MUTEX;
    result = GET_M_GLOBAL(x_ipcRootNodeGlobal);
    UNLOCK_M_MUTEX;

    return result;
  } else
    return NULL;
}
Пример #8
0
/*****************************************************************************
 *
 * FUNCTION: void centralSetVar
 *
 * DESCRIPTION:
 *
 * INPUTS:
 *
 * OUTPUTS: void
 *
 *****************************************************************************/
void centralSetVar(const char *varName, const char *value)
{
  char *setMsgName;

  if (!mGlobalp())
    return;
  
  setMsgName = (char *)x_ipcMalloc(1+strlen(varName)+strlen(VAR_SET_PREFIX));
  strcpy(setMsgName,VAR_SET_PREFIX);
  strcat(setMsgName,varName);
  
  centralInform(setMsgName, value);
  x_ipcFree(setMsgName);
}
Пример #9
0
void x_ipcModError(const char *description, ...)
{
#ifndef NMP_IPC
  x_ipcStats(stderr);
#endif

#ifdef NMP_IPC
  if (ipcVerbosity >= IPC_Print_Errors)
#endif
  if (description) {
    va_list args;
    va_start(args, description);
    vfprintf(stderr, (char *)description, args);
    fprintf(stderr, "\n");
    va_end(args);
    FLUSH_IF_NEEDED(stderr);
  }
  
#ifdef NMP_IPC
  if (ipcVerbosity >= IPC_Exit_On_Errors)
#endif
  {
    x_ipcClose();
  
    LOCK_M_MUTEX;
    if (mGlobalp()) {
#ifdef LISP
      if (IS_LISP_MODULE()) {
	if (GET_M_GLOBAL(lispExitGlobal) != NULL)
	  (*(GET_M_GLOBAL(lispExitGlobal)))();
      } else
#endif /* LISP */
	{
	  if (GET_M_GLOBAL(x_ipcExitHnd)) {
	    (*(GET_M_GLOBAL(x_ipcExitHnd)))();
	  } else {
	    exit(-1);
	  }
	}
      }
    UNLOCK_M_MUTEX;
  }
}
Пример #10
0
void *x_ipcMalloc(size_t amount)
#endif
{
  int i, j;
  void *mem;
  
  mem = NULL;
  
  if (!mGlobalp() || !GET_M_GLOBAL(x_ipcMallocMemHnd)) {
    /* X_IPC_MOD_WARNING1("calling x_ipcMalloc(%d) before initialized\n", amount);*/
#if defined(DBMALLOC)
    mem = malloc(file, line, amount);
#else
    mem = malloc(amount);
#endif
    if (!mem) 
      X_IPC_MOD_ERROR1("x_ipcMalloc: NULL returned from malloc for request: %d\n", 
		       amount);
    return mem;

  } else {
    LOCK_M_MUTEX;

    if (GET_M_GLOBAL(x_ipcMallocMemHnd)) 
      for(i=0;!mem && i < GET_M_GLOBAL(mallocMemRetryAmount);i++) {
#if defined(DBMALLOC)
	mem = (*GET_M_GLOBAL(x_ipcMallocMemHnd))(file,line,amount);
#else
	mem = (*GET_M_GLOBAL(x_ipcMallocMemHnd))(amount);
#endif
      }

    if (mem) {
      GET_M_GLOBAL(totalMemRequest)++;
      GET_M_GLOBAL(totalMemBytes) += amount;
      UNLOCK_M_MUTEX;
      return(mem);
    }
  
    if (GET_M_GLOBAL(x_ipcFreeMemoryHnd))
      for(j=0;!mem && j < GET_M_GLOBAL(freeMemRetryAmount);j++) {
	(*GET_M_GLOBAL(x_ipcFreeMemoryHnd))(amount);
      
	if (GET_M_GLOBAL(x_ipcMallocMemHnd)) 
	  for(i=0;!mem && i < GET_M_GLOBAL(mallocMemRetryAmount);i++) {
#if defined(DBMALLOC)
	    mem = (*GET_M_GLOBAL(x_ipcMallocMemHnd))(file,line,amount);
#else
	    mem = (*GET_M_GLOBAL(x_ipcMallocMemHnd))(amount);
#endif
	  }
      }
    
    if (mem) {
      GET_M_GLOBAL(totalMemRequest)++;
      GET_M_GLOBAL(totalMemBytes) += amount;
      UNLOCK_M_MUTEX;
      return(mem);
    }
  
    UNLOCK_M_MUTEX;
    X_IPC_MOD_ERROR1("x_ipcMalloc: NULL returned from malloc for request: %d\n",
		     amount);
    return NULL;
  }
}
Пример #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;
}