/** * Wait for events and process them (Darwin). * * @retval VINF_SUCCESS * @retval VERR_TIMEOUT * @retval VERR_INTERRUPTED * * @param cMsTimeout How long to wait, or RT_INDEFINITE_WAIT. */ static int waitForEventsOnDarwin(RTMSINTERVAL cMsTimeout) { /* * Wait for the requested time, if we get a hit we do a poll to process * any other pending messages. * * Note! About 1.0e10: According to the sources anything above 3.1556952e+9 * means indefinite wait and 1.0e10 is what CFRunLoopRun() uses. */ CFTimeInterval rdTimeout = cMsTimeout == RT_INDEFINITE_WAIT ? 1e10 : (double)cMsTimeout / 1000; OSStatus orc = CFRunLoopRunInMode(kCFRunLoopDefaultMode, rdTimeout, true /*returnAfterSourceHandled*/); if (orc == kCFRunLoopRunHandledSource) { OSStatus orc2 = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, false /*returnAfterSourceHandled*/); if ( orc2 == kCFRunLoopRunStopped || orc2 == kCFRunLoopRunFinished) orc = orc2; } if ( orc == 0 /*???*/ || orc == kCFRunLoopRunHandledSource) return VINF_SUCCESS; if ( orc == kCFRunLoopRunStopped || orc == kCFRunLoopRunFinished) return VERR_INTERRUPTED; AssertMsg(orc == kCFRunLoopRunTimedOut, ("Unexpected status code from CFRunLoopRunInMode: %#x", orc)); return VERR_TIMEOUT; }
void TeensyControls_find_new_usb_devices(void) { while (1) { int r = CFRunLoopRunInMode(dev_run_mode, 0, true); if (r != kCFRunLoopRunHandledSource) break; } }
int main(int argc, char **argv) { kern_return_t kr; mach_port_t service_port = MACH_PORT_NULL; openlog("eapolcfg_auth", LOG_CONS | LOG_PID, LOG_DAEMON); if (geteuid() != 0) { syslog(LOG_ERR, "not running as root - exiting"); exit(EX_CONFIG); } kr = bootstrap_check_in(bootstrap_port, EAPOLCFG_AUTH_SERVER, &service_port); if (kr != BOOTSTRAP_SUCCESS) { syslog(LOG_ERR, "bootstrap_check_in() failed: %s", bootstrap_strerror(kr)); exit(EX_UNAVAILABLE); } start_service(service_port); while (1) { SInt32 rlStatus; rlStatus = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 15.0, TRUE); if (rlStatus == kCFRunLoopRunTimedOut) { if (S_handled_request == FALSE) { /* we didn't handle a request in the last time interval */ break; } S_handled_request = FALSE; } } exit(EX_OK); return (0); }
static int iokit_unmount (MMCDEV *mmc) { if (0 == mmc->is_mounted) { return 0; /* nothing to do */ } BD_DEBUG(DBG_MMC, "Unmounting disk\n"); mmc->session = DASessionCreate (kCFAllocatorDefault); if (NULL == mmc->session) { BD_DEBUG(DBG_MMC, "Could not create a disc arbitration session\n"); return -1; } mmc->disk = DADiskCreateFromBSDName (kCFAllocatorDefault, mmc->session, mmc->bsd_name); if (NULL == mmc->disk) { BD_DEBUG(DBG_MMC, "Could not create a disc arbitration disc for the device\n"); CFRelease (mmc->session); mmc->session = NULL; return -1; } DAApprovalSessionScheduleWithRunLoop (mmc->session, CFRunLoopGetCurrent (), kCFRunLoopDefaultMode); DADiskUnmount (mmc->disk, kDADiskUnmountOptionForce, iokit_unmount_complete, mmc); CFRunLoopRunInMode (kCFRunLoopDefaultMode, 10, true); return mmc->is_mounted ? -1 : 0; }
void CInputProviderMacOsHid::InputDeviceListenerThread() { m_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, 0); { CFDictionaryRef matchingDict[3]; matchingDict[0] = CreateDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick); matchingDict[1] = CreateDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad); matchingDict[2] = CreateDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController); CFArrayRef array = CFArrayCreate(kCFAllocatorDefault, (const void**)matchingDict, 3, &kCFTypeArrayCallBacks); CFRelease(matchingDict[0]); CFRelease(matchingDict[1]); CFRelease(matchingDict[2]); IOHIDManagerSetDeviceMatchingMultiple(m_hidManager, array); } IOHIDManagerRegisterDeviceMatchingCallback(m_hidManager, OnDeviceMatchedStub, this); IOHIDManagerOpen(m_hidManager, kIOHIDOptionsTypeNone); IOHIDManagerScheduleWithRunLoop(m_hidManager, CFRunLoopGetCurrent(), CFSTR("CustomLoop")); while(CFRunLoopRunInMode(CFSTR("CustomLoop"), 1, true) != kCFRunLoopRunStopped && m_running) { } IOHIDManagerClose(m_hidManager, 0); }
bool HTTPInputSource::Open(CFErrorRef *error) { if(IsOpen()) { LOGGER_WARNING("org.sbooth.AudioEngine.InputSource.HTTP", "Open() called on an InputSource that is already open"); return true; } // Set up the HTTP request mRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), mURL, kCFHTTPVersion1_1); if(NULL == mRequest) { if(error) *error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL); return false; } CFHTTPMessageSetHeaderFieldValue(mRequest, CFSTR("User-Agent"), CFSTR("SFBAudioEngine")); // Seek support if(0 < mDesiredOffset) { CFStringRef byteRange = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%ld-"), mDesiredOffset); CFHTTPMessageSetHeaderFieldValue(mRequest, CFSTR("Range"), byteRange); CFRelease(byteRange), byteRange = NULL; } mReadStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, mRequest, NULL); if(NULL == mReadStream) { CFRelease(mRequest), mRequest = NULL; if(error) *error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL); return false; } // Start the HTTP connection CFStreamClientContext myContext = { 0, this, NULL, NULL, NULL }; CFOptionFlags clientFlags = kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered; if(!CFReadStreamSetClient(mReadStream, clientFlags, myCFReadStreamClientCallBack, &myContext)) { CFRelease(mRequest), mRequest = NULL; CFRelease(mReadStream), mReadStream = NULL; if(error) *error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL); return false; } CFReadStreamScheduleWithRunLoop(mReadStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); if(!CFReadStreamOpen(mReadStream)) { CFRelease(mRequest), mRequest = NULL; CFRelease(mReadStream), mReadStream = NULL; if(error) *error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL); return false; } while(NULL == mResponseHeaders) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); mIsOpen = true; return true; }
void CL_SoundOutput_MacOSX::wait() { while (fragments_available == 0) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true); } }
/** * Use the DiskArbitration Daemon to inform us of media changes */ void MonitorThreadDarwin::run(void) { CFDictionaryRef match = kDADiskDescriptionMatchVolumeMountable; DASessionRef daSession = DASessionCreate(kCFAllocatorDefault); IOMasterPort(MACH_PORT_NULL, &sMasterPort); DARegisterDiskAppearedCallback(daSession, match, diskAppearedCallback, this); DARegisterDiskDisappearedCallback(daSession, match, diskDisappearedCallback, this); DARegisterDiskDescriptionChangedCallback(daSession, match, kDADiskDescriptionWatchVolumeName, diskChangedCallback, this); DASessionScheduleWithRunLoop(daSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); // Nice and simple, as long as our monitor is valid and active, // loop and let daSession check the devices. while (m_Monitor && m_Monitor->IsActive()) { // Run the run loop for interval (milliseconds) - this will // handle any disk arbitration appeared/dissappeared events CFRunLoopRunInMode(kCFRunLoopDefaultMode, (float) m_Interval / 1000.0f, false ); } DAUnregisterCallback(daSession, (void(*))diskChangedCallback, this); DAUnregisterCallback(daSession, (void(*))diskDisappearedCallback, this); DAUnregisterCallback(daSession, (void(*))diskAppearedCallback, this); CFRelease(daSession); }
void TCPStream_CFNetwork::open() { if (!serviceName.empty() && serviceName.find_first_not_of("0123456789") == String::npos) { remoteHostName = domainName; remotePortNumber = atoi(serviceName.c_str()); if (connect()) { handleOpenedEvent(); } handleOpeningFailedEvent(); } DNS::SRVRecordResolver resolver(serviceName, "tcp", domainName); resolver.start(); while (!resolver.isDone()) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); } //The SRV lookup has completed. Get the results and try to connect auto results = DNS::SRVRecordResolver::prioritizeResults(resolver.getResults()); for (auto result : results) { remoteHostName = result.target; remotePortNumber = result.port; if (connect()) { return handleOpenedEvent(); } } return handleOpeningFailedEvent(); }
static SDL_bool ConfigHIDManager(CFArrayRef matchingArray) { CFRunLoopRef runloop = CFRunLoopGetCurrent(); /* Run in a custom RunLoop mode just while initializing, so we can detect sticks without messing with everything else. */ CFStringRef tempRunLoopMode = CFSTR("SDLJoystickInit"); if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) { return SDL_FALSE; } IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL); IOHIDManagerScheduleWithRunLoop(hidman, runloop, tempRunLoopMode); IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray); while (CFRunLoopRunInMode(tempRunLoopMode,0,TRUE)==kCFRunLoopRunHandledSource) { /* no-op. Callback fires once per existing device. */ } /* Put this in the normal RunLoop mode now, for future hotplug events. */ IOHIDManagerUnscheduleFromRunLoop(hidman, runloop, tempRunLoopMode); IOHIDManagerScheduleWithRunLoop(hidman, runloop, kCFRunLoopDefaultMode); return SDL_TRUE; /* good to go. */ }
void pollCfLoop() { // this should dispatch ready events and exit CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); scheduleCfLoop(); }
// Async processing thread for keyboard events: static void *KbQueueWorkerThreadMain(void *inarg) { int deviceIndex = (int) inarg; int rc; // Switch ourselves (NULL) to RT scheduling: We promise to use / require at most (0+1) == 1 msec every // 10 msecs and allow for wakeup delay/jitter of up to 2 msecs -- perfectly reasonable, given that we // only do minimal << 1 msec processing, only at the timescale of human reaction times, and driven by // input devices with at least 4+/-4 msecs jitter at 8 msec USB polling frequency. if ((rc = PsychSetThreadPriority(NULL, 2, 0)) > 0) { printf("PsychHID: KbQueueCreate: Failed to switch to realtime priority [%s].\n", strerror(rc)); } // Keep a global reference to the runloop, as we need it in KbQueueRelease to get this thread to exit: psychHIDKbQueueCFRunLoopRef[deviceIndex] = (CFRunLoopRef) CFRunLoopGetCurrent(); CFRetain(psychHIDKbQueueCFRunLoopRef[deviceIndex]); // Add HID queue to current runloop: IOHIDQueueScheduleWithRunLoop(queue[deviceIndex], psychHIDKbQueueCFRunLoopRef[deviceIndex], kCFRunLoopDefaultMode); // Start the run loop, code execution will block here until run loop is stopped again by PsychHIDKbQueueRelease // Meanwhile, the run loop of this thread will be responsible for executing code below in PsychHIDKbQueueCalbackFunction while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false) == kCFRunLoopRunTimedOut) {}; // Remove HID queue from current runloop: IOHIDQueueUnscheduleFromRunLoop(queue[deviceIndex], psychHIDKbQueueCFRunLoopRef[deviceIndex], kCFRunLoopDefaultMode); // Done. Die peacefully: return(NULL); }
Burger::RunQueue::eReturnCode BURGER_API Burger::Mouse::Poll(void *pData) { while (CFRunLoopRunInMode(g_BurgerMouse,0,TRUE)==kCFRunLoopRunHandledSource) { } #if 0 Word i; Mouse *pMouse = static_cast<Mouse *>(pData); DeviceStruct *pRat = pMouse->m_Mice; for (i = 0; i < pMouse->m_uMiceCount; i++) { if (pRat->m_bUnplugged) { IOHIDDeviceRef pDevice = pRat->m_pDevice; if (pDevice) { if (IOHIDDeviceOpen(pDevice,kIOHIDOptionsTypeNone) == kIOReturnSuccess) { pRat->m_bUnplugged = FALSE; // Connected! IOHIDDeviceRegisterRemovalCallback(pDevice,DisconnectionCallback,pMouse); IOHIDDeviceRegisterInputValueCallback(pDevice,InputCallback,pMouse); CFRunLoopRef pRunLoop = CFRunLoopGetCurrent(); IOHIDDeviceScheduleWithRunLoop(pDevice,pRunLoop,g_BurgerMouse); } } } ++pRat; } #endif return RunQueue::OKAY; }
CFRunLoopRunResult osx_cf_run_loop_run_in_mode (CFStringRef mode, CFTimeInterval seconds, Boolean returnAfterSourceHandled) { CFRunLoopRunResult r; caml_release_runtime_system(); r = CFRunLoopRunInMode(mode, seconds, returnAfterSourceHandled); caml_acquire_runtime_system(); return r; }
void HIDJoystickManager::update() { SInt32 status = kCFRunLoopRunHandledSource; while (status == kCFRunLoopRunHandledSource) { status = CFRunLoopRunInMode(RunLoopMode, 0, true); } }
static void FetchIPAddress() { if(publicIPState == IPStateFetching) return; publicIPState = IPStateFetching; const UInt8 bodyBytes[] = {0}; CFDataRef body = CFDataCreate(kCFAllocatorDefault, bodyBytes, 0); CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("http://icanhazip.com"), NULL); CFHTTPMessageRef request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), url, kCFHTTPVersion1_1); CFHTTPMessageSetBody(request, body); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" // Apple suggests the NSURLSession API instead of CFReadStreamCreateForHTTPRequest, // But obviously that doesn't really work here CFReadStreamRef stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request); #pragma clang diagnostic pop CFRelease(body); CFRelease(url); CFRelease(request); CFMutableDataRef responseData = CFDataCreateMutable(kCFAllocatorDefault, 17); CFStreamClientContext context = { 0, responseData, NULL, NULL, NULL }; if(!CFReadStreamSetClient(stream, kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred, &IPStreamCallback, &context)) { CFRelease(stream); publicIPState = IPStateInvalid; return; } // Add to the run loop and open the stream CFReadStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); if(!CFReadStreamOpen(stream)) { CFReadStreamSetClient(stream, 0, NULL, NULL); CFReadStreamUnscheduleFromRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); CFRelease(stream); publicIPState = IPStateInvalid; return; } // Run the run loop do { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, TRUE); } while(publicIPState == IPStateFetching); }
static VALUE method_play_file(VALUE self, VALUE filename) { playFile(StringValuePtr(filename)); struct timeval wait; wait.tv_sec=0; wait.tv_usec=100*1000; do { CHECK_INTS; CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.25, false); } while (aqData.mIsRunning); CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false); free_aqData(); return Qnil; }
void fxRunLoop(txMachine* the) { #if mxMacOSX SInt32 reason; do { reason = CFRunLoopRunInMode(gxRunLoopMode, 1, false); } while (reason == kCFRunLoopRunTimedOut); #endif }
/* Function to cause any queued joystick insertions to be processed */ void SDL_SYS_JoystickDetect() { while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) { /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */ } if (s_bDeviceAdded || s_bDeviceRemoved) { recDevice *device = gpDeviceList; s_bDeviceAdded = SDL_FALSE; s_bDeviceRemoved = SDL_FALSE; int device_index = 0; /* send notifications */ while (device) { if (device->send_open_event) { device->send_open_event = 0; /* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */ #if !SDL_EVENTS_DISABLED SDL_Event event; event.type = SDL_JOYDEVICEADDED; if (SDL_GetEventState(event.type) == SDL_ENABLE) { event.jdevice.which = device_index; if ((SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event)) { SDL_PushEvent(&event); } } #endif /* !SDL_EVENTS_DISABLED */ } if (device->removed) { const int instance_id = device->instance_id; device = FreeDevice(device); /* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */ #if !SDL_EVENTS_DISABLED SDL_Event event; event.type = SDL_JOYDEVICEREMOVED; if (SDL_GetEventState(event.type) == SDL_ENABLE) { event.jdevice.which = instance_id; if ((SDL_EventOK == NULL) || (*SDL_EventOK) (SDL_EventOKParam, &event)) { SDL_PushEvent(&event); } } #endif /* !SDL_EVENTS_DISABLED */ } else { device = device->pNext; device_index++; } } } }
HRESULT WebKitMessageLoop::performMessageLoopTasks() { #if USE(CF) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); #endif #if USE(GLIB) g_main_context_iteration(0, false); #endif return S_OK; }
void Gamepad_init() { if (hidManager == NULL) { CFStringRef keys[2]; int value; CFNumberRef values[2]; CFDictionaryRef dictionaries[3]; CFArrayRef array; hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); keys[0] = CFSTR(kIOHIDDeviceUsagePageKey); keys[1] = CFSTR(kIOHIDDeviceUsageKey); value = kHIDPage_GenericDesktop; values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); value = kHIDUsage_GD_Joystick; values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); dictionaries[0] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(values[0]); CFRelease(values[1]); value = kHIDPage_GenericDesktop; values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); value = kHIDUsage_GD_GamePad; values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); dictionaries[1] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(values[0]); CFRelease(values[1]); value = kHIDPage_GenericDesktop; values[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); value = kHIDUsage_GD_MultiAxisController; values[1] = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); dictionaries[2] = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(values[0]); CFRelease(values[1]); array = CFArrayCreate(kCFAllocatorDefault, (const void **) dictionaries, 3, &kCFTypeArrayCallBacks); CFRelease(dictionaries[0]); CFRelease(dictionaries[1]); CFRelease(dictionaries[2]); IOHIDManagerSetDeviceMatchingMultiple(hidManager, array); CFRelease(array); IOHIDManagerRegisterDeviceMatchingCallback(hidManager, onDeviceMatched, NULL); IOHIDManagerRegisterDeviceRemovalCallback(hidManager, onDeviceRemoved, NULL); IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); // Force gamepads to be recognized immediately. The normal run loop mode takes a few frames, // but we can run one iteration with a custom mode to do it without a delay. IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), GAMEPAD_RUN_LOOP_MODE); CFRunLoopRunInMode(GAMEPAD_RUN_LOOP_MODE, 0, true); } }
void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& vector) { LOG(Network, "ResourceHandle::loadResourceSynchronously:%s allowStoredCredentials:%u", request.url().string().utf8().data(), storedCredentials); ASSERT(!request.isEmpty()); ASSERT(response.isNull()); ASSERT(error.isNull()); OwnPtr<WebCoreSynchronousLoaderClient> client = WebCoreSynchronousLoaderClient::create(response, error); client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(request, client.get(), false /*defersLoading*/, true /*shouldContentSniff*/)); handle->d->m_storageSession = context->storageSession(); if (handle->d->m_scheduledFailureType != NoFailure) { error = context->blockedError(request); return; } handle->createCFURLConnection(storedCredentials == AllowStoredCredentials, shouldRelaxThirdPartyCookiePolicy(context, request.url()), ResourceHandle::shouldContentSniffURL(request.url())); CFURLConnectionScheduleWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionScheduleDownloadWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionStart(handle->connection()); while (!client->isDone()) CFRunLoopRunInMode(synchronousLoadRunLoopMode(), UINT_MAX, true); CFURLConnectionCancel(handle->connection()); if (error.isNull() && response.mimeType().isNull()) setDefaultMIMEType(response.cfURLResponse()); RetainPtr<CFDataRef> data = client->data(); if (!error.isNull()) { response = ResourceResponse(request.url(), String(), 0, String(), String()); CFErrorRef cfError = error; CFStringRef domain = CFErrorGetDomain(cfError); // FIXME: Return the actual response for failed authentication. if (domain == kCFErrorDomainCFNetwork) response.setHTTPStatusCode(CFErrorGetCode(cfError)); else response.setHTTPStatusCode(404); } if (data) { ASSERT(vector.isEmpty()); vector.append(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get())); } }
static int OSX_Mouse_Thread(void *ctx) { if (!ctx) return 0; struct osx_mouse_data *mdata = static_cast<struct osx_mouse_data *>(ctx); IOHIDManagerRef hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone); if (!hid_manager) { SDL_DestroyMutex(mdata->mouse_mutex); delete mdata; return 0; } if (IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) { CFRelease(hid_manager); SDL_DestroyMutex(mdata->mouse_mutex); delete mdata; return 0; } IOHIDManagerRegisterInputValueCallback(hid_manager, input_callback, mdata); IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); uint32_t page = kHIDPage_GenericDesktop; uint32_t usage = kHIDUsage_GD_Mouse; CFDictionaryRef dict = NULL; CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); const void *keys[2] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) }; const void *vals[2] = { pageNumRef, usageNumRef }; if (pageNumRef && usageNumRef) dict = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (pageNumRef) CFRelease(pageNumRef); if (usageNumRef) CFRelease(usageNumRef); IOHIDManagerSetDeviceMatching(hid_manager, dict); if (dict) CFRelease(dict); while (!mdata->should_exit) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false); } IOHIDManagerUnscheduleFromRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDManagerClose(hid_manager, kIOHIDOptionsTypeNone); CFRelease(hid_manager); SDL_DestroyMutex(mdata->mouse_mutex); delete mdata; return 0; }
static void ParkEventLoop() { // RunLoop needs at least one source, and 1e20 is pretty far into the future CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode); CFRelease(t); // Park this thread in the main run loop. int32_t result; do { result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false); } while (result != kCFRunLoopRunFinished); }
~TestProxy() { IMessageQueue::size_type count = 0; #ifdef _WIN32 BOOL result = 0; MSG msg; memset(&msg, 0, sizeof(msg)); while ((result = ::GetMessage(&msg, NULL, 0, 0)) != 0) { BOOST_CHECK(-1 != result) ::TranslateMessage(&msg); ::DispatchMessage(&msg); count = mThread->getTotalUnprocessedMessages(); count += mThread->getTotalUnprocessedMessages(); if (0 == count) break; memset(&msg, 0, sizeof(msg)); } #elif __APPLE__ count = mThread->getTotalUnprocessedMessages(); do { //Run loop to handle sources CFRunLoopRunInMode(kCFRunLoopDefaultMode,1,false); count = mThread->getTotalUnprocessedMessages(); } while (count > 0); #else do { count = mThread->getTotalUnprocessedMessages(); count += mThreadNeverCalled->getTotalUnprocessedMessages(); if (0 != count) boost::this_thread::yield(); } while (count > 0); #endif //_WIN32 BOOST_EQUAL(0, mThread->getTotalUnprocessedMessages()); BOOST_EQUAL(0, mThreadNeverCalled->getTotalUnprocessedMessages()); mThread->waitForShutdown(); mThreadNeverCalled->waitForShutdown(); BOOST_EQUAL(getCheck().mCalledFunc3, "func3"); BOOST_EQUAL(getCheck().mCalledFunc2, 1000); BOOST_CHECK(getCheck().mCalledFunc1); BOOST_CHECK(getCheck().mDestroyedTestProxyCallback); }
void QDeviceWatcherPrivate::run() { mStop = false; DASessionScheduleWithRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); SInt32 result; do { result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true); } while (!mStop && result); DASessionUnscheduleFromRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }
CF_EXPORT SInt32 rwsched_instance_CFRunLoopRunInMode(rwsched_instance_ptr_t instance, CFStringRef mode, CFTimeInterval seconds, Boolean returnAfterSourceHandled) { // Validate input parameters RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); // Call the native CFRunLoop function return CFRunLoopRunInMode(mode, seconds, returnAfterSourceHandled); }
int main(int argc, char **argv) { vuoInit(argc, argv); char *outputPath = getenv("TESTVUORUNNER_OUTPUTPATH"); file = fopen(outputPath, "a"); fprintf(file, "started\n"); while (! isStopped) CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.01,false); return 0; }
static void* Pt_Thread(void *p) { CFTimeInterval timerInterval; CFRunLoopTimerContext timerContext; CFRunLoopTimerRef timer; PtThreadParams *params = (PtThreadParams*)p; //CFTimeInterval timeout; /* raise the thread's priority */ kern_return_t error; thread_extended_policy_data_t extendedPolicy; thread_precedence_policy_data_t precedencePolicy; extendedPolicy.timeshare = 0; error = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread timeshare policy", error); } precedencePolicy.importance = THREAD_IMPORTANCE; error = thread_policy_set(mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread precedence policy", error); } /* set up the timer context */ timerContext.version = 0; timerContext.info = params; timerContext.retain = NULL; timerContext.release = NULL; timerContext.copyDescription = NULL; /* create a new timer */ timerInterval = (double)params->resolution / 1000.0; timer = CFRunLoopTimerCreate(NULL, startTime+timerInterval, timerInterval, 0, 0, Pt_CFTimerCallback, &timerContext); timerRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(timerRunLoop, timer, CFSTR("PtTimeMode")); /* run until we're told to stop by Pt_Stop() */ CFRunLoopRunInMode(CFSTR("PtTimeMode"), LONG_TIME, false); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer, CFSTR("PtTimeMode")); CFRelease(timer); free(params); return NULL; }
void Gamepad_detectDevices() { unsigned int eventIndex; if (hidManager == NULL) { return; } CFRunLoopRunInMode(GAMEPAD_RUN_LOOP_MODE, 0, true); for (eventIndex = 0; eventIndex < deviceEventCount; eventIndex++) { processQueuedEvent(deviceEventQueue[eventIndex]); } deviceEventCount = 0; }