コード例 #1
0
static void
hrt_event_loop_glib_quit(HrtEventLoop *loop)
{
    HrtEventLoopGLib *gloop = HRT_EVENT_LOOP_GLIB(loop);
    GSource *source;
    GMainContext *context;

    /* g_main_loop_quit() doesn't reliably work from another thread so
     * we install a one-shot idle to be sure it doesn't get wedged in
     * poll(). https://bugzilla.gnome.org/show_bug.cgi?id=632301
     */

    context = g_main_loop_get_context(gloop->loop);
    g_main_context_ref(context);

    g_main_loop_quit(gloop->loop);
    _hrt_event_loop_set_running(HRT_EVENT_LOOP(gloop), FALSE);

    source = g_idle_source_new();
    g_source_set_callback(source, do_nothing_return_false,
                          NULL, NULL);
    g_source_attach(source, context);
    g_source_unref(source);

    g_main_context_unref(context);
}
コード例 #2
0
ファイル: main.c プロジェクト: MasterOfPupets/ModemManager
int
main (int argc, char *argv[])
{
    DBusGConnection *bus;
    DBusGProxy *proxy;
    MMManager *manager;
    GError *err = NULL;
    guint id;

    mm_options_parse (argc, argv);
    g_type_init ();

    setup_signals ();

    if (!mm_options_debug ())
        logging_setup ();

    g_message ("ModemManager (version " MM_DIST_VERSION ") starting...");

    bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
    if (!bus) {
        g_warning ("Could not get the system bus. Make sure "
                   "the message bus daemon is running! Message: %s",
                   err->message);
        g_error_free (err);
        return -1;
    }

    proxy = create_dbus_proxy (bus);
    if (!proxy)
        return -1;

    manager = mm_manager_new (bus);
    g_idle_add (start_manager, manager);

    loop = g_main_loop_new (NULL, FALSE);
    id = g_signal_connect (proxy, "destroy", G_CALLBACK (destroy_cb), loop);

    g_main_loop_run (loop);

    g_signal_handler_disconnect (proxy, id);

    mm_manager_shutdown (manager);

    /* Wait for all modems to be removed */
    while (mm_manager_num_modems (manager)) {
        GMainContext *ctx = g_main_loop_get_context (loop);

        g_main_context_iteration (ctx, FALSE);
        g_usleep (50);
    }

    g_object_unref (manager);
    g_object_unref (proxy);
    dbus_g_connection_unref (bus);    

    logging_shutdown ();

    return 0;
}
コード例 #3
0
static VALUE
rg_run(VALUE self)
{
    CheckInterruptData data;
    GSource *interrupt_source;

    data.loop = _SELF(self);
    data.state = 0;

    interrupt_source = rbg_interrupt_source_new();
    g_source_set_callback(interrupt_source,
                          check_interrupt,
                          &data,
                          NULL);
    g_source_attach(interrupt_source,
                    g_main_loop_get_context(data.loop));
    g_main_loop_run(data.loop);
    g_source_destroy(interrupt_source);
    g_source_unref(interrupt_source);

    if (data.state == 0) {
        rb_thread_check_ints();
    } else {
        rb_jump_tag(data.state);
    }

    return self;
}
コード例 #4
0
ファイル: main.c プロジェクト: beekhof/pacemaker
/*!
 * \internal
 * \brief Clean up and exit immediately
 *
 * \param[in] data  Ignored
 *
 * \return Doesn't return
 * \note   This can be used as a timer callback.
 */
