Esempio n. 1
0
void
io_thread_init(void)
{
	assert(io.context == NULL);
	assert(io.loop == NULL);
	assert(io.thread == NULL);

	io.mutex = g_mutex_new();
	io.cond = g_cond_new();
	io.context = g_main_context_new();
	io.loop = g_main_loop_new(io.context, false);
}
Esempio n. 2
0
/* This is a somewhat hacky way to get FTP to almost work. The proper way to
 * get FTP to _really_ work involves hacking GIO to have APIs to handle
 * canoncial URLs.
 */
static GFile *
webkit_soup_request_file_ensure_file_ftp (SoupURI       *uri,
					  GCancellable  *cancellable,
					  GError       **error)
{
	SoupURI *host;
	char *s;
	GFile *file, *result;
	GMount *mount;

	host = soup_uri_copy_host (uri);
	s = soup_uri_to_string (host, FALSE);
	file = g_file_new_for_uri (s);
	soup_uri_free (host);
	g_free (s);

	mount = g_file_find_enclosing_mount (file, cancellable, error);
	if (mount == NULL && g_file_supports_thread_contexts (file)) {
		GMainContext *context = g_main_context_new ();
		GMainLoop *loop = g_main_loop_new (context, FALSE);

		g_clear_error (error);
		g_main_context_push_thread_default (context);
		g_file_mount_enclosing_volume (file,
					       G_MOUNT_MOUNT_NONE,
					       NULL, /* FIXME! */
					       cancellable,
					       webkit_soup_request_file_ftp_main_loop_quit,
					       loop);
		g_main_loop_run (loop);
		g_main_context_pop_thread_default (context);
		g_main_loop_unref (loop);
		g_main_context_unref (context);
		mount = g_file_find_enclosing_mount (file, cancellable, error);
	}
	if (mount == NULL)
		return NULL;
	g_object_unref (file);

	file = g_mount_get_default_location (mount);
	g_object_unref (mount);

	s = g_strdup (uri->path);
	if (strchr (s, ';'))
		*strchr (s, ';') = 0;

	result = g_file_resolve_relative_path (file, s);
	g_free (s);
	g_object_unref (file);

	return result;
}
Esempio n. 3
0
File: grustna.c Progetto: sp3d/grust
static GMainContext *
get_rust_thread_context ()
{
  GMainContext *context;

  context = g_private_get (&rust_thread_context);
  if (context == NULL)
    {
      context = g_main_context_new ();
      g_private_set (&rust_thread_context, context);
    }
  return context;
}
Esempio n. 4
0
File: Rgtk.c Progetto: hjy1210/RGtk2
gpointer R_gtk_timerThreadFunc(gpointer data) {
  GMainContext *ctx = g_main_context_new();
  eventLoopMain = g_main_loop_new(ctx, FALSE);
  GSource *timeout = g_timeout_source_new(100);
  //g_timeout_add(100, R_gtk_timerFunc, NULL);
  g_source_set_callback(timeout, R_gtk_timerFunc, NULL, NULL);
  g_source_attach(timeout, ctx);
  g_main_loop_run(eventLoopMain);
  g_source_destroy(timeout);
  g_main_loop_unref(eventLoopMain);
  g_main_context_unref(ctx);
  return 0;
}
/**
 * camel_async_closure_new:
 *
 * Creates a new #CamelAsyncClosure for use with asynchronous functions.
 *
 * Returns: a new #CamelAsyncClosure
 *
 * Since: 3.12
 **/
