static void on_scroll(GLFWwindow *window, double x, double y) { ui.scroll_x = x; ui.scroll_y = y; run_main_loop(); ui.scroll_x = ui.scroll_y = 0; }
static void on_char(GLFWwindow *window, unsigned int key, int mod) { ui.key = key; ui.mod = mod; run_main_loop(); ui.key = ui.mod = 0; }
DWORD WINAPI ServiceRunServer(LPVOID lpParam) { SOCKET server; if (run_udp_server(&server) == SERVER_ERROR) { return -1; } run_main_loop(&server); return 0; }
static void on_mouse_button(GLFWwindow *window, int button, int action, int mod) { switch (button) { case GLFW_MOUSE_BUTTON_LEFT: ui.down = (action == GLFW_PRESS); break; case GLFW_MOUSE_BUTTON_MIDDLE: ui.middle = (action == GLFW_PRESS); break; case GLFW_MOUSE_BUTTON_RIGHT: ui.right = (action == GLFW_PRESS); break; } run_main_loop(); }
int gui_back_end_main_default (void) { initialize_main_loop (); gtk_control_center_present (); run_main_loop (); return 0; }
static void on_key(GLFWwindow *window, int special, int scan, int action, int mod) { if (action == GLFW_PRESS || action == GLFW_REPEAT) { ui.key = 0; switch (special) { #ifndef GLFW_MUPDF_FIXES /* regular control characters: ^A, ^B, etc. */ default: if (special >= 'A' && special <= 'Z' && mod == GLFW_MOD_CONTROL) ui.key = KEY_CTL_A + special - 'A'; break; /* regular control characters: escape, enter, backspace, tab */ case GLFW_KEY_ESCAPE: ui.key = KEY_ESCAPE; break; case GLFW_KEY_ENTER: ui.key = KEY_ENTER; break; case GLFW_KEY_BACKSPACE: ui.key = KEY_BACKSPACE; break; case GLFW_KEY_TAB: ui.key = KEY_TAB; break; #endif case GLFW_KEY_INSERT: ui.key = KEY_INSERT; break; case GLFW_KEY_DELETE: ui.key = KEY_DELETE; break; case GLFW_KEY_RIGHT: ui.key = KEY_RIGHT; break; case GLFW_KEY_LEFT: ui.key = KEY_LEFT; break; case GLFW_KEY_DOWN: ui.key = KEY_DOWN; break; case GLFW_KEY_UP: ui.key = KEY_UP; break; case GLFW_KEY_PAGE_UP: ui.key = KEY_PAGE_UP; break; case GLFW_KEY_PAGE_DOWN: ui.key = KEY_PAGE_DOWN; break; case GLFW_KEY_HOME: ui.key = KEY_HOME; break; case GLFW_KEY_END: ui.key = KEY_END; break; case GLFW_KEY_F1: ui.key = KEY_F1; break; case GLFW_KEY_F2: ui.key = KEY_F2; break; case GLFW_KEY_F3: ui.key = KEY_F3; break; case GLFW_KEY_F4: ui.key = KEY_F4; break; case GLFW_KEY_F5: ui.key = KEY_F5; break; case GLFW_KEY_F6: ui.key = KEY_F6; break; case GLFW_KEY_F7: ui.key = KEY_F7; break; case GLFW_KEY_F8: ui.key = KEY_F8; break; case GLFW_KEY_F9: ui.key = KEY_F9; break; case GLFW_KEY_F10: ui.key = KEY_F10; break; case GLFW_KEY_F11: ui.key = KEY_F11; break; case GLFW_KEY_F12: ui.key = KEY_F12; break; } if (ui.key) { ui.mod = mod; run_main_loop(); ui.key = ui.mod = 0; } } }
int gui_back_end_main_open_files (int num_files, char **filenames) { int k; initialize_main_loop (); for (k = 0; k < num_files; k++) gtk_parse_sgf_file (filenames[k], NULL, NULL); run_main_loop (); return 0; }
int Application::start_application( Application* app, int width, int height, float fps, const char* title, bool show_window) { LoopData ldata; app->show_window = show_window; assert( app ); // only create an app the first time this function is called if ( SDL_WasInit( 0 ) ) return -2; // init SDL if (show_window) { if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) == -1 ) { std::cout << "Error initializing SDL: " << SDL_GetError() << std::endl; return -1; } } else { if ( SDL_Init( SDL_INIT_TIMER ) == -1 ) { std::cout << "Error initializing SDL: " << SDL_GetError() << std::endl; return -1; } } if (show_window) { if ( !initialize_window( width, height, title ) ) goto FAIL; } // initialize the application if ( !app->initialize() ) goto FAIL; // run main loop app->running = true; ldata.app = app; ldata.fps = fps; ldata.running = &app->running; run_main_loop( loop_update_func, &ldata, fps ); // clean up and exit app->destroy(); std::cout << "Exiting Normally" << std::endl; return 0; FAIL: std::cerr << "Failed to start applcation, aborting.\n"; return -1; }
int main(int argc, char *argv[]) { GError *error = NULL; gint32 err; g_type_init(); g_thread_init(NULL); err = process_args(argc, argv); if (err < 0) { usage(argv[0]); exit(1); } dbus_g_thread_init(); dbus_threads_init_default(); init_log("notifucation_test", verbose); connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (connection == NULL) { log(LOG_ERR, "Can't connect to system bus: %s\n", error->message); g_error_free(error); return -1; } proxy = dbus_g_proxy_new_for_name(connection, "com.test.Notification", "/com/test/Notification", "com.test.Notification"); dbus_g_proxy_add_signal(proxy, "Notify",G_TYPE_INVALID); dbus_g_proxy_connect_signal(proxy, "Notify", test_callback, NULL, NULL); // proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); // dbus_g_proxy_add_signal(proxy, "NameOwnerChanged", G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING, G_TYPE_INVALID); // dbus_g_proxy_connect_signal(proxy, "NameOwnerChanged", test_callback, NULL, NULL); err = run_main_loop(); if (err < 0) { log(LOG_ERR, "Can't run main loop\n"); exit(1); } return 0; }
PUBLIC int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: move [-t] <dbfilename> [<move-source-code-file> ...]\n" "\t-t\tInhibits loading threads which were active when the DB was saved\n"); exit(MOVE_EXIT_ERROR); } signal(SIGINT, siginthandler); /* %%% This can be made to emergency-flush the database to disk, later on %%% */ write_pid(); init_gc(); init_object(); init_prim(); init_vm_global(); init_thread(); checkpoint_filename = "move.checkpoint"; install_primitives(); { int load_threads = 1; if (!strcmp(argv[1], "-t")) { load_threads = 0; argv++; argc--; } import_db(argv[1], load_threads); } bind_primitives_to_symbols(); import_cmdline_files(argc - 2, argv + 2); run_main_loop(); done_gc(); return MOVE_EXIT_OK; }
int main (int argc, char ** argv) { struct world *world; FILE *f; int c, ret; int head_steps, tail_steps, skip_steps, next_step; int ants_count, resolution; int step; int performance_test; int window_width; int window_height; int hex_size; dump_format = 0; step = 0; head_steps = 0; tail_steps = 0; skip_steps = 1; performance_test = 0; window_width = 800; window_height = 614; hex_size = 3; /* These are used for dump format, since it is difficult to figure them out. */ resolution = 10; ants_count = 32; world = NULL; while ((c=getopt (argc, argv, "wdh:t:s:a:p:W:H:c:")) != EOF) { switch (c) { case 'd': dump_format = 1; break; case 't': if (!optarg) usage_and_exit (argv[0]); tail_steps = atoi (optarg); break; case 's': if (!optarg) usage_and_exit (argv[0]); skip_steps = atoi (optarg); break; case 'r': if (!optarg) usage_and_exit (argv[0]); resolution = atoi (optarg); break; case 'a': if (!optarg) usage_and_exit (argv[0]); ants_count = atoi (optarg); break; case 'h': if (!optarg) usage_and_exit (argv[0]); head_steps = atoi (optarg); break; case 'w': warnings = 1; break; case 'p': if (!optarg) usage_and_exit (argv[0]); performance_test = atoi (optarg); break; case 'W': if (!optarg) usage_and_exit (argv[0]); window_width = atoi (optarg); break; case 'H': if (!optarg) usage_and_exit (argv[0]); window_height = atoi (optarg); break; case 'c': if (!optarg) usage_and_exit (argv[0]); hex_size = atoi (optarg); break; case '?': default: usage_and_exit (argv[0]); } } if (skip_steps < 1 || tail_steps < head_steps) { fprintf (stderr, "Illegal step setting.\n"); exit (-1); } if (dump_format) { next_step = head_steps; f = open_next_file_from_argv (argv); v_set_geometry (window_width, window_height, hex_size); v_initialize (); while (!feof (f)) { if (read_world_as_icfp_dump (&world, f, resolution, resolution, ants_count) == 0) { if (step <= head_steps || step >= tail_steps || step == next_step) { printf ("Step %d ...\n", step); display_world (world); v_refit_view (); if ((ret = v_poll_event (0))) { if (ret == -1) { break; } } next_step = skip_steps+step; } } step++; } fclose (f); } else { f = open_next_file_from_argv (argv); if (read_world (&world, f) != 0) { fprintf (stderr, "Error in reading world map.\n"); exit (-1); } fclose (f); f = open_next_file_from_argv (argv); if (parse_world_trace (world, f) != 0) { fprintf (stderr, "Error in reading world trace.\n"); exit (-1); } fclose (f); v_set_geometry (window_width, window_height, hex_size); v_initialize (); display_world (world); // v_refit_view (); } if (performance_test) { return run_performance_test (world, performance_test); } else { return run_main_loop (world); } }
int main(int argc, char *argv[]) { int o, flags, server_fd = -1; char *endptr, *delim; int port = 4000; int usbbus = -1; int usbaddr = -1; int usbvendor = -1; int usbproduct = -1; int on = 1; struct sockaddr_in6 serveraddr; struct sigaction act; libusb_device_handle *handle = NULL; while ((o = getopt_long(argc, argv, "hp:v:", longopts, NULL)) != -1) { switch (o) { case 'p': port = strtol(optarg, &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "Invalid value for --port: '%s'\n", optarg); usage(1, argv[0]); } break; case 'v': verbose = strtol(optarg, &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "Invalid value for --verbose: '%s'\n", optarg); usage(1, argv[0]); } break; case '?': case 'h': usage(o == '?', argv[0]); break; } } if (optind == argc) { fprintf(stderr, "Missing usb device identifier argument\n"); usage(1, argv[0]); } delim = strchr(argv[optind], '-'); if (delim && delim[1]) { usbbus = strtol(argv[optind], &endptr, 10); if (*endptr != '-') { invalid_usb_device_id(argv[optind], argv[0]); } usbaddr = strtol(delim + 1, &endptr, 10); if (*endptr != '\0') { invalid_usb_device_id(argv[optind], argv[0]); } } else { delim = strchr(argv[optind], ':'); if (!delim || !delim[1]) { invalid_usb_device_id(argv[optind], argv[0]); } usbvendor = strtol(argv[optind], &endptr, 16); if (*endptr != ':') { invalid_usb_device_id(argv[optind], argv[0]); } usbproduct = strtol(delim + 1, &endptr, 16); if (*endptr != '\0') { invalid_usb_device_id(argv[optind], argv[0]); } } optind++; if (optind != argc) { fprintf(stderr, "Excess non option arguments\n"); usage(1, argv[0]); } memset(&act, 0, sizeof(act)); act.sa_handler = quit_handler; sigaction(SIGINT, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGQUIT, &act, NULL); if (libusb_init(&ctx)) { fprintf(stderr, "Could not init libusb\n"); exit(1); } libusb_set_debug(ctx, verbose); server_fd = socket(AF_INET6, SOCK_STREAM, 0); if (server_fd == -1) { perror("Error creating ipv6 socket"); exit(1); } if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) { perror("Error setsockopt(SO_REUSEADDR) failed"); exit(1); } memset(&serveraddr, 0, sizeof(serveraddr)); serveraddr.sin6_family = AF_INET6; serveraddr.sin6_port = htons(port); serveraddr.sin6_addr = in6addr_any; if (bind(server_fd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) { fprintf(stderr, "Error binding port %d: %s\n", port, strerror(errno)); exit(1); } if (listen(server_fd, 1)) { perror("Error listening"); exit(1); } while (running) { client_fd = accept(server_fd, NULL, 0); if (client_fd == -1) { if (errno == EINTR) { continue; } perror("accept"); break; } flags = fcntl(client_fd, F_GETFL); if (flags == -1) { perror("fcntl F_GETFL"); break; } flags = fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); if (flags == -1) { perror("fcntl F_SETFL O_NONBLOCK"); break; } /* Try to find the specified usb device */ if (usbvendor != -1) { handle = libusb_open_device_with_vid_pid(ctx, usbvendor, usbproduct); if (!handle) { fprintf(stderr, "Could not open an usb-device with vid:pid %04x:%04x\n", usbvendor, usbproduct); } } else { libusb_device **list = NULL; ssize_t i, n; n = libusb_get_device_list(ctx, &list); for (i = 0; i < n; i++) { if (libusb_get_bus_number(list[i]) == usbbus && libusb_get_device_address(list[i]) == usbaddr) break; } if (i < n) { if (libusb_open(list[i], &handle) != 0) { fprintf(stderr, "Could not open usb-device at bus-addr %d-%d\n", usbbus, usbaddr); } } else { fprintf(stderr, "Could not find an usb-device at bus-addr %d-%d\n", usbbus, usbaddr); } libusb_free_device_list(list, 1); } if (!handle) { close(client_fd); continue; } host = usbredirhost_open(ctx, handle, usbredirserver_log, usbredirserver_read, usbredirserver_write, NULL, SERVER_VERSION, verbose, 0); if (!host) exit(1); run_main_loop(); usbredirhost_close(host); handle = NULL; } close(server_fd); libusb_exit(ctx); exit(0); }
int main(int argc, char **argv) #endif { const GLFWvidmode *video_mode; int c; while ((c = fz_getopt(argc, argv, "p:r:W:H:S:U:X")) != -1) { switch (c) { default: usage(argv[0]); break; case 'p': password = fz_optarg; break; case 'r': currentzoom = fz_atof(fz_optarg); break; case 'W': layout_w = fz_atof(fz_optarg); break; case 'H': layout_h = fz_atof(fz_optarg); break; case 'S': layout_em = fz_atof(fz_optarg); break; case 'U': layout_css = fz_optarg; break; case 'X': layout_use_doc_css = 0; break; } } if (fz_optind < argc) { fz_strlcpy(filename, argv[fz_optind], sizeof filename); } else { #ifdef _WIN32 win_install(); if (!win_open_file(filename, sizeof filename)) exit(0); #else usage(argv[0]); #endif } title = strrchr(filename, '/'); if (!title) title = strrchr(filename, '\\'); if (title) ++title; else title = filename; memset(&ui, 0, sizeof ui); search_input.p = search_input.text; search_input.q = search_input.p; search_input.end = search_input.p; glfwSetErrorCallback(on_error); if (!glfwInit()) { fprintf(stderr, "cannot initialize glfw\n"); exit(1); } video_mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); screen_w = video_mode->width; screen_h = video_mode->height; window = glfwCreateWindow(DEFAULT_WINDOW_W, DEFAULT_WINDOW_H, filename, NULL, NULL); if (!window) { fprintf(stderr, "cannot create glfw window\n"); exit(1); } glfwMakeContextCurrent(window); ctx = fz_new_context(NULL, NULL, 0); fz_register_document_handlers(ctx); if (layout_css) { fz_buffer *buf = fz_read_file(ctx, layout_css); fz_set_user_css(ctx, fz_string_from_buffer(ctx, buf)); fz_drop_buffer(ctx, buf); } fz_set_use_document_css(ctx, layout_use_doc_css); has_ARB_texture_non_power_of_two = glfwExtensionSupported("GL_ARB_texture_non_power_of_two"); if (!has_ARB_texture_non_power_of_two) fz_warn(ctx, "OpenGL implementation does not support non-power of two texture sizes"); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); ui.fontsize = DEFAULT_UI_FONTSIZE; ui.baseline = DEFAULT_UI_BASELINE; ui.lineheight = DEFAULT_UI_LINEHEIGHT; ui_init_fonts(ctx, ui.fontsize); reload(); shrinkwrap(); glfwSetFramebufferSizeCallback(window, on_reshape); glfwSetCursorPosCallback(window, on_mouse_motion); glfwSetMouseButtonCallback(window, on_mouse_button); glfwSetScrollCallback(window, on_scroll); glfwSetCharModsCallback(window, on_char); glfwSetKeyCallback(window, on_key); glfwSetWindowRefreshCallback(window, on_display); glfwGetFramebufferSize(window, &window_w, &window_h); ui_needs_update = 1; while (!glfwWindowShouldClose(window)) { glfwWaitEvents(); if (ui_needs_update) run_main_loop(); } ui_finish_fonts(ctx); fz_drop_link(ctx, links); fz_drop_page(ctx, page); fz_drop_outline(ctx, outline); fz_drop_document(ctx, doc); fz_drop_context(ctx); glfwTerminate(); return 0; }
char *run_test(int nr, int threads, int gens, int hot, char *fail_msg) { debug("TEST IS: %s", fail_msg); struct timeval stv, etv; long long usecs, passes_per_sec; int rc = 0; FILE *perf = NULL; check(nr >= threads, "You can't have the nr less than threads."); max_threads = threads; max_generation = gens; perf = fopen("tests/perf.log", "a+"); check(perf, "Failed to open tests/perf.log"); pid_t mypid = getpid(); fprintf(perf, "%s %d %d %d %ld %d ", hot ? "poll" : "epoll", mypid, nr, max_threads, max_generation, BUFSIZE); makepipes(nr, hot); send_pending_tokes(); gettimeofday(&stv, NULL); seedthreads(max_threads); rc = run_main_loop(hot); check(rc == 0, "Looks like the main loop failed for '%s'", fail_msg); gettimeofday(&etv, NULL); etv.tv_sec -= stv.tv_sec; etv.tv_usec -= stv.tv_usec; if (etv.tv_usec < 0) { etv.tv_usec += 1000000; etv.tv_sec -= 1; } fprintf(perf, "%ld %ld.%06ld ", nr_token_passes, etv.tv_sec, (long int)etv.tv_usec); usecs = etv.tv_usec + etv.tv_sec * 1000000LL; if(usecs == 0) usecs++; // avoid divide-by-zero on some computers passes_per_sec = nr_token_passes * 1000000LL * 100; passes_per_sec /= usecs ; fprintf(perf, "%Ld.%02Ld\n", passes_per_sec / 100, passes_per_sec % 100); closepipes(nr); fclose(perf); return NULL; error: closepipes(nr); if(perf) fclose(perf); return fail_msg; }