/** * Allocate the information storage. (not Manager) */ ngclLocalMachineInformation_t * ngcliLocalMachineInformationAllocate( ngclContext_t *context, int *error) { int result; ngLog_t *log; ngclLocalMachineInformation_t *lmInfo; static const char fName[] = "ngcliLocalMachineInformationAllocate"; /* Is context valid? */ result = ngcliContextIsValid(context, error); if (result == 0) { ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName, "Ninf-G Context is not valid.\n"); return 0; } log = context->ngc_log; /* Allocate new storage */ lmInfo = ngiCalloc( 1, sizeof (ngclLocalMachineInformation_t), log, error); if (lmInfo == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't allocate the storage " "for LocalMachineInformationManager.\n"); return NULL; } return lmInfo; }
/** * Start the measurement. */ int ngiSessionInformationStartMeasurement( ngSessionInformation_t *info, int nArguments, ngLog_t *log, int *error) { int result; static const char fName[] = "ngiSessionInformationStartMeasurement"; /* Check the arguments */ assert(info != NULL); assert(nArguments >= 0); assert(info->ngsi_compressionInformation == NULL); /* Initialize */ result = ngiSessionInformationInitialize(info, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't initialize the Session Information.\n"); return 0; } /* Allocate the storage for Compression Information */ info->ngsi_nCompressionInformations = nArguments; if (nArguments > 0) { info->ngsi_compressionInformation = ngiCalloc( nArguments, sizeof (*info->ngsi_compressionInformation), log, error); if (info->ngsi_compressionInformation == NULL) { NGI_SET_ERROR(error, NG_ERROR_MEMORY); ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't allocate the storage for Session Information.\n"); return 0; } } /* Success */ return 1; }
/** * Copy the information. */ int ngcliLocalMachineInformationCopy( ngclContext_t *context, ngclLocalMachineInformation_t *src, ngclLocalMachineInformation_t *dest, int *error) { int result; ngLog_t *log; int *signalTable, *newSignalTable, i, size; static const char fName[] = "ngcliLocalMachineInformationCopy"; /* Is context valid? */ result = ngcliContextIsValid(context, error); if (result == 0) { ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName, "Ninf-G Context is not valid.\n"); return 0; } log = context->ngc_log; /* Check the arguments */ if ((src == NULL) || (dest == NULL)) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Invalid argument.\n"); return 0; } /* Initialize the members */ ngcllLocalMachineInformationInitializeMember(dest); /* Copy the members */ *dest = *src; /* Clear pointers for to error-release work fine */ ngcllLocalMachineInformationInitializePointer(dest); /* Copy the strings */ #define NGL_COPY_STRING(src, dest, member) \ do { \ if ((src)->member != NULL) {\ assert((src)->member != NULL); \ (dest)->member = ngiStrdup((src)->member, log, error); \ if ((dest)->member == NULL) { \ ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, \ "Can't allocate the storage " \ "for Local Machine Information.\n"); \ goto error; \ } \ } \ } while(0) NGL_COPY_STRING(src, dest, nglmi_hostName); NGL_COPY_STRING(src, dest, nglmi_tmpDir); NGL_COPY_STRING(src, dest, nglmi_invokeServerLog); NGL_COPY_STRING(src, dest, nglmi_commProxyLog); NGL_COPY_STRING(src, dest, nglmi_infoServiceLog); #undef NGL_COPY_STRING /* Copy the Log Information */ result = ngiLogInformationCopy( &src->nglmi_logInfo, &dest->nglmi_logInfo, log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't copy the Log Information.\n"); goto error; } result = ngiLogLevelInformationCopy( &src->nglmi_logLevels, &dest->nglmi_logLevels, log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't copy the Log Level.\n"); goto error; } size = 0; signalTable = src->nglmi_signals; newSignalTable = NULL; if (signalTable != NULL) { for (; signalTable[size] != 0; size++); newSignalTable = ngiCalloc(sizeof(int), size + 1, log, error); if (newSignalTable == NULL) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't allocate the storage of signal table.\n"); goto error; } for (i = 0; i < (size + 1); i++) { newSignalTable[i] = signalTable[i]; } } dest->nglmi_signals = newSignalTable; return 1; /* Error occurred */ error: /* Release */ result = ngclLocalMachineInformationRelease(context, dest, NULL); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't release the Local Machine Information.\n"); } /* Failed */ return 0; }