CamelAsyncClosure *
camel_async_closure_new (void)
{
	CamelAsyncClosure *closure;

	closure = g_slice_new0 (CamelAsyncClosure);
	closure->context = g_main_context_new ();
	closure->loop = g_main_loop_new (closure->context, FALSE);

	g_main_context_push_thread_default (closure->context);

	return closure;
}
Esempio n. 6
0
int main(int argc, char **argv)
{
  g_thread_init(NULL);

  thread1_context = g_main_context_default();
  thread2_context = g_main_context_new();

  main_loop1 = g_main_loop_new(thread1_context, FALSE);

  g_thread_create(thread2_entry, NULL, FALSE, NULL);

  g_main_loop_run(main_loop1);
  return 0;
}
static void
test_gupnp_simple_igd_custom_ctx (void)
{
  GMainContext *mainctx = g_main_context_new ();
  GUPnPSimpleIgd *igd;

  g_main_context_push_thread_default (mainctx);
  igd = gupnp_simple_igd_new ();
  g_main_context_pop_thread_default (mainctx);

  run_gupnp_simple_igd_test (mainctx, igd, INTERNAL_PORT);
  g_object_unref (igd);
  g_main_context_unref (mainctx);
}
Esempio n. 8
0
bool
LSFetchQueueNew(LSFetchQueue **ret_fetch_queue)
{
    if (!ret_fetch_queue) return false;

    *ret_fetch_queue = g_new0(LSFetchQueue, 1);

    if (*ret_fetch_queue)
    {
        (*ret_fetch_queue)->main_context = g_main_context_new();
    }

    return true;
}
Esempio n. 9
0
void WorkerThread::workerThread()
{
    // Propagate the mainThread's fenv to workers.
#if PLATFORM(IOS)
    FloatingPointEnvironment::singleton().propagateMainThreadEnvironment();
#endif

#if PLATFORM(GTK)
    GRefPtr<GMainContext> mainContext = adoptGRef(g_main_context_new());
    g_main_context_push_thread_default(mainContext.get());
#endif

    {
        LockHolder lock(m_threadCreationMutex);
        m_workerGlobalScope = createWorkerGlobalScope(m_startupData->m_scriptURL, m_startupData->m_userAgent, m_startupData->m_contentSecurityPolicyResponseHeaders, m_startupData->m_shouldBypassMainWorldContentSecurityPolicy, WTFMove(m_startupData->m_topOrigin));

        if (m_runLoop.terminated()) {
            // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
            // forbidExecution() couldn't be called from stop().
            m_workerGlobalScope->script()->forbidExecution();
        }
    }

    WorkerScriptController* script = m_workerGlobalScope->script();
    script->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL));
    // Free the startup data to cause its member variable deref's happen on the worker's thread (since
    // all ref/derefs of these objects are happening on the thread at this point). Note that
    // WorkerThread::~WorkerThread happens on a different thread where it was created.
    m_startupData = nullptr;

    runEventLoop();

#if PLATFORM(GTK)
    g_main_context_pop_thread_default(mainContext.get());
#endif

    ThreadIdentifier threadID = m_threadID;

    ASSERT(m_workerGlobalScope->hasOneRef());

    // The below assignment will destroy the context, which will in turn notify messaging proxy.
    // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
    m_workerGlobalScope = nullptr;

    // Clean up WebCore::ThreadGlobalData before WTF::WTFThreadData goes away!
    threadGlobalData().destroy();

    // The thread object may be already destroyed from notification now, don't try to access "this".
    detachThread(threadID);
}
Esempio n. 10
0
static gboolean
gst_soup_http_src_start (GstBaseSrc * bsrc)
{
  GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);

  GST_DEBUG_OBJECT (src, "start(\"%s\")", src->location);

  if (!src->location) {
    GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (_("No URL set.")),
        ("Missing location property"));
    return FALSE;
  }

  src->context = g_main_context_new ();

  src->loop = g_main_loop_new (src->context, TRUE);
  if (!src->loop) {
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
        (NULL), ("Failed to start GMainLoop"));
    g_main_context_unref (src->context);
    return FALSE;
  }

  if (src->proxy == NULL) {
    src->session =
        soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
        src->context, SOUP_SESSION_USER_AGENT, src->user_agent,
        SOUP_SESSION_TIMEOUT, src->timeout,
#ifdef HAVE_LIBSOUP_GNOME
        SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_GNOME,
#endif
        NULL);
  } else {
    src->session =
        soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
        src->context, SOUP_SESSION_PROXY_URI, src->proxy,
        SOUP_SESSION_TIMEOUT, src->timeout,
        SOUP_SESSION_USER_AGENT, src->user_agent, NULL);
  }

  if (!src->session) {
    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
        (NULL), ("Failed to create async session"));
    return FALSE;
  }

  g_signal_connect (src->session, "authenticate",
      G_CALLBACK (gst_soup_http_src_authenticate_cb), src);
  return TRUE;
}
Esempio n. 11
0
/**
 * g_socket_listener_accept_socket:
 * @listener: a #GSocketListener
 * @source_object: (out) (transfer none) (allow-none): location where #GObject pointer will be stored, or %NULL.
 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
 * @error: #GError for error reporting, or %NULL to ignore.
 *
 * Blocks waiting for a client to connect to any of the sockets added
 * to the listener. Returns the #GSocket that was accepted.
 *
 * If you want to accept the high-level #GSocketConnection, not a #GSocket,
 * which is often the case, then you should use g_socket_listener_accept()
 * instead.
 *
 * If @source_object is not %NULL it will be filled out with the source
 * object specified when the corresponding socket or address was added
 * to the listener.
 *
 * If @cancellable is not %NULL, then the operation can be cancelled by
 * triggering the cancellable object from another thread. If the operation
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
 *
 * Returns: (transfer full): a #GSocket on success, %NULL on error.
 *
 * Since: 2.22
 */