static gboolean
lrmd_exit(gpointer data)
{
    crm_info("Terminating with %d clients",
             crm_hash_table_size(client_connections));

    if (stonith_api) {
        stonith_api->cmds->remove_notification(stonith_api, T_STONITH_NOTIFY_DISCONNECT);
        stonith_api->cmds->disconnect(stonith_api);
        stonith_api_delete(stonith_api);
    }
    if (ipcs) {
        mainloop_del_ipc_server(ipcs);
    }

#ifdef ENABLE_PCMK_REMOTE
    lrmd_tls_server_destroy();
    ipc_proxy_cleanup();
#endif

    crm_client_cleanup();
    g_hash_table_destroy(rsc_list);

    if (mainloop) {
        lrmd_drain_alerts(g_main_loop_get_context(mainloop));
    }

    crm_exit(pcmk_ok);
    return FALSE;
}
コード例 #5
0
JNIEXPORT jint JNICALL CAST_JNI(addStreamNative,jlong agentCtxLong,jstring jstreamName,jint numberOfComponent) {
    
    AgentCtx* agentCtx = (AgentCtx*) agentCtxLong;
    NiceAgent* tmp_agent = agentCtx->agent;

    jboolean isCopy;
    const gchar *name = (gchar*) (*env)->GetStringUTFChars(env, jstreamName, &isCopy);
    // Create a new stream with one component
    int stream_id = nice_agent_add_stream(tmp_agent, numberOfComponent);
    if (stream_id == 0) {
        LOGD("Failed to add stream");
        return 0;
    }
    nice_agent_set_stream_name (tmp_agent, stream_id, name);

    if(name) {
      (*env)->ReleaseStringUTFChars(env,jstreamName,name);
    }

    agentCtx->totalComponentNumber = numberOfComponent;
    for(int i=0;i<numberOfComponent;i++) {
        nice_agent_attach_recv(tmp_agent, stream_id, i+1,
            g_main_loop_get_context (agentCtx->gloop), recv_callback, agentCtx);
    }
    return stream_id;
}
コード例 #6
0
ファイル: ipc.c プロジェクト: mantaraya36/xmms2-mantaraya36
/**
 * Put a message in the queue awaiting to be sent to the client.
 * Should hold client->lock.
 */
