/** * Destruct */ int ngiSessionInformationDestruct( ngSessionInformation_t *info, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiSessionInformationDestruct"; /* Check the arguments */ assert(info != NULL); /* Finalize */ result = ngiSessionInformationFinalize(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_FATAL, NULL, "%s: Can't finalize the Session Information.\n", fName); return 0; } result = ngiSessionInformationFree(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_FATAL, NULL, "%s: Can't deallocate the storage for Session Information.\n", fName); return 0; } /* Success */ return 1; }
/** * Destruct */ int ngiNetCommunicatorDestruct(NET_Communicator *netComm, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiNetCommunicatorDestruct"; /* Check the arguments */ assert(netComm != NULL); /* Finalize */ result = ngiNetCommunicatorFinalize(netComm, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_FATAL, NULL, "%s: Can't finalize the Communicator.\n", fName); return 0; } result = ngiNetCommunicatorFree(netComm, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_FATAL, NULL, "%s: Can't deallocate the storage for Communicator.\n", fName); return 0; } /* Success */ return 0; }
/** * Finalize */ int ngiSessionInformationFinalize( ngSessionInformation_t *info, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiSessionInformationFinalize"; /* Check the arguments */ assert(info != NULL); /* Finish the measurement */ result = ngiSessionInformationFinishMeasurement(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't finish the measurement.\n", fName); return 0; } /* Initialize the members */ nglSessionInformationInitializeMember(info); /* Success */ return 1; }
/** * Initialize */ int ngiNetCommunicatorInitialize( NET_Communicator *netComm, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiNetCommunicatorInitialize"; /* Check the arguments */ assert(netComm != NULL); /* Initialize the pointers */ nglNetCommunicatorInitializeMember(netComm); /* Get the data size */ result = nglNetCommunicatorInitializeDataSize(netComm, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't initialize the Data Size.\n", fName); return 0; } /* Success */ return 1; }
/** * Initialize XDR */ static int nglNetCommunicatorInitializeXDR( NET_Communicator *netComm, int dataType, int nElements, ngLog_t *log, int *error) { size_t xdrNbytes; int result; static const char fName[] = "nglNetCommunicatorInitializeXDR"; /* Check tha arguments */ assert(netComm != NULL); assert(netComm->nc_xdrBuffer == NULL); assert(nElements > 0); /* Get the number of bytes of data */ result = ngiNetCommunicatorGetDataSize( netComm, dataType, &xdrNbytes, log, error); if ((result == 0) || (nBytes < 0)) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the number of bytes of data.\n", fName); return 0; } netComm->nc_xdrNbytes = xdrNbytes * nElements; /* Allocate the data buffer */ netComm->nc_xdrBuffer = globus_libc_calloc(1, netComm->nc_xdrNbytes); if (netComm->nc_xdrBuffer == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Data Buffer.\n", fName); return 0; } /* Initialize the XDR stream */ xdrmem_create( &netComm->nc_xdrStream, netComm->nc_xdrBuffer, nBytes, XDR_FREE); xdrmem_create( &netComm->nc_xdrStream, netComm->nc_xdrBuffer, nBytes, XDR_ENCODE); /* Success */ return 1; }
/** * Construct */ ngSessionInformation_t * ngiSessionInformationConstruct( ngLog_t *log, int *error) { int result; ngSessionInformation_t *info; static const char fName[] = "ngiSessionInformationConstruct"; /* Allocate */ info = ngiSessionInformationAllocate(log, error); if (info == NULL) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Session Information.\n", fName); return NULL; } /* Initialize */ result = ngiSessionInformationInitialize(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't initialize the Session Information.\n", fName); goto error; } /* Success */ return info; /* Error occurred */ error: result = ngiSessionInformationFree(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't deallocate the storage for Session Information.\n", fName); return NULL; } /* Failed */ return NULL; }
/** * Start the measurement. */ int ngiSessionInformationStartMeasurement( ngSessionInformation_t *info, int nArguments, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiSessionInformationStartMeasurement"; /* Check tha arguments */ assert(info != NULL); assert(nArguments >= 0); assert(info->ngsi_compressionInformation == NULL); /* Initialize */ result = ngiSessionInformationInitialize(info, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't initialize the Session Information.\n", fName); return 0; } /* Allocate the storage for Compression Information */ info->ngsi_nCompressionInformations = nArguments; if (nArguments > 0) { info->ngsi_compressionInformation = globus_libc_calloc( nArguments, sizeof (*info->ngsi_compressionInformation)); if (info->ngsi_compressionInformation == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Session Information.\n", fName); return 0; } } /* Success */ return 1; }
/** * Construct */ NET_Communicator * ngiNetCommunicatorConstruct( ngLog_t *log, int *error) { int result; NET_Communicator *netComm; static const char fName[] = "ngiNetCommunicatorConstruct"; /* Allocate */ netComm = ngiNetCommunicatorAllocate(log, error); if (netComm == NULL) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Communicator.\n", fName); return NULL; } /* Initialize */ result = ngiNetCommunicatorInitialize(netComm, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't initialize the Communicator.\n", fName); goto error; } /* Success */ return netComm; /* Error occurred */ error: result = ngiNetCommunicatorFree(netComm, log, error); if (result == 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't deallocate the storage for Communicator.\n", fName); return NULL; } return NULL; }
/** * ObserveItem: EventTime change request */ int ngcliObserveItemEventTimeChangeRequest( ngclContext_t *context, ngcliObserveThread_t *observe, ngcliObserveItem_t *observeItem, int *error) { static const char fName[] = "ngcliObserveItemEventTimeChangeRequest"; int result; /* Check the arguments */ assert(context != NULL); assert(observe != NULL); assert(observeItem != NULL); #if 0 ngLogPrintf(context->ngc_log, NG_LOG_LEVEL_FATAL, NG_LOG_LEVEL_FATAL, NULL, "%s start...\n", fName); #endif #ifdef NG_PTHREAD result = ngcllObserveThreadEventTimeChangeRequest( context, observe, observeItem, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Changing ObserveItem eventTime failed.\n", fName); return 0; } #else /* NG_PTHREAD */ /* Do nothing */ result = 1; assert(result != 0); ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: observing is not supported for this GlobusToolkit flavor.\n", fName); ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: observing is supported only for pthread version.\n", fName); #endif /* NG_PTHREAD */ /* Success */ return 1; }
/** * Allocate */ ngSessionInformation_t * ngiSessionInformationAllocate(ngLog_t *log, int *error) { ngSessionInformation_t *info; static const char fName[] = "ngiSessionInformationAllocate"; info = globus_libc_calloc(1, sizeof (ngSessionInformation_t)); if (info == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Session Information.\n", fName); return NULL; } /* Success */ return info; }
/** * Allocate */ NET_Communicator * ngiNetCommunicatorAllocate(ngLog_t *log, int *error) { NET_Communicator *netComm; static const char fName[] = "ngiNetCommunicatorAllocate"; netComm = globus_libc_calloc(1, sizeof (NET_Communicator)); if (netComm == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't allocate the storage for Communicator.", fName); return NULL; } /* Success */ return netComm; }
/** * Get the data size. */ int ngiNetCommunicatorGetDataSize( NET_Communicator *netComm, ngArgumentDataType_t dataType, size_t *nBytes, ngLog_t *log, int *error) #if 1 { static const char fName[] = "ngiNetCommunicatorGetDataSize"; /* Check the arguments */ if (nBytes == NULL) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Invalid argument.\n", fName); return 0; } switch (dataType) { case NG_ARGUMENT_DATA_TYPE_CHAR: *nBytes = netComm->nc_dataSize.ngds_char; return 1; case NG_ARGUMENT_DATA_TYPE_SHORT: *nBytes = netComm->nc_dataSize.ngds_short; return 1; case NG_ARGUMENT_DATA_TYPE_INT: *nBytes = netComm->nc_dataSize.ngds_int; return 1; case NG_ARGUMENT_DATA_TYPE_LONG: *nBytes = netComm->nc_dataSize.ngds_long; return 1; case NG_ARGUMENT_DATA_TYPE_FLOAT: *nBytes = netComm->nc_dataSize.ngds_float; return 1; case NG_ARGUMENT_DATA_TYPE_DOUBLE: *nBytes = netComm->nc_dataSize.ngds_double; return 1; case NG_ARGUMENT_DATA_TYPE_SCOMPLEX: *nBytes = netComm->nc_dataSize.ngds_scomplex; return 1; case NG_ARGUMENT_DATA_TYPE_DCOMPLEX: *nBytes = netComm->nc_dataSize.ngds_dcomplex; return 1; default: /* Do nothing */ break; } ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Unknown data type %d.\n", fName, dataType); /* Failed */ return 0; }
/** * Initialize the data size. */ static int nglNetCommunicatorInitializeDataSize( NET_Communicator *netComm, ngLog_t *log, int *error) { int result; static const char fName[] = "nglNetCommunicatorInitializeDataSize"; /* Check the arguments */ assert(netComm != NULL); /* Get the size of char */ result = NET_xdrsizeof(NET_CHAR); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of char.\n", fName); return 0; } netComm->nc_dataSize.ngds_char = result; /* Get the size of short */ result = NET_xdrsizeof(NET_S_INT); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of short.\n", fName); return 0; } netComm->nc_dataSize.ngds_short = result; /* Get the size of int */ result = NET_xdrsizeof(NET_I); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of int.\n", fName); return 0; } netComm->nc_dataSize.ngds_int = result; /* Get the size of long */ result = NET_xdrsizeof(NET_L_INT); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of long.\n", fName); return 0; } netComm->nc_dataSize.ngds_long = result; /* Get the size of float */ result = NET_xdrsizeof(NET_S); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of float.\n", fName); return 0; } netComm->nc_dataSize.ngds_float = result; /* Get the size of double */ result = NET_xdrsizeof(NET_D); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of double.\n", fName); return 0; } netComm->nc_dataSize.ngds_double = result; /* Get the size of scomplex */ result = NET_xdrsizeof(NET_C); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of scomplex.\n", fName); return 0; } netComm->nc_dataSize.ngds_scomplex = result; /* Get the size of dcomplex */ result = NET_xdrsizeof(NET_Z); if (result <= 0) { ngLogPrintf(log, NG_LOG_CATEGORY_NINFG_PROTOCOL, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't get the size of dcomplex.\n", fName); return 0; } netComm->nc_dataSize.ngds_dcomplex = result; /* Success */ return 1; }
/** * ObserveThread: main proceeding */ static void * ngcllObserveThread(void *threadArgument) { static const char fName[] = "ngcllObserveThread"; ngcliObserveThread_t *observe; int errorEntity, *error; int result, wasTimedOut, sleepSec; ngclContext_t *context; ngLog_t *log; time_t now; /* Check the arguments */ assert(threadArgument != NULL); context = (ngclContext_t *)threadArgument; observe = &context->ngc_observe; log = context->ngc_log; error = &errorEntity; sleepSec = 0; now = 0; /* Check if the flag is valid */ assert(observe->ngot_stopped == 0); /** * Do observing. */ /* Lock */ result = ngiMutexLock(&observe->ngot_mutex, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't lock the Mutex.\n", fName); return NULL; } #if 0 ngLogPrintf(context->ngc_log, NG_LOG_LEVEL_FATAL, NG_LOG_LEVEL_FATAL, NULL, "%s start...\n", fName); #endif /* Get current time */ now = time(NULL); /* Proceed event time change if necessary */ result = ngcllObserveThreadProceedEventTimeChange( context, observe, now, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Proceeding Observe Thread event time change failed.\n", fName); goto error; } /* Wait the status */ while (observe->ngot_continue != 0) { /* Get sleep time */ result = ngcllObserveThreadGetSleepTime( context, observe, &sleepSec, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Getting Observe Thread sleep time failed.\n", fName); goto error; } /* Cond wait sleep */ result = ngiCondTimedWait( &observe->ngot_cond, &observe->ngot_mutex, sleepSec, &wasTimedOut, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't wait the Condition Variable.\n", fName); goto error; } if (observe->ngot_continue == 0) { break; } /* Get current time */ now = time(NULL); /* Proceed events if necessary */ result = ngcllObserveThreadProceedEvents( context, observe, now, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Proceeding Observe Thread event failed.\n", fName); goto error; } /* Proceed event time change if necessary */ result = ngcllObserveThreadProceedEventTimeChange( context, observe, now, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Proceeding Observe Thread event time change failed.\n", fName); goto error; } } /* Unlock */ result = ngiMutexUnlock(&observe->ngot_mutex, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't unlock the Mutex.\n", fName); return NULL; } /** * Tell the Main Thread that, Observe Thread was stopped. */ /* Lock */ result = ngiMutexLock(&observe->ngot_mutex, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't lock the Mutex.\n", fName); return NULL; } /* Set the status */ observe->ngot_stopped = 1; /* TRUE */ /* Notify signal */ result = ngiCondSignal(&observe->ngot_cond, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't signal the Condition Variable.\n", fName); goto error; } /* Unlock */ result = ngiMutexUnlock(&observe->ngot_mutex, log, error); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't unlock the Mutex.\n", fName); return NULL; } /* Success */ return NULL; error: /* Thread is stopped now */ observe->ngot_stopped = 1; /* TRUE */ /* Unlock */ result = ngiMutexUnlock(&observe->ngot_mutex, log, NULL); if (result == 0) { ngclLogPrintfContext(context, NG_LOG_CATEGORY_NINFG_PURE, NG_LOG_LEVEL_ERROR, NULL, "%s: Can't unlock the Mutex.\n", fName); return NULL; } /* Failed */ return NULL; }