GSocket *
g_socket_listener_accept_socket (GSocketListener  *listener,
				 GObject         **source_object,
				 GCancellable     *cancellable,
				 GError          **error)
{
  GSocket *accept_socket, *socket;

  g_return_val_if_fail (G_IS_SOCKET_LISTENER (listener), NULL);

  if (!check_listener (listener, error))
    return NULL;

  if (listener->priv->sockets->len == 1)
    {
      accept_socket = listener->priv->sockets->pdata[0];
      if (!g_socket_condition_wait (accept_socket, G_IO_IN,
				    cancellable, error))
	return NULL;
    }
  else
    {
      GList *sources;
      struct AcceptData data;
      GMainLoop *loop;

      if (listener->priv->main_context == NULL)
	listener->priv->main_context = g_main_context_new ();

      loop = g_main_loop_new (listener->priv->main_context, FALSE);
      data.loop = loop;
      sources = add_sources (listener,
			     accept_callback,
			     &data,
			     cancellable,
			     listener->priv->main_context);
      g_main_loop_run (loop);
      accept_socket = data.socket;
      free_sources (sources);
      g_main_loop_unref (loop);
    }

  if (!(socket = g_socket_accept (accept_socket, cancellable, error)))
    return NULL;

  if (source_object)
    *source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark);

  return socket;
}
Esempio n. 12
0
int
main(int argc, const char *argv[])
{
  DBusError error;
  DBusMessage *message = NULL, *reply = NULL;
  const char *str;

  main_context = g_main_context_new ();
  dbus_error_init (&error);
  bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
  if (!bus)
  {
    fprintf(stderr, "Couldn't connect to bus: %s\n", error.name);
    return 1;
  }
  dbus_connection_setup_with_g_main (bus, NULL);
  message = dbus_message_new_method_call ("org.freedesktop.DBus", "/org/freedesktop/DBus", DBUS_INTERFACE_DBUS, "GetId");
  reply = send_and_allow_reentry (bus, message);
  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
  {
    char *err;
    dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err, DBUS_TYPE_INVALID);
    fprintf (stderr, "Got error: %s\n", err);
    return 1;
  }
  dbus_message_unref (reply);
  dbus_message_unref (message);
  message = dbus_message_new_method_call ("org.freedesktop.DBus", "/org/freedesktop/DBus", DBUS_INTERFACE_DBUS, "GetId");
  reply = send_and_allow_reentry (bus, message);
  if (!reply)
  {
    fprintf(stderr, "Sorry; dbus wouldn't answer me: %s\n", error.message);
    exit(1);
  }
  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
  {
    char *err;
    dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err, DBUS_TYPE_INVALID);
    fprintf (stderr, "Got error: %s\n", err);
    return 1;
  }
  if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
  {
    fprintf(stderr, "Sorry; can't communicate: %s\n", error.message);
    exit(1);
  }

  return 0;
}
Esempio n. 13
0
void
_PowerdClientIPCRun(void)
{
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    if (!gServiceHandle)
    {
        retVal = LSRegister(NULL, &gServiceHandle, &lserror);
        if (!retVal) goto error;

        if (!gMainLoop)
        {
            int ret;

            GMainContext *context = g_main_context_new();
            if (!context) goto error;

            gMainLoop = g_main_loop_new(context, FALSE);
            g_main_context_unref(context);
            if (!gMainLoop) goto error;

            pthread_attr_t attr;
            pthread_attr_init(&attr);

            ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
            assert(ret == 0);

            pthread_t tid;
            pthread_create(&tid, &attr, _PowerdIPCThread, NULL);
        }

        retVal = LSGmainAttach(gServiceHandle, gMainLoop, &lserror);
        if (!retVal) goto error;
    }

    retVal = LSCall(gServiceHandle,
        "luna://com.palm.lunabus/signal/registerServerStatus",
        "{\"serviceName\":\"com.palm.power\"}", _powerd_server_up,
        NULL, NULL, &lserror);
    if (!retVal) goto error;

    return;
error:
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
    return;
}
Esempio n. 14
0
int main(int argc, char* argv[])
{
    GMainContext *context;
    if(g_thread_supported() == 0)
        g_thread_init(NULL);
    context = g_main_context_new();
    add_source(context);
    loop = g_main_loop_new(context, FALSE);
    g_print("input string('q' to quit)/n");
    g_main_loop_run(loop);
    g_main_loop_unref(loop);
    //Context用完计数器减1
    g_main_context_unref(context);
    return 0;
}
Esempio n. 15
0
static void
setup_main_context (GdaConnection *cnc, guint *ptr_to_incr)
{
	GMainContext *context;
	GSource *idle;

	context = g_main_context_new ();
	idle = g_idle_source_new ();
	g_source_set_priority (idle, G_PRIORITY_DEFAULT);
	g_source_attach (idle, context);
	g_source_set_callback (idle, (GSourceFunc) idle_incr, ptr_to_incr, NULL);
	g_source_unref (idle);
	gda_connection_set_main_context (cnc, context);
	g_main_context_unref (context);	
}
Esempio n. 16
0
/** 
* @brief Block till incoming message is ready.  This should only be
*        called by custom mainloops.
* 
* @param  sh 
* @param  *message  allocated store of next message from queue, NULL if queue is empty.
*                   You MUST call LSMessageUnref() to free this message.
* @param  lserror 
* 
* @retval
*/
bool
LSCustomWaitForMessage(LSHandle *sh, LSMessage **message,
                               LSError *lserror)
{
    _LSErrorIfFail(sh != NULL, lserror);
    _LSErrorIfFail(message != NULL, lserror);

    LSHANDLE_VALIDATE(sh);

    bool retVal;

    /* If the incoming queue contains messages, return immediately */
    retVal = LSCustomFetchMessage(sh, message, lserror);
    if (!retVal)
        return false;
    if (*message)
        return true;
    
    /* install custom message callback if not done already */
    if (G_UNLIKELY(sh->transport->msg_handler != _LSCustomMessageHandler))
    {
        sh->transport->msg_handler = _LSCustomMessageHandler;
        sh->transport->msg_context = sh;
        
        sh->transport->mainloop_context = g_main_context_new();

        if (!sh->transport->mainloop_context)
        {
            _LSErrorSet(lserror, -ENOMEM, "OOM");
            return false;
        }

        _LSTransportAddInitialWatches(sh->transport, sh->transport->mainloop_context);
    }

    /* 
     * Run an interation of the context: g_main_context_iteration, which
     * will call our special custom message callback and add to the queue of
     * messages
     */
    g_main_context_iteration(sh->transport->mainloop_context, TRUE);

    /* Fetch 1 message off incoming queue. */
    retVal = LSCustomFetchMessage(sh, message, lserror);
    if (!retVal) return false;

    return true;
}
Esempio n. 17
0
void svc_accessor::run()
{
    // Create context
    main_context_ = std::shared_ptr<GMainContext>(g_main_context_new(), g_main_context_unref);

    // Run loop
    main_loop_ = std::shared_ptr<GMainLoop>
      (g_main_loop_new(main_context_.get(), TRUE), g_main_loop_unref);

    LShlService* svc = 0;
    // Service handle
    hl::ls_error lserror;
    if (!LSRegisterhlService(svc_name_.c_str(), &svc, &lserror))
        lserror.warning("Error register service.");

    svc_ = std::shared_ptr<LShlService >(
             svc
             , [](LShlService* svc)
               {
                  hl::ls_error lserror;
                  if (!LSUnregisterhlService(svc, &lserror))
                    lserror.warning("LSUnregisterhlService ");
               }
            );

    LSGmainAttachhlService(svc_.get(), main_loop_.get(), &lserror);

    // The bus handle
    if (!(private_bus_ = LShlServiceGetPrivateConnection(svc_.get()))
        || !LSGmainSetPriority(private_bus_, priority_, &lserror))
    {
        lserror.warning("Set priority error.");
    }

    if (!(bus_ = LShlServiceGetPublicConnection(svc_.get()))
            || !LSGmainSetPriority(bus_, priority_, &lserror))
    {
        lserror.warning("Set priority error.");
    }

    std::shared_ptr<GMainLoop > locloop = main_loop_;
    loop_thread_ = std::unique_ptr<std::thread > (
        new std::thread([locloop]()
        {
            g_main_loop_run(locloop.get());
        })
    );
}
Esempio n. 18
0
static GMainContext *get_my_context(GError **exception)
{
	if (ctx == NULL)
		ctx = g_main_context_new();

	if (thread == NULL) {
		thread = g_thread_try_new("gmain", run_main_loop, NULL,
					  exception);
		if (*exception != NULL) {
			g_main_context_unref(ctx);
			ctx = NULL;
		}
	}

	return ctx;
}
Esempio n. 19
0
static gpointer iothread_g_main_context_init(gpointer opaque)
{
    AioContext *ctx;
    IOThread *iothread = opaque;
    GSource *source;

    iothread->worker_context = g_main_context_new();

    ctx = iothread_get_aio_context(iothread);
    source = aio_get_g_source(ctx);
    g_source_attach(source, iothread->worker_context);
    g_source_unref(source);

    aio_notify(iothread->ctx);
    return NULL;
}
int
PrivacyChecker::initializeGMain(void)
{
	std::unique_lock<std::mutex> initlock(m_initializeMutex);

	TryReturn(!m_isInitialized, PRIV_FLTR_ERROR_SUCCESS, , "Already Initalized");

	m_pHandlerGMainContext = g_main_context_new();
	TryReturn(m_pHandlerGMainContext != NULL, PRIV_FLTR_ERROR_SYSTEM_ERROR, ,"cannot create m_pHandlerGMainContext");

	m_pLoop = g_main_loop_new(m_pHandlerGMainContext, FALSE);
	TryReturn(m_pLoop != NULL, PRIV_FLTR_ERROR_SYSTEM_ERROR, ,"cannot create m_pLoop");

	std::unique_lock<std::mutex> lock(m_dbusMutex);
	int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL);
	TryReturn(res >= 0, PRIV_FLTR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));
