本文整理匯總了C++中CFRunLoopRunInMode函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFRunLoopRunInMode函數的具體用法?C++ CFRunLoopRunInMode怎麽用?C++ CFRunLoopRunInMode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFRunLoopRunInMode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: TeensyControls_find_new_usb_devices
void TeensyControls_find_new_usb_devices(void)
{
while (1) {
int r = CFRunLoopRunInMode(dev_run_mode, 0, true);
if (r != kCFRunLoopRunHandledSource) break;
}
}
示例2: main
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);
}
示例3: iokit_unmount
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;
}
示例4: IOHIDManagerCreate
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);
}
示例5: LOGGER_WARNING
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;
}
示例6: while
void CL_SoundOutput_MacOSX::wait()
{
while (fragments_available == 0)
{
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
}
}
示例7: DASessionCreate
/**
* 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);
}
示例8: atoi
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();
}
示例9: ConfigHIDManager
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. */
}
示例10: pollCfLoop
void
pollCfLoop()
{
// this should dispatch ready events and exit
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
scheduleCfLoop();
}
示例11: printf
// 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);
}
示例12: while
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;
}
示例13: caml_release_runtime_system
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;
}
示例14: while
void HIDJoystickManager::update()
{
SInt32 status = kCFRunLoopRunHandledSource;
while (status == kCFRunLoopRunHandledSource) {
status = CFRunLoopRunInMode(RunLoopMode, 0, true);
}
}
示例15: FetchIPAddress
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);
}