bool xme_core_exec_isValidFunctionDescriptor(xme_core_exec_functionDescriptor_t* desc) { XME_CHECK_MSG( NULL != desc, false, XME_LOG_ERROR, MODULE_ACRONYM "isValidFunctionDescriptor: function descriptor is NULL!\n"); XME_CHECK_MSG( XME_CORE_COMPONENT_INVALID_FUNCTION_CONTEXT != desc->functionId, false, XME_LOG_ERROR, MODULE_ACRONYM "isValidFunctionDescriptor: function descriptor [%d|X] has an invalid functionId!\n", desc->componentId); if(!(0 < desc->wcet_ns)) XME_LOG(XME_LOG_WARNING, MODULE_ACRONYM "isValidFunctionDescriptor: function descriptor [%d|%d] has a zero wcet!\n", desc->componentId, desc->functionId); XME_CHECK_MSG( NULL != desc->task, false, XME_LOG_ERROR, MODULE_ACRONYM "isValidFunctionDescriptor: function descriptor [%d|%d] has no task pointer!\n", desc->componentId, desc->functionId); return true; }
extern xme_status_t xme_core_loop_init( void ) { XME_HAL_SINGLYLINKEDLIST_INIT(xme_core_loop_SchedulerData.initQueue); XME_HAL_SINGLYLINKEDLIST_INIT(xme_core_loop_SchedulerData.chunks); /* Registration of the RTE modules */ XME_CHECK_MSG( XME_STATUS_SUCCESS == xme_core_loop_RegisterModulesCallback(), XME_STATUS_INVALID_CONFIGURATION, XME_LOG_FATAL, MODULE_ACRONYM "Could not register RTE modules!\n"); /* A configuration routine to define RTE "chunks" - the basic blocks of RTE module execution on OS level */ XME_CHECK_MSG( XME_STATUS_SUCCESS == xme_core_loop_CreateChunksCallback(), XME_STATUS_INVALID_CONFIGURATION, XME_LOG_FATAL, MODULE_ACRONYM "Could not create RTE chunks!\n"); /* Check the chunks for plausibility and register in EM */ XME_CHECK_MSG( XME_STATUS_SUCCESS == xme_core_loop_completeInitialization(), XME_STATUS_INVALID_CONFIGURATION, XME_LOG_FATAL, MODULE_ACRONYM "Could not complete RTE initialization!\n"); XME_HAL_SINGLYLINKEDLIST_ITERATE_BEGIN(xme_core_loop_SchedulerData.initQueue, xme_core_exec_componentDescriptor_t, compToInit); if(compToInit->autoInit) { XME_LOG(XME_LOG_NOTE, MODULE_ACRONYM "RTE scheduler: initialize component %3d with priority %5d\n", compToInit->componentId, compToInit->initPriority); XME_CHECK_MSG(XME_STATUS_SUCCESS == compToInit->init(compToInit->initParam), XME_STATUS_INVALID_CONFIGURATION, XME_LOG_FATAL, MODULE_ACRONYM "Failure during initialization of the component %d\n", compToInit->componentId); } XME_HAL_SINGLYLINKEDLIST_ITERATE_END(); XME_CHECK( XME_STATUS_SUCCESS == xme_core_loop_ActivateScheduleCallback(), XME_STATUS_INTERNAL_ERROR); return XME_STATUS_SUCCESS; }
/*--------------------------------------------------------------------------*/ xme_status_t xme_core_exec_getTaskState ( xme_core_component_t componentId, xme_core_component_functionId_t functionId, xme_core_exec_functionState_t* taskState ) { xme_core_exec_taskDescriptor_t* task = NULL; xme_status_t status; XME_CHECK_MSG(XME_STATUS_SUCCESS == (status = xme_core_exec_descriptorTable_getTaskDescriptor(componentId, functionId, &task)), status, XME_LOG_WARNING, MODULE_ACRONYM "error getting task descriptor for [%d|%d]\n", componentId, functionId); XME_CHECK(NULL != task, XME_STATUS_INTERNAL_ERROR); /* todo Is locking while reading such a thing necessary? */ xme_hal_sync_enterCriticalSection(taskDescriptorsMutex); *taskState = task->state; xme_hal_sync_leaveCriticalSection(taskDescriptorsMutex); return XME_STATUS_SUCCESS; }
/*--------------------------------------------------------------------------*/ xme_status_t xme_core_exec_dispatcher_createFunctionExecutionUnit ( xme_core_exec_functionDescriptor_t* functionDescriptor, bool eventTriggeredBehavior ) { xme_core_exec_taskDescriptor_t* taskRecord = NULL; if (!xme_core_exec_isInitialized()) return XME_STATUS_UNEXPECTED; XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "> dispatcher_createFunctionExecutionUnit()\n"); XME_CHECK_MSG( true == xme_core_exec_isValidFunctionDescriptor(functionDescriptor), XME_STATUS_INVALID_PARAMETER, XME_LOG_WARNING, "error adding a new task descriptor to the descriptor table.\n"); XME_CHECK_MSG( XME_STATUS_NOT_FOUND == xme_core_exec_descriptorTable_getTaskDescriptor( functionDescriptor->componentId, functionDescriptor->functionId, &taskRecord), XME_STATUS_ALREADY_EXIST, XME_LOG_WARNING, MODULE_ACRONYM "error: the task descriptor exists for [%d|%d]\n", functionDescriptor->componentId, functionDescriptor->functionId); XME_CHECK_MSG( XME_STATUS_SUCCESS == xme_core_exec_dispatcher_addNewTaskDescriptor(&taskRecord), XME_STATUS_INTERNAL_ERROR, XME_LOG_WARNING, "error adding a new task descriptor to the descriptor table.\n"); XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_dispatcher_initializeTaskDescriptor(taskRecord, functionDescriptor, eventTriggeredBehavior), XME_STATUS_INTERNAL_ERROR, XME_LOG_WARNING, "error adding a new task descriptor to the descriptor table.\n"); XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_dispatcher_startRunnable(functionDescriptor), XME_STATUS_INTERNAL_ERROR, XME_LOG_WARNING, "error starting runnable.\n"); XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "< dispatcher_createFunctionExecutionUnit()\n"); return XME_STATUS_SUCCESS; }
xme_status_t sensorMonitor_adv_monitorB_monitorBComponentWrapper_readNextPacket ( sensorMonitor_adv_monitorB_monitorBComponentWrapper_internalPortId_t portId ) { xme_status_t status = XME_STATUS_SUCCESS; #ifdef XME_MULTITHREAD char* accessed; #endif // #ifdef XME_MULTITHREAD XME_ASSERT(portId < inputPortCount); #ifdef XME_MULTITHREAD XME_ASSERT(inputPortAccessed != XME_HAL_TLS_INVALID_TLS_HANDLE); accessed = (char*) xme_hal_tls_get(inputPortAccessed); XME_ASSERT(NULL != accessed); // We need to complete the read operation if the port has been accessed if (accessed[portId / 8U] & (1 << (portId % 8U))) #else // #ifdef XME_MULTITHREAD if (inputPorts[portId].state.locked) #endif // #ifdef XME_MULTITHREAD { status = xme_core_dataHandler_completeReadOperation(inputPorts[portId].dataPacketId); XME_CHECK_MSG ( XME_STATUS_SUCCESS == status, XME_STATUS_INTERNAL_ERROR, XME_LOG_ERROR, "[monitorBComponentWrapper] CompleteReadOperation for port (interalPortId: %d, dataPacketId: %d) returned error code %d.\n", portId, inputPorts[portId].dataPacketId, status ); #ifdef XME_MULTITHREAD accessed[portId / 8U] &= ~(1 << (portId % 8U)); #endif // #ifdef XME_MULTITHREAD inputPorts[portId].state.dataValid = 0; inputPorts[portId].state.attributesValid = 0; inputPorts[portId].state.locked = 0; inputPorts[portId].state.error = 0; } return status; }
xme_status_t xme_core_exec_dispatcher_waitForStart ( xme_core_component_t componentId, xme_core_component_functionId_t functionId, void** functionArguments ) { xme_core_exec_taskDescriptor_t* thisTask = NULL; /* We only deal with an initialized component */ if (!xme_core_exec_isInitialized()) return XME_STATUS_UNEXPECTED; XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "(t): > dispatcher_waitForStart()\n"); XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_descriptorTable_getTaskDescriptor(componentId, functionId, &thisTask), XME_STATUS_NOT_FOUND, XME_LOG_FATAL, MODULE_ACRONYM "task [%d|%d] not present in the task table!\n", componentId, functionId); XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "(t): [%d|%d] waitForStart()\n", componentId, functionId); XME_CHECK(XME_STATUS_SUCCESS == xme_core_exec_dispatcher_requestExecutionToken(thisTask), XME_STATUS_INTERNAL_ERROR); XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "passing %" PRIu32 " to function [%d|%d]\n", (uint32_t)(uintptr_t)startData, componentId, functionId); if (NULL != functionArguments) *functionArguments = startData; /* XXX temporary workaround to allow smooth transition to xme_core_exec_getTaskState() */ thisTask->wrapper->state = thisTask->state; XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "(t): < [%d|%d] dispatcher_waitForStart()\n", componentId, functionId); return XME_STATUS_SUCCESS; }
/*--------------------------------------------------------------------------*/ xme_status_t xme_core_exec_descriptorTable_forEach ( void (*fun)(xme_core_exec_taskDescriptor_t*) ) { XME_CHECK_MSG( fun!=NULL, XME_STATUS_INVALID_PARAMETER, XME_LOG_WARNING, MODULE_ACRONYM "Callback function is NULL!\n"); XME_HAL_TABLE_ITERATE_BEGIN(taskDescriptorsTable, int, rowHandle, xme_core_exec_taskDescriptor_t, curTask); fun(curTask); XME_HAL_TABLE_ITERATE_END(); return XME_STATUS_SUCCESS; }
extern xme_status_t xme_core_loop_addChunkToGlobalSchedule ( xme_core_exec_schedule_handle_t scheduleId, xme_core_loop_Chunk_handle_t chunkId ) { xme_hal_sched_taskHandle_t taskHandle; xme_core_exec_schedule_table_t* schedule = NULL; xme_core_loop_ChunkDescriptor_t* chunkDesc = xme_core_loop_getChunkDescriptor(chunkId); XME_CHECK( NULL != chunkDesc, XME_STATUS_NOT_FOUND); // If a chunk has already been registered, do not do it if(XME_STATUS_NOT_FOUND == xme_core_exec_dispatcher_getRunnable(chunkDesc->executionUnit->componentId, chunkDesc->executionUnit->functionId,&taskHandle)) { XME_LOG(XME_LOG_DEBUG, MODULE_ACRONYM "addToGlobalSchedule(%d, %d)\n", scheduleId, chunkDesc->id); // fixme: hello Lint, ist it ok? XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_dispatcher_createFunctionExecutionUnit( chunkDesc->executionUnit, (bool) false), XME_STATUS_INTERNAL_ERROR, XME_LOG_ERROR, MODULE_ACRONYM "execution unit could not be started\n"); } XME_CHECK(XME_STATUS_SUCCESS == xme_core_exec_scheduler_getSchedule(scheduleId, &schedule), XME_STATUS_NOT_FOUND); return xme_core_exec_scheduler_addElementToScheduleTable( schedule, RTE_BASE_COMPONENT_ID, chunkDesc->id, (xme_core_component_functionVariantId_t)(chunkDesc->id), chunkDesc->startTime_ns, chunkDesc->endTime_ns-chunkDesc->startTime_ns, 0, 0, (bool) true ); }
/*--------------------------------------------------------------------------*/ xme_status_t xme_core_exec_setTaskState ( xme_core_component_t componentId, xme_core_component_functionId_t functionId, xme_core_exec_functionState_t newTaskState ) { xme_core_exec_taskDescriptor_t* task = NULL; XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_descriptorTable_getTaskDescriptor(componentId, functionId, &task), XME_STATUS_INTERNAL_ERROR, XME_LOG_WARNING, MODULE_ACRONYM "error getting task descriptor for [%d|%d]\n", componentId, functionId); XME_CHECK(NULL != task, XME_STATUS_INTERNAL_ERROR); xme_hal_sync_enterCriticalSection(taskDescriptorsMutex); task->state = newTaskState; xme_hal_sync_leaveCriticalSection(taskDescriptorsMutex); return XME_STATUS_SUCCESS; }
xme_status_t setUp(void) { xme_core_broker_initStruct_t brokerParams; xme_core_exec_schedule_handle_t* schedule; printf("fixture:setup\n"); /* Initialization of XME components */ /* Init sync */ XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_hal_sync_init(), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of XME sync Module failed!\n"); /* Init tls */ XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_hal_tls_init(), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of XME tls Module failed!\n"); /* Init sched */ XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_hal_context_init(), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of XME context Module failed!\n"); /* Init sched */ XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_hal_sched_init(), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of XME sched Module failed!\n"); brokerParams.componentId = (xme_core_component_t)BROKER_ID; XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_broker_init(&brokerParams), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of Broker failed!\n"); XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_dataHandler_init(DATAHANDLERMEMORY), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of DataHandler failed!\n"); XME_CHECK_MSG(XME_STATUS_SUCCESS == xme_core_exec_init(NULL), XME_STATUS_INTERNAL_ERROR, XME_LOG_FATAL, MODULE_ACRONYM "Initialization of RTE failed!\n"); XME_HAL_SINGLYLINKEDLIST_INIT(modeList); schedule = (xme_core_exec_schedule_handle_t*) xme_hal_mem_alloc(sizeof(xme_core_exec_schedule_handle_t)); *schedule = (xme_core_exec_schedule_handle_t)LS_NORMAL_OPERATION; XME_HAL_SINGLYLINKEDLIST_ADD_ITEM(modeList, schedule); schedule = (xme_core_exec_schedule_handle_t*)xme_hal_mem_alloc(sizeof(xme_core_exec_schedule_handle_t)); *schedule = (xme_core_exec_schedule_handle_t)LS_NORMAL_OPERATION_INITIALIZE; XME_HAL_SINGLYLINKEDLIST_ADD_ITEM(modeList, schedule); schedule = (xme_core_exec_schedule_handle_t*)xme_hal_mem_alloc(sizeof(xme_core_exec_schedule_handle_t)); *schedule = (xme_core_exec_schedule_handle_t)LS_OFF_OR_SLEEPING; XME_HAL_SINGLYLINKEDLIST_ADD_ITEM(modeList, schedule); /* Instantiate components */ createHelperInstance((xme_core_component_t)1, (xme_core_component_functionId_t)1, 5000000); createHelperInstance((xme_core_component_t)2, (xme_core_component_functionId_t)1, 6000000); createHelperInstance((xme_core_component_t)3, (xme_core_component_functionId_t)1, 4000000); createHelperInstance((xme_core_component_t)4, (xme_core_component_functionId_t)1, 1000000); createHelperInstance((xme_core_component_t)5, (xme_core_component_functionId_t)1, 2000000); /* Create up a schedule set */ { xme_core_exec_schedule_table_t* table=NULL; int i; for(i=0; i<LS_MAX; i++) { xme_core_exec_scheduler_createScheduleTable(&table, xme_hal_time_timeIntervalFromMicroseconds(5000)); xme_core_exec_scheduler_registerSchedule(table, &(schedules[i])); } } return XME_STATUS_SUCCESS; }
void sensorMonitor_adv_common_fillSensorTopic ( xme_core_component_config_t* const componentConfig ) { sensorMonitor_adv_sensorB_sensorBComponent_config_t* config = (sensorMonitor_adv_sensorB_sensorBComponent_config_t*) componentConfig; #ifndef WIN32 // Linux implementation int driveCount = 0; int selectedDrive = 0; FILE* fp; struct mntent *ent; fp = setmntent("/etc/mtab", "r"); while ((ent = getmntent(fp)) != NULL) { if (strcmp(ent->mnt_fsname, "none") == 0 || strcmp(ent->mnt_fsname, "sysfs") == 0 || strcmp(ent->mnt_fsname, "proc") == 0 || strcmp(ent->mnt_fsname, "gvfs-fuse-daemon") == 0 || strcmp(ent->mnt_fsname, "devpts") == 0) { // Ignore this partition continue; } // List this partition XME_LOG(XME_LOG_ALWAYS, "[%d] %s %s\n", driveCount++, ent->mnt_dir, ent->mnt_type); } endmntent(fp); do { XME_LOG(XME_LOG_ALWAYS, "Which partition do you wish to monitor? [0-%d]: ", driveCount-1); if (!scanf("%d", &selectedDrive)) { selectedDrive = -1; } } while (selectedDrive < 0 || selectedDrive> driveCount-1); driveCount = 0; fp = setmntent("/etc/mtab", "r"); while ((ent = getmntent(fp)) != NULL) { if (strcmp(ent->mnt_fsname, "none") == 0 || strcmp(ent->mnt_fsname, "sysfs") == 0 || strcmp(ent->mnt_fsname, "proc") == 0 || strcmp(ent->mnt_fsname, "gvfs-fuse-daemon") == 0 || strcmp(ent->mnt_fsname, "devpts") == 0) { // Ignore this partition continue; } // Check for matching drive if (driveCount++ == selectedDrive) { xme_hal_safeString_strncpy(config->sensorInstance, ent->mnt_dir, sizeof(config->sensorInstance)); break; } } endmntent(fp); #else // #ifndef WIN32 // Windows implementation char szBuffer[1024]; int driveCount = 0; int selectedDrive = 0; unsigned int i; DWORD length; length = GetLogicalDriveStrings(1024, (LPTSTR)szBuffer); XME_CHECK_MSG(0 != length, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "GetLogicalDriveStrings() failed: %d\n", GetLastError()); XME_LOG(XME_LOG_ALWAYS, "The logical drives of this machine are:\n"); for (i = 0U; i < length;) { if (szBuffer[i] != 0) { UINT type = GetDriveType((LPCSTR)(&szBuffer[i])); if (DRIVE_REMOVABLE != type && DRIVE_FIXED != type && DRIVE_RAMDISK != type) { // Ignore this drive i += strlen(&szBuffer[i]) + 1U; continue; } // List this drive XME_LOG(XME_LOG_ALWAYS, "[%d] : %s\n", driveCount++, (LPTSTR)(&szBuffer[i])); i += strlen(&szBuffer[i]) + 1U; } if (0 == szBuffer[i+1]) { i++; } } do { XME_LOG(XME_LOG_ALWAYS, "\nWhich drive do you wish to monitor? [0-%d]: ", driveCount-1); scanf_s("%d", &selectedDrive); } while (selectedDrive < 0 || selectedDrive > driveCount-1); XME_LOG(XME_LOG_ALWAYS, "\n"); driveCount = 0; for (i = 0; i < length;) { if (szBuffer[i] != 0) { UINT type = GetDriveType((LPCSTR)(&szBuffer[i])); if (DRIVE_REMOVABLE != type && DRIVE_FIXED != type && DRIVE_RAMDISK != type) { // Ignore this drive i += strlen(&szBuffer[i]) + 1; continue; } // Check for matching drive if(driveCount++ == selectedDrive) { xme_hal_safeString_strncpy(config->sensorInstance, (LPTSTR)(&szBuffer[i]), sizeof(config->sensorInstance)); break; } i += strlen(&szBuffer[i]) + 1; } if (0 == szBuffer[i+1]) { i++; } } #endif // #ifndef WIN32 }
void userInputTask(void* userData) { char inputBuffer[100]; char cmdBuffer[CMD_BUFFER_SIZE]; command_t* command = (command_t*)xme_hal_mem_alloc(sizeof(command_t)); XME_UNUSED_PARAMETER(userData); XME_LOG ( XME_LOG_ALWAYS, "\nEnter command (to print help type \"help\" without quotes):\n>" ); XME_CHECK ( inputBuffer == fgets(inputBuffer, sizeof(inputBuffer), stdin), XME_CHECK_RVAL_VOID ); #ifdef _MSC_VER (void)sscanf_s(inputBuffer, "%" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE); #else (void)sscanf(inputBuffer, "%" CMD_STRLEN_STRING "s", cmdBuffer); #endif tolowerString(cmdBuffer, cmdBuffer, CMD_BUFFER_SIZE); // TODO: // - Allow nodeName instead of nodeID (add "subscriberNode" 4099) // - Allow componentTypeName instead of componentType (add 2 "subscriber") if (0 == strcmp(cmdBuffer, BUILD_STRING)) { xme_core_node_nodeId_t nodeID; xme_core_componentType_t componentType; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, BUILD_STRING " %d %d", &nodeID, &componentType); #else (void)sscanf(inputBuffer, BUILD_STRING " %d %d", (int*)&nodeID, (int*)&componentType); #endif xme_core_nodeMgr_compRep_cancelBuild(builder); builder = xme_core_nodeMgr_compRep_createBuilder(nodeID, componentType); return; } else if (0 == strcmp(cmdBuffer, SET_QUEUE_SIZE_STRING)) { uint32_t portTypeID; uint32_t queueSize; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, SET_QUEUE_SIZE_STRING " %" PRIu32 " %" PRIu32, &portTypeID, &queueSize); #else (void)sscanf(inputBuffer, SET_QUEUE_SIZE_STRING " %" PRIu32 " %" PRIu32, &portTypeID, &queueSize); #endif XME_CHECK_MSG(queueSize <= UCHAR_MAX, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Maximum queue size is 255.\n"); xme_core_nodeMgr_compRep_builderSetQueueSize(builder, portTypeID, (uint8_t)queueSize); return; } else if (0 == strcmp(cmdBuffer, SET_EXECUTION_PERIOD_STRING)) { uint32_t functionTypeID; xme_hal_time_timeInterval_t execPeriod; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, SET_EXECUTION_PERIOD_STRING " %" PRIu32 " %" PRIu64, &functionTypeID, (uint64_t*)&execPeriod); #else (void)sscanf(inputBuffer, SET_EXECUTION_PERIOD_STRING " %" PRIu32 " %" PRIu64, &functionTypeID, (uint64_t*)&execPeriod); #endif xme_core_nodeMgr_compRep_builderSetExecutionPeriod(builder, functionTypeID, execPeriod); return; } else if (0 == strcmp(cmdBuffer, SET_INITIALIZATION_STRING_STRING)) { char* initializationString; size_t len = xme_hal_safeString_strnlen(inputBuffer, sizeof(inputBuffer)); if (inputBuffer[len-1] == '\n') { inputBuffer[len-1] = 0; } initializationString = &inputBuffer[strlen(SET_INITIALIZATION_STRING_STRING)+1]; xme_core_nodeMgr_compRep_builderSetInitializationString(builder, initializationString); return; } else if (0 == strcmp(cmdBuffer, COMMIT_STRING)) { xme_status_t status; xme_core_nodeMgr_compRep_componentHandle_t componentHandle; status = xme_core_nodeMgr_compRep_build(builder, &componentHandle); builder = NULL; XME_CHECK_MSG(XME_STATUS_SUCCESS == status, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Command could not be executed.\n"); command->commandType = ADD; command->commandData.addComponent.componentHandle = componentHandle; } else if (0 == strcmp(cmdBuffer, ADD_STRING)) { xme_status_t status; xme_core_node_nodeId_t nodeID; xme_core_componentType_t componentType; xme_core_nodeMgr_compRep_componentBuilder_t* addBuilder = NULL; xme_core_nodeMgr_compRep_componentHandle_t componentHandle; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, ADD_STRING " %d %d", &nodeID, &componentType); #else (void)sscanf(inputBuffer, ADD_STRING " %d %d", (int*)&nodeID, (int*)&componentType); #endif addBuilder = xme_core_nodeMgr_compRep_createBuilder(nodeID, componentType); XME_CHECK(NULL != addBuilder, XME_CHECK_RVAL_VOID); status = xme_core_nodeMgr_compRep_build(addBuilder, &componentHandle); XME_CHECK_MSG(XME_STATUS_SUCCESS == status, XME_CHECK_RVAL_VOID, XME_LOG_ERROR, "Command could not be executed.\n"); command->commandType = ADD; command->commandData.addComponent.componentHandle = componentHandle; } else if (0 == strcmp(cmdBuffer, REMOVE_STRING)) { command->commandType = REMOVE; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, REMOVE_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID); #else (void)sscanf(inputBuffer, REMOVE_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID); #endif } else if (0 == strcmp(cmdBuffer, REMOVE2_STRING)) // equivalent alternative for REMOVE_STRING { command->commandType = REMOVE; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, REMOVE2_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID); #else (void)sscanf(inputBuffer, REMOVE2_STRING " %d %d", (int*)&command->commandData.removeComponent.nodeID, &command->commandData.removeComponent.componentID); #endif } else if (0 == strcmp(cmdBuffer, LOGOUT_STRING)) { command->commandType = LOGOUT; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, LOGOUT_STRING " %d", (int*)&command->commandData.logout.nodeID); #else (void)sscanf(inputBuffer, LOGOUT_STRING " %d", (int*)&command->commandData.logout.nodeID); #endif } else if (0 == strcmp(cmdBuffer, LIST_STRING)) { // TODO: Upper case LIST will not work here. More robust parsing needed. #ifdef _MSC_VER (void)sscanf_s(inputBuffer, LIST_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE); #else (void)sscanf(inputBuffer, LIST_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer); #endif tolowerString(cmdBuffer, cmdBuffer, CMD_BUFFER_SIZE); if (0 == strcmp(cmdBuffer, LIST_TYPES_STRING)) { xme_core_manifestRepository_iterator_t iter; xme_core_componentManifest_t* compManifest; iter = xme_core_manifestRepository_initIterator(); XME_LOG(XME_LOG_ALWAYS, "\nContent of manifest repository of this node:\n"); XME_LOG(XME_LOG_ALWAYS, " component type name | component type ID\n"); XME_LOG(XME_LOG_ALWAYS, "---------------------------------|------------------\n"); while (xme_core_manifestRepository_hasNext(iter)) { compManifest = xme_core_manifestRepository_next(&iter); XME_LOG(XME_LOG_NOTE, "%32s | %5d\n", compManifest->name, compManifest->componentType); } xme_core_manifestRepository_finiIterator(iter); return; } else if (0 == strcmp(cmdBuffer, LIST_NODES_STRING)) { // Print list of all nodes in the system char nodeNameBuffer[20]; xme_core_directory_nodeRegistryController_nodeIDIterator_t nodeIDIterator; XME_LOG(XME_LOG_ALWAYS, "\nThe following nodes are registered in the system:\n"); XME_LOG(XME_LOG_ALWAYS, " node name | node ID\n"); XME_LOG(XME_LOG_ALWAYS, "---------------------|--------\n"); xme_core_directory_nodeRegistryController_initNodeIDIterator(&nodeIDIterator); while (xme_core_directory_nodeRegistryController_hasNextNodeID(&nodeIDIterator)) { xme_core_node_nodeId_t nodeID; nodeID = xme_core_directory_nodeRegistryController_nextNodeID(&nodeIDIterator); xme_core_directory_nodeRegistryController_getNodeName(nodeID, nodeNameBuffer, sizeof(nodeNameBuffer)); XME_LOG(XME_LOG_NOTE, "%20s | %2d\n", nodeNameBuffer, nodeID); } xme_core_directory_nodeRegistryController_finiNodeIDIterator(&nodeIDIterator); return; } else if (0 == strcmp(cmdBuffer, LIST_COMPONENTS_STRING)) { // Print list of all components in the system bool verbose = false; char nodeNameBuffer[20]; char portBuffer[6]; char functionBuffer[30]; #ifdef _MSC_VER (void)sscanf_s(inputBuffer, LIST_STRING " " LIST_COMPONENTS_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer, CMD_BUFFER_SIZE); #else (void)sscanf(inputBuffer, LIST_STRING " " LIST_COMPONENTS_STRING " %" CMD_STRLEN_STRING "s", cmdBuffer); #endif if (0 == strcmp(cmdBuffer, LIST_COMPONENTS_VERBOSE_STRING)) { verbose = true; } XME_LOG(XME_LOG_ALWAYS, "\nThe following components are registered in the system:\n"); if (verbose) { XME_LOG(XME_LOG_ALWAYS, " | comp. | | port: | function:\n"); XME_LOG(XME_LOG_ALWAYS, " node name (ID) | ID | comp. type name (ID) | queue | exec.period\n"); XME_LOG(XME_LOG_ALWAYS, "----------------------|-------|---------------------------|-------|------------\n"); } else { XME_LOG(XME_LOG_ALWAYS, " | comp. |\n"); XME_LOG(XME_LOG_ALWAYS, " node name (ID) | ID | comp. type name (ID)\n"); XME_LOG(XME_LOG_ALWAYS, "----------------------|-------|--------------------------\n"); } xme_core_nodeMgr_compRep_componentIteratorInit(); while (xme_core_nodeMgr_compRep_componentIteratorHasNext()) { xme_core_node_nodeId_t nodeID; xme_core_component_t componentID; xme_core_componentType_t componentType; xme_core_componentManifest_t manifest; xme_core_nodeMgr_compRep_componentHandle_t componentHandle; xme_core_nodeMgr_compRep_portHandle_t portHandle; xme_core_nodeMgr_compRep_functionHandle_t functionHandle; uint16_t i = 0u; componentHandle = xme_core_nodeMgr_compRep_componentIteratorNext(); nodeID = xme_core_nodeMgr_compRep_getNodeID(componentHandle); componentID = xme_core_nodeMgr_compRep_getComponentID(componentHandle); componentType = xme_core_nodeMgr_compRep_getComponentType(componentHandle); xme_core_manifestRepository_findComponentManifest(componentType, &manifest); xme_core_directory_nodeRegistryController_getNodeName(nodeID, nodeNameBuffer, sizeof(nodeNameBuffer)); if (verbose) { XME_LOG(XME_LOG_NOTE, "%16s (%2d) | %5d | %17s (%5d) | |\n", nodeNameBuffer, nodeID, componentID, manifest.name, componentType); } else { XME_LOG(XME_LOG_NOTE, "%16s (%2d) | %5d | %17s (%5d)\n", nodeNameBuffer, nodeID, componentID, manifest.name, componentType); } if (verbose) { i = 0u; do { uint16_t queueSize; xme_hal_time_timeInterval_t execPeriod; portHandle = xme_core_nodeMgr_compRep_getPort(componentHandle, i); if (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != portHandle) { queueSize = xme_core_nodeMgr_compRep_getQueueSize(portHandle); xme_hal_safeString_snprintf(portBuffer, sizeof(portBuffer), "%2d:%2" PRIu16, i, queueSize); } else { xme_hal_safeString_snprintf(portBuffer, sizeof(portBuffer), " "); } functionHandle = xme_core_nodeMgr_compRep_getFunction(componentHandle, i); if (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != functionHandle) { execPeriod = xme_core_nodeMgr_compRep_getExecutionPeriod(portHandle); if (0ull == execPeriod || 1000000ull < execPeriod) { execPeriod = execPeriod / 1000000ull; xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), "%2d:%2" PRIu64 "ms", i, execPeriod); } else { xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), "%2d:%2" PRIu64 "ns", i, execPeriod); } } else { xme_hal_safeString_snprintf(functionBuffer, sizeof(functionBuffer), " "); } XME_LOG(XME_LOG_NOTE, " | | | %s | %s\n", portBuffer, functionBuffer); i++; } while (XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != portHandle && XME_CORE_NODEMGR_COMPREP_INVALID_HANDLE != functionHandle); } } xme_core_nodeMgr_compRep_componentIteratorFini(); return; } else { XME_LOG(XME_LOG_ERROR, "Unknown command. Enter help to print available commands."); return; } } else if (0 == strcmp(cmdBuffer, HELP_STRING)) { XME_LOG ( XME_LOG_ALWAYS, "Enter one of the following commands:\n" "COMMAND [PARAMS...] DESCRIPTION\n" "add <nodeID> <componentType> Adds a new component of the given component type\n" " to the given node.\n" "rem <nodeID> <componentID> Removes the given component instance from the\n" " given node.\n" "logout <nodeID> Trigger logout of the given node.\n" "list nodes Prints list of all nodes.\n" "list components Prints list of all components.\n" "list components verbose Prints list of all components with verbose\n" " information.\n" "list types Prints list of all component types.\n" "\n" "Advanced options for building a component:\n" "build <nodeID> <componentType> Like \"add\", but the component is not immediately\n" " added. Use the following functions to further\n" " refine the component definition.\n" "setqs <portTypeID> <queueSize> Set queue size of the given port to the given\n" " value.\n" "setep <functTypeID> <timeInNs> Set execution period of the given function to\n" " the given time value in nanoseconds.\n" "setis <initializationString> Set the initialization string for the new\n" "commit component. Finally add the constructed component.\n" ); return; } else { XME_LOG(XME_LOG_ERROR, "Unknown command. Enter help to print available commands."); return; } xme_hal_sync_enterCriticalSection(commandQueueMutex); xme_hal_singlyLinkedList_addItem(&commandQueue, command); xme_hal_sync_leaveCriticalSection(commandQueueMutex); }
void sensorMonitor_adv_logoutTrigger_triggerFunction_step ( sensorMonitor_adv_logoutTrigger_logoutTriggerComponent_config_t* const componentConfig ) { { // PROTECTED REGION ID(SENSORMONITOR_ADV_LOGOUTTRIGGER_TRIGGERFUNCTION_STEP_C) ENABLED START //counter determines the number of iteration when loggedOutNode will be send a message to log out from the ecosystem static int counter = 70; char loggedOutNode[20] = "lonelyNode"; XME_UNUSED_PARAMETER(componentConfig); if (1 == counter) { xme_core_directory_nodeRegistryController_nodeIDIterator_t nodeIDIterator; char nodeNameBuffer[20]; xme_core_node_nodeId_t nodeID = XME_CORE_NODE_INVALID_NODE_ID; xme_core_directory_nodeRegistryController_initNodeIDIterator(&nodeIDIterator); while (xme_core_directory_nodeRegistryController_hasNextNodeID(&nodeIDIterator)) { nodeID = xme_core_directory_nodeRegistryController_nextNodeID(&nodeIDIterator); xme_core_directory_nodeRegistryController_getNodeName(nodeID, nodeNameBuffer, sizeof(nodeNameBuffer)); if (0 == xme_hal_mem_compare(loggedOutNode, nodeNameBuffer, strlen(loggedOutNode))) { break; } nodeID = XME_CORE_NODE_INVALID_NODE_ID; } xme_core_directory_nodeRegistryController_finiNodeIDIterator(&nodeIDIterator); if (XME_CORE_NODE_INVALID_NODE_ID != nodeID) { XME_CHECK_MSG ( XME_STATUS_SUCCESS == xme_core_pnp_pnpManager_unannounceNode(nodeID), XME_CHECK_RVAL_VOID, XME_LOG_WARNING, "[logoutTrigger/tiggerFunction] Cannot process the logout request.\n" ); } } if (0 != counter) { counter--; } // PROTECTED REGION END } { // PROTECTED REGION ID(SENSORMONITOR_ADV_LOGOUTTRIGGER_TRIGGERFUNCTION_STEP_2_C) ENABLED START // TODO: Auto-generated stub // Check return values of writePort calls here // PROTECTED REGION END } }