static void*
no_bus_thread_func (void *data)
{
  DBusError error;
  GMainContext *context;
  DBusConnection *connection;
  ClientData cd;
  
  g_printerr ("Starting client thread %p\n", g_thread_self());  
  
  dbus_error_init (&error);
  connection = dbus_connection_open_private (messages_address, &error);
  if (connection == NULL)
    {
      g_printerr ("could not open connection: %s\n", error.message);
      dbus_error_free (&error);
      exit (1);
    }

  context = g_main_context_new ();

  cd.iterations = 1;
  cd.loop = g_main_loop_new (context, FALSE);
  
  if (!dbus_connection_add_filter (connection,
				   no_bus_client_filter, &cd, NULL))
    g_error ("no memory");
  
  
  dbus_connection_setup_with_g_main (connection, context);

  g_printerr ("Client thread sending message to prime pingpong\n");
  send_echo_method_call (connection);
  g_printerr ("Client thread sent message\n");

  g_printerr ("Client thread entering main loop\n");
  g_main_loop_run (cd.loop);
  g_printerr ("Client thread %p exiting main loop\n",
              g_thread_self());

  dbus_connection_close (connection);
  
  g_main_loop_unref (cd.loop);
  g_main_context_unref (context);
  
  return NULL;
}
Esempio n. 22
0
/**
 * metadata_thread_main:
 *
 * Called from the metadatascan worker thread. If we're missing an
 * object from one of them, we queue a request to the main thread to
 * fetch it.  When it's fetched, we get passed the object back and
 * scan it.
 */
