void startListen(){ CFMachPortRef eventTap; CGEventMask eventMask; CFRunLoopSourceRef runLoopSource; // Create an event tap. We are interested in key presses. //eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventFlagsChanged)); eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventFlagsChanged)); eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, myCGEventCallback, NULL); if (!eventTap) { fprintf(stderr, "failed to create event tap\n"); exit(1); } // Create a run loop source. runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0); // Add to the current run loop. CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); // Enable the event tap. CGEventTapEnable(eventTap, true); // Set it all running. CFRunLoopRun(); // In a real program, one would have arranged for cleaning up. }
Status EventTappingEventPublisher::run() { Status s = restart(); if (s.ok()) { CFRunLoopRun(); } return s; }
/* druBurn Called to do a burn. Burning is a long async process, so this function mostly handles providing appropriate progress and completion information to the user. */ int druBurn(DRBurnRef burn, CFTypeRef layout) { DRNotificationCenterRef notificationCenter = NULL; CFRunLoopSourceRef source = NULL; druBurnStatus status = {0, NULL, NULL, NULL, {0}, 0}; /* Create a progress bar. */ status.progressBar = druProgressBarCreate(); /* Sign up for notifications from the burn object. */ notificationCenter = DRNotificationCenterCreate(); source = DRNotificationCenterCreateRunLoopSource(notificationCenter); CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); DRNotificationCenterAddObserver(notificationCenter,&status,druProgressCallback, kDRBurnStatusChangedNotification, burn); /* Okay, kick off the burn. */ DRBurnWriteLayout(burn, layout); /* Enter a runloop until the burn finishes. */ CFRunLoopRun(); /* Clean up memory and exit. */ CFRunLoopSourceInvalidate(source); if (notificationCenter != NULL) CFRelease(notificationCenter); if (source != NULL) CFRelease(source); if (status.progressBar != NULL) druProgressBarDispose(status.progressBar,status.success); if (status.success) printf("Burn completed.\n"); else druPrintFailureMessage("Burn", status.completionStatus); if (status.completionStatus != NULL) CFRelease(status.completionStatus); return status.success; }
void play() { int i; AudioStreamBasicDescription format; AudioQueueRef queue; AudioQueueBufferRef buffers[NUM_BUFFERS]; format.mSampleRate = SAMPLE_RATE; format.mFormatID = kAudioFormatLinearPCM; format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; format.mBitsPerChannel = 8*sizeof(SAMPLE_TYPE); format.mChannelsPerFrame = NUM_CHANNELS; format.mBytesPerFrame = sizeof(SAMPLE_TYPE)*NUM_CHANNELS; format.mFramesPerPacket = 1; format.mBytesPerPacket = format.mBytesPerFrame*format.mFramesPerPacket; format.mReserved = 0; AudioQueueNewOutput(&format, callback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &queue); for (i = 0; i < NUM_BUFFERS; i++) { AudioQueueAllocateBuffer(queue, BUFFER_SIZE, &buffers[i]); buffers[i]->mAudioDataByteSize = BUFFER_SIZE; callback(NULL, queue, buffers[i]); } AudioQueueStart(queue, NULL); CFRunLoopRun(); }
int main(int argc, char *argv[]) { if (argc > 1) { struct stat st; if (stat(dirname(argv[1]), &st)==-1 && errno==ENOENT) { fprintf(stderr, "Directory for writing does not exist.\n"); exit(1); } realpath(argv[1], outputfile); gen_path = 1; } else { is_cwd = 1; getcwd(outputfile, PATH_MAX); } am_device_notification *notification; assert(AMDeviceNotificationSubscribe(device_notification_callback, 0, 0, NULL, ¬ification) == MDERR_OK); puts("Waiting for device."); signal(SIGINT, &sigint_handler); CFRunLoopRun(); puts("Ending."); return 0; }
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); }
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 }
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; }
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; }
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; }
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; }
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; }
int main() { int err = 0; #ifdef __APPLE_CC__ pthread_t id; pthread_create(&id, NULL, run_main, &err); CFRunLoopSourceContext sourceContext; sourceContext.version = 0; sourceContext.info = NULL; sourceContext.retain = NULL; sourceContext.release = NULL; sourceContext.copyDescription = NULL; sourceContext.equal = NULL; sourceContext.hash = NULL; sourceContext.schedule = NULL; sourceContext.cancel = NULL; sourceContext.perform = NULL; CFRunLoopSourceRef sourceRef = CFRunLoopSourceCreate(NULL, 0, &sourceContext); CFRunLoopAddSource(CFRunLoopGetCurrent(), sourceRef, kCFRunLoopCommonModes); CFRunLoopRun(); #else run_main(&err); #endif return err; }
int main (int argc, const char **argv) { int ret; makeRealtime(); ret = pulseAudioClientStart(); if (ret) { printf("pulseAudioClientStart() returned %d\n", ret); return -1; } ret = driverClientStart(); if (ret) { printf("driverClientStart() returned %d\n", ret); return -1; } ret = notificationCenterStart(); if (ret) { printf("deviceClientStart() returned %d\n", ret); return -1; } CFRunLoopRun(); printf("%s(): terminating ...\n", __func__); pulseAudioClientStop(); return 0; }
int main( int argc, char* argv[] ){ /* Define variables and create a CFArray object containing CFString objects containing paths to watch. */ CFStringRef mypath = CFStringCreateWithCString( NULL, argv[ 1 ], kCFStringEncodingUTF8); CFArrayRef pathsToWatch = CFArrayCreate( NULL, ( const void ** ) &mypath, 1, NULL ); void *callbackInfo = NULL; // could put stream-specific data here. FSEventStreamRef stream;*/ CFAbsoluteTime latency = 3.0; /* Latency in seconds */ FSEventStreamRef stream; /* Create the stream, passing in a callback */ stream = FSEventStreamCreate( NULL, &myCallbackFunction, callbackInfo, pathsToWatch, kFSEventStreamEventIdSinceNow, /* Or a previous event ID */ latency, kFSEventStreamCreateFlagFileEvents /* Flags explained in reference: https://developer.apple.com/library/mac/documentation/Darwin/Reference/FSEvents_Ref/Reference/reference.html */ ); /* Create the stream before calling this. */ FSEventStreamScheduleWithRunLoop( stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode ); FSEventStreamStart( stream ); CFRunLoopRun(); return 0; }
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; }
bool wxOSXAudioToolboxSoundData::Play(unsigned flags) { Stop(); m_flags = flags; wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(m_sndname))); CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); AudioServicesCreateSystemSoundID(url, &m_soundID); AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); bool sync = !(flags & wxSOUND_ASYNC); AudioServicesPlaySystemSound(m_soundID); if ( sync ) { while( m_soundID ) { CFRunLoopRun(); } } return true; }
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; }
static void* btstack_thread_func(void* data) { RARCH_LOG("BTstack: Thread started"); if (bt_open_ptr()) { RARCH_LOG("BTstack: bt_open() failed\n"); return 0; } 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); RARCH_LOG("BTstack: Turning on\n"); bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON); RARCH_LOG("BTstack: Running\n"); CFRunLoopRun(); RARCH_LOG("BTstack: Done\n"); CFRunLoopSourceInvalidate(btstack_quit_source); CFRelease(btstack_quit_source); return 0; }
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); }
static void DoListen(ConnectionRef conn) // Implements the "listen" command. First this does a listen RPC // to tell the server that this connection is now a listener. Next it // calls ConnectionRegisterListener to register a packet listener callback // (GotPacket, above) on the runloop. It then runs the runloop until its // stopped (by a SIGINT, via SIGINTRunLoopCallback, below). { int err; PacketListen request; PacketReply reply; InitPacketHeader(&request.fHeader, kPacketTypeListen, sizeof(request), true); err = ConnectionRPC(conn, &request.fHeader, &reply.fHeader, sizeof(reply)); if (err == 0) { err = reply.fErr; } if (err == 0) { err = ConnectionRegisterListener( conn, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, GotPacket, CFRunLoopGetCurrent() ); } if (err != 0) { PrintResult("listen", err, NULL); } else { fprintf(stderr, "%*s Press ^C to quit.\n", kResultColumnWidth, "listen"); CFRunLoopRun(); } }
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; }
int main() { initscr(); start_color(); use_default_colors(); init_pair(1, COLOR_RED, -1); IOHIDManagerRef hidManager = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone); IOHIDManagerRegisterDeviceMatchingCallback( hidManager, match_callback, NULL); IOHIDManagerScheduleWithRunLoop( hidManager, CFRunLoopGetMain(), kCFRunLoopCommonModes); // all keyboards CFDictionaryRef match = matching_dictionary_create(0, 0, 1, 6); // kinesis /* CFDictionaryRef match = matching_dictionary_create(0x05f3, 0x0007, 0, 0); */ // noppoo /* CFDictionaryRef match = matching_dictionary_create(0x1006, 0x0022, 1, 6); */ // a4tech /* CFDictionaryRef match = matching_dictionary_create(0x1241, 0x1603, 0, 0); */ IOHIDManagerSetDeviceMatching(hidManager, match); CFRelease(match); CFRunLoopRun(); }
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(); }
static void cbWork(uv_work_t *req) { // We have this check in case we `Stop` before this thread starts, // otherwise the process will hang if(!isRunning) { return; } uv_signal_start(&int_signal, cbTerminate, SIGINT); uv_signal_start(&term_signal, cbTerminate, SIGTERM); runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort); gRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddSource(gRunLoop, runLoopSource, kCFRunLoopDefaultMode); // Creating `gRunLoop` can take some cycles so we also need this second // `isRunning` check here because it happens at a future time if(isRunning) { // Start the run loop. Now we'll receive notifications. CFRunLoopRun(); } // The `CFRunLoopRun` is a blocking call so we also need this second // `isRunning` check here because it happens at a future time if(isRunning) { // We should never get here while running fprintf(stderr, "Unexpectedly back from CFRunLoopRun()!\n"); } }
int HostDnsServiceDarwin::monitorWorker() { m->m_RunLoopRef = CFRunLoopGetCurrent(); AssertReturn(m->m_RunLoopRef, VERR_INTERNAL_ERROR); CFRetain(m->m_RunLoopRef); CFArrayRef watchingArrayRef = CFArrayCreate(NULL, (const void **)&kStateNetworkGlobalDNSKey, 1, &kCFTypeArrayCallBacks); if (!watchingArrayRef) { CFRelease(m->m_DnsWatcher); return E_OUTOFMEMORY; } if(SCDynamicStoreSetNotificationKeys(m->m_store, watchingArrayRef, NULL)) CFRunLoopAddSource(CFRunLoopGetCurrent(), m->m_DnsWatcher, kCFRunLoopCommonModes); CFRelease(watchingArrayRef); monitorThreadInitializationDone(); while (!m->m_fStop) { CFRunLoopRun(); } CFRelease(m->m_RunLoopRef); /* We're notifying stopper thread. */ RTSemEventSignal(m->m_evtStop); return VINF_SUCCESS; }
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; }
//set up fsevents and callback int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "You must specify a directory to watch and a command to execute on change\n"); exit(1); } to_run = argv[2]; CFStringRef mypath = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8); CFArrayRef pathsToWatch = CFStringCreateArrayBySeparatingStrings (NULL, mypath, CFSTR(":")); void *callbackInfo = NULL; FSEventStreamRef stream; CFAbsoluteTime latency = 1.0; stream = FSEventStreamCreate(NULL, &callback, callbackInfo, pathsToWatch, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNone ); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); CFRunLoopRun(); }
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 }
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); }