本文整理匯總了C++中CFRunLoopRun函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFRunLoopRun函數的具體用法?C++ CFRunLoopRun怎麽用?C++ CFRunLoopRun使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFRunLoopRun函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: nc_watch
static void
nc_watch(int argc, char **argv)
{
SCNetworkConnectionStatus status;
nc_create_connection(argc, argv, TRUE);
status = SCNetworkConnectionGetStatus(connection);
// report initial status
n_callback = 0;
nc_callback(connection, status, &n_callback);
// setup watcher
if (doDispatch) {
if (!SCNetworkConnectionSetDispatchQueue(connection, dispatch_get_main_queue())) {
SCPrint(TRUE, stderr, CFSTR("Unable to schedule watch process: %s\n"), SCErrorString(SCError()));
exit(1);
}
} else {
if (!SCNetworkConnectionScheduleWithRunLoop(connection, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
SCPrint(TRUE, stderr, CFSTR("Unable to schedule watch process: %s\n"), SCErrorString(SCError()));
exit(1);
}
}
// wait for changes
CFRunLoopRun();
nc_release_connection();
exit(0);
}
示例2: hostMonitoringRoutine
static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser)
{
NOREF(ThreadSelf);
NOREF(pvUser);
g_RunLoopRef = CFRunLoopGetCurrent();
AssertReturn(g_RunLoopRef, VERR_INTERNAL_ERROR);
CFRetain(g_RunLoopRef);
CFArrayRef watchingArrayRef = CFArrayCreate(NULL,
(const void **)&kStateNetworkGlobalDNSKey,
1, &kCFTypeArrayCallBacks);
if (!watchingArrayRef)
{
CFRelease(g_DnsWatcher);
return E_OUTOFMEMORY;
}
if(SCDynamicStoreSetNotificationKeys(g_store, watchingArrayRef, NULL))
CFRunLoopAddSource(CFRunLoopGetCurrent(), g_DnsWatcher, kCFRunLoopCommonModes);
CFRelease(watchingArrayRef);
RTSemEventSignal(g_DnsInitEvent);
CFRunLoopRun();
CFRelease(g_RunLoopRef);
return VINF_SUCCESS;
}
示例3: threadrun
void* threadrun(void* context){
// Tell the device manager which devices we want to look for
CFMutableArrayRef devices = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
if(devices){
int vendor = V_CORSAIR;
int products[] = { P_K65, P_K70, P_K70_NRGB, P_K95, P_K95_NRGB };
for(uint i = 0; i < sizeof(products) / sizeof(int); i++){
int product = products[i];
CFMutableDictionaryRef device = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if(device){
CFDictionarySetValue(device, CFSTR(kIOHIDVendorIDKey), CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vendor));
CFDictionarySetValue(device, CFSTR(kIOHIDProductIDKey), CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &product));
CFArrayAppendValue(devices, device);
CFRelease(device);
}
}
IOHIDManagerSetDeviceMatchingMultiple(usbmanager, devices);
CFRelease(devices);
}
// Set up device add callback
IOHIDManagerRegisterDeviceMatchingCallback(usbmanager, usbadd, 0);
IOHIDManagerScheduleWithRunLoop(usbmanager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerOpen(usbmanager, kIOHIDOptionsTypeSeizeDevice);
// Make a new thread to handle key repeats. The OS won't do it for us.
pthread_create(&keyrepeatthread, 0, krthread, 0);
// Run the event loop. Existing devices will be detected automatically.
while(1){
CFRunLoopRun();
}
return 0;
}
示例4: RunLoopThread
void* RunLoopThread(void* args)
{
unsigned i;
InitUSB();
currentRunLoop = CFRunLoopGetCurrent();
CFRunLoopTimerContext context = {0, NULL, NULL, NULL, NULL};
CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.1, 0.1, 0, 0, &onTimerFired, &context);
CFRunLoopAddTimer(currentRunLoop, timer, kCFRunLoopCommonModes);
// Signal the parent that we are running
adb_mutex_lock(&start_lock);
adb_cond_signal(&start_cond);
adb_mutex_unlock(&start_lock);
CFRunLoopRun();
currentRunLoop = 0;
for (i = 0; i < vendorIdCount; i++) {
IOObjectRelease(notificationIterators[i]);
}
IONotificationPortDestroy(notificationPort);
usb_cleanup();
DBG("RunLoopThread done\n");
return NULL;
}
示例5: runServer
static void runServer()
{
IOHIDEventSystemRef eventSystem = IOHIDEventSystemCreate(kCFAllocatorDefault);
IOHIDNotificationRef notification = NULL;
require(eventSystem, exit);
IOHIDEventSystemOpen(eventSystem, eventCallback, NULL, NULL, 0);
if ( !__serviceNotifications )
__serviceNotifications = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFArrayRef services = IOHIDEventSystemCopyMatchingServices(eventSystem, NULL, servicesAddedCallback, NULL, NULL, ¬ification);
if ( services ) {
servicesAddedCallback(NULL, NULL, NULL, services);
CFRelease(services);
}
CFRunLoopRun();
exit:
if ( eventSystem )
CFRelease(eventSystem);
}
示例6: main
int main(int argc, char **argv)
{
if(CheckArguments(argc, argv))
return 0;
KwmInit();
KWMMach.EventMask = ((1 << kCGEventKeyDown) |
(1 << kCGEventKeyUp) |
(1 << kCGEventMouseMoved));
KWMMach.EventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, KWMMach.EventMask, CGEventCallback, NULL);
if(!KWMMach.EventTap || !CGEventTapIsEnabled(KWMMach.EventTap))
Fatal("ERROR: Could not create event-tap!");
CFRunLoopAddSource(CFRunLoopGetMain(),
CFMachPortCreateRunLoopSource(kCFAllocatorDefault, KWMMach.EventTap, 0),
kCFRunLoopCommonModes);
CGEventTapEnable(KWMMach.EventTap, true);
CreateWorkspaceWatcher(KWMMach.WorkspaceWatcher);
// NOTE(koekeishiya): Initialize AXLIB
// AXLibInit(&AXApplications);
// AXLibRunningApplications();
NSApplicationLoad();
CFRunLoopRun();
return 0;
}
示例7: main
int main(int argc, char *argv[]) {
if (argc < 2 || argc > 4) {
printf("usage: %s [-d] <app> [device_id]\n", argv[0]);
exit(1);
}
if (strcmp(argv[1], "-d") == 0) {
assert(argc == 3 || argc == 4);
debug = true;
app_path = argv[2];
if (argc == 4) {
device_id = argv[3];
}
printf("------ Install phase ------\n");
} else {
assert(argc == 2 || argc == 3);
app_path = argv[1];
if (argc == 3) {
device_id = argv[2];
}
}
assert(access(app_path, F_OK) == 0);
AMDSetLogLevel(5); // otherwise syslog gets flooded with crap
printf("[....] Waiting for iOS device to be connected\n");
struct am_device_notification *notify;
AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, ¬ify);
CFRunLoopRun();
}
示例8: transferData
void transferData(IOUSBInterfaceInterface245 **intf, UInt8 inPipeRef, UInt8 outPipeRef)
{
IOReturn err;
CFRunLoopSourceRef cfSource;
int i;
err = (*intf)->CreateInterfaceAsyncEventSource(intf, &cfSource);
if (err)
{
printf("transferData: unable to create event source, err = %08x\n", err);
return;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
for (i=0; i < 12; i++)
outBuf[i] = 'R';
err = (*intf)->WritePipeAsync(intf, outPipeRef, outBuf, 12, (IOAsyncCallback1)MyCallBackFunction, (void*)(UInt32)inPipeRef);
if (err)
{
printf("transferData: WritePipeAsyncFailed, err = %08x\n", err);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
return;
}
printf("transferData: calling CFRunLoopRun\n");
CFRunLoopRun();
printf("transferData: returned from CFRunLoopRun\n");
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
}
示例9: main
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: %s <directory-to-watch>\n", argv[0]);
exit(1);
}
CFStringRef path = CFStringCreateWithCString(
kCFAllocatorDefault,
argv[1],
kCFStringEncodingUTF8
);
CFArrayRef pathsToWatch = CFArrayCreate(
kCFAllocatorDefault,
(const void **)&path,
1,
NULL
);
// create stream
FSEventStreamRef stream = FSEventStreamCreate(
kCFAllocatorDefault,
_eventStreamCallback,
NULL, // context for callback
pathsToWatch,
kFSEventStreamEventIdSinceNow,
0, // latency
kFSEventStreamCreateFlagFileEvents // this flag was introduced in 10.7
);
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
CFRunLoopRun();
return EXIT_SUCCESS; // CFRunLoopRun never returns, we never get here
}
示例10: main
int main(int argc, const char *argv[]) {
// Create an event tap to retrieve keypresses.
CGEventMask eventMask = (CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventFlagsChanged));
CFMachPortRef eventTap = CGEventTapCreate(
kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, CGEventCallback, NULL
);
// Exit the program if unable to create the event tap.
if(!eventTap) {
fprintf(stderr, "ERROR: Unable to create event tap.\n");
exit(1);
}
// Create a run loop source and add enable the event tap.
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
initscr();
int row, col;
getmaxyx(stdscr,row,col);
clear();
mvprintw(row/2,(col-10)/2,"0.000000%%");
refresh();
CFRunLoopRun();
return 0;
}
示例11: main
int main (int argc, const char * argv[])
{
SCNetworkReachabilityRef r = SCNetworkReachabilityCreateWithName(NULL, "api.del.icio.us");
if(r == NULL)
{
printf("Error creating reachability reference.\n");
goto bail;
}
if(!SCNetworkReachabilitySetCallback(r, my_SCNetworkReachabilityCallBack, NULL))
{
printf("Unable to set reachability callback\n");
goto bail;
}
if(!SCNetworkReachabilityScheduleWithRunLoop(r, CFRunLoopGetCurrent(), kCFRunLoopCommonModes))
{
printf("Unable to schedule run loop monitoring on run loop.\n");
goto bail;
}
printf("Starting run loop. Enable and disable network interfaces to fire the callback.\n");
CFRunLoopRun();
printf("Run loop stopped\n");
bail:
if(r)
CFRelease(r);
return 0;
}
示例12: main
int main (int argc, const char * argv[]) {
// Show help
if (argc != 2 || strncmp(argv[1], "-h", 2) == 0) {
printf("Sleep until a file in or below the watchdir is modified.\n");
printf("Usage: fsevent_watch /path/to/watchdir\n");
exit(1);
}
// Create event stream
CFStringRef pathToWatch = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8);
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&pathToWatch, 1, NULL);
void *callbackInfo = NULL;
FSEventStreamRef stream;
CFAbsoluteTime latency = 0.5;
stream = FSEventStreamCreate(
kCFAllocatorDefault,
callback,
callbackInfo,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNone
);
// Add stream to run loop
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
CFRunLoopRun();
// Exit
return 2;
}
示例13: main
int main(void) {
// Prepare MIDI Interface Client/Port for writing MIDI data:
MIDIClientRef midiclient;
MIDIPortRef midiin;
OSStatus status;
if (status = MIDIClientCreate(CFSTR("TeStInG"), NULL, NULL, &midiclient)) {
printf("Error trying to create MIDI Client structure: %d\n", status);
printf("%s\n", GetMacOSStatusErrorString(status));
exit(status);
}
if (status = MIDIInputPortCreate(midiclient, CFSTR("InPuT"), myReadProc,
NULL, &midiin)) {
printf("Error trying to create MIDI output port: %d\n", status);
printf("%s\n", GetMacOSStatusErrorString(status));
exit(status);
}
ItemCount nSrcs = MIDIGetNumberOfSources();
ItemCount iSrc;
for (iSrc=0; iSrc<nSrcs; iSrc++) {
MIDIEndpointRef src = MIDIGetSource(iSrc);
MIDIPortConnectSource(midiin, src, NULL);
}
t = lo_address_new(NULL, "7777");
CFRunLoopRef runLoop;
runLoop = CFRunLoopGetCurrent();
CFRunLoopRun();
return 0;
}
示例14: main
int main(int argc, char** argv)
{
//
// From https://developer.apple.com/library/mac/qa/qa1340/_index.html
// I have basically no idea how this works :)
//
// notification port allocated by IORegisterForSystemPower
IONotificationPortRef notifyPortRef;
// notifier object, used to deregister later
io_object_t notifierObject;
// this parameter is passed to the callback
void* refCon;
// register to receive system sleep notifications
root_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, SleepCallBack, ¬ifierObject);
if (root_port == 0) {
printf("IORegisterForSystemPower failed\n");
return 1;
}
// add the notification port to the application runloop
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes);
/* Start the run loop to receive sleep notifications. Don't call CFRunLoopRun if this code
is running on the main thread of a Cocoa or Carbon application. Cocoa and Carbon
manage the main thread's run loop for you as part of their event handling
mechanisms.
*/
CFRunLoopRun();
//Not reached, CFRunLoopRun doesn't return in this case.
return 0;
}
示例15: btstack_thread_func
static void btstack_thread_func(void* data)
{
RARCH_LOG("[BTstack]: Thread started");
if (bt_open_ptr())
return;
#ifdef __APPLE__
CFRunLoopSourceContext ctx = { 0, 0, 0, 0, 0, 0, 0, 0, 0, btstack_thread_stop };
btstack_quit_source = CFRunLoopSourceCreate(0, 0, &ctx);
CFRunLoopAddSource(CFRunLoopGetCurrent(), btstack_quit_source, kCFRunLoopCommonModes);
#endif
RARCH_LOG("[BTstack]: Turning on...\n");
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON);
RARCH_LOG("BTstack: Thread running...\n");
#ifdef __APPLE__
CFRunLoopRun();
#endif
RARCH_LOG("[BTstack]: Thread done.\n");
#ifdef __APPLE__
CFRunLoopSourceInvalidate(btstack_quit_source);
CFRelease(btstack_quit_source);
#endif
}