static gboolean
xmms_ipc_client_msg_write (xmms_ipc_client_t *client, xmms_ipc_msg_t *msg)
{
	gboolean queue_empty;

	g_return_val_if_fail (client, FALSE);
	g_return_val_if_fail (msg, FALSE);

	queue_empty = g_queue_is_empty (client->out_msg);
	g_queue_push_tail (client->out_msg, msg);

	/* If there's no write in progress, add a new callback */
	if (queue_empty) {
		GMainContext *context = g_main_loop_get_context (client->ml);
		GSource *source = g_io_create_watch (client->iochan, G_IO_OUT);

		g_source_set_callback (source,
		                       (GSourceFunc) xmms_ipc_client_write_cb,
		                       (gpointer) client,
		                       NULL);
		g_source_attach (source, context);
		g_source_unref (source);

		g_main_context_wakeup (context);
	}

	return TRUE;
}
コード例 #7
0
ファイル: luna_invoke.cpp プロジェクト: hl-plus/hl
void svc_accessor::stop()
{
    // stop main loop
    if (main_loop_)
    {
        GMainLoop* loop = main_loop_.get();
        if (loop && g_main_loop_is_running(loop))
        {
            g_main_loop_quit(loop);
            loop_thread_->join();

            // wait for exit thread
            loop_thread_.reset();
        }

        // wait for clear context
        GMainContext* main_context = g_main_loop_get_context(loop);
        while(!g_main_context_acquire(main_context))
                sched_yield();

        g_main_context_release(main_context_.get());
        main_context_.reset();
        main_loop_.reset();
        // unregister service
        if (svc_)
            svc_.reset();
    }
}
コード例 #8
0
void pcm_play_dma_init(void)
{
    maemo_init_libplayback();

    GMainContext *ctx = g_main_loop_get_context(maemo_main_loop);
    pcm_loop = g_main_loop_new (ctx, true);

    gst_init (NULL, NULL);

    gst_pipeline = gst_pipeline_new ("rockbox");

    gst_appsrc = gst_element_factory_make ("appsrc", NULL);
    gst_volume = gst_element_factory_make ("volume", NULL);
    gst_pulsesink = gst_element_factory_make ("pulsesink", NULL);

    /* Connect elements */
    gst_bin_add_many (GST_BIN (gst_pipeline),
                        gst_appsrc, gst_volume, gst_pulsesink, NULL);
    gst_element_link_many (gst_appsrc, gst_volume, gst_pulsesink, NULL);

    /* Connect to gstreamer bus of the pipeline */
    gst_bus = gst_pipeline_get_bus (GST_PIPELINE (gst_pipeline));
    bus_watch_id = gst_bus_add_watch (gst_bus, (GstBusFunc) gst_bus_message, NULL);

    maemo_configure_appsrc();
}
コード例 #9
0
void IpcClientHost::onDisconnected()
{
	g_message("%s (%d): Disconnected", __PRETTY_FUNCTION__, __LINE__);

	m_clearing = true;

	for (WindowMap::const_iterator it = m_winMap.begin(); it != m_winMap.end(); ++it) {
		static_cast<HostWindow*>(it->second)->channelRemoved();
		static_cast<HostWindow*>(it->second)->setClientHost(0);
		WindowServer::instance()->removeWindow(it->second);
	}

	m_winMap.clear();
	m_winSet.clear();
	m_closedWinSet.clear();

	// http://bugreports.qt.nokia.com/browse/QTBUG-18434: deleteLater does
	// not work when used in a g_idle_dispatch
	//deleteLater();
	if (!m_idleDestroySrc) {
		GSource* src = g_idle_source_new();
		g_source_set_callback(src, (GSourceFunc) idleDestroyCallback, this, NULL);
		g_source_attach(src, g_main_loop_get_context(IpcServer::instance()->mainLoop()));
		m_idleDestroySrc = src;
	}
}
コード例 #10
0
ファイル: mainloop.c プロジェクト: android-808/dsme
void dsme_main_loop_run(void (*iteration)(void))
{
    if (state == NOT_STARTED) {
        if (!(the_loop = g_main_loop_new(0, FALSE)) ||
            !set_up_signal_pipe())
        {
            // TODO: crash and burn
            exit(EXIT_FAILURE);
        }

        GMainContext* ctx = g_main_loop_get_context(the_loop);

        state = RUNNING;
        while (state == RUNNING) {
            if (iteration) {
                iteration();
            }
            if (state == RUNNING) {
                (void)g_main_context_iteration(ctx, TRUE);
            }
        }

        g_main_loop_unref(the_loop);
        the_loop = 0;
    }
}
コード例 #11
0
ファイル: toolsRpc.c プロジェクト: angelovescio/open-vm-tools
gboolean
ToolsCore_InitRpc(ToolsServiceState *state)
{
   static RpcChannelCallback rpcs[] = {
      { "Capabilities_Register", ToolsCoreRpcCapReg, NULL, NULL, NULL, 0 },
      { "Set_Option", ToolsCoreRpcSetOption, NULL, NULL, NULL, 0 },
   };

   size_t i;
   const gchar *app;
   GMainContext *mainCtx = g_main_loop_get_context(state->ctx.mainLoop);

   ASSERT(state->ctx.rpc == NULL);

   if (state->debugPlugin != NULL) {
      app = "debug";
      state->ctx.rpc = state->debugData->newDebugChannel(&state->ctx,
                                                         state->debugData);
   } else {
      /*
       * Currently we try to bring up an RpcIn channel, which will only run
       * inside a Virtual Machine. Some plugins may still want to launch and at
       * least begin even in not in a VM (typically because the installation is dual
       * purposed between a VM and Bootcamp) - plugins may wish to undo some state
       * if not in a VM.
       *
       * XXX: this should be relaxed when we try to bring up a VMCI or TCP channel.
       */
      if (!state->ctx.isVMware) {
         g_warning("The %s service needs to run inside a virtual machine.\n",
                   state->name);
         state->ctx.rpc = NULL;
      } else {
         state->ctx.rpc = BackdoorChannel_New();
      }
      app = ToolsCore_GetTcloName(state);
      if (app == NULL) {
         g_warning("Trying to start RPC channel for invalid %s container.", state->name);
         return FALSE;
      }
   }

   if (state->ctx.rpc) {
      RpcChannel_Setup(state->ctx.rpc,
                       app,
                       mainCtx,
                       &state->ctx,
                       ToolsCoreCheckReset,
                       state);

      /* Register the "built in" RPCs. */
      for (i = 0; i < ARRAYSIZE(rpcs); i++) {
         RpcChannelCallback *rpc = &rpcs[i];
         rpc->clientData = state;
         RpcChannel_RegisterCallback(state->ctx.rpc, rpc);
      }
   }

   return TRUE;
}
コード例 #12
0
static void
_new_connection (DBusServer *server,
		 DBusConnection *connection,
		 void *data)
{
	ServiceData *svc = (ServiceData *)data;
	DBusObjectPathVTable vt = {
		_unregister_handler,
		_handle_message,
		NULL, NULL, NULL, NULL
	};

	rb_debug ("new connection to metadata service");

	/* don't allow more than one connection at a time */
	if (svc->connection) {
		rb_debug ("metadata service already has a client.  go away.");
		return;
	}

	dbus_connection_register_object_path (connection,
					      RB_METADATA_DBUS_OBJECT_PATH,
					      &vt,
					      svc);
	dbus_connection_ref (connection);
	dbus_connection_setup_with_g_main (connection,
					   g_main_loop_get_context (svc->loop));
	if (!svc->external)
		dbus_connection_set_exit_on_disconnect (connection, TRUE);
}
コード例 #13
0
ファイル: jabber.c プロジェクト: Jajcus/jggtrans
int jabber_connect(){

	stream=stream_connect(server,port,1,jabber_event_cb);
	g_assert(stream!=NULL);
	jabber_source=g_source_new(&jabber_source_funcs,sizeof(GSource));
	g_source_attach(jabber_source,g_main_loop_get_context(main_loop));
	return 0;
}
コード例 #14
0
ファイル: main.c プロジェクト: AtheistSpacePirate/xfdashboard
/* Quit running application and restart application */
static gboolean _restart(XfdashboardApplication *inApplication)
{
	GMainLoop			*mainLoop;
	guint				dbusWatcherID;
	GSource				*timeoutSource;
	RestartData			restartData;

	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION(inApplication), FALSE);

	/* Create main loop for watching DBUS for application to disappear */
	mainLoop=g_main_loop_new(NULL, FALSE);

	/* Set up user data for callbacks */
	restartData.mainLoop=mainLoop;
	restartData.application=inApplication;
	restartData.appHasQuitted=FALSE;

	/* Set up DBUS watcher to get noticed when application disappears
	 * which means it is safe to start a new instance. But if it takes
	 * too long assume that either application did not quit and is still
	 * running or we did get notified although we set up DBUS watcher
	 * before quitting application.
	 */
	dbusWatcherID=g_bus_watch_name(G_BUS_TYPE_SESSION,
									g_application_get_application_id(G_APPLICATION(inApplication)),
									G_BUS_NAME_WATCHER_FLAGS_NONE,
									_on_dbus_watcher_name_appeared,
									_on_dbus_watcher_name_vanished,
									&restartData,
									NULL);

	/* Add an idle source to main loop to quit running application _after_
	 * the main loop is running and the DBUS watcher was set up.
	 */
	timeoutSource=g_timeout_source_new(DEFAULT_RESTART_WAIT_TIMEOUT);
	g_source_set_callback(timeoutSource, _on_quit_timeout, &restartData, NULL);
	g_source_attach(timeoutSource, g_main_loop_get_context(mainLoop));
	g_source_unref(timeoutSource);

	/* Run main loop */
	g_debug("Starting main loop for waiting the application to quit");
	g_main_loop_run(mainLoop);
	g_debug("Returned from main loop for waiting the application to quit");

	/* Show warning if timeout had been reached */
	if(!restartData.appHasQuitted)
	{
		g_warning(_("Cannot restart application: Failed to quit running instance"));
	}

	/* Destroy DBUS watcher */
	g_bus_unwatch_name(dbusWatcherID);

	/* Return TRUE if application was quitted successfully
	 * otherwise FALSE.
	 */
	return(restartData.appHasQuitted);
}
コード例 #15
0
static gboolean
iterate (GCutEventLoop *loop, gboolean may_block)
{
    GCutGLibEventLoopPrivate *priv;

    priv = GCUT_GLIB_EVENT_LOOP_GET_PRIVATE(loop);
    return g_main_context_iteration(g_main_loop_get_context(priv->loop),
                                    may_block);
}
コード例 #16
0
static void initMallocStatsCb(GMainLoop* mainLoop, int secs)
{
	// negative means no stats
	if ((secs < 0) || (s_mallocStatsFileStr == NULL)) return;

	GSource *timeoutSource = g_timeout_source_new_seconds(secs);
	g_source_set_callback(timeoutSource, mallocStatsCb, NULL, NULL);
	g_source_attach(timeoutSource, g_main_loop_get_context(mainLoop));
}
コード例 #17
0
MojErr MojGmainReactor::dispatch()
{
	MojAssert(m_mainLoop.get());

	GMainContext* context = g_main_loop_get_context(m_mainLoop.get());
	MojAssert(context);
	g_main_context_iteration(context, true);

	return MojErrNone;
}
コード例 #18
0
ファイル: gst-glib.c プロジェクト: tonyg/smalltalk
static void
main_loop_dispatch (void)
{
  GMainContext *context = g_main_loop_get_context (loop);
  if (!g_main_context_acquire (context))
    abort ();

  g_main_context_dispatch (context);
  g_main_context_release (context);
}
コード例 #19
0
ファイル: test-new-dribble.c プロジェクト: WilliamRen/libnice
static void init_test(NiceAgent *lagent, NiceAgent *ragent, gboolean connect_new_candidate_signal)
{
  global_lagent_state = NICE_COMPONENT_STATE_DISCONNECTED;
  global_ragent_state = NICE_COMPONENT_STATE_DISCONNECTED;

  lagent_candidate_gathering_done = FALSE;
  ragent_candidate_gathering_done = FALSE;

  global_ls_id = nice_agent_add_stream (lagent, 1);
  global_rs_id = nice_agent_add_stream (ragent, 1);

  g_assert (global_ls_id > 0);
  g_assert (global_rs_id > 0);

  g_debug ("lagent stream is : %d and ragent stream is %d",
           global_ls_id,
           global_rs_id);

  g_object_set_data (G_OBJECT (lagent), "id", GUINT_TO_POINTER (global_ls_id));
  g_object_set_data (G_OBJECT (ragent), "id", GUINT_TO_POINTER (global_rs_id));

  if (connect_new_candidate_signal) {
    g_signal_connect (G_OBJECT(lagent), "new-candidate",
                      G_CALLBACK(cb_agent_new_candidate), LEFT_AGENT);
    g_signal_connect (G_OBJECT(ragent), "new-candidate",
                      G_CALLBACK(cb_agent_new_candidate), RIGHT_AGENT);
  } else {
    g_signal_handlers_disconnect_by_func (G_OBJECT(lagent), cb_agent_new_candidate,
                                 LEFT_AGENT);
    g_signal_handlers_disconnect_by_func (G_OBJECT(ragent), cb_agent_new_candidate,
                                 RIGHT_AGENT);
  }

  data_received = FALSE;

  nice_agent_attach_recv (lagent, global_ls_id, NICE_COMPONENT_TYPE_RTP,
                   g_main_loop_get_context(global_mainloop),
                   cb_nice_recv, LEFT_AGENT);
  nice_agent_attach_recv (ragent, global_rs_id, NICE_COMPONENT_TYPE_RTP,
                   g_main_loop_get_context(global_mainloop),
                   cb_nice_recv, RIGHT_AGENT);
}
コード例 #20
0
ファイル: send_video.c プロジェクト: cxp1991/WORKING
void*  _video_send_main()
{
	printf("[send video]\n");
	//NiceAgent *agent;
	//guint streamID = 0;

	//nice_debug_enable(TRUE);
	/* Init agent */
	RpiData_SendVideo->agent = nice_agent_new(g_main_loop_get_context (gloop),
	NICE_COMPATIBILITY_RFC5245);

	if (RpiData_SendVideo->agent == NULL)
		g_error("Failed to create agent");

	g_object_set(G_OBJECT(RpiData_SendVideo->agent), "stun-server", STUNSR_ADDR, NULL);
	g_object_set(G_OBJECT(RpiData_SendVideo->agent), "stun-server-port", STUNSR_PORT, NULL);
	g_object_set(G_OBJECT(RpiData_SendVideo->agent), "controlling-mode", CONTROLLING_MODE, NULL);

	g_signal_connect(G_OBJECT(RpiData_SendVideo->agent), "candidate-gathering-done",
	G_CALLBACK( _video_send_cb_candidate_gathering_done), NULL);

	//g_signal_connect(G_OBJECT(agent), "new-selected-pair",
	//G_CALLBACK( _video_receive_cb_new_selected_pair), NULL);

	RpiData_SendVideo->streamID = nice_agent_add_stream(RpiData_SendVideo->agent, 1);
	if (RpiData_SendVideo->streamID == 0)
		g_error("Failed to add stream");

	/* Init Gstreamer */
	_video_send_init_gstreamer(RpiData_SendVideo->agent, RpiData_SendVideo->streamID);

	nice_agent_attach_recv(RpiData_SendVideo->agent, RpiData_SendVideo->streamID, 1,
      	g_main_loop_get_context (gloop), _video_send_cb_nice_recv, NULL);

	/* Start gathering local candidates */
  	if (!nice_agent_gather_candidates(RpiData_SendVideo->agent, RpiData_SendVideo->streamID))
		g_error("Failed to start candidate gathering");

  	printf("[send video] Start Gathering!\n");
  	printf("[send video] Agent = %d!\n", RpiData_SendVideo->agent);

}
コード例 #21
0
ファイル: MojLunaService.cpp プロジェクト: sailesharya/db8
// Note: this is a blocking interface exclusively for unit tests.
// It will not deliver cancel callbacks if clients drop off the bus.
MojErr MojLunaService::dispatch()
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
	MojAssertMutexUnlocked(m_mutex);

	MojAssert(m_loop);
	GMainContext* context = g_main_loop_get_context(m_loop);
	g_main_context_iteration(context, true);

	return MojErrNone;
}
コード例 #22
0
/* Perform one context loop iteration (for bus message handling) if doWait == false,
 * or two seconds worth of iterations if doWait == true. This drives the message-bus
 * callback, so needs to be performed to get any error reporting etc.
 */
