int rtm_run(struct fins_module *module, pthread_attr_t *attr) { PRINT_DEBUG("Entered: module=%p, attr=%p", module, attr); module->state = FMS_RUNNING; rtm_get_ff(module); struct rtm_data *md = (struct rtm_data *) module->data; secure_pthread_create(&md->switch_to_rtm_thread, attr, switch_to_rtm, module); secure_pthread_create(&md->accept_console_thread, attr, accept_console, module); secure_pthread_create(&md->console_to_rtm_thread, attr, console_to_rtm, module); return 1; }
void *switch_to_rtm(void *local) { struct fins_module *module = (struct fins_module *) local; PRINT_IMPORTANT("Entered: module=%p", module); while (module->state == FMS_RUNNING) { rtm_get_ff(module); PRINT_DEBUG(""); } PRINT_IMPORTANT("Exited: module=%p", module); return NULL; }
void *switch_to_rtm(void *local) { struct fins_module *module = (struct fins_module *) local; PRINT_DEBUG("Entered: module=%p", module); PRINT_IMPORTANT("Thread started: module=%p, index=%u, id=%u, name='%s'", module, module->index, module->id, module->name); while (module->state == FMS_RUNNING) { rtm_get_ff(module); PRINT_DEBUG(""); } PRINT_IMPORTANT("Thread exited: module=%p, index=%u, id=%u, name='%s'", module, module->index, module->id, module->name); PRINT_DEBUG("Exited: module=%p", module); return NULL; }
//RTM's main function //Gets information from RTM_IN pipe //Is started as a thread in core.c void rtm_init(pthread_attr_t *fins_pthread_attr) { PRINT_IMPORTANT("RTM has started"); /* //added to include code from fins_daemon.sh -- mrd015 !!!!! //TODO move this to RTM module if (mkfifo(RTM_PIPE_IN, 0777) != 0) { if (errno == EEXIST) { PRINT_DEBUG("mkfifo(" RTM_PIPE_IN ", 0777) already exists."); } else { PRINT_ERROR("mkfifo(" RTM_PIPE_IN ", 0777) failed."); exit(-1); } } if (mkfifo(RTM_PIPE_OUT, 0777) != 0) { if (errno == EEXIST) { PRINT_DEBUG("mkfifo(" RTM_PIPE_OUT ", 0777) already exists."); } else { PRINT_ERROR("mkfifo(" RTM_PIPE_OUT ", 0777) failed."); exit(-1); } } */ //int datalen; int numBytes; //int val_len; int temp_serial_cntr = 0; unsigned char* serialized_FCF = NULL; int length_serialized_FCF; //create a finsframe to be sent tover the queue struct finsFrame *fins_frame = (struct finsFrame *) secure_malloc(sizeof(struct finsFrame)); fins_frame->dataOrCtrl = CONTROL; //opens the pipe from clicomm (or wherever) rtm_in_fd = open(RTM_PIPE_IN, O_RDWR); if (rtm_in_fd == -1) { PRINT_DEBUG("rtm_in_fd Pipe failure "); exit(EXIT_FAILURE); } fflush(stdout); while (1) { temp_serial_cntr++; //used as a temporary serial_number generator //READ FROM PIPE RTM_IN numBytes = 0; numBytes += read(rtm_in_fd, &length_serialized_FCF, sizeof(int)); //length of incoming serialized FCF numBytes += read(rtm_in_fd, serialized_FCF, length_serialized_FCF); //incoming serialized FCF fins_frame = unserializeCtrlFrame(serialized_FCF, length_serialized_FCF); //value, Assumption was made, notice the size PRINT_DEBUG("received data"); numBytes = 0; //ERROR Message fflush(stdout); if (numBytes >= 0) { PRINT_DEBUG("numBytes written %d", numBytes); } //CHANGE SenderID and SerialNum fins_frame->ctrlFrame.senderID = RTM_ID; fins_frame->ctrlFrame.serial_num = temp_serial_cntr; //SEND TO QUEUE secure_sem_wait(&RTM_to_Switch_Qsem); write_queue(fins_frame, RTM_to_Switch_Queue); sem_post(&RTM_to_Switch_Qsem); PRINT_DEBUG("sent data "); //READ FROM QUEUE rtm_get_ff(); } }