static gpointer
metadata_thread_main (gpointer user_data)
{
  OtPullData *pull_data = user_data;
  GSource *src;

  pull_data->metadata_thread_context = g_main_context_new ();
  pull_data->metadata_thread_loop = g_main_loop_new (pull_data->metadata_thread_context, TRUE);

  src = ot_waitable_queue_create_source (pull_data->metadata_objects_to_scan);
  g_source_set_callback (src, (GSourceFunc)on_metadata_objects_to_scan_ready, pull_data, NULL);
  g_source_attach (src, pull_data->metadata_thread_context);
  g_source_unref (src);

  g_main_loop_run (pull_data->metadata_thread_loop);
  return NULL;
}
Esempio n. 23
0
gboolean
gst_task_pool_need_schedule_thread (GstTaskPool * pool, gboolean needed)
{
  gboolean ret;

  g_return_val_if_fail (GST_IS_TASK_POOL (pool), FALSE);
  g_return_val_if_fail (needed || pool->priv->need_schedule_thread > 0, FALSE);

  /* We don't allow this for the default pool */
  if (pool == gst_task_pool_get_default ()) {
    gst_object_unref (pool);
    return FALSE;
  }

  g_mutex_lock (&pool->priv->schedule_lock);
  if (needed) {
    ret = TRUE;
    if (pool->priv->need_schedule_thread == 0) {
      pool->priv->schedule_context = g_main_context_new ();
      pool->priv->schedule_loop =
          g_main_loop_new (pool->priv->schedule_context, FALSE);

      pool->priv->schedule_thread =
          g_thread_new (GST_OBJECT_NAME (pool), gst_task_pool_schedule_func,
          pool);

      g_cond_wait (&pool->priv->schedule_cond, &pool->priv->schedule_lock);
    }
    pool->priv->need_schedule_thread++;
  } else {
    ret = FALSE;
    pool->priv->need_schedule_thread--;
    if (pool->priv->need_schedule_thread == 0) {
      g_main_loop_quit (pool->priv->schedule_loop);
      g_thread_join (pool->priv->schedule_thread);
      g_main_loop_unref (pool->priv->schedule_loop);
      pool->priv->schedule_loop = NULL;
      g_main_context_unref (pool->priv->schedule_context);
      pool->priv->schedule_context = NULL;
      pool->priv->schedule_thread = NULL;
    }
  }
  g_mutex_unlock (&pool->priv->schedule_lock);

  return ret;
}
WindowContentTransitionRunner::WindowContentTransitionRunner()
    : m_mainLoop(0)
    , m_mainCtxt(0)
    , m_transitionType(Transition_Invalid)
    , m_app(0)
    , m_channel(0)
    , m_ipcBuffer(0)
    , m_dstContext(0)
    , m_fromSceneSurface(0)
    , m_toSceneSurface(0)
    , m_transitionIsPop(false)
    , m_currRotateAngle(0)
    , m_targRotateAngle(0)
{
    m_mainCtxt = g_main_context_new();
    m_mainLoop = g_main_loop_new(m_mainCtxt, TRUE);
}
Esempio n. 25
0
static void
gst_gl_window_init (GstGLWindow * window)
{
  GstGLWindowPrivate *priv = GST_GL_WINDOW_GET_PRIVATE (window);
  window->priv = priv;

  g_mutex_init (&window->lock);
  window->is_drawing = FALSE;

  g_weak_ref_init (&window->context_ref, NULL);

  g_mutex_init (&window->priv->sync_message_lock);
  g_cond_init (&window->priv->sync_message_cond);

  priv->main_context = g_main_context_new ();
  priv->loop = g_main_loop_new (priv->main_context, FALSE);
}
Esempio n. 26
0
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context)
    : mainContext(context)
{
    if (qgetenv("QT_NO_THREADED_GLIB").isEmpty()) {
        static int dummyValue = 0; // only used for its address
        QMutexLocker locker(QMutexPool::instance()->get(&dummyValue));
        if (!g_thread_supported())
            g_thread_init(NULL);
    }

    if (mainContext) {
        g_main_context_ref(mainContext);
    } else {
        QCoreApplication *app = QCoreApplication::instance();
	if (app && QThread::currentThread() == app->thread()) {
	    mainContext = g_main_context_default();
	    g_main_context_ref(mainContext);
	} else {
	    mainContext = g_main_context_new();
	}
    }

    postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,
                                                                        sizeof(GPostEventSource)));
    postEventSource->serialNumber = 1;
    g_source_set_can_recurse(&postEventSource->source, true);
    g_source_attach(&postEventSource->source, mainContext);

    // setup socketNotifierSource
    socketNotifierSource =
        reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs,
                                                               sizeof(GSocketNotifierSource)));
    (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>();
    g_source_set_can_recurse(&socketNotifierSource->source, true);
    g_source_attach(&socketNotifierSource->source, mainContext);

    // setup timerSource
    timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs,
                                                                sizeof(GTimerSource)));
    (void) new (&timerSource->timerList) QTimerInfoList();
    timerSource->processEventsFlags = QEventLoop::AllEvents;
    g_source_set_can_recurse(&timerSource->source, true);
    g_source_set_priority(&timerSource->source, G_PRIORITY_DEFAULT_IDLE);
    g_source_attach(&timerSource->source, mainContext);
}
Esempio n. 27
0
/* main function run by each thread, which submit jobs */
static gpointer
test9_main_func (GdaWorker *worker)
{
	GError *error = NULL;
	GMainContext *context = NULL;
	static guint counter = 0;

	context = g_main_context_new ();

	if (! gda_worker_set_callback (worker, context, (GdaWorkerCallback) test9_worker_cb, g_thread_self (), &error)) {
		g_print ("gda_worker_set_callback() from thread %p error: %s\n", g_thread_self (),
			 error && error->message ? error->message : "No detail");
		g_clear_error (&error);
		return (gpointer) 0x01;
	}

	GMainLoop *loop;
	loop = g_main_loop_new (context, FALSE);
#define N_JOBS 2
	guint i;
	for (i = 0; i < N_JOBS; i++) {
		guint jid;
		Test9Data *data;
		data = g_new (Test9Data, 1);
		data->in = (guint) GPOINTER_TO_INT (g_thread_self ()) + (counter++);
		data->out = 0;
		data->loop = (i == N_JOBS - 1) ? loop : NULL;
		jid = gda_worker_submit_job (worker, context, (GdaWorkerFunc) test9_job_func, data,
					     NULL, (GDestroyNotify) test9data_free, &error);
		if (jid == 0) {
			g_print ("gda_worker_submit_job() from thread %p error: %s\n", g_thread_self (),
				 error && error->message ? error->message : "No detail");
			g_clear_error (&error);
			return (gpointer) 0x01;
		}
		else
			g_print ("Submitted job %u from thread %p, with data %p\n", jid, g_thread_self(), data);
	}
				     
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	g_main_context_unref (context);
	return NULL;
}
Esempio n. 28
0
static SoupServer *
test_server_new (gboolean in_own_thread, gboolean ssl)
{
	SoupServer *server;
	GMainContext *async_context;
	const char *ssl_cert_file, *ssl_key_file;
	SoupAddress *addr;

	async_context = in_own_thread ? g_main_context_new () : NULL;

	if (ssl) {
		ssl_cert_file = SRCDIR "/test-cert.pem";
		ssl_key_file = SRCDIR "/test-key.pem";
	} else
		ssl_cert_file = ssl_key_file = NULL;

	addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
	soup_address_resolve_sync (addr, NULL);

	server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
				  SOUP_SERVER_ASYNC_CONTEXT, async_context,
				  SOUP_SERVER_SSL_CERT_FILE, ssl_cert_file,
				  SOUP_SERVER_SSL_KEY_FILE, ssl_key_file,
				  NULL);
	g_object_unref (addr);
	if (async_context)
		g_main_context_unref (async_context);

	if (!server) {
		fprintf (stderr, "Unable to create server\n");
		exit (1);
	}

	if (in_own_thread) {
		GThread *thread;

		thread = g_thread_create (run_server_thread, server,
					  TRUE, NULL);
		g_object_set_data (G_OBJECT (server), "thread", thread);
	} else
		soup_server_run_async (server);

	return server;
}
Esempio n. 29
0
File: gpoll.c Progetto: cosimoc/glib
int
main (int   argc,
      char *argv[])
{
  int result;
  GMainContext *ctx;

  g_test_init (&argc, &argv, NULL);
  init_networking ();
  ctx = g_main_context_new ();

  g_test_add_func ("/gpoll/gpoll", test_gpoll);

  result = g_test_run ();

  g_main_context_unref (ctx);

  return result;
}
Esempio n. 30
0
static libnm_glib_ctx *
_libnm_glib_ctx_new (void)
{
	libnm_glib_ctx *ctx = g_malloc0 (sizeof (libnm_glib_ctx));

	if (!(ctx->g_main_ctx = g_main_context_new ()))
		goto error;
	if (!(ctx->g_main_loop = g_main_loop_new (ctx->g_main_ctx, FALSE)))
		goto error;
	if (!(ctx->callbacks_lock = g_mutex_new ()))
		goto error;
	ctx->dbus_watch_interval = 1000;

	return ctx;

error:
	_libnm_glib_ctx_free (ctx);
	return NULL;
}