static void dev_file_open(GtkAction *action, GtkWindow *parent) { (void)action; static GtkWidget *dialog; const gchar *filename; if(!dialog) dialog = gtk_file_chooser_dialog_new("Open", parent, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { /* Dialog was cancelled or closed */ gtk_widget_hide(dialog); return; } gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); load_input_file(parent, filename); }
int run() { const message_catalog_type message_catalog{}; diagram_view_type diagram_view{ m_model, message_catalog }; timetable_view_type timetable_down_view{ view::timetable::direction_type::down, m_model, message_catalog }; timetable_view_type timetable_up_view{ view::timetable::direction_type::up, m_model, message_catalog }; const command_set_holder_type command_set_holder{ m_settings, m_model, diagram_view, message_catalog }; main_window_type main_window(message_catalog, m_settings, command_set_holder.confirm_file_save()); set_message_observers( command_set_holder.command_set(), diagram_view, timetable_down_view, timetable_up_view, main_window, message_catalog ); m_model.reset_timetable(); main_window.set_menu_bar( main_window_menu_builder_type( command_set_holder.command_set(), m_model, main_window, message_catalog ).build() ); main_window.set_visible(true); load_input_file(main_window, command_set_holder.command_set()); return message_loop_type{ main_window }(); }
int main(int argc, char **argv) { g_log_set_default_handler(logger, NULL); if (parse_options(argc, argv)) { return 1; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) goto done; if (sr_init(&sr_ctx) != SR_OK) goto done; #ifdef HAVE_SRD /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) goto done; if (opt_pds) { if (srd_init(NULL) != SRD_OK) goto done; if (srd_session_new(&srd_sess) != SRD_OK) { g_critical("Failed to create new decode session."); goto done; } if (register_pds(opt_pds, opt_pd_annotations) != 0) goto done; if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0) goto done; /* Only one output type is ever shown. */ if (opt_pd_binary) { if (setup_pd_binary(opt_pd_binary) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY, show_pd_binary, NULL) != SRD_OK) goto done; } else if (opt_pd_meta) { if (setup_pd_meta(opt_pd_meta) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_META, show_pd_meta, NULL) != SRD_OK) goto done; } else { if (opt_pd_annotations) if (setup_pd_annotations(opt_pd_annotations) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) goto done; } } #endif if (opt_version) show_version(); else if (opt_input_format && opt_show) show_input(); else if (opt_output_format && opt_show) show_output(); else if (opt_transform_module && opt_show) show_transform(); else if (opt_scan_devs) show_dev_list(); #ifdef HAVE_SRD else if (opt_pds && opt_show) show_pd_detail(); #endif else if (opt_show) show_dev_detail(); else if (opt_input_file) load_input_file(); else if (opt_get) get_option(); else if (opt_set) set_options(); else if (opt_samples || opt_time || opt_frames || opt_continuous) run_session(); else show_help(); #ifdef HAVE_SRD if (opt_pds) srd_exit(); #endif done: if (sr_ctx) sr_exit(sr_ctx); return 0; }
int main() { FILE *plane_list, *storm_list, *output_log_verbose, *output_log, *output_log_read, *verification_log, *statistics_log; //int sim_length = TIME_YEAR; init_simlib(); /* Set the log list to be ordered by event time */ list_rank[LIST_LOG] = EVENT_TIME; /* Set the in-port residence time list to be ordered by plane id */ list_rank[LIST_PLANE_PORT_TIME] = PLANE_ID; list_rank[LIST_AVG_PLANES_RUNWAY] = EVENT_TIME; list_rank[LIST_AVG_PLANES_DEBERTH] = EVENT_TIME; /* Set max attributes in a list to 9, for simlog */ maxatr = 10; storm_state = STORM_OFF; taxi_state = TAXI_IDLE; int i; for (i=0; i<NUMBER_OF_BERTHS; i++) { berths[i].state = BERTH_FREE; berths[i].time_unoccupied_last = 0; berths[i].time_unoccupied = 0; berths[i].time_loading = 0; berths[i].time_loading_last = 0; berths[i].time_occupied = 0; berths[i].time_occupied_last = 0; } stats.taxi_time_idle = 0; stats.taxi_time_idle_last = 0; stats.taxi_time_travelling = 0; stats.taxi_time_travelling_last = 0; stats.taxi_time_berthing_deberthing = 0; stats.taxi_time_berthing_deberthing_last = 0; /* initialize timest */ timest(0.0, 0); /* Load the input paramters for times and such */ FILE *input = fopen("config.ini", "r"); verification_log = fopen("verification.log", "w"); load_input_file(input, verification_log); fclose(input); /* initialize berths array to specified size */ //berths = (struct berth *)malloc(sizeof(struct berth)*G.num_berths); /* Generate the plane and storm list */ generate_input_files(); /* Schedule the plane landing and storm events using the input lists*/ plane_list = fopen("plane_list.dat", "r"); storm_list = fopen("storm_list.dat", "r"); schedule_input_list(plane_list); schedule_input_list(storm_list); fclose(plane_list); fclose(storm_list); plane_list = fopen("plane_list.dat", "r"); storm_list = fopen("storm_list.dat", "r"); verify_actors(storm_list, plane_list, verification_log); fclose(plane_list); fclose(storm_list); while(list_size[LIST_EVENT] != 0) { timing(); /* If sim time passes a year, exit the simulation. */ if ((int)sim_time>=G.sim_length) {//TIME_YEAR) { if (taxi_state == TAXI_IDLE) stats.taxi_time_idle += G.sim_length - stats.taxi_time_idle_last; if (taxi_state == TAXI_TRAVELLING_BERTHS || taxi_state == TAXI_TRAVELLING_RUNWAY) stats.taxi_time_travelling += G.sim_length - stats.taxi_time_travelling_last; if (taxi_state == TAXI_BERTHING || taxi_state == TAXI_DEBERTHING) stats.taxi_time_berthing_deberthing += G.sim_length - stats.taxi_time_berthing_deberthing_last; /* Because the stats.taxi_time_travelling isn't quite getting all of the time but I know that the idle and berthing/deberthing times are correct, I'm cheating and using those to figure out the travelling time. */ stats.taxi_time_travelling = G.sim_length - stats.taxi_time_idle - stats.taxi_time_berthing_deberthing; break; } /* printf("%.1f %.1f %s %s\n", sim_time/60, stats.taxi_time_berthing_deberthing/60.0f, strings_event[(int)transfer[EVENT_TYPE]], strings_taxi[taxi_state]); */ /* Main event handler switch */ switch(next_event_type) { case EVENT_LAND1: case EVENT_LAND2: case EVENT_LAND3: plane_land(next_event_type, transfer[EVENT_PLANE_ID]); break; case EVENT_STORM_START: storm_start(); break; case EVENT_STORM_END: storm_end(); break; case EVENT_BERTH: berth(transfer[BERTH_NUMBER]); break; case EVENT_DEBERTH: deberth(transfer[BERTH_NUMBER]); break; case EVENT_FINISH_LOADING: finish_loading(transfer[BERTH_NUMBER]); break; case EVENT_BERTH_FINISH: berth_finish(transfer[BERTH_NUMBER]); break; case EVENT_DEBERTH_FINISH: deberth_finish(transfer[BERTH_NUMBER]); break; case EVENT_TAXI_RETURNS_IDLE: taxi_returns(); break; } if (sim_time == 129705) printf("%d\n", taxi_state == TAXI_IDLE); /* Taxi handler */ switch (taxi_state) { case TAXI_IDLE: taxi_idle(); break; case TAXI_TRAVELLING_RUNWAY: taxi_travelling_runway(); break; case TAXI_TRAVELLING_BERTHS: taxi_travelling_berths(); break; case TAXI_BERTHING: taxi_berthing(); break; case TAXI_DEBERTHING: taxi_deberthing(); break; } }// end simulation loop printf("Log list size: %d\n", list_size[LIST_LOG]); output_log_verbose = fopen("output_log_verbose.csv", "w"); save_log_file_verbose(output_log_verbose); fclose(output_log_verbose); output_log = fopen("output_log.csv", "w"); save_log_file(output_log); fclose(output_log); /* output_log = fopen("output_log.csv", "w"); //verify_output(output_log, verification_log); fclose(output_log); fclose(verification_log); */ statistics_log = fopen("statistics.log", "w"); generate_statistics(statistics_log); fclose(statistics_log); /* Clean up files */ remove("plane_list.dat"); remove("storm_list.dat"); remove("storm_list.csv"); }
int main(int argc, char **argv) { GOptionContext *context; GError *error; g_log_set_default_handler(logger, NULL); error = NULL; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, optargs, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_critical("%s", error->message); return 1; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) return 1; /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) return 1; if (sr_init() != SR_OK) return 1; if (opt_pds) { if (srd_init(NULL) != SRD_OK) return 1; if (register_pds(NULL, opt_pds) != 0) return 1; if (srd_pd_output_callback_add(SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) return 1; if (setup_pd_stack() != 0) return 1; if (setup_pd_annotations() != 0) return 1; } if (setup_output_format() != 0) return 1; if (opt_version) show_version(); else if (opt_list_devs) show_dev_list(); else if (opt_input_file) load_input_file(); else if (opt_samples || opt_time || opt_frames || opt_continuous) run_session(); else if (opt_dev) show_dev_detail(); else if (opt_pds) show_pd_detail(); else printf("%s", g_option_context_get_help(context, TRUE, NULL)); if (opt_pds) srd_exit(); g_option_context_free(context); sr_exit(); return 0; }