示例#1
0
	DispatchSource createSourceTimer(void * ctx, dispatch_function_t handler)
	{
		dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
														  DISPATCH_TARGET_QUEUE_DEFAULT);
		dispatch_set_context(source, ctx);
		dispatch_source_set_event_handler_f(source, handler);
		dispatch_resume(source);
		return DispatchSource(source);
	}
示例#2
0
	DispatchSource createSourceSignal(int sig, void * ctx, dispatch_function_t handler)
	{
		signal(sig, SIG_IGN);
		dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, sig, 0,
														  DISPATCH_TARGET_QUEUE_DEFAULT);
		dispatch_set_context(source, ctx);
		dispatch_source_set_event_handler_f(source, handler);
		dispatch_resume(source);
		return DispatchSource(source);
	}
示例#3
0
文件: mach.c 项目: Acorld/libxpc
static dispatch_source_t
mach_create_client_source(xpc_port_t port, void *context, dispatch_queue_t tq)
{
	mach_port_t mp = (mach_port_t)port;
	dispatch_source_t ret;

	ret = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV,
	    (uintptr_t)mp, 0, tq);

	dispatch_set_context(ret, context);
	dispatch_source_set_event_handler_f(ret, xpc_connection_recv_message);
	dispatch_source_set_cancel_handler(ret, ^{
	    xpc_connection_destroy_peer(dispatch_get_context(ret));
	});
void IOHIDEventSystemStatistics::scheduleWithDispatchQueue(dispatch_queue_t queue)
{
    _dispatch_queue = queue;
    
    if ( _dispatch_queue ) {
        _pending_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_ADD, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0));
        dispatch_set_context(_pending_source, this);
        dispatch_source_set_event_handler_f(_pending_source, IOHIDEventSystemStatistics::handlePendingStats);
        dispatch_resume(_pending_source);
        
        notify_register_dispatch( "com.apple.iokit.hid.displayStatus", &_displayToken,_dispatch_queue, ^(__unused int token){
            
            notify_get_state(_displayToken, &_displayState);
        });
    }
示例#5
0
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::MessageDecoder&)
{
#if ENABLE(SECCOMP_FILTERS)
    {
        WebKit::SeccompFiltersWebProcessQt seccompFilters(parameters);
        seccompFilters.initialize();
    }
#endif

    m_networkAccessManager = new QtNetworkAccessManager(this);

    if (!parameters.cookieStorageDirectory.isEmpty()) {
        WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory);
        m_networkAccessManager->setCookieJar(jar);
        // Do not let QNetworkAccessManager delete the jar.
        jar->setParent(0);
    }

    if (!parameters.diskCacheDirectory.isEmpty()) {
        QNetworkDiskCache* diskCache = new QNetworkDiskCache();
        diskCache->setCacheDirectory(parameters.diskCacheDirectory);
        // The m_networkAccessManager takes ownership of the diskCache object upon the following call.
        m_networkAccessManager->setCache(diskCache);
    }

#if defined(Q_OS_MACX)
    pid_t ppid = getppid();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ppid, DISPATCH_PROC_EXIT, queue);
    if (source) {
        dispatch_source_set_event_handler_f(source, parentProcessDiedCallback);
        dispatch_resume(source);
    }
#endif

    WebCore::RuntimeEnabledFeatures::setSpeechInputEnabled(false);

    // We'll only install the Qt builtin bundle if we don't have one given by the UI process.
    // Currently only WTR provides its own bundle.
    if (parameters.injectedBundlePath.isEmpty()) {
        m_injectedBundle = InjectedBundle::create(String());
        m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle));
        QtBuiltinBundle::shared().initialize(toAPI(m_injectedBundle.get()));
    }
}
示例#6
0
static int
_gcdpoll_timeout_add(AvahiTimeout *t, const struct timeval *tv)
{
  struct timeval e_tv;
  struct timeval now;
  int64_t nsecs;
  int ret;

  ret = gettimeofday(&now, NULL);
  if (ret != 0)
    return -1;

  if (!t->timer)
    {
      t->timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, mdns_sq);
      if (!t->timer)
	return -1;

      dispatch_set_context(t->timer, t);
      dispatch_source_set_event_handler_f(t->timer, gcdpollcb_timer);
    }
  else
    dispatch_suspend(t->timer);

  if ((tv->tv_sec == 0) && (tv->tv_usec == 0))
    {
      dispatch_source_set_timer(t->timer,
				DISPATCH_TIME_NOW,
				DISPATCH_TIME_FOREVER /* one-shot */, 0);
    }
  else
    {
      timersub(tv, &now, &e_tv);

      nsecs = e_tv.tv_sec * NSEC_PER_SEC + e_tv.tv_usec * 1000;

      dispatch_source_set_timer(t->timer,
				dispatch_time(DISPATCH_TIME_NOW, nsecs),
				DISPATCH_TIME_FOREVER /* one-shot */, 0);
    }

  dispatch_resume(t->timer);

  return 0;
}
示例#7
0
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder* arguments)
{
    m_networkAccessManager = new QtNetworkAccessManager(this);

    ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull());
    QNetworkDiskCache* diskCache = new QNetworkDiskCache();
    diskCache->setCacheDirectory(parameters.diskCacheDirectory);
    // The m_networkAccessManager takes ownership of the diskCache object upon the following call.
    m_networkAccessManager->setCache(diskCache);

    ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull());
    WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory);
    m_networkAccessManager->setCookieJar(jar);
    // Do not let QNetworkAccessManager delete the jar.
    jar->setParent(0);

#if defined(Q_OS_MACX)
    pid_t ppid = getppid();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ppid, DISPATCH_PROC_EXIT, queue);
    if (source) {
        dispatch_source_set_event_handler_f(source, parentProcessDiedCallback);
        dispatch_resume(source);
    }
#endif

    // Disable runtime enabled features that have no WebKit2 implementation yet.
#if ENABLE(DEVICE_ORIENTATION)
    WebCore::RuntimeEnabledFeatures::setDeviceMotionEnabled(false);
    WebCore::RuntimeEnabledFeatures::setDeviceOrientationEnabled(false);
#endif
#if ENABLE(SPEECH_INPUT)
    WebCore::RuntimeEnabledFeatures::setSpeechInputEnabled(false);
#endif

    // We'll only install the Qt builtin bundle if we don't have one given by the UI process.
    // Currently only WTR provides its own bundle.
    if (parameters.injectedBundlePath.isEmpty()) {
        m_injectedBundle = InjectedBundle::create(String());
        m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle));
        QtBuiltinBundle::shared().initialize(toAPI(m_injectedBundle.get()));
    }
}
int
main(void)
{
	dispatch_queue_t main_q;

	test_start("Dispatch Update Timer");

	main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());
	
	timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q);
	dispatch_source_set_timer(timer, 1000000000ull, 0, 0);
	dispatch_source_set_cancel_handler_f(timer, cancel_handler);
	dispatch_source_set_event_handler_f(timer, event_handler);
	test_ptr_notnull("dispatch_source_timer_create", timer);

	gettimeofday(&start_time, NULL);
	dispatch_resume(as_do(timer));

	dispatch_main();
}