int PsychGSProcessMovieContext(GMainLoop *loop, psych_bool doWait)
{
	double tdeadline, tnow;
	PsychGetAdjustedPrecisionTimerSeconds(&tdeadline);
    tnow = tdeadline;
	tdeadline+=2.0;

	if (NULL == loop) return(0);

	while (doWait && (tnow < tdeadline)) {
		// Perform non-blocking work iteration:
		if (!g_main_context_iteration(g_main_loop_get_context(loop), false)) PsychYieldIntervalSeconds(0.010);

		// Update time:
		PsychGetAdjustedPrecisionTimerSeconds(&tnow);
	}

	// Perform one more work iteration of the event context, but don't block:
	return(g_main_context_iteration(g_main_loop_get_context(loop), false));
}
コード例 #23
0
JNIEXPORT jlong JNICALL CAST_JNI(createAgentNative,jlong gloopLong,jint useReliable) {
    
    GMainLoop* tmp_gloop = (GMainLoop*)gloopLong;
    NiceAgent* tmp_agent = NULL;
    // initialize the Ctx
    AgentCtx* agentCtx = (AgentCtx*) calloc(1,sizeof(AgentCtx));



    agentCtx->hasStateObserver = 0;
    agentCtx->stateObserverObj = 0;
    agentCtx->cbCandidateGatheringDoneId=0;
    agentCtx->cbComponentStateChangedId=0;
    for(int i=0;i<MAX_COMPONENT;i++) {
        agentCtx->recvCallbackCtx[i] = NULL;
    }
    agentCtx->gloop = tmp_gloop;
    // Create the nice agent
    if(useReliable==1) {
      tmp_agent = nice_agent_new_reliable(g_main_loop_get_context (tmp_gloop), NICE_COMPATIBILITY_RFC5245);
    } else {
      tmp_agent = nice_agent_new(g_main_loop_get_context (tmp_gloop), NICE_COMPATIBILITY_RFC5245);
    }
    if (tmp_agent == NULL) 
    {
        LOGD("Failed to create agent");
        return 0;
    }
    agentCtx->agent = tmp_agent;


    // Connect to the signals
    g_signal_connect(tmp_agent, "candidate-gathering-done",
      G_CALLBACK(cb_candidate_gathering_done), agentCtx);
    g_signal_connect(tmp_agent, "component-state-changed",
      G_CALLBACK(cb_component_state_changed), agentCtx);
    g_signal_connect(tmp_agent, "new-selected-pair",
      G_CALLBACK(cb_new_selected_pair), agentCtx);

    return (long)agentCtx;
}
コード例 #24
0
ファイル: test-mainloop.c プロジェクト: helloIAmPau/libnice
int
main (void)
{
  NiceAgent *agent;
  NiceAddress addr;
  guint stream;

  nice_address_init (&addr);
  g_type_init ();
  g_thread_init(NULL);

  loop = g_main_loop_new (NULL, FALSE);

  agent = nice_agent_new (g_main_loop_get_context (loop), NICE_COMPATIBILITY_RFC5245);
  nice_address_set_ipv4 (&addr, 0x7f000001);
  nice_agent_add_local_address (agent, &addr);
  stream = nice_agent_add_stream (agent, 1);
  nice_agent_gather_candidates (agent, stream);

  // attach to default main context
  nice_agent_attach_recv (agent, stream, NICE_COMPONENT_TYPE_RTP,
      g_main_loop_get_context (loop), recv_cb, GUINT_TO_POINTER (42));

    {
      NiceCandidate *candidate;
      GSList *candidates, *i;

      candidates = nice_agent_get_local_candidates (agent, 1, 1);
      candidate = candidates->data;

      nice_socket_send (candidate->sockptr, &(candidate->addr), 6, "\x80hello");
      for (i = candidates; i; i = i->next)
        nice_candidate_free ((NiceCandidate *) i->data);
      g_slist_free (candidates);
    }

  g_main_loop_run (loop);

  g_object_unref (agent);
  return 0;
}
コード例 #25
0
int GTK2_Gui_Dialog_Run(GWEN_DIALOG *dlg, int untilEnd) {
  GTK2_GUI_DIALOG *xdlg;
  GtkWidget *g;

  assert(dlg);
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GTK2_GUI_DIALOG, dlg);
  assert(xdlg);

  g=Gtk2Gui_Dialog_GetMainWidget(dlg);
  if (g==NULL) {
    DBG_ERROR(GWEN_LOGDOMAIN, "No main widget");
    Gtk2Gui_Dialog_Unextend(dlg);
    return GWEN_ERROR_INVALID;
  }

  xdlg->unmap_handler =
    g_signal_connect(g,
                     "unmap",
                     G_CALLBACK (run_unmap_handler),
                     dlg);

  xdlg->delete_handler =
    g_signal_connect(g,
                     "delete-event",
                     G_CALLBACK (run_delete_handler),
                     dlg);

  xdlg->destroy_handler =
    g_signal_connect(g,
                     "destroy",
                     G_CALLBACK (run_destroy_handler),
                     dlg);

  xdlg->loop=g_main_loop_new(NULL, FALSE);
  if (untilEnd)
    g_main_loop_run(xdlg->loop);
  else {
    GMainContext *ctx;

    ctx=g_main_loop_get_context(xdlg->loop);
    while(g_main_context_pending(ctx))
      g_main_context_iteration(ctx, FALSE);
  }
  g_main_loop_unref(xdlg->loop);

  if (!xdlg->destroyed) {
    g_signal_handler_disconnect(g, xdlg->unmap_handler);
    g_signal_handler_disconnect(g, xdlg->delete_handler);
    g_signal_handler_disconnect(g, xdlg->destroy_handler);
  }

  return xdlg->response;
}
コード例 #26
0
/**
 * Start a UPnP service. This function will block until the service is stopped.
 *
 * @param service The service to start
 * @return -1 on errors, 0 on success
 */
