// Function: cmptStartup // Access: Public // Description: This function allows the abstracted component functionality contained in this file to be started from an external source. // It must be called first before the component state machine and node manager interaction will begin // Each call to "cmptStartup" should be followed by one call to the "cmptShutdown" function int cmptStartup(void) { FILE * propertyFile; pthread_attr_t attr; // Thread attributed for the component threads spawned in this function if(cmpt->state == JAUS_SHUTDOWN_STATE) // Execute the startup routines only if the component is not running { propertyFile = fopen("./config/cmpt.conf", "r"); if(propertyFile) { cmptProperties = propertiesCreate(); cmptProperties = propertiesLoad(cmptProperties, propertyFile); fclose(propertyFile); } else { cError("cmpt: Cannot find or open properties file\n"); return CMPT_LOAD_CONFIGURATION_ERROR; } // Check in to the Node Manager and obtain Instance, Node and Subsystem IDs cmptNode = jausNodeCreate(); cmptSubsystem = jausSubsystemCreate(); cmptNode->subsystem = cmptSubsystem; cmpt->node = cmptNode; cmpt->services = jausServicesCreate(); cmpt->state = JAUS_INITIALIZE_STATE; // Set the state of the JAUS state machine to INITIALIZE cmptNmi = nodeManagerOpen(cmpt); if(cmptNmi == NULL) { cError("cmpt: Could not open connection to node manager\n"); return CMPT_NODE_MANAGER_OPEN_ERROR; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); cmptRun = TRUE; if(pthread_create(&cmptThreadId, &attr, cmptThread, NULL) != 0) { cError("cmpt: Could not create cmptThread\n"); cmptShutdown(); pthread_attr_destroy(&attr); return CMPT_THREAD_CREATE_ERROR; } pthread_attr_destroy(&attr); } else { cError("cmpt: Attempted startup while not shutdown\n"); return CMPT_STARTUP_BEFORE_SHUTDOWN_ERROR; } return 0; }
int vehicleSimStartup(void) { FILE * propertyFile = NULL; char *property = NULL; pthread_attr_t attr; // Thread attributed for the component threads spawned in this function char fileName[128] = {0}; // Create vehiclePosLla object vehiclePosLla = pointLlaCreate(); if(!vehiclePosLla) { //cError("vehicleSim: Could not create vehicleSimThread\n"); vehicleSimShutdown(); return VEHICLE_SIM_MALLOC_ERROR; } sprintf(fileName, "%svehicleSim.conf", CONFIG_DIRECTORY); propertyFile = fopen(fileName, "r"); if(propertyFile) { vehicleSimProperties = propertiesCreate(); vehicleSimProperties = propertiesLoad(vehicleSimProperties, propertyFile); fclose(propertyFile); } else { //cError("vehicleSim: Cannot find or open properties file\n"); return VEHICLE_SIM_LOAD_CONFIGURATION_ERROR; } property = propertiesGetProperty(vehicleSimProperties, "INITIAL_LAT_DEGREES"); if(property) { vehiclePosLla->latitudeRadians = atof( property ); //cDebug(3, "vehicleSim: Property loaded INITIAL_LAT_DEGREES: %lf\n", vehiclePosLla->latitudeRadians); vehiclePosLla->latitudeRadians *= RAD_PER_DEG; } else { //cDebug(3, "vehicleSim: Property INITIAL_LAT_DEGREES not found, using default value: %lf\n", vehiclePosLla->latitudeRadians); } property = propertiesGetProperty(vehicleSimProperties, "INITIAL_LON_DEGREES"); if(property) { vehiclePosLla->longitudeRadians = atof( property ); //cDebug(3, "vehicleSim: Property loaded INITIAL_LON_DEGREES: %lf\n", vehiclePosLla->longitudeRadians); vehiclePosLla->longitudeRadians *= RAD_PER_DEG; } else { //cDebug(3, "vehicleSim: Property INITIAL_LON_DEGREES not found, using default value: %lf\n", vehiclePosLla->longitudeRadians); } property = propertiesGetProperty(vehicleSimProperties, "INITIAL_HEADING_DEGREES"); if(property) { vehicleH = atof( property ); //cDebug(3, "vehicleSim: Property loaded INITIAL_HEADING_DEGREES: %lf\n", vehicleH); } else { //cDebug(3, "vehicleSim: Property INITIAL_HEADING_DEGREES not found, using default value: %lf\n", vehicleH); } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); vehicleSimRun = TRUE; if(pthread_create(&vehicleSimThreadId, &attr, vehicleSimThread, NULL) != 0) { //cError("vehicleSim: Could not create vehicleSimThread\n"); vehicleSimShutdown(); pthread_attr_destroy(&attr); return VEHICLE_SIM_THREAD_CREATE_ERROR; } pthread_attr_destroy(&attr); return 0; }
// Function: wdStartup // Access: Public // Description: This function allows the abstracted component functionality contained in this file to be started from an external source. // It must be called first before the component state machine and node manager interaction will begin // Each call to "wdStartup" should be followed by one call to the "wdShutdown" function int wdStartup(void) { FILE * propertyFile; pthread_attr_t attr; // Thread attributed for the component threads spawned in this function char fileName[128] = {0}; if(!wd) { wd = jausComponentCreate(); wd->address->component = JAUS_GLOBAL_WAYPOINT_DRIVER; wd->identification = "Waypoint Driver"; wd->state = JAUS_SHUTDOWN_STATE; } if(wd->state == JAUS_SHUTDOWN_STATE) // Execute the startup routines only if the component is not running { sprintf(fileName, "%swd.conf", CONFIG_DIRECTORY); propertyFile = fopen(fileName, "r"); if(propertyFile) { wdProperties = propertiesCreate(); wdProperties = propertiesLoad(wdProperties, propertyFile); fclose(propertyFile); } else { //cError("wd: Cannot find or open properties file\n"); return WD_LOAD_CONFIGURATION_ERROR; } // Check in to the Node Manager and obtain Instance, Node and Subsystem IDs wdNode = jausNodeCreate(); wdSubsystem = jausSubsystemCreate(); wdNode->subsystem = wdSubsystem; wd->node = wdNode; wd->services = jausServicesCreate(); wd->state = JAUS_INITIALIZE_STATE; // Set the state of the JAUS state machine to INITIALIZE wdNmi = nodeManagerOpen(wd); if(wdNmi == NULL) { //cError("wd: Could not open connection to node manager\n"); return WD_NODE_MANAGER_OPEN_ERROR; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); wdRun = TRUE; if(pthread_create(&wdThreadId, &attr, wdThread, NULL) != 0) { //cError("wd: Could not create wdThread\n"); wdShutdown(); pthread_attr_destroy(&attr); return WD_THREAD_CREATE_ERROR; } pthread_attr_destroy(&attr); } else { //cError("wd: Attempted startup while not shutdown\n"); return WD_STARTUP_BEFORE_SHUTDOWN_ERROR; } return 0; }