static void restore_poll_func(VALUE data) { if (g_main_context_get_poll_func(NULL) == (GPollFunc)rbglib_poll) { g_main_context_set_poll_func(NULL, default_poll_func); } }
nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); if (!gWidgetFocusLog) gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); if (!gWidgetDragLog) gWidgetDragLog = PR_NewLogModule("WidgetDrag"); if (!gWidgetDrawLog) gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); #endif if (!sPollFunc) { sPollFunc = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, &PollWrapper); } if (PR_GetEnv("MOZ_DEBUG_PAINTS")) gdk_window_set_debug_updates(TRUE); int err = pipe(mPipeFDs); if (err) return NS_ERROR_OUT_OF_MEMORY; GIOChannel *ioc; GSource *source; // make the pipe nonblocking int flags = fcntl(mPipeFDs[0], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; flags = fcntl(mPipeFDs[1], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; ioc = g_io_channel_unix_new(mPipeFDs[0]); source = g_io_create_watch(ioc, G_IO_IN); g_io_channel_unref(ioc); g_source_set_callback(source, (GSourceFunc)EventProcessorCallback, this, nullptr); g_source_set_can_recurse(source, TRUE); mTag = g_source_attach(source, nullptr); g_source_unref(source); return nsBaseAppShell::Init(); failed: close(mPipeFDs[0]); close(mPipeFDs[1]); mPipeFDs[0] = mPipeFDs[1] = 0; return NS_ERROR_FAILURE; }
/* The main() function. */ int main(int argc, char **argv) { struct sigaction sa; GIOChannel *channel; setlocale(LC_CTYPE, ""); /* Cleanup and signal handling */ atexit(cleanup); g_unix_signal_add(SIGINT, signal_handler, NULL); g_unix_signal_add(SIGTERM, signal_handler, NULL); sa.sa_handler = signal_fatal; sa.sa_flags = SA_RESETHAND; sigemptyset(&sa.sa_mask); sigaction(SIGABRT, &sa, 0); sigaction(SIGBUS, &sa, 0); sigaction(SIGFPE, &sa, 0); sigaction(SIGILL, &sa, 0); sigaction(SIGSEGV, &sa, 0); /* App core */ kixterm.app = kt_app_new(); /* Preferences */ kixterm.prefs = kt_prefs_new(); /* Font */ kixterm.font = kt_font_new(kixterm.app, kixterm.prefs); /* Color */ kixterm.color = kt_color_new(kixterm.app, kixterm.prefs); /* Main window */ kixterm.win = kt_window_new(kixterm.app, kixterm.prefs, kixterm.font, kixterm.color); /* Watch the X file descriptor for events */ channel = g_io_channel_unix_new(kt_app_get_xfd(kixterm.app)); g_io_add_watch(channel, G_IO_IN, kt_xcb_io_cb, NULL); g_io_channel_unref(channel); /* Main context */ g_main_context_set_poll_func(g_main_context_default(), &kt_poll); /* main event loop */ loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(loop); /* Cleanup */ g_main_loop_unref(loop); loop = NULL; exit(EXIT_SUCCESS); }
void misc_test() { GPollFunc func = g_main_context_get_poll_func(context); g_assert(func != NULL); g_main_context_set_poll_func(context,dummy_poll_func); func = g_main_context_get_poll_func(context); g_assert(func == dummy_poll_func); }
gint gtk_module_init (gint argc, gchar *argv[]) { GDBusConnection *dbus; gchar *address; const gchar *socket; GError *error = NULL; ENTRY; if (!(socket = g_getenv("GDKEVENT_SOCKET"))) { CRITICAL(Gdk, "Failed to load gdkevent socket."); RETURN(-1); } address = g_strdup_printf("unix:path=%s", socket); dbus = g_dbus_connection_new_for_address_sync(address, G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, NULL, NULL, &error); g_free(address); if (!dbus) { CRITICAL(Gdk, "Failed to load IPC socket: %s", error->message); g_error_free(error); RETURN(-1); } connection = dbus; gdk_event_handler_set(gdkevent_dispatcher, dbus, gdkevent_module_unloaded); g_get_current_time(&last_time); poll_func = g_main_context_get_poll_func(g_main_context_default()); g_main_context_set_poll_func(g_main_context_default(), gdkevent_poll); RETURN(0); }
int main (int argc, char *argv[]) { const gchar *dir; GeditCommandLine *command_line; gboolean ret; gboolean service = FALSE; #ifdef G_OS_UNIX GeditDBus *dbus; GeditDBusResult dbusret; #endif #ifdef OS_OSX GPollFunc orig_poll_func; GPollFunc gdk_poll_func; #endif #ifndef ENABLE_GVFS_METADATA const gchar *cache_dir; gchar *metadata_filename; #endif /* Setup debugging */ gedit_debug_init (); gedit_debug_message (DEBUG_APP, "Startup"); /* Setup locale/gettext */ setlocale (LC_ALL, ""); gedit_dirs_init (); dir = gedit_dirs_get_gedit_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, dir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifndef ENABLE_GVFS_METADATA /* Setup metadata-manager */ cache_dir = gedit_dirs_get_user_cache_dir (); metadata_filename = g_build_filename (cache_dir, METADATA_FILE, NULL); gedit_metadata_manager_init (metadata_filename); g_free (metadata_filename); #endif #ifdef OS_OSX orig_poll_func = g_main_context_get_poll_func (NULL); #endif /* Parse command line arguments */ command_line = gedit_command_line_get_default (); ret = gedit_command_line_parse (command_line, &argc, &argv); if (!ret) { g_object_unref (command_line); return 1; } #ifdef G_OS_UNIX #ifdef OS_OSX /* Note: this is a bit of a hack. What happens here is that we are going to * store the poll function installed by gdk (happens in post-parse of options) * and replace it with the original main loop poll handler. We do this because * the gedit dbus stuff is going to run some main loops to run async gdbus calls. * The problem is that for OS X, the gdk poll func in the main context (which * will be run due to the fact that the main loops in our dbus code iterate the * main context) is going to process events from NSApp, INCLUDING apple events * such as OpenFiles. Since we are not setup yet, we are going to miss these * events. By swapping out the gdk poll func, and swapping it back in later, * we prevent this from happening. Note that we only do this when building * on OS X to prevent any possible future problems for other platforms. * This is a dirty hack, but it works for now. */ gdk_poll_func = g_main_context_get_poll_func (NULL); g_main_context_set_poll_func (NULL, orig_poll_func); #endif /* Run over dbus */ dbus = gedit_dbus_new (); dbusret = gedit_dbus_run (dbus); #ifdef OS_OSX g_main_context_set_poll_func (NULL, gdk_poll_func); #endif switch (dbusret) { case GEDIT_DBUS_RESULT_SUCCESS: case GEDIT_DBUS_RESULT_FAILED: /* fallthrough */ g_object_unref (command_line); g_object_unref (dbus); return dbusret == GEDIT_DBUS_RESULT_SUCCESS ? 0 : 1; break; case GEDIT_DBUS_RESULT_PROCEED_SERVICE: service = TRUE; break; case GEDIT_DBUS_RESULT_PROCEED: break; } #endif gedit_main (service); #ifdef G_OS_UNIX g_object_unref (dbus); #endif g_object_unref (command_line); return 0; }
bool wxApp::Initialize(int& argc, wxChar **argv) { bool init_result; #if wxUSE_THREADS if (!g_thread_supported()) g_thread_init(NULL); wxgs_poll_func = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, wxapp_poll_func); #endif // wxUSE_THREADS gtk_set_locale(); // We should have the wxUSE_WCHAR_T test on the _outside_ #if wxUSE_WCHAR_T // gtk+ 2.0 supports Unicode through UTF-8 strings wxConvCurrent = &wxConvUTF8; #else // !wxUSE_WCHAR_T if (!wxOKlibc()) wxConvCurrent = (wxMBConv*) NULL; #endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T // decide which conversion to use for the file names // (1) this variable exists for the sole purpose of specifying the encoding // of the filenames for GTK+ programs, so use it if it is set wxString encName(wxGetenv(_T("G_FILENAME_ENCODING"))); encName = encName.BeforeFirst(_T(',')); if (encName.CmpNoCase(_T("@locale")) == 0) encName.clear(); encName.MakeUpper(); #if wxUSE_INTL if (encName.empty()) { // (2) if a non default locale is set, assume that the user wants his // filenames in this locale too encName = wxLocale::GetSystemEncodingName().Upper(); // (3) finally use UTF-8 by default if (encName.empty() || encName == _T("US-ASCII")) encName = _T("UTF-8"); wxSetEnv(_T("G_FILENAME_ENCODING"), encName); } #else if (encName.empty()) encName = _T("UTF-8"); #endif // wxUSE_INTL #if wxUSE_WCHAR_T static wxConvBrokenFileNames fileconv(encName); wxConvFileName = &fileconv; #endif // wxUSE_WCHAR_T #if wxUSE_UNICODE // gtk_init() wants UTF-8, not wchar_t, so convert int i; char **argvGTK = new char *[argc + 1]; for ( i = 0; i < argc; i++ ) { argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i])); } argvGTK[argc] = NULL; int argcGTK = argc; #ifdef __WXGPE__ init_result = true; // is there a _check() version of this? gpe_application_init( &argcGTK, &argvGTK ); #else init_result = gtk_init_check( &argcGTK, &argvGTK ); #endif if ( argcGTK != argc ) { // we have to drop the parameters which were consumed by GTK+ for ( i = 0; i < argcGTK; i++ ) { while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 ) { memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); } } argc = argcGTK; } //else: gtk_init() didn't modify our parameters // free our copy for ( i = 0; i < argcGTK; i++ ) { free(argvGTK[i]); } delete [] argvGTK; #else // !wxUSE_UNICODE // gtk_init() shouldn't actually change argv itself (just its contents) so // it's ok to pass pointer to it init_result = gtk_init_check( &argc, &argv ); #endif // wxUSE_UNICODE/!wxUSE_UNICODE if (!init_result) { wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?")); return false; } // update internal arg[cv] as GTK+ may have removed processed options: this->argc = argc; this->argv = argv; // we can not enter threads before gtk_init is done gdk_threads_enter(); if ( !wxAppBase::Initialize(argc, argv) ) { gdk_threads_leave(); return false; } wxSetDetectableAutoRepeat( true ); #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif return true; }
void NiceConnection::init() { if(this->checkIceState() != NICE_INITIAL){ ELOG_DEBUG("Initing NiceConnection not in INITIAL state, exiting... %p", this); return; }; { boost::unique_lock<boost::mutex> lock(agentMutex_); if(!running_) return; this->updateIceState(NICE_INITIAL); g_type_init(); context_ = g_main_context_new(); g_main_context_set_poll_func(context_,timed_poll); /* loop_ = g_main_loop_new(context_, FALSE); */ ELOG_DEBUG("Creating Agent"); //loop_ = g_main_loop_new(NULL, FALSE); // nice_debug_enable( TRUE ); // Create a nice agent //agent_ = nice_agent_new(g_main_loop_get_context(loop_), NICE_COMPATIBILITY_RFC5245); agent_ = nice_agent_new(context_, NICE_COMPATIBILITY_RFC5245); GValue controllingMode = { 0 }; g_value_init(&controllingMode, G_TYPE_BOOLEAN); g_value_set_boolean(&controllingMode, false); g_object_set_property(G_OBJECT( agent_ ), "controlling-mode", &controllingMode); // NiceAddress* naddr = nice_address_new(); // nice_agent_add_local_address(agent_, naddr); if (stunServer_.compare("") != 0 && stunPort_!=0){ GValue val = { 0 }, val2 = { 0 }; g_value_init(&val, G_TYPE_STRING); g_value_set_string(&val, stunServer_.c_str()); g_object_set_property(G_OBJECT( agent_ ), "stun-server", &val); g_value_init(&val2, G_TYPE_UINT); g_value_set_uint(&val2, stunPort_); g_object_set_property(G_OBJECT( agent_ ), "stun-server-port", &val2); ELOG_DEBUG("Setting STUN server %s:%d", stunServer_.c_str(), stunPort_); } // Connect the signals g_signal_connect( G_OBJECT( agent_ ), "candidate-gathering-done", G_CALLBACK( cb_candidate_gathering_done ), this); g_signal_connect( G_OBJECT( agent_ ), "component-state-changed", G_CALLBACK( cb_component_state_changed ), this); g_signal_connect( G_OBJECT( agent_ ), "new-selected-pair", G_CALLBACK( cb_new_selected_pair ), this); // Create a new stream and start gathering candidates ELOG_DEBUG("Adding Stream... Number of components %d", iceComponents_); nice_agent_add_stream(agent_, iceComponents_); // Set Port Range ----> If this doesn't work when linking the file libnice.sym has to be modified to include this call if (minPort_!=0 && maxPort_!=0){ ELOG_DEBUG("Setting port range: %d to %d\n", minPort_, maxPort_); nice_agent_set_port_range(agent_, (guint)1, (guint)1, (guint)minPort_, (guint)maxPort_); } if (SERVER_SIDE_TURN){ for (int i = 1; i < (iceComponents_ +1); i++){ ELOG_DEBUG("Setting TURN Comp %d\n", i); nice_agent_set_relay_info (agent_, 1, i, "", // TURN Server IP 3479, // TURN Server PORT "", // Username "", // Pass NICE_RELAY_TYPE_TURN_UDP); } } ELOG_DEBUG("Gathering candidates %p", this); nice_agent_gather_candidates(agent_, 1); if(agent_){ nice_agent_attach_recv(agent_, 1, 1, context_, cb_nice_recv, this); if (iceComponents_ > 1) { nice_agent_attach_recv(agent_, 1, 2, context_,cb_nice_recv, this); } }else{ running_=false; } } // Attach to the component to receive the data while(running_){ boost::unique_lock<boost::mutex> lockContext(agentMutex_); if(this->checkIceState()>=NICE_FINISHED) break; g_main_context_iteration(context_, true); } ELOG_DEBUG("LibNice thread finished %p", this); }
int main (int argc, char *argv[]) { GtkWidget *label; GdkPixbuf *icon_pixbuf; GError *err = NULL; bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); srand (time(NULL)); gnome_program_init (APPID, APPVERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_POPT_TABLE, options, GNOME_PARAM_NONE); textbox_setup (); /* needs to be done before text boxes are created */ /* Initialize the GConf library */ if (!gconf_init (argc, argv, &err)) { fprintf (stderr, _("Failed to init GConf: %s\n"), err->message); g_error_free (err); err = NULL; } /* Start a GConf client */ gconf_client = gconf_client_get_default (); /* Add the GTetrinet directories to the list of directories that GConf client must watch */ gconf_client_add_dir (gconf_client, "/apps/gtetrinet/sound", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/themes", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/keys", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/partyline", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); /* Request notification of change for these gconf keys */ gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/midi_player", (GConfClientNotifyFunc) sound_midi_player_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/enable_sound", (GConfClientNotifyFunc) sound_enable_sound_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/enable_midi", (GConfClientNotifyFunc) sound_enable_midi_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/themes/theme_dir", (GConfClientNotifyFunc) themes_theme_dir_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/down", (GConfClientNotifyFunc) keys_down_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/left", (GConfClientNotifyFunc) keys_left_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/right", (GConfClientNotifyFunc) keys_right_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/rotate_left", (GConfClientNotifyFunc) keys_rotate_left_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/rotate_right", (GConfClientNotifyFunc) keys_rotate_right_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/drop", (GConfClientNotifyFunc) keys_drop_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/message", (GConfClientNotifyFunc) keys_message_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/discard", (GConfClientNotifyFunc) keys_discard_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special1", (GConfClientNotifyFunc) keys_special1_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special2", (GConfClientNotifyFunc) keys_special2_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special3", (GConfClientNotifyFunc) keys_special3_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special4", (GConfClientNotifyFunc) keys_special4_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special5", (GConfClientNotifyFunc) keys_special5_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special6", (GConfClientNotifyFunc) keys_special6_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special_self", (GConfClientNotifyFunc) keys_special_self_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_timestamps", (GConfClientNotifyFunc) partyline_enable_timestamps_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_channel_list", (GConfClientNotifyFunc) partyline_enable_channel_list_changed, NULL, NULL, NULL); /* load settings */ config_loadconfig (); /* initialise some stuff */ fields_init (); if (!g_thread_supported()) g_thread_init (NULL); /* first set up the display */ /* create the main window */ app = gnome_app_new (APPID, APPNAME); g_signal_connect (G_OBJECT(app), "destroy", GTK_SIGNAL_FUNC(destroymain), NULL); keypress_signal = g_signal_connect (G_OBJECT(app), "key-press-event", GTK_SIGNAL_FUNC(keypress), NULL); g_signal_connect (G_OBJECT(app), "key-release-event", GTK_SIGNAL_FUNC(keyrelease), NULL); gtk_widget_set_events (app, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); gtk_window_set_resizable (GTK_WINDOW (app), TRUE); /* create and set the window icon */ icon_pixbuf = gdk_pixbuf_new_from_file (PIXMAPSDIR "/gtetrinet.png", NULL); if (icon_pixbuf) { gtk_window_set_icon (GTK_WINDOW (app), icon_pixbuf); gdk_pixbuf_unref (icon_pixbuf); } /* create the notebook */ notebook = gtk_notebook_new (); gtk_notebook_set_tab_pos (GTK_NOTEBOOK(notebook), GTK_POS_TOP); /* put it in the main window */ gnome_app_set_contents (GNOME_APP(app), notebook); /* make menus + toolbar */ make_menus (GNOME_APP(app)); /* create the pages in the notebook */ fieldswidget = fields_page_new (); gtk_widget_set_sensitive (fieldswidget, TRUE); gtk_widget_show (fieldswidget); pfields = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pfields), 0); gtk_container_add (GTK_CONTAINER(pfields), fieldswidget); gtk_widget_show (pfields); g_object_set_data (G_OBJECT(fieldswidget), "title", "Playing Fields"); // FIXME label = pixmapdata_label (fields_xpm, _("Playing Fields")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pfields, label); partywidget = partyline_page_new (); gtk_widget_show (partywidget); pparty = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pparty), 0); gtk_container_add (GTK_CONTAINER(pparty), partywidget); gtk_widget_show (pparty); g_object_set_data (G_OBJECT(partywidget), "title", "Partyline"); // FIXME label = pixmapdata_label (partyline_xpm, _("Partyline")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pparty, label); winlistwidget = winlist_page_new (); gtk_widget_show (winlistwidget); pwinlist = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pwinlist), 0); gtk_container_add (GTK_CONTAINER(pwinlist), winlistwidget); gtk_widget_show (pwinlist); g_object_set_data (G_OBJECT(winlistwidget), "title", "Winlist"); // FIXME label = pixmapdata_label (winlist_xpm, _("Winlist")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pwinlist, label); /* add signal to focus the text entry when switching to the partyline page*/ g_signal_connect_after(G_OBJECT (notebook), "switch-page", GTK_SIGNAL_FUNC (switch_focus), NULL); gtk_widget_show (notebook); g_object_set (G_OBJECT (notebook), "can-focus", FALSE, NULL); partyline_show_channel_list (list_enabled); gtk_widget_show (app); // gtk_widget_set_size_request (partywidget, 480, 360); // gtk_widget_set_size_request (winlistwidget, 480, 360); /* initialise some stuff */ commands_checkstate (); /* check command line params */ #ifdef DEBUG printf ("option_connect: %s\n" "option_nick: %s\n" "option_team: %s\n" "option_pass: %s\n" "option_spec: %i\n", option_connect, option_nick, option_team, option_pass, option_spec); #endif if (option_nick) GTET_O_STRCPY(nick, option_nick); if (option_team) GTET_O_STRCPY(team, option_team); if (option_pass) GTET_O_STRCPY(specpassword, option_pass); if (option_spec) spectating = TRUE; if (option_connect) { client_init (option_connect, nick); } /* Don't schedule if data is ready, glib should do this itself, * but welcome to anything that works... */ g_main_context_set_poll_func(NULL, gtetrinet_poll_func); /* gtk_main() */ gtk_main (); client_disconnect (); /* cleanup */ fields_cleanup (); sound_stopmidi (); return 0; }
nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); if (!gWidgetFocusLog) gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); if (!gWidgetDragLog) gWidgetDragLog = PR_NewLogModule("WidgetDrag"); if (!gWidgetDrawLog) gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); #endif if (!sPollFunc) { sPollFunc = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, &PollWrapper); } if (PR_GetEnv("MOZ_DEBUG_PAINTS")) gdk_window_set_debug_updates(TRUE); // Disable JasPer module (jpeg2000) in GDK-PixBuf. // Also disable known buggy TGA and icns formats GSList* pixbufFormats = gdk_pixbuf_get_formats(); for (GSList* iter = pixbufFormats; iter; iter = iter->next) { GdkPixbufFormat* format = static_cast<GdkPixbufFormat*>(iter->data); gchar* name = gdk_pixbuf_format_get_name(format); if (strcmp(name, "jpeg2000") == 0 || strcmp(name, "tga") == 0 || strcmp(name, "icns") == 0) { gdk_pixbuf_format_set_disabled(format, TRUE); } g_free(name); } g_slist_free(pixbufFormats); int err = pipe(mPipeFDs); if (err) return NS_ERROR_OUT_OF_MEMORY; GIOChannel *ioc; GSource *source; // make the pipe nonblocking int flags = fcntl(mPipeFDs[0], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; flags = fcntl(mPipeFDs[1], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; ioc = g_io_channel_unix_new(mPipeFDs[0]); source = g_io_create_watch(ioc, G_IO_IN); g_io_channel_unref(ioc); g_source_set_callback(source, (GSourceFunc)EventProcessorCallback, this, nullptr); g_source_set_can_recurse(source, TRUE); mTag = g_source_attach(source, nullptr); g_source_unref(source); return nsBaseAppShell::Init(); failed: close(mPipeFDs[0]); close(mPipeFDs[1]); mPipeFDs[0] = mPipeFDs[1] = 0; return NS_ERROR_FAILURE; }
NiceConnection::NiceConnection(MediaType med, const std::string &transport_name,NiceConnectionListener* listener, unsigned int iceComponents, const IceConfig& iceConfig, std::string username, std::string password) : mediaType(med), agent_(NULL), listener_(listener), candsDelivered_(0), context_(NULL), iceState_(NICE_INITIAL), iceComponents_(iceComponents) { localCandidates.reset(new std::vector<CandidateInfo>()); transportName.reset(new std::string(transport_name)); for (unsigned int i = 1; i<=iceComponents_; i++) { comp_state_list_[i] = NICE_INITIAL; } g_type_init(); context_ = g_main_context_new(); g_main_context_set_poll_func(context_,timed_poll); ELOG_DEBUG("Creating Agent"); nice_debug_enable( FALSE ); // Create a nice agent agent_ = nice_agent_new(context_, NICE_COMPATIBILITY_RFC5245); GValue controllingMode = { 0 }; g_value_init(&controllingMode, G_TYPE_BOOLEAN); g_value_set_boolean(&controllingMode, false); g_object_set_property(G_OBJECT( agent_ ), "controlling-mode", &controllingMode); GValue checks = { 0 }; g_value_init(&checks, G_TYPE_UINT); g_value_set_uint(&checks, 100); g_object_set_property(G_OBJECT( agent_ ), "max-connectivity-checks", &checks); if (iceConfig.stunServer.compare("") != 0 && iceConfig.stunPort!=0){ GValue val = { 0 }, val2 = { 0 }; g_value_init(&val, G_TYPE_STRING); g_value_set_string(&val, iceConfig.stunServer.c_str()); g_object_set_property(G_OBJECT( agent_ ), "stun-server", &val); g_value_init(&val2, G_TYPE_UINT); g_value_set_uint(&val2, iceConfig.stunPort); g_object_set_property(G_OBJECT( agent_ ), "stun-server-port", &val2); ELOG_DEBUG("Setting STUN server %s:%d", iceConfig.stunServer.c_str(), iceConfig.stunPort); } // Connect the signals g_signal_connect( G_OBJECT( agent_ ), "candidate-gathering-done", G_CALLBACK( cb_candidate_gathering_done ), this); g_signal_connect( G_OBJECT( agent_ ), "component-state-changed", G_CALLBACK( cb_component_state_changed ), this); g_signal_connect( G_OBJECT( agent_ ), "new-selected-pair", G_CALLBACK( cb_new_selected_pair ), this); g_signal_connect( G_OBJECT( agent_ ), "new-candidate", G_CALLBACK( cb_new_candidate ), this); // Create a new stream and start gathering candidates ELOG_DEBUG("Adding Stream... Number of components %d", iceComponents_); nice_agent_add_stream(agent_, iceComponents_); gchar *ufrag = NULL, *upass = NULL; nice_agent_get_local_credentials(agent_, 1, &ufrag, &upass); ufrag_ = std::string(ufrag); g_free(ufrag); upass_ = std::string(upass); g_free(upass); // Set our remote credentials. This must be done *after* we add a stream. if (username.compare("")!=0 && password.compare("")!=0){ ELOG_DEBUG("Setting remote credentials in constructor"); this->setRemoteCredentials(username, password); } // Set Port Range ----> If this doesn't work when linking the file libnice.sym has to be modified to include this call if (iceConfig.minPort!=0 && iceConfig.maxPort!=0){ ELOG_DEBUG("Setting port range: %d to %d\n", iceConfig.minPort, iceConfig.maxPort); nice_agent_set_port_range(agent_, (guint)1, (guint)1, (guint)iceConfig.minPort, (guint)iceConfig.maxPort); } if (iceConfig.turnServer.compare("") != 0 && iceConfig.turnPort!=0){ ELOG_DEBUG("Setting TURN server %s:%d", iceConfig.turnServer.c_str(), iceConfig.turnPort); ELOG_DEBUG("Setting TURN credentials %s:%s", iceConfig.turnUsername.c_str(), iceConfig.turnPass.c_str()); for (unsigned int i = 1; i <= iceComponents_ ; i++){ nice_agent_set_relay_info (agent_, 1, i, iceConfig.turnServer.c_str(), // TURN Server IP iceConfig.turnPort, // TURN Server PORT iceConfig.turnUsername.c_str(), // Username iceConfig.turnPass.c_str(), // Pass NICE_RELAY_TYPE_TURN_UDP); } } if(agent_){ for (unsigned int i = 1; i<=iceComponents_; i++){ nice_agent_attach_recv(agent_, 1, i, context_, cb_nice_recv, this); } running_ = true; } else{ running_=false; } m_Thread_ = boost::thread(&NiceConnection::init, this); }
/* ``unplug'' our polling function from the glib: */ void lwt_glib_reset() { g_main_context_set_poll_func(NULL, old_poll_func); }
/* ``plug'' our polling function into the glib: */ void lwt_glib_setup() { old_poll_func = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, lwt_glib_poll); }