static void scheduler_msg_dispatch(void) { size_t n, sz, count; struct evpstate evpstates[MAX_BATCH_SIZE]; uint64_t evpid, evpids[MAX_BATCH_SIZE], u64; uint32_t msgids[MAX_BATCH_SIZE], version, msgid; struct scheduler_info info; int typemask, r, type, types[MAX_BATCH_SIZE]; int delay; switch (imsg.hdr.type) { case PROC_SCHEDULER_INIT: log_debug("scheduler-api: PROC_SCHEDULER_INIT"); scheduler_msg_get(&version, sizeof(version)); scheduler_msg_end(); if (version != PROC_SCHEDULER_API_VERSION) { log_warnx("warn: scheduler-api: bad API version"); fatalx("scheduler-api: exiting"); } r = handler_init(); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_INSERT: log_debug("scheduler-api: PROC_SCHEDULER_INSERT"); scheduler_msg_get(&info, sizeof(info)); scheduler_msg_end(); r = handler_insert(&info); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_COMMIT: log_debug("scheduler-api: PROC_SCHEDULER_COMMIT"); scheduler_msg_get(&msgid, sizeof(msgid)); scheduler_msg_end(); n = handler_commit(msgid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &n, sizeof(n)); break; case PROC_SCHEDULER_ROLLBACK: log_debug("scheduler-api: PROC_SCHEDULER_ROLLBACK"); scheduler_msg_get(&msgid, sizeof(msgid)); scheduler_msg_end(); n = handler_rollback(msgid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &n, sizeof(n)); break; case PROC_SCHEDULER_UPDATE: log_debug("scheduler-api: PROC_SCHEDULER_UPDATE"); scheduler_msg_get(&info, sizeof(info)); scheduler_msg_end(); r = handler_update(&info); scheduler_msg_add(&r, sizeof(r)); if (r == 1) scheduler_msg_add(&info, sizeof(info)); scheduler_msg_close(); break; case PROC_SCHEDULER_DELETE: log_debug("scheduler-api: PROC_SCHEDULER_DELETE"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_end(); r = handler_delete(evpid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_HOLD: log_debug("scheduler-api: PROC_SCHEDULER_HOLD"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_get(&u64, sizeof(u64)); scheduler_msg_end(); r = handler_hold(evpid, u64); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_RELEASE: log_debug("scheduler-api: PROC_SCHEDULER_RELEASE"); scheduler_msg_get(&type, sizeof(type)); scheduler_msg_get(&u64, sizeof(u64)); scheduler_msg_get(&r, sizeof(r)); scheduler_msg_end(); r = handler_release(type, u64, r); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_BATCH: log_debug("scheduler-api: PROC_SCHEDULER_BATCH"); scheduler_msg_get(&typemask, sizeof(typemask)); scheduler_msg_get(&count, sizeof(count)); scheduler_msg_end(); if (count > MAX_BATCH_SIZE) count = MAX_BATCH_SIZE; r = handler_batch(typemask, &delay, &count, evpids, types); scheduler_msg_add(&r, sizeof(r)); scheduler_msg_add(&delay, sizeof(delay)); scheduler_msg_add(&count, sizeof(count)); if (r > 0) { scheduler_msg_add(evpids, sizeof(*evpids) * count); scheduler_msg_add(types, sizeof(*types) * count); } scheduler_msg_close(); break; case PROC_SCHEDULER_MESSAGES: log_debug("scheduler-api: PROC_SCHEDULER_MESSAGES"); scheduler_msg_get(&msgid, sizeof(msgid)); scheduler_msg_get(&sz, sizeof(sz)); scheduler_msg_end(); if (sz > MAX_BATCH_SIZE) sz = MAX_BATCH_SIZE; n = handler_messages(msgid, msgids, sz); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, msgids, n * sizeof(*msgids)); break; case PROC_SCHEDULER_ENVELOPES: log_debug("scheduler-api: PROC_SCHEDULER_ENVELOPES"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_get(&sz, sizeof(sz)); scheduler_msg_end(); if (sz > MAX_BATCH_SIZE) sz = MAX_BATCH_SIZE; n = handler_envelopes(evpid, evpstates, sz); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, evpstates, n * sizeof(*evpstates)); break; case PROC_SCHEDULER_SCHEDULE: log_debug("scheduler-api: PROC_SCHEDULER_SCHEDULE"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_end(); r = handler_schedule(evpid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_REMOVE: log_debug("scheduler-api: PROC_SCHEDULER_REMOVE"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_end(); r = handler_remove(evpid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_SUSPEND: log_debug("scheduler-api: PROC_SCHEDULER_SUSPEND"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_end(); r = handler_suspend(evpid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; case PROC_SCHEDULER_RESUME: log_debug("scheduler-api: PROC_SCHEDULER_RESUME"); scheduler_msg_get(&evpid, sizeof(evpid)); scheduler_msg_end(); r = handler_resume(evpid); imsg_compose(&ibuf, PROC_SCHEDULER_OK, 0, 0, -1, &r, sizeof(r)); break; default: log_warnx("warn: scheduler-api: bad message %d", imsg.hdr.type); fatalx("scheduler-api: exiting"); } }
/** Procedure: commandHandler Purpose: Handles User Commands & Command Execution Parameters: None Return value: None Calls: displayWelcome, keyboardInput, cmpP2S, handler_help, handler_version, handler_set_date, handler_get_date, handler_display_mpx, handler_display_history, handler_terminate_mpx, change_prompt, handler_help_function, handler_create_pcb, handler_delete_pcb, handler_block, handler_unblock, handler_suspend, handler_resume, handler_set_priority, handler_show_pcb, handler_show, displayClosing, commandCleanup, sys_exit Globals: comDone, userCommand Errors: None **/ void commandHandler(){ int userCommandSize; displayWelcome(); //2.1 Display the Welcome Message while(comDone !=1){ //2.2 Begin While Loop for User Commands userCommand = NULL; printf("\nPlease enter the command to be executed(case sensitive).\n"); userCommand = keyboardInput(0); //2.2.1 Request User Input & Accept Command from User printf("\n"); //Decision Statement if(cmpP2S(userCommand, "help") == 1 || cmpP2S(userCommand, "/?") == 1){ handler_help(); } else if(cmpP2S(userCommand, "version") == 1){ handler_version(); } else if(cmpP2S(userCommand, "set_date") == 1){ handler_set_date(); //fix = 1; } else if(cmpP2S(userCommand, "get_date") == 1){ handler_get_date(); } else if(cmpP2S(userCommand, "display_mpx") == 1){ handler_display_mpx(); } //else if(cmpP2S(userCommand, "display_history") == 1){ // handler_display_history(); //} else if(cmpP2S(userCommand, "terminate_mpx") == 1||cmpP2S(userCommand, "exit") == 1||cmpP2S(userCommand, "quit") == 1){ handler_terminate_mpx(); } else if(cmpP2S(userCommand, "change_prompt") == 1){ change_prompt(); //fix = 1; } else if(cmpP2S(userCommand, "help_version")==1){ handler_help_function("version"); } else if(cmpP2S(userCommand, "help_set_date")==1){ handler_help_function("set_date"); } else if(cmpP2S(userCommand, "help_get_date")==1){ handler_help_function("get_date"); } else if(cmpP2S(userCommand, "help_display_mpx")==1){ handler_help_function("display_mpx"); } else if(cmpP2S(userCommand, "help_terminate_mpx")==1){ handler_help_function("terminate_mpx"); } else if(cmpP2S(userCommand, "help_change_prompt")==1){ handler_help_function("change_prompt"); } else if(cmpP2S(userCommand, "help_create_pcb")==1){ handler_help_function("create_pcb"); } else if(cmpP2S(userCommand, "create_pcb")==1){ handler_create_pcb(); } else if(cmpP2S(userCommand, "help_delete_pcb")==1){ handler_help_function("delete_pcb"); } else if(cmpP2S(userCommand, "delete_pcb")==1){ handler_delete_pcb(); } else if(cmpP2S(userCommand, "help_block")==1){ handler_help_function("block"); } else if(cmpP2S(userCommand, "block")==1){ handler_block(); } else if(cmpP2S(userCommand, "help_unblock")==1){ handler_help_function("unblock"); } else if(cmpP2S(userCommand, "unblock")==1){ handler_unblock(); } else if(cmpP2S(userCommand, "help_suspend")==1){ handler_help_function("suspend"); } else if(cmpP2S(userCommand, "suspend")==1){ handler_suspend(); } else if(cmpP2S(userCommand, "help_resume")==1){ handler_help_function("resume"); } else if(cmpP2S(userCommand, "resume")==1){ handler_resume(); } else if(cmpP2S(userCommand, "help_set_priority")==1){ handler_help_function("set_priority"); } else if(cmpP2S(userCommand, "set_priority")==1){ handler_set_priority(); } else if(cmpP2S(userCommand, "help_show_pcb")==1){ handler_help_function("show_pcb"); } else if(cmpP2S(userCommand, "show_pcb")==1){ handler_show_pcb(); } else if(cmpP2S(userCommand, "help_show_all")==1){ handler_help_function("show_all"); } else if(cmpP2S(userCommand, "show_all")==1){ handler_show(0); } else if(cmpP2S(userCommand, "help_show_ready")==1){ handler_help_function("show_ready"); } else if(cmpP2S(userCommand, "show_ready")==1){ handler_show(4); handler_show(6); } else if(cmpP2S(userCommand, "help_show_blocked")==1){ handler_help_function("show_blocked"); } else if(cmpP2S(userCommand, "show_blocked")==1){ handler_show(5); handler_show(7); } else { printf("Invalid Command.\n"); }//end if - Decision }//end while displayClosing(); //2.2.4 Display closing message commandCleanup(); //2.2.5 Cleanup Allocated Memory keyboardInput(0); sys_exit(); //2.2.6 Return to host system }