void moloch_http_free_server(void *serverV) { MolochHttp_t *server = serverV; int n=0; while (server->requestQ.r_count > 0 || server->inProgress > 0) { n++; if (n%10000 == 0) LOG("%s %d %d", server->names[0], server->requestQ.r_count, server->inProgress); g_main_context_iteration (g_main_context_default(), FALSE); } MolochConn_t *conn = 0; while (DLL_POP_HEAD(e_, &server->connQ, conn)) { moloch_http_free_conn(conn, FALSE); } moloch_http_free_conn(server->syncConn, FALSE); server->syncConn = 0; g_strfreev(server->names); MOLOCH_TYPE_FREE(MolochHttp_t, server); }
static void ep_msg_send (EPassMsg *msg) { gint needidle = 0; G_LOCK (passwords); g_queue_push_tail (&message_queue, msg); if (!idle_id) { if (!msg->ismain) idle_id = g_idle_add (ep_idle_dispatch, NULL); else needidle = 1; } G_UNLOCK (passwords); if (msg->ismain) { if (needidle) ep_idle_dispatch (NULL); while (!e_flag_is_set (msg->done)) g_main_context_iteration (NULL, TRUE); } else e_flag_wait (msg->done); }
static void sxftd_advanced_clicked(SXFromTransInfo *sxfti) { guint sx_error = sxftd_compute_sx(sxfti); GMainContext *context; if ( sx_error != 0 && sx_error != SXFTD_ERRNO_UNBALANCED_XACTION ) { // unbalanced-xaction is "okay", since this is also checked for by // the advanced editor. g_warning("something bad happened in sxftd_compute_sx [%d]", sx_error); return; } gtk_widget_hide( sxfti->dialog ); /* force a gui update. */ context = g_main_context_default(); while (g_main_context_iteration(context, FALSE)); gnc_ui_scheduled_xaction_editor_dialog_create(sxfti->sx, TRUE /* newSX */); /* close ourself, since advanced editing entails us, and there are sync * issues otherwise. */ sxftd_close(sxfti, FALSE); }
gboolean ot_admin_sysroot_lock (OstreeSysroot *sysroot, GError **error) { gboolean ret = FALSE; gboolean acquired; struct ContextState state = { .mainctx = g_main_context_new (), .running = TRUE, }; g_main_context_push_thread_default (state.mainctx); if (!ostree_sysroot_try_lock (sysroot, &acquired, error)) goto out; if (!acquired) { GSource *timeout_src = g_timeout_source_new_seconds (3); g_source_set_callback (timeout_src, (GSourceFunc)on_sysroot_lock_timeout, &state, NULL); g_source_attach (timeout_src, state.mainctx); g_source_unref (timeout_src); on_sysroot_lock_timeout (&state); ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, &state); while (state.running) g_main_context_iteration (state.mainctx, TRUE); } ret = TRUE; out: g_main_context_pop_thread_default (state.mainctx); g_main_context_unref (state.mainctx); return ret; }
void gstreamer_destroy_pipeline() { main_set_normal_scheduling_policy(); GstState state, pending; gst_element_set_state (pipeline, GST_STATE_PAUSED); gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE); /* Iterate main loop to process pending stuff. */ while (g_main_context_iteration (NULL, FALSE)); gst_element_set_state (pipeline, GST_STATE_READY); gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE); gst_element_set_state(pipeline, GST_STATE_NULL); g_source_remove(bus_watch_id); gst_object_unref(GST_OBJECT(pipeline)); pipeline_description = ""; GList *list = g_list_first(inform_pipeline_destroyed_cb_list); GValue value = G_VALUE_INIT; g_value_init(&value, G_TYPE_POINTER); g_value_set_pointer(&value, NULL); while (list != NULL) { GClosure *closure = list->data; g_closure_invoke(closure, NULL, 1, &value, NULL); g_closure_unref(closure); list = g_list_next(list); } g_value_unset(&value); g_list_free(inform_pipeline_destroyed_cb_list); stats_reset(); gui_set_window_title("gstplay"); }
static void do_verify(DBusGProxy *dev) { GError *error; gboolean verify_completed = FALSE; dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL); dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_INT, NULL); dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result), &verify_completed, NULL); dbus_g_proxy_connect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected), NULL, NULL); if (!net_reactivated_Fprint_Device_verify_start(dev, finger_name, &error)) g_error("VerifyStart failed: %s", error->message); while (!verify_completed) g_main_context_iteration(NULL, TRUE); dbus_g_proxy_disconnect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result), &verify_completed); dbus_g_proxy_disconnect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected), NULL); if (!net_reactivated_Fprint_Device_verify_stop(dev, &error)) g_error("VerifyStop failed: %s", error->message); }
static void run_test (gconstpointer data) { GFileInputStream *stream; gchar contents[1024]; gsize bytes; gchar *curi, *newline; gchar **uriv; GFile *file = G_FILE (data); YelpUri *uri; GOutputStream *outstream; gchar *out; stream = g_file_read (file, NULL, NULL); g_assert (g_input_stream_read_all (G_INPUT_STREAM (stream), contents, 1024, &bytes, NULL, NULL)); newline = strchr (contents, '\n'); curi = g_strndup (contents, newline - contents); uriv = g_strsplit (curi, " ", 2); uri = yelp_uri_new (uriv[0]); if (uriv[1] != NULL) uri = yelp_uri_new_relative (uri, uriv[1]); g_strfreev (uriv); yelp_uri_resolve (uri); while (!yelp_uri_is_resolved (uri)) while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); outstream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); print_uri (curi, uri, outstream); out = (gchar *) g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (outstream)); g_free (curi); g_assert (!strncmp (out, contents, bytes)); }
int main (int argc, char **argv) { g_autoptr(GError) error = NULL; setlocale (LC_ALL, ""); if (argc < 5 || (argc % 2) != 1) { g_printerr ("Usage: %s REPO MOUNT-ROOT COLLECTION-ID REF-NAME [COLLECTION-ID REF-NAME …]\n", argv[0]); return 1; } g_autoptr(GMainContext) context = g_main_context_new (); g_main_context_push_thread_default (context); g_autoptr(OstreeRepo) parent_repo = ostree_repo_open_at (AT_FDCWD, argv[1], NULL, &error); g_assert_no_error (error); /* Set up a mock volume. */ g_autoptr(GFile) mount_root = g_file_new_for_commandline_arg (argv[2]); g_autoptr(GMount) mount = G_MOUNT (ostree_mock_mount_new ("mount", mount_root)); g_autoptr(GList) mounts = g_list_prepend (NULL, mount); g_autoptr(GVolumeMonitor) monitor = ostree_mock_volume_monitor_new (mounts, NULL); g_autoptr(OstreeRepoFinderMount) finder = ostree_repo_finder_mount_new (monitor); /* Resolve the refs. */ g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func ((GDestroyNotify) collection_ref_free0); for (gsize i = 3; i < argc; i += 2) { const char *collection_id = argv[i]; const char *ref_name = argv[i + 1]; g_ptr_array_add (refs, ostree_collection_ref_new (collection_id, ref_name)); } g_ptr_array_add (refs, NULL); /* NULL terminator */ g_autoptr(GAsyncResult) result = NULL; ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), (const OstreeCollectionRef * const *) refs->pdata, parent_repo, NULL, result_cb, &result); while (result == NULL) g_main_context_iteration (context, TRUE); g_autoptr(GPtrArray) results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), result, &error); g_assert_no_error (error); /* Check that the results are correct: the invalid refs should have been * ignored, and the valid results canonicalised and deduplicated. */ for (gsize i = 0; i < results->len; i++) { const OstreeRepoFinderResult *result = g_ptr_array_index (results, i); GHashTableIter iter; OstreeCollectionRef *ref; const gchar *checksum; g_hash_table_iter_init (&iter, result->ref_to_checksum); while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum)) g_print ("%" G_GSIZE_FORMAT " %s %s %s %s\n", i, ostree_remote_get_name (result->remote), ref->collection_id, ref->ref_name, checksum); } g_main_context_pop_thread_default (context); return 0; }
static VALUE run_one_loop( VALUE self ) { g_main_context_iteration(NULL, 0); return Qnil; }
static void ui_create(ggcov_params_t ¶ms, const char *full_argv0, int successes) { /* * If we're being run from the source directory, fiddle the * glade search path to point to ../ui first. This means * we can run ggcov before installation without having to * compile with UI_DEBUG=1. */ estring dir = file_make_absolute(full_argv0); const char *p = strrchr(dir, '/'); if (p != 0 && (p -= 4) >= dir.data() && !strncmp(p, "/src/", 5)) { dir.truncate_to(p - dir); dir.append_string("/ui"); if (!file_is_directory(dir)) { _log.info("running from source directory, " "so prepending %s to glade search path\n", dir.data()); ui_prepend_glade_path(dir); } } const struct window *wp; for (wp = windows ; wp->name ; wp++) ui_register_windows_entry(_(wp->label), wp->create, 0); ui_set_default_icon(ggcov32_xpm); prefs.load(); if (!successes) { /* No files discovered from commandline...show the File->Open dialog to get some */ on_file_open_activate(0, 0); while (!*cov_file_t::first()) gtk_main_iteration(); } /* Possibly have files from commandline or dialog...show initial windows */ tok_t tok(params.get_initial_windows(), ", \n\r"); const char *name; int nwindows = 0; while ((name = tok.next()) != 0) { for (wp = windows ; wp->name ; wp++) { if (!strcmp(name, wp->name)) { wp->create(0, 0); nwindows++; break; } } if (!wp->name) _log.warning("unknown window name \"%s\"\n", name); } if (!nwindows) on_windows_new_summarywin_activated(0, 0); if (params.get_profile_mode()) { while (g_main_context_iteration(NULL, FALSE)) ; exit(0); } }
int main (int argc, char **argv) { CockpitTransport *transport; gboolean terminated = FALSE; gboolean interupted = FALSE; gboolean closed = FALSE; GOptionContext *context; GError *error = NULL; guint sig_term; guint sig_int; int outfd; static GOptionEntry entries[] = { { "lower", 0, 0, G_OPTION_ARG_NONE, &opt_lower, "Lower case channel type", NULL }, { "upper", 0, 0, G_OPTION_ARG_NONE, &opt_upper, "Upper case channel type", NULL }, { NULL } }; signal (SIGPIPE, SIG_IGN); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_setenv ("GIO_USE_PROXY_RESOLVER", "dummy", TRUE); g_setenv ("GIO_USE_VFS", "local", TRUE); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "mock-bridge as used in tests\n"); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_printerr ("mock-bridge: %s\n", error->message); g_error_free (error); return 1; } outfd = dup (1); if (outfd < 0 || dup2 (2, 1) < 1) { g_warning ("bridge couldn't redirect stdout to stderr"); outfd = 1; } sig_term = g_unix_signal_add (SIGTERM, on_signal_done, &terminated); sig_int = g_unix_signal_add (SIGINT, on_signal_done, &interupted); g_type_init (); transport = cockpit_pipe_transport_new_fds ("stdio", 0, outfd); g_signal_connect (transport, "control", G_CALLBACK (on_transport_control), NULL); g_signal_connect (transport, "closed", G_CALLBACK (on_closed_set_flag), &closed); send_init_command (transport); /* Owns the channels */ channels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); while (!terminated && !closed && !interupted) g_main_context_iteration (NULL, TRUE); g_object_unref (transport); g_hash_table_destroy (channels); g_source_remove (sig_term); g_source_remove (sig_int); /* So the caller gets the right signal */ if (terminated) raise (SIGTERM); return 0; }
static gboolean run (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; const char *dirpath; OtTrivialHttpd appstruct = { 0, }; OtTrivialHttpd *app = &appstruct; glnx_unref_object SoupServer *server = NULL; g_autoptr(GFileMonitor) dirmon = NULL; context = g_option_context_new ("[DIR] - Simple webserver"); g_option_context_add_main_entries (context, options, NULL); app->root_dfd = -1; if (!g_option_context_parse (context, &argc, &argv, error)) goto out; if (argc > 1) dirpath = argv[1]; else dirpath = "."; if (!glnx_opendirat (AT_FDCWD, dirpath, TRUE, &app->root_dfd, error)) goto out; if (!(opt_random_500s_percentage >= 0 && opt_random_500s_percentage <= 99)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid --random-500s=%u", opt_random_500s_percentage); goto out; } if (opt_log) { GOutputStream *stream = NULL; if (g_strcmp0 (opt_log, "-") == 0) { if (opt_daemonize) { ot_util_usage_error (context, "Cannot use --log-file=- and --daemonize at the same time", error); goto out; } stream = G_OUTPUT_STREAM (g_unix_output_stream_new (STDOUT_FILENO, FALSE)); } else { g_autoptr(GFile) log_file = NULL; GFileOutputStream* log_stream; log_file = g_file_new_for_path (opt_log); log_stream = g_file_create (log_file, G_FILE_CREATE_PRIVATE, cancellable, error); if (!log_stream) goto out; stream = G_OUTPUT_STREAM (log_stream); } app->log = stream; } #if SOUP_CHECK_VERSION(2, 48, 0) server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL); if (!soup_server_listen_all (server, opt_port, 0, error)) goto out; #else server = soup_server_new (SOUP_SERVER_PORT, opt_port, SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL); #endif soup_server_add_handler (server, NULL, httpd_callback, app, NULL); if (opt_port_file) { g_autofree char *portstr = NULL; #if SOUP_CHECK_VERSION(2, 48, 0) GSList *listeners = soup_server_get_listeners (server); g_autoptr(GSocket) listener = NULL; g_autoptr(GSocketAddress) addr = NULL; g_assert (listeners); listener = g_object_ref (listeners->data); g_slist_free (listeners); listeners = NULL; addr = g_socket_get_local_address (listener, error); if (!addr) goto out; g_assert (G_IS_INET_SOCKET_ADDRESS (addr)); portstr = g_strdup_printf ("%u\n", g_inet_socket_address_get_port ((GInetSocketAddress*)addr)); #else portstr = g_strdup_printf ("%u\n", soup_server_get_port (server)); #endif if (g_strcmp0 ("-", opt_port_file) == 0) { fputs (portstr, stdout); // not g_print - this must go to stdout, not a handler fflush (stdout); } else if (!g_file_set_contents (opt_port_file, portstr, strlen (portstr), error)) goto out; } #if !SOUP_CHECK_VERSION(2, 48, 0) soup_server_run_async (server); #endif if (opt_daemonize) { pid_t pid = fork(); if (pid == -1) { int errsv = errno; g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errsv), g_strerror (errsv)); goto out; } else if (pid > 0) { ret = TRUE; goto out; } /* Child, continue */ if (setsid () < 0) err (1, "setsid"); /* Daemonising: close stdout/stderr so $() et al work on us */ if (freopen("/dev/null", "r", stdin) == NULL) err (1, "freopen"); if (freopen("/dev/null", "w", stdout) == NULL) err (1, "freopen"); if (freopen("/dev/null", "w", stderr) == NULL) err (1, "freopen"); } else { /* Since we're used for testing purposes, let's just do this by * default. This ensures we exit when our parent does. */ if (prctl (PR_SET_PDEATHSIG, SIGTERM) != 0) { if (errno != ENOSYS) { glnx_set_error_from_errno (error); goto out; } } } app->running = TRUE; if (opt_autoexit) { gboolean is_symlink = FALSE; g_autoptr(GFile) root = NULL; g_autoptr(GFileInfo) info = NULL; root = g_file_new_for_path (dirpath); info = g_file_query_info (root, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!info) goto out; is_symlink = g_file_info_get_is_symlink (info); if (is_symlink) dirmon = g_file_monitor_file (root, 0, cancellable, error); else dirmon = g_file_monitor_directory (root, 0, cancellable, error); if (!dirmon) goto out; g_signal_connect (dirmon, "changed", G_CALLBACK (on_dir_changed), app); } httpd_log (app, "serving at root %s\n", dirpath); while (app->running) g_main_context_iteration (NULL, TRUE); ret = TRUE; out: if (app->root_dfd != -1) (void) close (app->root_dfd); g_clear_object (&app->log); return ret; }
/** * gcr_importer_import: * @importer: the importer * @cancellable: a #GCancellable, or %NULL * @error: the location to place an error on failure, or %NULL * * Import the queued items in the importer. This call will block * until the operation completes. * * Returns: whether the items were imported successfully or not */ gboolean gcr_importer_import (GcrImporter *importer, GCancellable *cancellable, GError **error) { gboolean result; ImportClosure *closure; GcrImporterIface *iface; g_return_val_if_fail (GCR_IS_IMPORTER (importer), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); iface = GCR_IMPORTER_GET_INTERFACE (importer); if (iface->import_sync) return (iface->import_sync) (importer, cancellable, error); g_return_val_if_fail (iface->import_async != NULL, FALSE); g_return_val_if_fail (iface->import_finish != NULL, FALSE); closure = g_new0 (ImportClosure, 1); closure->cond = g_new (GCond, 1); g_cond_init (closure->cond); closure->mutex = g_new (GMutex, 1); g_mutex_init (closure->mutex); closure->context = g_main_context_get_thread_default (); g_mutex_lock (closure->mutex); (iface->import_async) (importer, cancellable, on_import_async_complete, closure); /* * Handle the case where we've been called from within the main context * or in the case where the main context is not running. This approximates * the behavior of a modal dialog. */ if (g_main_context_acquire (closure->context)) { while (!closure->complete) { g_mutex_unlock (closure->mutex); g_main_context_iteration (closure->context, TRUE); g_mutex_lock (closure->mutex); } g_main_context_release (closure->context); /* * Handle the case where we're in a different thread than the main * context and a main loop is running. */ } else { while (!closure->complete) g_cond_wait (closure->cond, closure->mutex); } g_mutex_unlock (closure->mutex); result = (closure->error == NULL); if (closure->error) g_propagate_error (error, closure->error); g_cond_clear (closure->cond); g_free (closure->cond); g_mutex_clear (closure->mutex); g_free (closure->mutex); g_free (closure); return result; }
long wxWebViewWebKit::Find(const wxString& text, int flags) { WebKitFindController* findctrl = webkit_web_view_get_find_controller(m_web_view); bool newSearch = false; if(text != m_findText || (flags & wxWEBVIEW_FIND_MATCH_CASE) != (m_findFlags & wxWEBVIEW_FIND_MATCH_CASE)) { newSearch = true; //If it is a new search we need to clear existing highlights webkit_find_controller_search_finish(findctrl); } m_findFlags = flags; m_findText = text; //If the search string is empty then we clear any selection and highlight if(text.empty()) { webkit_find_controller_search_finish(findctrl); ClearSelection(); return wxNOT_FOUND; } bool wrap = false, forward = true; guint32 options = WEBKIT_FIND_OPTIONS_NONE; if(flags & wxWEBVIEW_FIND_WRAP) { wrap = true; options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; } if(!(flags & wxWEBVIEW_FIND_MATCH_CASE)) { options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; } if(flags & wxWEBVIEW_FIND_BACKWARDS) { forward = false; options |= WEBKIT_FIND_OPTIONS_BACKWARDS; } if(newSearch) { //Initially we count the matches to know how many we have m_findCount = -1; webkit_find_controller_count_matches(findctrl, wxGTK_CONV(text), options, G_MAXUINT); GMainContext *main_context = g_main_context_get_thread_default(); while (m_findCount == -1) { g_main_context_iteration(main_context, TRUE); } //Highlight them if needed if(flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) { webkit_find_controller_search(findctrl, wxGTK_CONV(text), options, G_MAXUINT); } //In this case we return early to match IE behaviour m_findPosition = -1; return m_findCount; } else { if(forward) m_findPosition++; else m_findPosition--; if(m_findPosition < 0) m_findPosition += m_findCount; if(m_findPosition > m_findCount) m_findPosition -= m_findCount; } if(forward) { webkit_find_controller_search_next(findctrl); if(m_findPosition == m_findCount && !wrap) { return wxNOT_FOUND; } } else { webkit_find_controller_search_previous(findctrl); if(m_findPosition == -1 && !wrap) { return wxNOT_FOUND; } } return newSearch ? m_findCount : m_findPosition; }
int main(int argc, char *argv[]) { NCLError err; GOptionContext *context; GError *error = NULL; char **opt_command = NULL; char *opt_script = NULL; gboolean opt_keep_running = FALSE, show_help = FALSE; GOptionEntry options[] = { { "exec", 'e', 0, G_OPTION_ARG_STRING_ARRAY, &opt_command, "Execute command", "command" }, { "script", 's', 0, G_OPTION_ARG_STRING , &opt_script, "Execute script", "filename" }, { "keep", 'k', 0, G_OPTION_ARG_NONE, &opt_keep_running, "Keep running after command/script execution" }, { NULL } }; neardal_output_cb = ncl_trace; rl_callback_handler_install(NCL_PROMPT, ncl_parse_line); NCL_CMD_PRINT("Compiled at %s : %s\n\n", __DATE__, __TIME__); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { NCL_CMD_PRINTERR("%s\n", error->message); g_error_free(error); return NCLERR_INIT; } g_option_context_free(context); if ((err = ncl_prv_init()) != NCLERR_NOERROR) goto exit; if (!opt_script && !opt_command) { opt_keep_running = TRUE; show_help = TRUE; } if (opt_script) ncl_prv_parse_script_file(opt_script); while (opt_command) { gNclCtx.errOnExit = ncl_exec(*opt_command); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); g_free(*opt_command++); if (!*opt_command) opt_command = NULL; } if (opt_keep_running) { gNclCtx.channel = g_io_channel_unix_new(STDIN_FILENO); gNclCtx.tag = g_io_add_watch(gNclCtx.channel, G_IO_IN, (GIOFunc) ncl_prv_kbinput_cb, &gNclCtx); g_io_channel_unref(gNclCtx.channel); if (show_help) ncl_exec(LISTCMD_NAME); g_main_loop_run(gNclCtx.main_loop); } err = gNclCtx.errOnExit; exit: ncl_finalize(); if (err != NCLERR_NOERROR) NCL_CMD_PRINTERR("Exit with error %d\n", err); return err; }
/* Update TLE from local files */ static void menubar_tle_local_cb(GtkWidget * widget, gpointer data) { gchar *dir; /* selected directory */ GtkWidget *dir_chooser; /* directory chooser button */ GtkWidget *dialog; /* dialog window */ GtkWidget *label; /* misc labels */ GtkWidget *progress; /* progress indicator */ GtkWidget *label1, *label2; /* activitity and stats labels */ GtkWidget *box; gint response; /* dialog response */ gboolean doupdate = FALSE; (void)widget; (void)data; /* get last used directory */ dir = sat_cfg_get_str(SAT_CFG_STR_TLE_FILE_DIR); /* if there is no last used dir fall back to $HOME */ if (dir == NULL) { dir = g_strdup(g_get_home_dir()); } /* create file chooser */ dir_chooser = gtk_file_chooser_button_new(_("Select directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dir_chooser), dir); g_free(dir); /* create label */ label = gtk_label_new(_("Select TLE directory:")); /* pack label and chooser into a hbox */ box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(box), FALSE); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), dir_chooser, TRUE, TRUE, 5); gtk_widget_show_all(box); /* create the dalog */ dialog = gtk_dialog_new_with_buttons(_("Update TLE from files"), GTK_WINDOW(app), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "_Cancel", GTK_RESPONSE_REJECT, "_OK", GTK_RESPONSE_ACCEPT, NULL); gtk_box_pack_start(GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), box, TRUE, TRUE, 30); response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_ACCEPT) doupdate = TRUE; else doupdate = FALSE; /* get directory before we destroy the dialog */ dir = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dir_chooser)); /* nuke the dialog */ gtk_widget_destroy(dialog); if (doupdate) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Running TLE update from %s"), __func__, dir); /* store last used TLE dir */ sat_cfg_set_str(SAT_CFG_STR_TLE_FILE_DIR, dir); /* create new dialog with progress indicator */ dialog = gtk_dialog_new_with_buttons(_("TLE Update"), GTK_WINDOW(app), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "_Close", GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE); /* create a vbox */ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_set_homogeneous(GTK_BOX(box), FALSE); gtk_container_set_border_width(GTK_CONTAINER(box), 20); /* add static label */ label = gtk_label_new(NULL); g_object_set(label, "xalign", 0.5, "yalign", 0.5, NULL); gtk_label_set_markup(GTK_LABEL(label), _("<b>Updating TLE files from files</b>")); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); /* activity label */ label1 = gtk_label_new("..."); g_object_set(label1, "xalign", 0.5, "yalign", 0.5, NULL); gtk_box_pack_start(GTK_BOX(box), label1, FALSE, FALSE, 0); /* add progress bar */ progress = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(box), progress, FALSE, FALSE, 10); /* statistics */ label2 = gtk_label_new(_("Satellites updated:\t 0\n" "Satellites skipped:\t 0\n" "Missing Satellites:\t 0\n")); gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 0); /* finalise dialog */ gtk_container_add(GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), box); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); gtk_widget_show_all(dialog); /* Force the drawing queue to be processed otherwise the dialog may not appear before we enter the TLE updating func - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602 */ while (g_main_context_iteration(NULL, FALSE)); /* update TLE */ tle_update_from_files(dir, NULL, FALSE, progress, label1, label2); /* set progress bar to 100% */ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 1.0); gtk_label_set_text(GTK_LABEL(label1), _("Finished")); /* enable close button */ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, TRUE); } if (dir) g_free(dir); /* reload satellites */ mod_mgr_reload_sats(); }
static int run_bridge (const gchar *interactive) { CockpitTransport *transport; CockpitBridge *bridge; gboolean terminated = FALSE; gboolean interupted = FALSE; gboolean closed = FALSE; gboolean init_received = FALSE; guint sig_term; guint sig_int; int outfd; cockpit_set_journal_logging (G_LOG_DOMAIN, !isatty (2)); /* * This process talks on stdin/stdout. However lots of stuff wants to write * to stdout, such as g_debug, and uses fd 1 to do that. Reroute fd 1 so that * it goes to stderr, and use another fd for stdout. */ outfd = dup (1); if (outfd < 0 || dup2 (2, 1) < 1) { g_warning ("bridge couldn't redirect stdout to stderr"); outfd = 1; } sig_term = g_unix_signal_add (SIGTERM, on_signal_done, &terminated); sig_int = g_unix_signal_add (SIGINT, on_signal_done, &interupted); g_type_init (); cockpit_dbus_json_allow_external = FALSE; packages = cockpit_packages_new (); cockpit_dbus_internal_startup (interactive != NULL); if (interactive) { /* Allow skipping the init message when interactive */ init_received = TRUE; transport = cockpit_interact_transport_new (0, outfd, interactive); } else { transport = cockpit_pipe_transport_new_fds ("stdio", 0, outfd); } g_resources_register (cockpitassets_get_resource ()); cockpit_web_failure_resource = "/org/cockpit-project/Cockpit/fail.html"; bridge = cockpit_bridge_new (transport, payload_types, init_received); cockpit_dbus_environment_startup (); g_signal_connect (transport, "closed", G_CALLBACK (on_closed_set_flag), &closed); send_init_command (transport); while (!terminated && !closed && !interupted) g_main_context_iteration (NULL, TRUE); g_object_unref (bridge); g_object_unref (transport); cockpit_packages_free (packages); packages = NULL; g_source_remove (sig_term); g_source_remove (sig_int); /* So the caller gets the right signal */ if (terminated) raise (SIGTERM); return 0; }
/* Update TLE from network */ static void menubar_tle_net_cb(GtkWidget * widget, gpointer data) { GtkWidget *dialog; GtkWidget *label; GtkWidget *progress; GtkWidget *label1, *label2; GtkWidget *box; (void)widget; (void)data; /* create new dialog with progress indicator */ dialog = gtk_dialog_new_with_buttons(_("TLE Update"), GTK_WINDOW(app), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "_Close", GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE); /* create a vbox */ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_set_homogeneous(GTK_BOX(box), FALSE); gtk_container_set_border_width(GTK_CONTAINER(box), 20); /* add static label */ label = gtk_label_new(NULL); g_object_set(label, "xalign", 0.5, "yalign", 0.5, NULL); gtk_label_set_markup(GTK_LABEL(label), _("<b>Updating TLE files from network</b>")); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); /* activity label */ label1 = gtk_label_new("..."); g_object_set(label1, "xalign", 0.5, "yalign", 0.5, NULL); gtk_box_pack_start(GTK_BOX(box), label1, FALSE, FALSE, 0); /* add progress bar */ progress = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(box), progress, FALSE, FALSE, 10); /* statistics */ label2 = gtk_label_new(_("Satellites updated:\t 0\n" "Satellites skipped:\t 0\n" "Missing Satellites:\t 0\n")); gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 0); /* finalise dialog */ gtk_container_add(GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), box); g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); gtk_widget_show_all(dialog); /* Force the drawing queue to be processed otherwise the dialog may not appear before we enter the TLE updating func - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602 */ while (g_main_context_iteration(NULL, FALSE)); /* update TLE */ tle_update_from_network(FALSE, progress, label1, label2); /* set progress bar to 100% */ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 1.0); gtk_label_set_text(GTK_LABEL(label1), _("Finished")); /* enable close button */ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, TRUE); /* reload satellites */ mod_mgr_reload_sats(); }
int main (int argc, char *argv[]) { GMainLoop *inner; GError *err = NULL; guint name_id; g_type_init (); /* Setup application context */ mm_context_init (argc, argv); if (!mm_log_setup (mm_context_get_log_level (), mm_context_get_log_file (), mm_context_get_timestamps (), mm_context_get_relative_timestamps (), mm_context_get_debug (), &err)) { g_warning ("Failed to set up logging: %s", err->message); g_error_free (err); exit (1); } g_unix_signal_add (SIGTERM, quit_cb, NULL); g_unix_signal_add (SIGINT, quit_cb, NULL); mm_info ("ModemManager (version " MM_DIST_VERSION ") starting in %s bus...", mm_context_get_test_session () ? "session" : "system"); /* Acquire name, don't allow replacement */ name_id = g_bus_own_name (mm_context_get_test_session () ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM, MM_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired_cb, name_acquired_cb, name_lost_cb, NULL, NULL); /* Go into the main loop */ loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); /* Clear the global variable, so that subsequent requests to * exit succeed. */ inner = loop; loop = NULL; if (manager) { GTimer *timer; mm_base_manager_shutdown (manager); /* Wait for all modems to be disabled and removed, but don't wait * forever: if disabling the modems takes longer than 20s, just * shutdown anyway. */ timer = g_timer_new (); while (mm_base_manager_num_modems (manager) && g_timer_elapsed (timer, NULL) < (gdouble)MAX_SHUTDOWN_TIME_SECS) { GMainContext *ctx = g_main_loop_get_context (inner); g_main_context_iteration (ctx, FALSE); g_usleep (50); } if (mm_base_manager_num_modems (manager)) mm_warn ("Disabling modems took too long, " "shutting down with '%u' modems around", mm_base_manager_num_modems (manager)); g_object_unref (manager); g_timer_destroy (timer); } g_main_loop_unref (inner); g_bus_unown_name (name_id); mm_info ("ModemManager is shut down"); mm_log_shutdown (); return 0; }
static int run_bridge (const gchar *interactive, gboolean privileged_slave) { CockpitTransport *transport; gboolean terminated = FALSE; gboolean interupted = FALSE; gboolean closed = FALSE; CockpitPortal *super = NULL; CockpitPortal *pcp = NULL; gpointer polkit_agent = NULL; const gchar *directory; struct passwd *pwd; GPid daemon_pid = 0; GPid agent_pid = 0; guint sig_term; guint sig_int; int outfd; uid_t uid; cockpit_set_journal_logging (G_LOG_DOMAIN, !isatty (2)); /* * The bridge always runs from within $XDG_RUNTIME_DIR * This makes it easy to create user sockets and/or files. */ if (!privileged_slave) { directory = g_get_user_runtime_dir (); if (g_mkdir_with_parents (directory, 0700) < 0) g_warning ("couldn't create runtime dir: %s: %s", directory, g_strerror (errno)); else if (g_chdir (directory) < 0) g_warning ("couldn't change to runtime dir: %s: %s", directory, g_strerror (errno)); } /* Always set environment variables early */ uid = geteuid(); pwd = getpwuid_a (uid); if (pwd == NULL) { g_message ("couldn't get user info: %s", g_strerror (errno)); } else { g_setenv ("USER", pwd->pw_name, TRUE); g_setenv ("HOME", pwd->pw_dir, TRUE); g_setenv ("SHELL", pwd->pw_shell, TRUE); } /* Reset the umask, typically this is done in .bashrc for a login shell */ umask (022); /* * This process talks on stdin/stdout. However lots of stuff wants to write * to stdout, such as g_debug, and uses fd 1 to do that. Reroute fd 1 so that * it goes to stderr, and use another fd for stdout. */ outfd = dup (1); if (outfd < 0 || dup2 (2, 1) < 1) { g_warning ("bridge couldn't redirect stdout to stderr"); outfd = 1; } sig_term = g_unix_signal_add (SIGTERM, on_signal_done, &terminated); sig_int = g_unix_signal_add (SIGINT, on_signal_done, &interupted); g_type_init (); /* Start daemons if necessary */ if (!interactive && !privileged_slave) { if (!have_env ("DBUS_SESSION_BUS_ADDRESS")) daemon_pid = start_dbus_daemon (); if (!have_env ("SSH_AUTH_SOCK")) agent_pid = start_ssh_agent (); } packages = cockpit_packages_new (); cockpit_dbus_internal_startup (interactive != NULL); if (interactive) { /* Allow skipping the init message when interactive */ init_received = TRUE; transport = cockpit_interact_transport_new (0, outfd, interactive); } else { transport = cockpit_pipe_transport_new_fds ("stdio", 0, outfd); } if (uid != 0) { if (!interactive) polkit_agent = cockpit_polkit_agent_register (transport, NULL); super = cockpit_portal_new_superuser (transport); } g_resources_register (cockpitassets_get_resource ()); cockpit_web_failure_resource = "/org/cockpit-project/Cockpit/fail.html"; pcp = cockpit_portal_new_pcp (transport); cockpit_dbus_time_startup (); cockpit_dbus_user_startup (pwd); cockpit_dbus_setup_startup (); g_free (pwd); pwd = NULL; g_signal_connect (transport, "control", G_CALLBACK (on_transport_control), NULL); g_signal_connect (transport, "closed", G_CALLBACK (on_closed_set_flag), &closed); send_init_command (transport); /* Owns the channels */ channels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); while (!terminated && !closed && !interupted) g_main_context_iteration (NULL, TRUE); if (polkit_agent) cockpit_polkit_agent_unregister (polkit_agent); if (super) g_object_unref (super); g_object_unref (pcp); g_object_unref (transport); g_hash_table_destroy (channels); cockpit_dbus_internal_cleanup (); cockpit_packages_free (packages); packages = NULL; if (daemon_pid) kill (daemon_pid, SIGTERM); if (agent_pid) kill (agent_pid, SIGTERM); g_source_remove (sig_term); g_source_remove (sig_int); /* So the caller gets the right signal */ if (terminated) raise (SIGTERM); return 0; }
bool mmsGstPlay(GstElement *pipelineX) { pipeline = pipelineX; GstState state, pending; caught_error = event_loop (pipeline, FALSE, GST_STATE_PLAYING); if (caught_error) { fprintf (stderr, "ERROR: pipeline doesn't want to preroll.\n"); } else { GstClockTime tfthen, tfnow; GstClockTimeDiff diff; fprintf (stderr, "Setting pipeline to PLAYING ...\n"); if (gst_element_set_state (pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { GstMessage *err_msg; GstBus *bus; fprintf (stderr, "ERROR: pipeline doesn't want to play.\n"); bus = gst_element_get_bus (pipeline); if ((err_msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0))) { GError *gerror; gchar *debug; gst_message_parse_error (err_msg, &gerror, &debug); gst_object_default_error (GST_MESSAGE_SRC (err_msg), gerror, debug); gst_message_unref (err_msg); g_error_free (gerror); g_free (debug); } gst_object_unref (bus); mmsGstFree(); return false; } tfthen = gst_util_get_timestamp (); caught_error = event_loop (pipeline, TRUE, GST_STATE_PLAYING); tfnow = gst_util_get_timestamp (); diff = GST_CLOCK_DIFF (tfthen, tfnow); g_print ("Execution ended after %" G_GUINT64_FORMAT " ns.\n", diff); } /* iterate mainloop to process pending stuff */ while (g_main_context_iteration (NULL, FALSE)); fprintf (stderr, "Setting pipeline to PAUSED ...\n"); gst_element_set_state (pipeline, GST_STATE_PAUSED); if (!caught_error) gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE); fprintf (stderr, "Setting pipeline to READY ...\n"); gst_element_set_state (pipeline, GST_STATE_READY); gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE); // playback is finished return true; }
void *BrowserMain(void * argument) { printf("%s:%d\n", __func__, __LINE__); int argc = 0; char**argv = NULL; pthread_mutex_init (&mutex, NULL); g_type_init(); g_thread_init(NULL); lite_open( &argc, &argv ); WebKitDFB_Initialize( lite_get_dfb_interface() ); IDirectFBDisplayLayer *layer; DFBDisplayLayerConfig config; lite_get_layer_interface( &layer ); layer->GetConfiguration( layer, &config ); DFBRectangle windowRect = { 0, 0, config.width, config.height }; DFBRectangle webviewRect = { 0, 0, config.width, config.height }; lite_new_window( NULL, &windowRect, DWCAPS_NONE, liteNoWindowTheme, "WebKitDFB", &g_window ); lite_new_webview( LITE_BOX(g_window), &webviewRect, liteDefaultWebViewTheme, &g_webview); lite_on_webview_doc_loaded ( g_webview, on_webview_doc_loaded, NULL ); lite_on_raw_window_keyboard(g_window, on_key_press, g_webview ); lite_focus_box( LITE_BOX(g_webview) ); lite_set_window_opacity(g_window, 0xff); g_window->bg.enabled = DFB_FALSE; //lite_set_window_background_color(g_window, 0xff, 0, 0, 0xff); registerJsFunctions(g_webview, g_Callback); lite_webview_load(g_webview, g_url); lite_webview_set_transparent(g_webview, true); // FAKE KEY INTERFACE //IDirectFB *dfb; //dfb = lite_get_dfb_interface(); //IDirectFBDisplayLayer *layer = NULL; //dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer); layer->GetWindow(layer, 1, &g_dfb_window); lite_enqueue_window_timeout(200, timeout_cb, NULL, &timer_id); g_run = 1; while (g_run) { pthread_mutex_lock(&mutex); g_main_context_iteration(NULL, FALSE); lite_window_event_loop(g_window, 1); pthread_mutex_unlock(&mutex); } lite_close(); return NULL; }
int main(int argc, char *argv[]) { bool haveNFlag = false; bool haveTFlag = false; std::string sizeStr; std::string typeStr; for (int i = 1; i < argc; i++) { std::string thisArg = argv[i]; if (thisArg == "-s") { if (i == (argc - 1)) { Usage(); } sizeStr = argv[i + 1]; fileSize = atoi(sizeStr.c_str()); if (fileSize < 0) { Usage(); } i++; } else if (thisArg == "-n") { haveNFlag = true; if (i == (argc -1)) { Usage(); } std::string nFileStr = argv[i + 1]; nFiles = atoi(nFilesStr.c_str()); if (nFiles < 0) { Usage(); } i++; } else if (thisArg == "-t") { haveTFlag = true; if (i == (argc - 1)) { Usage(); } typeStr = argv[i + 1]; i++; } else { Usage(); } } if (!haveTFlag) { Usage(); } if (haveNFlag) { printf("Run for %d files\n", nFiles); } else { printf("Run forever\n"); } printf("File size %d bytes\n", fileSize); printf("Use filecache type %s\n", typeStr.c_str()); LSError lserror; LSErrorInit(&lserror); GMainLoop *mainLoop = NULL; mainLoop = g_main_loop_new(NULL, FALSE); bool ret = LSRegister(NULL, &filecacheService, &lserror); if (!ret) { fprintf(stderr, "LSRegister failed\n"); exit(1); } ret = LSGmainAttach(filecacheService, mainLoop, &lserror); if (!ret) { fprintf(stderr, "LSGmainAttach failed\n"); exit(1); } // // Create types in filecache. // std::string typeName = typeStr; std::string loWatermark = "10000"; std::string hiWatermark = "100000000"; std::string size = sizeStr; std::string cost = "1"; std::string lifetime = "100000"; std::string payload = "{\"typeName\":\"" + typeName + "\"" + ", \"loWatermark\": " + loWatermark + ", \"hiWatermark\": " + hiWatermark + ", \"size\": " + size + ", \"cost\": " + cost + ", \"lifetime\": " + lifetime + ", \"dirType\": false }"; std::string DefineTypeURI = std::string(FILECACHE_SERVICE_URI) + "/DefineType"; printf("calling DefineType %s\n", payload.c_str()); ret = LSCall(filecacheService, DefineTypeURI.c_str(), payload.c_str(), FilecacheServiceCb, GINT_TO_POINTER(send_count - 1), NULL, &lserror); if (!ret) { fprintf(stderr, "DefineType failed\n"); exit(1); } // // Wait for response from this LSCall() // handledResponse = false; while (!handledResponse) { g_main_context_iteration(NULL, true); } printf("created filecache type %s\n", typeName.c_str()); // // OK now create file in the cache. // int filesCreated = 0; while (true) { std::string fileName = "a.txt"; size = sizeStr; std::string cost = "1"; std::string lifetime = "100000"; std::string subscribe = "true"; payload = "{\"typeName\":\"" + typeName + "\"" + ", \"fileName\":\"" + fileName + "\"" + ", \"size\": " + size + ", \"cost\": " + cost + ", \"lifetime\": " + lifetime + ", \"subscribe\": true }"; std::string InsertCacheObjectURI = std::string(FILECACHE_SERVICE_URI) + "/InsertCacheObject"; LSMessageToken token; handledResponse = false; printf("calling InsertCacheObject %s\n", payload.c_str()); ret = LSCall(filecacheService, InsertCacheObjectURI.c_str(), payload.c_str(), FilecacheServiceCb, GINT_TO_POINTER(send_count -1), &token, &lserror); if (!ret) { fprintf(stderr, "InsertCacheObject failed\n"); goto error; } while (!handledResponse) { g_main_context_iteration(NULL, true); } printf("created cache object\n"); // // Parse the returned json. // pbnjson::JSchemaFragment inputSchema("{}"); pbnjson::JDomParser parser(NULL); if (!parser.parse(jsonResponseStr, inputSchema, NULL)) { // handle error fprintf(stderr, "Error parsing json response\n"); exit(1); } pbnjson::JValue parsed = parser.getDom(); std::string cacheFileName = parsed["pathName"].asString(); printf("cacheFileName = %s\n", cacheFileName.c_str()); // // Write data to the file. // char buf[fileSize]; int fd; if ((fd = open(cacheFileName.c_str(), O_WRONLY)) == -1) { fprintf(stderr, "Error, unable to open file %s for writing\n", cacheFileName.c_str()); exit(1); } if (write(fd, buf, fileSize) != fileSize) { fprintf(stderr, "Error, write to %s failed\n", cacheFileName.c_str()); exit(1); } close(fd); // // Cancel the subscription. // ret = LSCallCancel(filecacheService, token, &lserror); if (!ret) { fprintf(stderr, "Cancel of subscription failed\n"); goto error; } printf("subscription cancelled\n"); filesCreated++; if (filesCreated == nFiles) { printf("Done with %d files created\n", nFiles); exit(0); } } exit(0); error: fprintf(stderr, "stresstest exits\n"); exit(1); }
int I_PickIWad_Gtk (WadStuff *wads, int numwads, bool showwin, int defaultiwad) { GtkWidget *window; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *bbox; GtkWidget *widget; GtkWidget *tree; GtkWidget *check; GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *selection; GtkTreeIter iter, defiter; int close_style = 0; int i; char caption[100]; // Create the dialog window. window = gtk_window_new (GTK_WINDOW_TOPLEVEL); mysnprintf(caption, countof(caption), GAMESIG " %s: Select an IWAD to use", GetVersionString()); gtk_window_set_title (GTK_WINDOW(window), caption); gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_container_set_border_width (GTK_CONTAINER(window), 10); g_signal_connect (window, "delete_event", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect (window, "key_press_event", G_CALLBACK(CheckEscape), NULL); // Create the vbox container. vbox = gtk_vbox_new (FALSE, 10); gtk_container_add (GTK_CONTAINER(window), vbox); // Create the top label. widget = gtk_label_new ("ZDoom found more than one IWAD\nSelect from the list below to determine which one to use:"); gtk_box_pack_start (GTK_BOX(vbox), widget, false, false, 0); gtk_misc_set_alignment (GTK_MISC(widget), 0, 0); // Create a list store with all the found IWADs. store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); for (i = 0; i < numwads; ++i) { const char *filepart = strrchr (wads[i].Path, '/'); if (filepart == NULL) filepart = wads[i].Path; else filepart++; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, filepart, 1, wads[i].Name.GetChars(), 2, i, -1); if (i == defaultiwad) { defiter = iter; } } // Create the tree view control to show the list. tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store)); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("IWAD", renderer, "text", 0, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW(tree), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Game", renderer, "text", 1, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW(tree), column); gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(tree), true, true, 0); g_signal_connect(G_OBJECT(tree), "button_press_event", G_CALLBACK(DoubleClickChecker), &close_style); g_signal_connect(G_OBJECT(tree), "key_press_event", G_CALLBACK(AllowDefault), window); // Select the default IWAD. selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); gtk_tree_selection_select_iter (selection, &defiter); // Create the hbox for the bottom row. hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_end (GTK_BOX(vbox), hbox, false, false, 0); // Create the "Don't ask" checkbox. check = gtk_check_button_new_with_label ("Don't ask me this again"); gtk_box_pack_start (GTK_BOX(hbox), check, false, false, 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(check), !showwin); // Create the OK/Cancel button box. bbox = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX(bbox), 10); gtk_box_pack_end (GTK_BOX(hbox), bbox, false, false, 0); // Create the OK button. widget = gtk_button_new_from_stock (GTK_STOCK_OK); gtk_box_pack_start (GTK_BOX(bbox), widget, false, false, 0); GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT); gtk_widget_grab_default (widget); g_signal_connect (widget, "clicked", G_CALLBACK(ClickedOK), &close_style); g_signal_connect (widget, "activate", G_CALLBACK(ClickedOK), &close_style); // Create the cancel button. widget = gtk_button_new_from_stock (GTK_STOCK_CANCEL); gtk_box_pack_start (GTK_BOX(bbox), widget, false, false, 0); g_signal_connect (widget, "clicked", G_CALLBACK(gtk_main_quit), &window); // Finally we can show everything. gtk_widget_show_all (window); gtk_main (); if (close_style == 1) { GtkTreeModel *model; GValue value = { 0, { {0} } }; // Find out which IWAD was selected. gtk_tree_selection_get_selected (selection, &model, &iter); gtk_tree_model_get_value (GTK_TREE_MODEL(model), &iter, 2, &value); i = g_value_get_int (&value); g_value_unset (&value); // Set state of queryiwad based on the checkbox. queryiwad = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(check)); } else { i = -1; } if (GTK_IS_WINDOW(window)) { gtk_widget_destroy (window); // If we don't do this, then the X window might not actually disappear. while (g_main_context_iteration (NULL, FALSE)) {} } return i; }
void VolumeCatcherImpl::pump() { gboolean may_block = FALSE; g_main_context_iteration(g_main_context_default(), may_block); }
int manager_request_authorization(struct obex_transfer *transfer, int32_t time, char **new_folder, char **new_name) { struct obex_session *os = transfer->session; DBusMessage *msg; DBusPendingCall *call; unsigned int watch; gboolean got_reply; if (!agent) return -1; if (agent->auth_pending) return -EPERM; if (!new_folder || !new_name) return -EINVAL; msg = dbus_message_new_method_call(agent->bus_name, agent->path, AGENT_INTERFACE, "AuthorizePush"); dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &transfer->path, DBUS_TYPE_INVALID); if (!g_dbus_send_message_with_reply(connection, msg, &call, TIMEOUT)) { dbus_message_unref(msg); return -EPERM; } dbus_message_unref(msg); agent->auth_pending = TRUE; got_reply = FALSE; /* Catches errors before authorization response comes */ watch = g_io_add_watch_full(os->io, G_PRIORITY_DEFAULT, G_IO_HUP | G_IO_ERR | G_IO_NVAL, auth_error, NULL, NULL); dbus_pending_call_set_notify(call, agent_reply, &got_reply, NULL); /* Workaround: process events while agent doesn't reply */ while (agent && agent->auth_pending) g_main_context_iteration(NULL, TRUE); g_source_remove(watch); if (!got_reply) { dbus_pending_call_cancel(call); agent_cancel(); } dbus_pending_call_unref(call); if (!agent || !agent->new_name) return -EPERM; *new_folder = agent->new_folder; *new_name = agent->new_name; agent->new_folder = NULL; agent->new_name = NULL; return 0; }
bool nsAppShell::ProcessNextNativeEvent(bool mayWait) { return g_main_context_iteration(NULL, mayWait); }
int main (int argc, char *argv[]) { GtkWidget *button; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *menubar; GtkWidget *menuitem; GtkWidget *menu; GtkWidget *entry; GtkWidget *checkbutton; GtkAccelGroup *accel_group; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_window_set_title (GTK_WINDOW (window), "Socket Test"); gtk_container_set_border_width (GTK_CONTAINER (window), 0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (window), vbox); menubar = gtk_menu_bar_new (); menuitem = gtk_menu_item_new_with_mnemonic ("_File"); gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem); menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); menuitem = gtk_menu_item_new_with_mnemonic ("_Quit"); g_signal_connect (menuitem, "activate", G_CALLBACK (quit_cb), window); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); button = gtk_button_new_with_label ("Add Active Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_active_child), vbox); button = gtk_button_new_with_label ("Add Passive Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_passive_child), vbox); button = gtk_button_new_with_label ("Add Local Active Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_local_active_child), vbox); button = gtk_button_new_with_label ("Add Local Passive Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_local_passive_child), vbox); button = gtk_button_new_with_label ("Remove Last Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); g_signal_connect_swapped (button, "clicked", G_CALLBACK (remove_child), vbox); checkbutton = gtk_check_button_new_with_label ("Grab keyboard"); gtk_box_pack_start (GTK_BOX (vbox), checkbutton, FALSE, FALSE, 0); g_signal_connect (checkbutton, "toggled", G_CALLBACK (grab_window_toggled), window); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); entry = gtk_entry_new (); gtk_box_pack_start (GTK_BOX(hbox), entry, FALSE, FALSE, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); box = hbox; gtk_widget_show_all (window); gtk_main (); if (n_children) { g_print ("Waiting for children to exit\n"); while (n_children) g_main_context_iteration (NULL, TRUE); } return 0; }
static void file_remote_progress_callback (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) { RemoteProgress *progress = user_data; GTimeVal now; /* update the progress only up to 10 times a second */ g_get_current_time (&now); if (progress->last_time.tv_sec && ((now.tv_sec - progress->last_time.tv_sec) * 1000 + (now.tv_usec - progress->last_time.tv_usec) / 1000) < 100) return; progress->last_time = now; if (total_num_bytes > 0) { const gchar *format; gchar *done = g_format_size (current_num_bytes); gchar *total = g_format_size (total_num_bytes); switch (progress->mode) { case DOWNLOAD: format = _("Downloading image (%s of %s)"); break; case UPLOAD: format = _("Uploading image (%s of %s)"); break; default: g_assert_not_reached (); } gimp_progress_set_text (progress->progress, format, done, total); g_free (total); g_free (done); gimp_progress_set_value (progress->progress, (gdouble) current_num_bytes / (gdouble) total_num_bytes); } else { const gchar *format; gchar *done = g_format_size (current_num_bytes); switch (progress->mode) { case DOWNLOAD: format = _("Downloaded %s of image data"); break; case UPLOAD: format = _("Uploaded %s of image data"); break; default: g_assert_not_reached (); } gimp_progress_set_text (progress->progress, format, done); g_free (done); gimp_progress_pulse (progress->progress); } while (! progress->cancel && g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); }
/* make sure our script gets called with the right parameters */ static void test_pb_utils_install_plugins_do_callout (const gchar * const *details, GstInstallPluginsContext * ctx, const gchar * script, GstInstallPluginsReturn expected_result) { #ifdef G_OS_UNIX GstInstallPluginsReturn ret; GError *err = NULL; gchar *path; path = g_strdup_printf ("%s/gst-plugins-base-unit-test-helper.%s.%lu", g_get_tmp_dir (), (g_get_user_name ())? g_get_user_name () : "nobody", (gulong) getpid ()); if (!g_file_set_contents (path, script, -1, &err)) { GST_DEBUG ("Failed to write test script to %s: %s", path, err->message); g_error_free (err); goto done; } if (chmod (path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { GST_DEBUG ("Could not set mode u+rwx on '%s'", path); goto done; } /* test gst_install_plugins_supported() I */ g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/i/do/not/ex.ist!", 1); fail_if (gst_install_plugins_supported ()); GST_LOG ("setting GST_INSTALL_PLUGINS_HELPER to '%s'", path); g_setenv ("GST_INSTALL_PLUGINS_HELPER", path, 1); /* test gst_install_plugins_supported() II */ fail_unless (gst_install_plugins_supported ()); /* test sync callout */ ret = gst_install_plugins_sync (details, ctx); fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING || ret == expected_result, "gst_install_plugins_sync() failed with unexpected ret %d, which is " "neither HELPER_MISSING nor %d", ret, expected_result); /* test async callout */ marker = -333; ret = gst_install_plugins_async (details, ctx, result_cb, (gpointer) & marker); fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING || ret == GST_INSTALL_PLUGINS_STARTED_OK, "gst_install_plugins_async() failed with unexpected ret %d", ret); if (ret == GST_INSTALL_PLUGINS_STARTED_OK) { while (marker == -333) { g_usleep (500); g_main_context_iteration (NULL, FALSE); } /* and check that the callback was called with the expected code */ fail_unless_equals_int (marker, expected_result); } done: unlink (path); g_free (path); #endif /* G_OS_UNIX */ }