void line_eval(char* line) { if(line[0] == '/') { char inpt_command = line[1]; if(inpt_command == 'f') { add_friend(); } else if (inpt_command == 'r') { do_header(); printf("\n\n"); } else if (inpt_command == 'l') { list_friends(); } else if (inpt_command == 'd') { delete_friend(); } /* Send message to friend */ else if (inpt_command == 'm') { message_friend(); } else if (inpt_command == 'n') { change_nickname(); } else if (inpt_command == 's') { change_status(1); } else if (inpt_command == 'a') { if (friend_request_received == 1) accept_friend_request(line); } /* EXIT */ else if (inpt_command == 'q') { strcpy(line, "---Offline"); change_status(0); exit(EXIT_SUCCESS); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QObject::connect(&mb, SIGNAL(error(QModBus::ModBusError)), this, SLOT(process_error(QModBus::ModBusError))); QObject::connect(&mb, SIGNAL(connected()), this, SLOT(change_status())); QObject::connect(&mb, SIGNAL(disconnected()), this, SLOT(change_status())); QObject::connect(ui->connect_button, SIGNAL(clicked()), this, SLOT(connect_btn_clicked())); //read button QObject::connect(ui->rd_button, SIGNAL(clicked()), this, SLOT(read_regs())); QObject::connect(&mb, SIGNAL(response_to_read_regs(int)), this, SLOT(response_to_read_regs(int))); //write button QObject::connect(ui->wr_button, SIGNAL(clicked()), this, SLOT(write_reg())); QObject::connect(&mb, SIGNAL(response_to_write_reg(int)), this, SLOT(response_to_write_reg(int))); }
static void execute_shell(t_shell *sh, CMD *c, int fd_out, int fd_error) { sh->inside_status = 1; if (c->type == C_ERROR) { exec_error(c, fd_error); change_status(sh, 1); } else if (c->type == C_BUILTIN && !is_extern_builtin(c)) exec_builtin(sh, c, fd_out, fd_error); else sh->inside_status = 0; }
static void do_execute_and_distrib(t_shell *sh, t_command *c, int pip[2]) { pid_t child2; int status; status = 0; close(pip[1]); child2 = execute_and_distrib(sh, c); close(pip[0]); waitpid(child2, &status, 0); if (sh->inside_status == 0 && c->pipe == NULL) change_status(sh, exit_status(status, sh)); dup2(sh->save_in, 0); }
void replace(char **str, t_list *list, int ant) { t_list *link; int i; i = 0; link = list; while (str[i]) { TC->name = change_name(str[i], link); link = link->next; i++; } i--; change_status(list, i, ant); }
void simulation(struct area * board, int itr, char * out, int zoom) { int i, status; char name[50]; status = mkdir("generation", S_IRWXU | S_IRWXG | S_IRWXO); if (status != 0) { fprintf(stderr,"Katalog \'generation\' juz istnieje.\nProsze usunac go recznie przed ponownym uzyciem programu.\n"); exit(-10); } name[0] = '\0'; sprintf(name, "generation/%s%d.png", out, 0); save_generation(board, name, zoom); for (i = 0; i < itr; i++) { analyze_neighborhood(board); change_status(board); name[0] = '\0'; sprintf(name, "generation/%s%d.png", out, i + 1); save_generation(board, name, zoom); } save_last_gen( board ); }
void mixer_agent_t::run() { // TODO:ミキサーの実装 // COMの初期化 sf::com_initialize init(0,multi_threaded); // MMCSSの初期化 //av_mm_thread_characteristics avmm(wstring(L"Pro Audio")); //avmm.set_priority(AVRT_PRIORITY::AVRT_PRIORITY_HIGH); int status; application& app(*application::instance()); // outputデバイスが稼働するまで待つ //app.output_thread().wait_status(output_agent_t::status_processing,10); // バッファ初期化 //init_buffer(); change_status(status_config); while(status = status_.load(),status !=status_exit) { switch(status) { case status_config: { change_status(status_config_ok); } break; case status_process: { init_buffer(); change_status(status_processing); } case status_processing: { Sleep(app.output_device().get_buffer_duration() / 20000); BYTE *in(0),*reader(0); app.input_ringbuffer().pop(in); app.reader_ringbuffer().pop(reader); int size(app.output_device().get_buffer_byte_size()); BYTE *dest(buffer_[index_].get()); if(in != 0 && reader != 0) { ::CopyMemory(dest,in,size); size = size / app.output_device().get_frame_size(); WORD *destw((WORD*)dest),*srcw((WORD*)reader); for(int i = 0;i < size;++i) { *destw++ += *srcw++; *destw++ += *srcw++; } } else if(in != 0) { ::CopyMemory(dest,in,size); } else if(reader != 0) { ::CopyMemory(dest,reader,size); } else { ::ZeroMemory(dest,size); } while(!ringbuffer_.push(buffer_[index_].get())) { Sleep(app.output_device().get_buffer_duration() / 20000); } index_ = (index_ + 1) & (buffer_.size() -1 ); } break; case status_pause: change_status(status_pause_ok); break; default: wait_event(); // WaitForSingleObject(event_.get(),WAIT_TIMEOUT_DEFAULT); } } debug_out(L"***** mixerは終了!\n"); agent::done(); }
virtual ~plugin_thread() { change_status(stopping); wait_status(); }
static void process_meeting (ECalendarView *cal_view, icalparameter_partstat status) { GList *selected; icalcomponent *clone; selected = e_calendar_view_get_selected_events (cal_view); if (selected) { ECalendarViewEvent *event = (ECalendarViewEvent *) selected->data; ECalComponent *comp = e_cal_component_new (); ReceiveData *r_data = g_new0 (ReceiveData, 1); gboolean recurring = FALSE; GThread *thread = NULL; GError *error = NULL; char *address = NULL; e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); address = itip_get_comp_attendee (comp, event->comp_data->client); if (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp)) recurring = TRUE; /* Free comp */ g_object_unref (comp); comp = NULL; clone = icalcomponent_new_clone (event->comp_data->icalcomp); change_status (clone, address, status); r_data->ecal = g_object_ref (event->comp_data->client); r_data->icalcomp = clone; if (recurring) { gint response; const char *arg; if (status == ICAL_PARTSTAT_ACCEPTED || status == ICAL_PARTSTAT_TENTATIVE) arg = "accept"; else arg = "decline"; response = e_error_run (NULL, "org.gnome.evolution.mail_shared_folder:recurrence", arg, NULL); if (response == GTK_RESPONSE_YES) { icalproperty *prop; const char *uid = icalcomponent_get_uid (r_data->icalcomp); prop = icalproperty_new_x ("All"); icalproperty_set_x_name (prop, "X-GW-RECUR-INSTANCES-MOD-TYPE"); icalcomponent_add_property (r_data->icalcomp, prop); prop = icalproperty_new_x (uid); icalproperty_set_x_name (prop, "X-GW-RECURRENCE-KEY"); icalcomponent_add_property (r_data->icalcomp, prop); } else if (response == GTK_RESPONSE_CANCEL) { finalize_receive_data (r_data); return; } } thread = g_thread_create ((GThreadFunc) receive_objects, r_data , FALSE, &error); if (!thread) { g_warning (G_STRLOC ": %s", error->message); g_error_free (error); } } }
/** * rr simulation */ void s_rr(priority_queue q, v_memory vm, int num, int cs_t, float *a_wait_t, int *total_cs, int *total_t, int *total_d, int t_memmove, int t_slice) { int cur_t = 0; // current time int cur_cs_t = cs_t + 1; // current context switch time (-1 when not switching) int cur_s_t = 0; // current time-slice time int in_use = 0; // boolean for processor usage int procs_t[num]; // processor countdowns process *procs[num]; // processes in use process *tmp; // process to pop from waiting queue int active; // active processor in use int pri = 0; // rr priority (fcfs) char *algo; // fitting algorithm priority_queue pq; // processes queue // zero arrays int i; for(i = 0; i < num; ++i) { procs_t[i] = 0; procs[i] = 0; } // initialize stuff pq = pq_new(0); // print vm algorithm switch(vm.algo) { case 'f': algo = "First-Fit"; break; case 'n': algo = "Next-Fit"; break; case 'b': algo = "Best-Fit"; break; default: break; } printf("time 0ms: Simulator started for RR (t_slice %d) and %s\n", t_slice, algo); while(1) { // check process arrival times tmp = NULL; while(tmp == NULL) { tmp = pq_peek(q, NULL); if(tmp && tmp->a_t == cur_t) { int rc; // add process to system tmp = pq_pop(q, NULL); pq_push(pq, tmp, ++pri); rc = vm_add(&vm, *tmp); if(rc != 1) { // (defrag) event_call("", cur_t, tmp->num, 'a', NULL); event_call("", cur_t, 0, 'b', NULL); event_call("", cur_t, 0, '9', NULL); vm_print(vm); *total_d += vm_defrag(&vm, 10); event_call("", cur_t, 0, 'c', NULL); event_call("", cur_t, 0, '9', NULL); vm_print(vm); vm_add(&vm, *tmp); } // print event_call("", cur_t, tmp->num, '8', pq); event_call("", cur_t, 0, '9', NULL); vm_print(vm); tmp = NULL; } else { tmp = NULL; break; } } // switching context if(cur_cs_t > 0) --cur_cs_t; // switched context if(cur_cs_t == 0) { --cur_cs_t; // check if open process available and run it if possible if((pq_size(pq) != 0) && !in_use) { int procs_u = 0; while(procs[procs_u] != 0) ++procs_u; // get next open index in_use = 1; procs[procs_u] = pq_pop(pq, NULL); // pop the next open process change_status(procs[procs_u], 1); // set status to using cpu procs_t[procs_u] = procs[procs_u]->b_t + 1; // start process timer cur_s_t = t_slice + 1; // start t_slice timer if(procs[procs_u]->cur_t > 0) procs_t[procs_u] = procs[procs_u]->cur_t; active = procs_u; --procs[procs_u]->b_n; event_call("", cur_t, procs[procs_u]->num, '1', pq); } } // process timers for(i = 0; i < num; ++i) { if(procs[i] != 0) { // check timers if(procs_t[i] > 0) { --procs_t[i]; if(cur_s_t > 0) --cur_s_t; // handle timers if(procs_t[i] == 0) { // completed cpu burst if(procs[i]->status == 1) { change_status(procs[i], 2); procs_t[i] = procs[i]->io_t; if(procs[i]->cur_t > 0) procs[i]->cur_t = 0; // reset cur_t in_use = 0; cur_cs_t = cs_t; ++*total_cs; // if process does not require i/o if(procs_t[i] == 0) { if(procs[i]->b_n <= 0) { vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); change_status(procs[i], 3); // terminate } else { change_status(procs[i], 0); pq_push(pq, procs[i], ++pri); event_call("", cur_t, procs[i]->num, '2', pq); procs[i] = 0; } } else { if(procs[i]->b_n != 0) { event_call("", cur_t, procs[i]->num, '2', pq); event_call("", cur_t, procs[i]->num, '3', pq); } // terminate process else { procs_t[i] = 0; change_status(procs[i], 3); vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); } } } // completed i/o else if(procs[i]->status == 2) { change_status(procs[i], 0); if(!in_use) cur_cs_t = cs_t; // finished burst if(procs[i]->b_n <= 0) { // terminate on last burst if(pq_size(pq) != 0) { vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); } change_status(procs[i], 3); } else { pq_push(pq, procs[i], ++pri); event_call("", cur_t, procs[i]->num, '4', pq); procs[i] = 0; } } } // check time slice expiration else if(cur_s_t == 0 && procs[i]->status == 1) { if(pq_size(pq) != 0) { procs[active]->cur_t = procs_t[active]; // store the current processing time ++procs[active]->b_n; // restore burst number since it hasnt finished change_status(procs[active], 0); // reset status pq_push(pq, procs[active], ++pri); // push back into queue preempt_call(cur_t, procs[active]->num, '0', pq); // print cur_cs_t = cs_t; // switch contexts ++*total_cs; // void existing processors procs_t[active] = 0; procs[active] = 0; in_use = 0; cur_s_t = -1; } } } } } // get statistics from all processes for(i = 1; i <= pq_size(pq); ++i) { if(((process*)(pq->buf[i].data))->status == 0) { ++*a_wait_t; } } if(pq_size(pq) == 0 && !in_use && done(procs_t, sizeof(procs_t) / sizeof(int))) { *total_t = cur_t; event_call("RR", cur_t, 0, '7', pq); return; } ++cur_t; } }