/** * 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) { ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Can't finalize the Session Information.\n"); return 0; } result = NGI_DEALLOCATE(ngSessionInformation_t, info, log, error); if (result == 0) { ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Can't deallocate the storage for Session Information.\n"); return 0; } /* Success */ return 1; }
/** * Release. */ int ngclLocalMachineInformationRelease( ngclContext_t *context, ngclLocalMachineInformation_t *lmInfo, int *error) { int local_error, result; static const char fName[] = "ngclLocalMachineInformationRelease"; /* Clear the error */ NGI_SET_ERROR(&local_error, NG_ERROR_NO_ERROR); /* Is context valid? */ result = ngcliContextIsValid(context, &local_error); if (result == 0) { ngLogFatal(NULL, NG_LOGCAT_NINFG_PURE, fName, "Ninf-G Context is not valid.\n"); NGI_SET_ERROR(error, local_error); return 0; } result = ngcllLocalMachineInformationRelease(context, lmInfo, &local_error); NGI_SET_ERROR_CONTEXT(context, local_error, NULL); NGI_SET_ERROR(error, local_error); return result; }
/** * Free the information storage. (not Manager) */ int ngcliLocalMachineInformationFree( ngclContext_t *context, ngclLocalMachineInformation_t *lmInfo, int *error) { int result; ngLog_t *log; static const char fName[] = "ngcliLocalMachineInformationFree"; /* 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 (lmInfo == NULL) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Invalid argument.\n"); return 0; } ngiFree(lmInfo, log, error); return 1; }
/** * 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; }
/** * Get the information. * * Note: * Lock the list before using this function, and unlock the list after use. */ ngcliLocalMachineInformationManager_t * ngcliLocalMachineInformationCacheGet( ngclContext_t *context, int *error) { int result; static const char fName[] = "ngcliLocalMachineInformationCacheGet"; /* 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 NULL; } if (context->ngc_lmInfo == NULL) { /* Not found */ NGI_SET_ERROR(error, NG_ERROR_NOT_EXIST); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't get LocalMachineInformation list.\n"); return NULL; } return context->ngc_lmInfo; }
/** * Information delete. */ int ngcliLocalMachineInformationCacheUnregister( ngclContext_t *context, int *error) { int result; static const char fName[] = "ngcliLocalMachineInformationCacheUnregister"; /* 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; } /* Lock the list */ result = ngcliLocalMachineInformationListWriteLock(context, context->ngc_log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't lock LocalMachineInformation list.\n"); return 0; } /* Is information registered? */ if (context->ngc_lmInfo == NULL) { /* Not registered */ NGI_SET_ERROR(error, NG_ERROR_NOT_EXIST); ngcliLocalMachineInformationListWriteUnlock(context, context->ngc_log, NULL); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't unregister DefaultRemoteMachineInformation list.\n"); return 0; } /* Delete */ result = ngcllLocalMachineInformationDestruct( context, context->ngc_lmInfo, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't destruct LocalMachineInformation.\n"); return 0; } /* Unlock the list */ result = ngcliLocalMachineInformationListWriteUnlock(context, context->ngc_log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't unlock LocalMachineInformation list.\n"); return 0; } return 1; }
/** * Initialize the members. */ int ngcliLocalMachineInformationInitialize( ngclContext_t *context, ngclLocalMachineInformation_t *lmInfo, int *error) { int result; ngLog_t *log; static const char fName[] = "ngcliLocalMachineInformationInitialize"; /* 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 (lmInfo == NULL) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Invalid argument.\n"); return 0; } ngcllLocalMachineInformationInitializeMember(lmInfo); result = ngiLogInformationInitialize(&lmInfo->nglmi_logInfo, log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't initialize the log information.\n"); return 0; } result = ngiLogLevelInformationInitialize(&lmInfo->nglmi_logLevels, log, error); if (result == 0) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't initialize the log levels.\n"); return 0; } /* Success */ return 1; }
/** * Information append. */ int ngcliLocalMachineInformationCacheRegister( ngclContext_t *context, ngclLocalMachineInformation_t *lmInfo, int *error) { int result; ngcliLocalMachineInformationManager_t *lmInfoMng; static const char fName[] = "ngcliLocalMachineInformationCacheRegister"; /* 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; } /* Check the arguments */ if (lmInfo == NULL) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Invalid argument.\n"); return 0; } /* Note : No Replace for Local Machine Information. */ /* Construct */ lmInfoMng = ngcllLocalMachineInformationConstruct(context, lmInfo, error); if (lmInfoMng == NULL) { ngclLogErrorContext(context, NG_LOGCAT_NINFG_PURE, fName, "Can't construct Local Machine Information.\n"); return 0; } /* Success */ return 1; }
static int ngexlStubGetArgument(int argumentNo, void *data, int *error) { int result; int methodID; ngLog_t *log; ngiArgument_t *arg; ngiArgumentPointer_t src, dest; ngRemoteMethodInformation_t *rmInfo; ngexiContext_t *context; static const char fName[] = "ngexlStubGetArgument"; static const ngexiExecutableStatus_t reqStatus[] = { NGEXI_EXECUTABLE_STATUS_CALCULATING, }; /* Initialize the local variables */ context = &ngexiContext; log = context->ngc_log; /* Get methodID */ methodID = ngexiContextGetMethodID(context); /* log */ ngLogInfo(log, NG_LOGCAT_NINFG_PURE, fName, "Getting argument %3d for method %d from Context.\n", argumentNo, methodID); /* Check the status */ result = ngexiContextExecutableStatusCheck( context, &reqStatus[0], NGI_NELEMENTS(reqStatus), log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Invalid state.\n"); return 0; } /* Get the Method Information */ rmInfo = ngexiRemoteMethodInformationGet( context, methodID, log, error); if (rmInfo == NULL) { ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Remote Method Information is not found.\n"); return 0; } /* Get the Argument Data */ ngexiContextGetMethodArgument(context, &arg); if (arg == NULL) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Argument Data is NULL.\n"); return 0; } if (arg->nga_nArguments < 0) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "The number of Argument Data is smaller than zero.\n"); return 0; } if (arg->nga_nArguments > rmInfo->ngrmi_nArguments) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "The number of Argument Data %d is greater than maximum %d.\n", arg->nga_nArguments, rmInfo->ngrmi_nArguments); return 0; } if (argumentNo < 0) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "The requested Argument No. %d is smaller equal zero.\n", argumentNo); return 0; } if (argumentNo >= rmInfo->ngrmi_nArguments) { NGI_SET_ERROR(error, NG_ERROR_INVALID_ARGUMENT); ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "The number of Argument Data %d is greater than maximum %d.\n", argumentNo, rmInfo->ngrmi_nArguments); return 0; } /* Is argument scalar variable? */ src = arg->nga_argument[argumentNo].ngae_pointer; if (arg->nga_argument[argumentNo].ngae_dataType == NG_ARGUMENT_DATA_TYPE_FILENAME) { if (arg->nga_argument[argumentNo].ngae_tmpFileNameTable == NULL) { *(char **)data = NULL; } else if (arg->nga_argument[argumentNo].ngae_nDimensions <= 0) { *(char **)data = arg->nga_argument[argumentNo].ngae_tmpFileNameTable[0]; } else { *(char ***)data = arg->nga_argument[argumentNo].ngae_tmpFileNameTable; } } else if (arg->nga_argument[argumentNo].ngae_dataType == NG_ARGUMENT_DATA_TYPE_STRING) { if (src.ngap_string == NULL) { *(char **)data = NULL; } else if (arg->nga_argument[argumentNo].ngae_nDimensions <= 0) { *(char **)data = src.ngap_stringArray[0]; } else { *(char ***)data = src.ngap_stringArray; } } else if (arg->nga_argument[argumentNo].ngae_nDimensions != 0) { *(void **)data = src.ngap_void; } else { dest.ngap_void = data; result = ngiGetArgumentData( arg->nga_argument[argumentNo].ngae_dataType, src, dest, log, error); if (result == 0) { ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Can't get the Argument Data.\n"); return 0; } } /* log */ ngLogDebug(log, NG_LOGCAT_NINFG_PURE, fName, "Getting argument %3d for method %d finished.\n", argumentNo, methodID); /* Success */ return 1; }
/** * Callback function is performed. */ int ngexStubCallback(int callbackID, int *error, ...) { int result; va_list ap; int finished; int methodID; char *string; ngLog_t *log; int i, count = 0; ngiProtocol_t *protocol; ngexiContext_t *context; ngexiExecutableStatus_t status; ngiArgument_t *arg, *callbackArg; ngRemoteMethodInformation_t *rmInfo, *rmInfoCallback; static const char fName[] = "ngexStubCallback"; static ngexiExecutableStatus_t waitStatus[] = { NGEXI_EXECUTABLE_STATUS_CALCULATING, NGEXI_EXECUTABLE_STATUS_CANCEL_REQUESTED, NGEXI_EXECUTABLE_STATUS_RESET_REQUESTED, NGEXI_EXECUTABLE_STATUS_EXIT_REQUESTED, NGEXI_EXECUTABLE_STATUS_END, }; /* Initialize the local variables */ context = &ngexiContext; protocol = context->ngc_protocol; log = context->ngc_log; /* log */ ngLogInfo(log, NG_LOGCAT_NINFG_PURE, fName, "Performing callback (id=%d).\n", callbackID); /* Get status */ status = ngexiContextExecutableStatusGet(context, error); /* Check Status */ switch(status) { case NGEXI_EXECUTABLE_STATUS_CALCULATING: /* Do nothing, go next */ break; case NGEXI_EXECUTABLE_STATUS_CANCEL_REQUESTED: case NGEXI_EXECUTABLE_STATUS_RESET_REQUESTED: case NGEXI_EXECUTABLE_STATUS_EXIT_REQUESTED: case NGEXI_EXECUTABLE_STATUS_PULL_WAIT: case NGEXI_EXECUTABLE_STATUS_END: NGI_SET_ERROR(error, NG_ERROR_INVALID_STATE); ngLogInfo(log, NG_LOGCAT_NINFG_PURE, fName, "The session is already canceled. (status=%d)\n", status); return 0; default: NGI_SET_ERROR(error, NG_ERROR_INVALID_STATE); ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Unexpected state: %d.\n", status); return 0; } /* Set the callback ID to Protocol */ result = ngiProtocolSetCallbackID(protocol, callbackID, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't set the callback ID.\n"); return 0; } /* Get the argument pointer */ va_start(ap, error); /* Get the Method Information */ methodID = ngexiContextGetMethodID(context); rmInfo = ngexiRemoteMethodInformationGet( context, methodID, log, error); if (rmInfo == NULL) { ngLogFatal(log, NG_LOGCAT_NINFG_PURE, fName, "Remote Method Information is not found.\n"); return 0; } for (i = 0; i < rmInfo->ngrmi_nArguments; i++) { if (rmInfo->ngrmi_arguments[i].ngai_dataType == NG_ARGUMENT_DATA_TYPE_CALLBACK) { if (count == callbackID) { break; } count += 1; } } if ((i == rmInfo->ngrmi_nArguments) && (count != callbackID)) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Callback ID %d is not valid.\n", callbackID); return 0; } rmInfoCallback = rmInfo->ngrmi_arguments[i].ngai_callback; /* Get the argument */ ngexiContextGetMethodArgument(&ngexiContext, &arg); if (arg == NULL) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't get the argument.\n"); return 0; } /* Construct the Argument */ callbackArg = ngiArgumentConstruct( rmInfoCallback->ngrmi_arguments, rmInfoCallback->ngrmi_nArguments, log, error); if (callbackArg == NULL) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't construct the argument.\n"); return 0; } result = ngiArgumentElementInitializeVarg( callbackArg, rmInfoCallback->ngrmi_nArguments, ap, NGI_ARGUMENT_DELIVERY_C, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't initialize the Argument Element.\n"); return 0; } /* Initialize the Subscript Value of Argument */ result = ngiArgumentInitializeSubscriptValue( callbackArg, arg, rmInfoCallback->ngrmi_arguments, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't initialize the Argument Element.\n"); return 0; } /* Check the Subscript Value of Argument */ result = ngiArgumentCheckSubscriptValue(callbackArg, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Subscript Value of Argument is not valid.\n"); goto error; } /* Set the Argument for Callback*/ ngexiContextSetCallbackArgument(context, callbackArg); /* Set the argument to protocol */ result = ngiProtocolSetCallbackArgument(protocol, callbackArg, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't set the argument to protocol.\n"); return 0; } /* Send Notify Invoke Callback */ result = ngexiProtocolNotifyInvokeCallback( context, protocol, callbackID, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't set executable ID to protocol.\n"); return 0; } /* Increment the number of times to which the callback was called */ context->ngc_sessionInfo.ngsi_callbackNtimesCalled++; finished = 0; while (finished == 0) { /* Wait the status */ result = ngexiContextExecutableStatusWait( context, &waitStatus[0], NGI_NELEMENTS(waitStatus), &status, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PURE, fName, "Can't wait the status.\n"); goto error; } switch (status) { case NGEXI_EXECUTABLE_STATUS_CANCEL_REQUESTED: case NGEXI_EXECUTABLE_STATUS_RESET_REQUESTED: case NGEXI_EXECUTABLE_STATUS_EXIT_REQUESTED: /* Do not reply. reply is treated by ngexStubGetRequest */ finished = 1; break; case NGEXI_EXECUTABLE_STATUS_CALCULATING: finished = 1; break; case NGEXI_EXECUTABLE_STATUS_END: default: /* log */ string = ngexiContextExecutableStatusStringGet(status, log, NULL); if (string == NULL) { string = "Not valid status"; } ngLogWarn(log, NG_LOGCAT_NINFG_PURE, fName, "Unexpected status \"%s\":%d was found.\n", string, status); goto error; } } /* Release the argument pointer */ va_end(ap); /* Release the argument to protocol */ result = ngiProtocolReleaseCallbackArgument(protocol, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't release the argument to protocol.\n"); return 0; } /* Release the callback ID to protocol */ result = ngiProtocolReleaseCallbackID(protocol, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't release the callback ID to protocol.\n"); return 0; } /* Check canceled */ switch (status) { case NGEXI_EXECUTABLE_STATUS_CANCEL_REQUESTED: case NGEXI_EXECUTABLE_STATUS_RESET_REQUESTED: case NGEXI_EXECUTABLE_STATUS_EXIT_REQUESTED: return 0; default: break; } /* log */ ngLogInfo(log, NG_LOGCAT_NINFG_PURE, fName, "The callback was successfully done (id=%d).\n", callbackID); /* Success */ return 1; /* Error occurred */ error: /* Release the argument pointer */ va_end(ap); /* Release the argument to protocol */ result = ngiProtocolReleaseCallbackArgument(protocol, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't release the argument to protocol.\n"); } /* Release the callback ID to protocol */ result = ngiProtocolReleaseCallbackID(protocol, log, error); if (result == 0) { ngLogError(log, NG_LOGCAT_NINFG_PROTOCOL, fName, "Can't release the callback ID to protocol.\n"); } /* Initialize the IDs */ ngiProtocolInitializeID(protocol); return 0; }
/** * 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; }