gint sib_service_start(SIBService* service)
{
  gint retval = 0;
  whiteboard_log_debug_fb();

  g_return_val_if_fail(service != NULL, -1);
  g_return_val_if_fail(service->main_loop != NULL, -1);

  if (g_main_loop_is_running(service->main_loop) == TRUE)
    {
      whiteboard_log_debug("sib_service_start(): main loop running\n");
      whiteboard_log_debug_fe();
      return -1;
    }
  else
    {
    
  
      /* TODO: control channel uuid define */
      service->control_channel = 
	WHITEBOARD_SIB_ACCESS(whiteboard_sib_access_new(NULL,
							(guchar *)"unique_whiteboard_sib_nota_cc_id",
						       NULL,
						       (guchar *)"SIB Access",
						       (guchar *)"Not yet done"));
      
      g_signal_connect(G_OBJECT(service->control_channel),
		       WHITEBOARD_SIB_ACCESS_SIGNAL_REFRESH,
		       (GCallback) sib_service_refresh_cb,
		       NULL);
      
      g_signal_connect(G_OBJECT(service->control_channel),
		       WHITEBOARD_SIB_ACCESS_SIGNAL_SHUTDOWN,
		       (GCallback) sib_service_shutdown_cb,
		       NULL);
      
      retval = sib_service_controller_start( g_main_loop_get_context(service->main_loop) );
      if(retval < 0)
	{
	  whiteboard_log_error("SIB Controller start failed\n");
	  retval = -1;
	  //	  exit(1);
	}
      
      whiteboard_log_debug("RUnning main loop\n");
      g_main_loop_run(service->main_loop);
    }
  
  whiteboard_log_debug_fe();
  
  return retval;
}
コード例 #27
0
RemotePlayer::RemotePlayer (GameSession* session, DPID id)
    :
    Player(session, id),
    agent(new NiceAgent(g_main_loop_get_context(mainLoop))) {
  g_debug("[RemotePlayer::RemotePlayer]");
  // Set the STUN settings and controlling mode
  g_object_set(this->agent->unwrap(), "stun-server", "74.125.136.127", NULL);
  g_object_set(this->agent->unwrap(), "stun-server-port", 19302, NULL);

  // Connect to the signals
  g_signal_connect(this->agent->unwrap(), "candidate-gathering-done", G_CALLBACK(onNiceCandidates), this);
  g_signal_connect(this->agent->unwrap(), "component-state-changed", G_CALLBACK(onNiceStateChange), this);
}
コード例 #28
0
ファイル: caleserver.c プロジェクト: aaronkim/iotivity
CAResult_t CAStopLEGattServer()
{
    OIC_LOG(DEBUG, TAG, "IN");

    ca_mutex_lock(g_leServerStateMutex);

    if (false == g_isLEGattServerStarted)
    {
        OIC_LOG(ERROR, TAG, "Gatt Server is not running to stop");
        ca_mutex_unlock(g_leServerStateMutex);
        return CA_STATUS_OK;
    }

    g_isLEGattServerStarted = false;

    CAResult_t res = CALEStopAdvertise();
    {
        OIC_LOG_V(ERROR, TAG, "CALEStopAdvertise failed with ret[%d]", res);
    }

    res = CADeInitLEGattServer();
    if (CA_STATUS_OK != res)
    {
        OIC_LOG_V(ERROR, TAG, "CADeInitLEGattService failed with ret[%d]", res);
    }

    GMainContext  *context_event_loop = NULL;
    // Required for waking up the thread which is running in gmain loop
    if (NULL != g_eventLoop)
    {
        context_event_loop = g_main_loop_get_context(g_eventLoop);

        if (context_event_loop)
        {
            OIC_LOG_V(DEBUG,  TAG, "g_eventLoop context %x", context_event_loop);
            g_main_context_wakeup(context_event_loop);

            // Kill g main loops and kill threads
            g_main_loop_quit(g_eventLoop);
        }
    }
    else
    {
        OIC_LOG(ERROR, TAG, "g_eventLoop context is NULL");
    }

    ca_mutex_unlock(g_leServerStateMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #29
0
ファイル: unity-taskbar.cpp プロジェクト: JenniBee/residualvm
// Unity requires the glib event loop to the run to function properly
// as events are sent asynchronously
bool UnityTaskbarManager::pollEvent(Common::Event &event) {
	if (!_loop)
		return false;

	// Get context
	GMainContext *context = g_main_loop_get_context(_loop);
	if (!context)
		return false;

	// Dispatch events
	g_main_context_iteration(context, FALSE);

	return false;
}
コード例 #30
0
ファイル: 08.c プロジェクト: hudsonzuo/DOCs
int
main (void)
{
        GMainLoop *loop = g_main_loop_new (NULL, TRUE);
        GMainContext *context = g_main_loop_get_context (loop);
        
                g_timeout_add (10000, timeout_func, loop);
        g_main_loop_run (loop);
        
        g_main_context_unref (context);
        g_main_loop_unref (loop);
        
        return 0;
}