这篇教程C++ CFRunLoopAddSource函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CFRunLoopAddSource函数的典型用法代码示例。如果您正苦于以下问题:C++ CFRunLoopAddSource函数的具体用法?C++ CFRunLoopAddSource怎么用?C++ CFRunLoopAddSource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CFRunLoopAddSource函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: initializeDisplayNotificationsstatic void initializeDisplayNotifications (void){ io_service_t displayWrangler; IONotificationPortRef notificationPort; io_object_t notifier; displayWrangler = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceNameMatching("IODisplayWrangler")); if (! displayWrangler) { message (LOG_ERR, "IOServiceGetMatchingService failed/n"); exit (1); } notificationPort = IONotificationPortCreate(kIOMasterPortDefault); if (! notificationPort) { message (LOG_ERR, "IONotificationPortCreate failed/n"); exit (1); } if (IOServiceAddInterestNotification(notificationPort, displayWrangler, kIOGeneralInterest, displayCallback, NULL, ¬ifier) != kIOReturnSuccess) { message (LOG_ERR, "IOServiceAddInterestNotification failed/n"); exit (1); } CFRunLoopAddSource (CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopDefaultMode); IOObjectRelease (displayWrangler);}
开发者ID:Gems,项目名称:majormaco,代码行数:24,
示例2: m_isOnLineNetworkStateNotifier::NetworkStateNotifier() : m_isOnLine(false) , m_networkStateChangedFunction(0) , m_networkStateChangeTimer(this, &NetworkStateNotifier::networkStateChangeTimerFired){ SCDynamicStoreContext context = { 0, this, 0, 0, 0 }; m_store.adoptCF(SCDynamicStoreCreate(0, CFSTR("com.apple.WebCore"), dynamicStoreCallback, &context)); if (!m_store) return; RetainPtr<CFRunLoopSourceRef> configSource = SCDynamicStoreCreateRunLoopSource(0, m_store.get(), 0); if (!configSource) return; CFRunLoopAddSource(CFRunLoopGetMain(), configSource.get(), kCFRunLoopCommonModes); RetainPtr<CFMutableArrayRef> keys(AdoptCF, CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks)); RetainPtr<CFMutableArrayRef> patterns(AdoptCF, CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks)); RetainPtr<CFStringRef> key; RetainPtr<CFStringRef> pattern; key.adoptCF(SCDynamicStoreKeyCreateNetworkGlobalEntity(0, kSCDynamicStoreDomainState, kSCEntNetIPv4)); CFArrayAppendValue(keys.get(), key.get()); pattern.adoptCF(SCDynamicStoreKeyCreateNetworkInterfaceEntity(0, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4)); CFArrayAppendValue(patterns.get(), pattern.get()); key.adoptCF(SCDynamicStoreKeyCreateNetworkGlobalEntity(0, kSCDynamicStoreDomainState, kSCEntNetDNS)); CFArrayAppendValue(keys.get(), key.get()); SCDynamicStoreSetNotificationKeys(m_store.get(), keys.get(), patterns.get()); updateState();}
开发者ID:achellies,项目名称:WinCEWebKit,代码行数:36,
示例3: MyDNSServiceAddToRunLoopstatic voidMyDNSServiceAddToRunLoop(MyDNSServiceState *ref){ CFSocketNativeHandle sock; CFOptionFlags sockFlags; CFRunLoopSourceRef source; CFSocketContext context = { 0, ref, NULL, NULL, NULL }; // Use MyDNSServiceState as context data. assert(ref); // Access the underlying Unix domain socket to communicate with the mDNSResponder daemon. sock = DNSServiceRefSockFD(ref->service); assert(sock >= 0); // Create a CFSocket using the Unix domain socket. ref->socket = CFSocketCreateWithNative(NULL, sock, kCFSocketReadCallBack, MyDNSServiceSocketCallBack, &context); assert(ref->socket); // Prevent CFSocketInvalidate from closing DNSServiceRef's socket. sockFlags = CFSocketGetSocketFlags(ref->socket); CFSocketSetSocketFlags(ref->socket, sockFlags & (~kCFSocketCloseOnInvalidate)); // Create a CFRunLoopSource from the CFSocket. source = CFSocketCreateRunLoopSource(NULL, ref->socket, 0); assert(source); // Add the CFRunLoopSource to the current runloop. CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); // We no longer need our reference to source. The runloop continues to // hold a reference to it, but we don't care about that. When we invalidate // the socket, the runloop will drop its reference and the source will get // destroyed. CFRelease(source);}
开发者ID:aosm,项目名称:DirectoryService,代码行数:36,
示例4: watchQuietEnablestatic voidwatchQuietEnable(){ CFArrayRef keys; Boolean ok; initKey = SCDynamicStoreKeyCreate(NULL, CFSTR("%@" "InterfaceNamer"), kSCDynamicStoreDomainPlugin); initRls = SCDynamicStoreCreateRunLoopSource(NULL, store, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), initRls, kCFRunLoopDefaultMode); keys = CFArrayCreate(NULL, (const void **)&initKey, 1, &kCFTypeArrayCallBacks); ok = SCDynamicStoreSetNotificationKeys(store, keys, NULL); CFRelease(keys); if (!ok) { SCLog(TRUE, LOG_ERR, CFSTR("SCDynamicStoreSetNotificationKeys() failed: %s/n"), SCErrorString(SCError())); watchQuietDisable(); } return;}
开发者ID:010001111,项目名称:darling,代码行数:24,
示例5: IOHIDDeviceScheduleWithRunLoopstatic void *read_thread(void *param){ hid_device *dev = param; /* Move the device's run loop to this thread. */ IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetCurrent(), dev->run_loop_mode); /* Create the RunLoopSource which is used to signal the event loop to stop when hid_close() is called. */ CFRunLoopSourceContext ctx; memset(&ctx, 0, sizeof(ctx)); ctx.version = 0; ctx.info = dev; ctx.perform = &perform_signal_callback; dev->source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0/*order*/, &ctx); CFRunLoopAddSource(CFRunLoopGetCurrent(), dev->source, dev->run_loop_mode); /* Store off the Run Loop so it can be stopped from hid_close() and on device disconnection. */ dev->run_loop = CFRunLoopGetCurrent(); /* Notify the main thread that the read thread is up and running. */ pthread_barrier_wait(&dev->barrier); /* Run the Event Loop. CFRunLoopRunInMode() will dispatch HID input reports into the hid_report_callback(). */ SInt32 code; while (!dev->shutdown_thread && !dev->disconnected) { code = CFRunLoopRunInMode(dev->run_loop_mode, 1000/*sec*/, FALSE); /* Return if the device has been disconnected */ if (code == kCFRunLoopRunFinished) { dev->disconnected = 1; break; } /* Break if The Run Loop returns Finished or Stopped. */ if (code != kCFRunLoopRunTimedOut && code != kCFRunLoopRunHandledSource) { /* There was some kind of error. Setting shutdown seems to make sense, but there may be something else more appropriate */ dev->shutdown_thread = 1; break; } } /* Now that the read thread is stopping, Wake any threads which are waiting on data (in hid_read_timeout()). Do this under a mutex to make sure that a thread which is about to go to sleep waiting on the condition acutally will go to sleep before the condition is signaled. */ pthread_mutex_lock(&dev->mutex); pthread_cond_broadcast(&dev->condition); pthread_mutex_unlock(&dev->mutex); /* Close the OS handle to the device, but only if it's not been unplugged. If it's been unplugged, then calling IOHIDDeviceClose() will crash. */ if (!dev->disconnected) { IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone); } /* Wait here until hid_close() is called and makes it past the call to CFRunLoopWakeUp(). This thread still needs to be valid when that function is called on the other thread. */ pthread_barrier_wait(&dev->shutdown_barrier); return NULL;}
开发者ID:AaronPerl,项目名称:HackRU-DigitalTheremin,代码行数:70,
示例6: ConnectionRegisterListenerstatic int ConnectionRegisterListener( ConnectionRef conn, CFRunLoopRef runLoop, CFStringRef runLoopMode, ConnectionCallbackProcPtr callback, void * refCon) // Register a listener to be called when packets arrive. Once you've done // this, you can no longer use conn for RPCs. // // conn must be a valid connection // // runLoop and runLoopMode specify the context in which the callback will // be called; in most cases you specify CFRunLoopGetCurrent() and // kCFRunLoopDefaultMode // // callback is the function you want to be called when packets arrive; it // must not be NULL // // refCon is passed to callback // // Returns an errno-style error code // On success, the connection has been converted to a listener and your // callback will be called from the context of the specific runloop when // a packet arrives; on error, the connection is no longer useful (conn is // still valid, but you can't use it to transmit any more data){ int err; assert(conn != NULL); assert(runLoop != NULL); assert(runLoopMode != NULL); assert(callback != NULL); assert(conn->fSockFD != -1); // connection must not be shut down assert(conn->fSockCF == NULL); // can't register twice // Create the packet buffer. err = 0; conn->fBufferedPackets = CFDataCreateMutable(NULL, 0); if (conn->fBufferedPackets == NULL) { err = ENOMEM; } // Add the source to the runloop. if (err == 0) { CFSocketContext context; memset(&context, 0, sizeof(context)); context.info = conn; conn->fSockCF = CFSocketCreateWithNative( NULL, (CFSocketNativeHandle) conn->fSockFD, kCFSocketDataCallBack, ConnectionGotData, &context ); if (conn->fSockCF == NULL) { err = EINVAL; } } if (err == 0) { conn->fRunLoopSource = CFSocketCreateRunLoopSource(NULL, conn->fSockCF, 0); if (conn->fRunLoopSource == NULL) { err = EINVAL; } } if (err == 0) { conn->fCallback = callback; conn->fCallbackRefCon = refCon; CFRunLoopAddSource( runLoop, conn->fRunLoopSource, runLoopMode); } // Any failure means the entire connection is dead; again, this is the // draconian approach to error handling. But hey, connections are // (relatively) cheap. if (err != 0) { ConnectionShutdown(conn); } return err;}
开发者ID:dark-saber,项目名称:public,代码行数:87,
示例7: UPSDeviceAddedvoid UPSDeviceAdded(void *refCon, io_iterator_t iterator){ io_object_t upsDevice = MACH_PORT_NULL; UPSDataRef upsDataRef = NULL; CFDictionaryRef upsProperties = NULL; CFDictionaryRef upsEvent = NULL; CFSetRef upsCapabilites = NULL; CFRunLoopSourceRef upsEventSource = NULL; CFRunLoopTimerRef upsEventTimer = NULL; CFTypeRef typeRef = NULL; IOCFPlugInInterface ** plugInInterface = NULL; IOUPSPlugInInterface_v140 ** upsPlugInInterface = NULL; HRESULT result = S_FALSE; IOReturn kr; SInt32 score; while ( (upsDevice = IOIteratorNext(iterator)) ) { // Create the CF plugin for this device kr = IOCreatePlugInInterfaceForService(upsDevice, kIOUPSPlugInTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score); if ( kr != kIOReturnSuccess ) goto UPSDEVICEADDED_NONPLUGIN_CLEANUP; // Grab the new v140 interface result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID_v140), (LPVOID)&upsPlugInInterface); if ( ( result == S_OK ) && upsPlugInInterface ) { kr = (*upsPlugInInterface)->createAsyncEventSource(upsPlugInInterface, &typeRef); if ((kr != kIOReturnSuccess) || !typeRef) goto UPSDEVICEADDED_FAIL; if ( CFGetTypeID(typeRef) == CFRunLoopTimerGetTypeID() ) { upsEventTimer = (CFRunLoopTimerRef)typeRef; CFRunLoopAddTimer(CFRunLoopGetCurrent(), upsEventTimer, kCFRunLoopDefaultMode); } else if ( CFGetTypeID(typeRef) == CFRunLoopSourceGetTypeID() ) { upsEventSource = (CFRunLoopSourceRef)typeRef; CFRunLoopAddSource(CFRunLoopGetCurrent(), upsEventSource, kCFRunLoopDefaultMode); } } // Couldn't grab the new interface. Fallback on the old. else { result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUPSPlugInInterfaceID), (LPVOID)&upsPlugInInterface); } // Got the interface if ( ( result == S_OK ) && upsPlugInInterface ) { kr = (*upsPlugInInterface)->getProperties(upsPlugInInterface, &upsProperties); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; upsDataRef = GetPrivateData(upsProperties); if ( !upsDataRef ) goto UPSDEVICEADDED_FAIL; upsDataRef->upsPlugInInterface = (IOUPSPlugInInterface **)upsPlugInInterface; upsDataRef->upsEventSource = upsEventSource; upsDataRef->upsEventTimer = upsEventTimer; upsDataRef->isPresent = true; kr = (*upsPlugInInterface)->getCapabilities(upsPlugInInterface, &upsCapabilites); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; kr = CreatePowerManagerUPSEntry(upsDataRef, upsProperties, upsCapabilites); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; kr = (*upsPlugInInterface)->getEvent(upsPlugInInterface, &upsEvent); if (kr != kIOReturnSuccess) goto UPSDEVICEADDED_FAIL; ProcessUPSEvent(upsDataRef, upsEvent); (*upsPlugInInterface)->setEventCallback(upsPlugInInterface, UPSEventCallback, NULL, upsDataRef); IOServiceAddInterestNotification( gNotifyPort, // notifyPort upsDevice, // service kIOGeneralInterest, // interestType DeviceNotification, // callback upsDataRef, // refCon &(upsDataRef->notification) // notification ); //.........这里部分代码省略.........
开发者ID:hashier,项目名称:caffeinate_fix,代码行数:101,
示例8: CreateIPAddressListChangeCallbackSCFstatic OSStatusCreateIPAddressListChangeCallbackSCF(SCDynamicStoreCallBack callback, void *contextPtr, SCDynamicStoreRef *storeRef, CFRunLoopSourceRef *sourceRef) // Create a SCF dynamic store reference and a // corresponding CFRunLoop source. If you add the // run loop source to your run loop then the supplied // callback function will be called when local IP // address list changes.{ OSStatus err = 0; SCDynamicStoreContext context = {0, NULL, NULL, NULL, NULL}; SCDynamicStoreRef ref; CFStringRef pattern; CFArrayRef patternList; CFRunLoopSourceRef rls; assert(callback != NULL); assert( storeRef != NULL); assert(*storeRef == NULL); assert( sourceRef != NULL); assert(*sourceRef == NULL); ref = NULL; pattern = NULL; patternList = NULL; rls = NULL; // Create a connection to the dynamic store, then create // a search pattern that finds all IPv4 entities. // The pattern is "State:/Network/Service/[^/]+/IPv4". context.info = contextPtr; ref = SCDynamicStoreCreate( NULL, CFSTR("AddIPAddressListChangeCallbackSCF"), callback, &context); //err = MoreSCError(ref); if (err == noErr) { pattern = SCDynamicStoreKeyCreateNetworkServiceEntity( NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4); //err = MoreSCError(pattern); } // Create a pattern list containing just one pattern, // then tell SCF that we want to watch changes in keys // that match that pattern list, then create our run loop // source. if (err == noErr) { patternList = CFArrayCreate(NULL, (const void **) &pattern, 1, &kCFTypeArrayCallBacks); //err = CFQError(patternList); } if (err == noErr) { //err = MoreSCErrorBoolean( SCDynamicStoreSetNotificationKeys( ref, NULL, patternList); // ); } if (err == noErr) { rls = SCDynamicStoreCreateRunLoopSource(NULL, ref, 0); //err = MoreSCError(rls); } CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode); // Clean up. //CFQRelease(pattern); //CFQRelease(patternList); if (err != noErr) { //CFQRelease(ref); ref = NULL; } *storeRef = ref; *sourceRef = rls; assert( (err == noErr) == (*storeRef != NULL) ); assert( (err == noErr) == (*sourceRef != NULL) ); return err;}
开发者ID:PeterXu,项目名称:sipstack,代码行数:91,
示例9: darwinHIDKeyboardCacheCreateEntry/** * Creates a keyboard cache entry. * * @returns true if the entry was created successfully, otherwise false. * @param pKeyboardEntry Pointer to the entry. * @param KeyboardDevice The keyboard device to create the entry for. * */static bool darwinHIDKeyboardCacheCreateEntry(struct KeyboardCacheData *pKeyboardEntry, io_object_t KeyboardDevice){ unsigned long cRefs = 0; memset(pKeyboardEntry, 0, sizeof(*pKeyboardEntry)); /* * Query the HIDDeviceInterface for this HID (keyboard) object. */ SInt32 Score = 0; IOCFPlugInInterface **ppPlugInInterface = NULL; IOReturn rc = IOCreatePlugInInterfaceForService(KeyboardDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPlugInInterface, &Score); if (rc == kIOReturnSuccess) { IOHIDDeviceInterface **ppHidDeviceInterface = NULL; HRESULT hrc = (*ppPlugInInterface)->QueryInterface(ppPlugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID *)&ppHidDeviceInterface); cRefs = (*ppPlugInInterface)->Release(ppPlugInInterface); MY_CHECK_CREFS(cRefs); ppPlugInInterface = NULL; if (hrc == S_OK) { rc = (*ppHidDeviceInterface)->open(ppHidDeviceInterface, 0); if (rc == kIOReturnSuccess) { /* * create a removal callback. */ /** @todo */ /* * Create the queue so we can insert elements while searching the properties. */ IOHIDQueueInterface **ppHidQueueInterface = (*ppHidDeviceInterface)->allocQueue(ppHidDeviceInterface); if (ppHidQueueInterface) { rc = (*ppHidQueueInterface)->create(ppHidQueueInterface, 0, 32); if (rc != kIOReturnSuccess) { AssertMsgFailed(("rc=%d/n", rc)); cRefs = (*ppHidQueueInterface)->Release(ppHidQueueInterface); MY_CHECK_CREFS(cRefs); ppHidQueueInterface = NULL; } } else AssertFailed(); pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface; /* * Brute force getting of attributes. */ /** @todo read up on how to do this in a less resource intensive way! Suggestions are welcome! */ CFMutableDictionaryRef PropertiesRef = 0; kern_return_t krc = IORegistryEntryCreateCFProperties(KeyboardDevice, &PropertiesRef, kCFAllocatorDefault, kNilOptions); if (krc == KERN_SUCCESS) { darwinBruteForcePropertySearch(PropertiesRef, pKeyboardEntry); CFRelease(PropertiesRef); } else AssertMsgFailed(("krc=%#x/n", krc)); if (ppHidQueueInterface) { /* * Now install our queue callback. */ CFRunLoopSourceRef RunLoopSrcRef = NULL; rc = (*ppHidQueueInterface)->createAsyncEventSource(ppHidQueueInterface, &RunLoopSrcRef); if (rc == kIOReturnSuccess) { CFRunLoopRef RunLoopRef = (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetMainEventLoop()); CFRunLoopAddSource(RunLoopRef, RunLoopSrcRef, kCFRunLoopDefaultMode); } /* * Now install our queue callback. */ rc = (*ppHidQueueInterface)->setEventCallout(ppHidQueueInterface, darwinQueueCallback, ppHidQueueInterface, pKeyboardEntry); if (rc != kIOReturnSuccess) AssertMsgFailed(("rc=%d/n", rc)); } /* * Complete the new keyboard cache entry. */ pKeyboardEntry->ppHidDeviceInterface = ppHidDeviceInterface; pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface; return true; }//.........这里部分代码省略.........
开发者ID:VirtualMonitor,项目名称:VirtualMonitor,代码行数:101,
示例10: mainint main(int argc, const char *argv[]){ time_t current_time = time(NULL); char* c_time_string = ctime(¤t_time); size_t l = strlen(c_time_string); if (l > 0) c_time_string[l-1] = 0; DEBUG_LOG("%s: VoodooPS2Daemon 1.7.12 starting.../n", c_time_string); // first check for trackpad driver g_ioservice = IOServiceGetMatchingService(0, IOServiceMatching("ApplePS2SynapticsTouchPad")); if (!g_ioservice) { // otherwise, talk to mouse driver g_ioservice = IOServiceGetMatchingService(0, IOServiceMatching("ApplePS2Mouse")); if (!g_ioservice) { DEBUG_LOG("No ApplePS2SynapticsTouchPad or ApplePS2Mouse found/n"); return -1; } } // Set up a signal handler so we can clean up when we're interrupted from the command line // or otherwise asked to terminate. if (SIG_ERR == signal(SIGINT, SignalHandler1)) DEBUG_LOG("Could not establish new SIGINT handler/n"); if (SIG_ERR == signal(SIGTERM, SignalHandler1)) DEBUG_LOG("Could not establish new SIGTERM handler/n"); // First create a master_port for my task mach_port_t masterPort; kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort); if (kr || !masterPort) { DEBUG_LOG("ERR: Couldn't create a master IOKit Port(%08x)/n", kr); return -1; } // Create dictionary to match all USB devices CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName); if (!matchingDict) { DEBUG_LOG("Can't create a USB matching dictionary/n"); mach_port_deallocate(mach_task_self(), masterPort); return -1; } // Create a notification port and add its run loop event source to our run loop // This is how async notifications get set up. g_NotifyPort = IONotificationPortCreate(masterPort); CFRunLoopSourceRef runLoopSource = IONotificationPortGetRunLoopSource(g_NotifyPort); CFRunLoopRef runLoop = CFRunLoopGetCurrent(); CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopDefaultMode); // Now set up a notification to be called when a device is first matched by I/O Kit. // Note that this will not catch any devices that were already plugged in so we take // care of those later. kr = IOServiceAddMatchingNotification(g_NotifyPort, kIOFirstMatchNotification, matchingDict, DeviceAdded, NULL, &g_AddedIter); // Iterate once to get already-present devices and arm the notification DeviceAdded(NULL, g_AddedIter); // Now done with the master_port mach_port_deallocate(mach_task_self(), masterPort); masterPort = 0; // Start the run loop. Now we'll receive notifications. CFRunLoopRun(); // We should never get here DEBUG_LOG("Unexpectedly back from CFRunLoopRun()!/n"); return 0;}
开发者ID:k0gen,项目名称:OS-X-Voodoo-PS2-Controller,代码行数:74,
示例11: Tcl_InitNotifierClientDataTcl_InitNotifier(void){ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); tsdPtr->eventReady = 0;#ifdef WEAK_IMPORT_SPINLOCKLOCK /* * Initialize support for weakly imported spinlock API. */ if (pthread_once(&spinLockLockInitControl, SpinLockLockInit)) { Tcl_Panic("Tcl_InitNotifier: pthread_once failed"); }#endif#ifndef __CONSTANT_CFSTRINGS__ if (!tclEventsOnlyRunLoopMode) { tclEventsOnlyRunLoopMode = CFSTR(TCL_EVENTS_ONLY_RUN_LOOP_MODE); }#endif /* * Initialize CFRunLoopSource and add it to CFRunLoop of this thread. */ if (!tsdPtr->runLoop) { CFRunLoopRef runLoop = CFRunLoopGetCurrent(); CFRunLoopSourceRef runLoopSource; CFRunLoopSourceContext runLoopSourceContext; bzero(&runLoopSourceContext, sizeof(CFRunLoopSourceContext)); runLoopSourceContext.info = tsdPtr; runLoopSource = CFRunLoopSourceCreate(NULL, 0, &runLoopSourceContext); if (!runLoopSource) { Tcl_Panic("Tcl_InitNotifier: could not create CFRunLoopSource"); } CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopCommonModes); CFRunLoopAddSource(runLoop, runLoopSource, tclEventsOnlyRunLoopMode); tsdPtr->runLoopSource = runLoopSource; tsdPtr->runLoop = runLoop; } LOCK_NOTIFIER_INIT;#ifdef HAVE_PTHREAD_ATFORK /* * Install pthread_atfork handlers to reinitialize the notifier in the * child of a fork. */ if (#ifdef WEAK_IMPORT_PTHREAD_ATFORK pthread_atfork != NULL &&#endif !atForkInit) { int result = pthread_atfork(AtForkPrepare, AtForkParent, AtForkChild); if (result) { Tcl_Panic("Tcl_InitNotifier: pthread_atfork failed"); } atForkInit = 1; }#endif if (notifierCount == 0) { int fds[2], status; /* * Initialize trigger pipe. */ if (pipe(fds) != 0) { Tcl_Panic("Tcl_InitNotifier: could not create trigger pipe"); } status = fcntl(fds[0], F_GETFL); status |= O_NONBLOCK; if (fcntl(fds[0], F_SETFL, status) < 0) { Tcl_Panic("Tcl_InitNotifier: could not make receive pipe non blocking"); } status = fcntl(fds[1], F_GETFL); status |= O_NONBLOCK; if (fcntl(fds[1], F_SETFL, status) < 0) { Tcl_Panic("Tcl_InitNotifier: could not make trigger pipe non blocking"); } receivePipe = fds[0]; triggerPipe = fds[1]; /* * Create notifier thread lazily in Tcl_WaitForEvent() to avoid * interfering with fork() followed immediately by execve() * (cannot execve() when more than one thread is present). */ notifierThread = 0; } notifierCount++; UNLOCK_NOTIFIER_INIT; return (ClientData) tsdPtr;}
开发者ID:aosm,项目名称:tcl,代码行数:100,
示例12: rawhid_open// rawhid_open - open 1 or more devices//// Inputs:// max = maximum number of devices to open// vid = Vendor ID, or -1 if any// pid = Product ID, or -1 if any// usage_page = top level usage page, or -1 if any// usage = top level usage number, or -1 if any// Output:// actual number of devices opened//int rawhid_open(int max, int vid, int pid, int usage_page, int usage){ //*** kern_return_t result; mach_port_t masterPort; CFMutableDictionaryRef matchingDict; CFRunLoopSourceRef runLoopSource; //Create a master port for communication with the I/O Kit result = IOMasterPort(MACH_PORT_NULL, &masterPort); if (result || !masterPort) { return -1; } //To set up asynchronous notifications, create a notification port and //add its run loop event source to the programs run loop gNotifyPort = IONotificationPortCreate(masterPort); runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode); // *** /* IOServiceAddMatchingNotification( gNotifyPort, kIOFirstMatchNotification, matchingDict, attach_callback, NULL, &gAddedIter); */ // *** static IOHIDManagerRef hid_manager=NULL; CFMutableDictionaryRef dict; CFNumberRef num; IOReturn ret; hid_t *p; int count=0; //fprintf(stderr,"fprintf rawhid_open/n"); if (first_hid) free_all_hid(); //printf("rawhid_open, max=%d/n", max); //fflush (stdout); if (max < 1) return 0; // Start the HID Manager // http://developer.apple.com/technotes/tn2007/tn2187.html if (!hid_manager) { hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (hid_manager == NULL || CFGetTypeID(hid_manager) != IOHIDManagerGetTypeID()) { if (hid_manager) CFRelease(hid_manager); return 0; } } if (vid > 0 || pid > 0 || usage_page > 0 || usage > 0) { // Tell the HID Manager what type of devices we want dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!dict) return 0; if (vid > 0) { num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vid); CFDictionarySetValue(dict, CFSTR(kIOHIDVendorIDKey), num); CFRelease(num); } if (pid > 0) { num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid); CFDictionarySetValue(dict, CFSTR(kIOHIDProductIDKey), num); CFRelease(num); } if (usage_page > 0) { num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage_page); CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsagePageKey), num); CFRelease(num); } if (usage > 0) { num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsageKey), num); CFRelease(num); } IOHIDManagerSetDeviceMatching(hid_manager, dict); CFRelease(dict); } else { IOHIDManagerSetDeviceMatching(hid_manager, NULL);//.........这里部分代码省略.........
开发者ID:bethp0413,项目名称:CNC_Stepper_34,代码行数:101,
示例13: mainint main (int argc, const char *argv[]){ mach_port_t masterPort; CFMutableDictionaryRef matchingDict; CFRunLoopSourceRef runLoopSource; kern_return_t kr; SInt32 usbVendor = kOurVendorID; SInt32 usbProduct = kOurProductID; sig_t oldHandler; // pick up command line arguments if (argc > 1) usbVendor = atoi(argv[1]); if (argc > 2) usbProduct = atoi(argv[2]); // Set up a signal handler so we can clean up when we're interrupted from the command line // Otherwise we stay in our run loop forever. oldHandler = signal(SIGINT, SignalHandler); if (oldHandler == SIG_ERR) printf("Could not establish new signal handler"); // first create a master_port for my task kr = IOMasterPort(MACH_PORT_NULL, &masterPort); if (kr || !masterPort) { printf("ERR: Couldn't create a master IOKit Port(%08x)/n", kr); return -1; } printf("Looking for devices matching vendor ID=%ld and product ID=%ld/n", usbVendor, usbProduct); // Set up the matching criteria for the devices we're interested in matchingDict = IOServiceMatching(kIOUSBDeviceClassName); // Interested in instances of class IOUSBDevice and its subclasses if (!matchingDict) { printf("Can't create a USB matching dictionary/n"); mach_port_deallocate(mach_task_self(), masterPort); return -1; } // Add our vendor and product IDs to the matching criteria CFDictionarySetValue( matchingDict, CFSTR(kUSBVendorID), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor)); CFDictionarySetValue( matchingDict, CFSTR(kUSBProductID), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct)); // Create a notification port and add its run loop event source to our run loop // This is how async notifications get set up. gNotifyPort = IONotificationPortCreate(masterPort); runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode); // Retain additional references because we use this same dictionary with four calls to // IOServiceAddMatchingNotification, each of which consumes one reference. matchingDict = (CFMutableDictionaryRef) CFRetain( matchingDict ); matchingDict = (CFMutableDictionaryRef) CFRetain( matchingDict ); matchingDict = (CFMutableDictionaryRef) CFRetain( matchingDict ); // Now set up two notifications, one to be called when a raw device is first matched by I/O Kit, and the other to be // called when the device is terminated. kr = IOServiceAddMatchingNotification( gNotifyPort, kIOFirstMatchNotification, matchingDict, RawDeviceAdded, NULL, &gRawAddedIter ); RawDeviceAdded(NULL, gRawAddedIter); // Iterate once to get already-present devices and // arm the notification kr = IOServiceAddMatchingNotification( gNotifyPort, kIOTerminatedNotification, matchingDict, RawDeviceRemoved, NULL, &gRawRemovedIter ); RawDeviceRemoved(NULL, gRawRemovedIter); // Iterate once to arm the notification // Change the USB product ID in our matching dictionary to the one the device will have once the // bulktest firmware has been downloaded. usbProduct = kOurProductIDBulkTest; CFDictionarySetValue( matchingDict, CFSTR(kUSBProductID), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct)); // Now set up two more notifications, one to be called when a bulk test device is first matched by I/O Kit, and the other to be // called when the device is terminated. kr = IOServiceAddMatchingNotification( gNotifyPort, kIOFirstMatchNotification, matchingDict, BulkTestDeviceAdded,//.........这里部分代码省略.........
开发者ID:aosm,项目名称:IOUSBFamily,代码行数:101,
示例14: FindInterfaces//.........这里部分代码省略......... break; case kUSBIn: message = "in"; break; case kUSBNone: message = "none"; break; case kUSBAnyDirn: message = "any"; break; default: message = "???"; } printf("direction %s, ", message); switch (transferType) { case kUSBControl: message = "control"; break; case kUSBIsoc: message = "isoc"; break; case kUSBBulk: message = "bulk"; break; case kUSBInterrupt: message = "interrupt"; break; case kUSBAnyType: message = "any"; break; default: message = "???"; } printf("transfer type %s, maxPacketSize %d/n", message, maxPacketSize); } } // We can now address endpoints 1 through intfNumEndpoints. Or, we can also address endpoint 0, // the default control endpoint. But it's usually better to use (*usbDevice)->DeviceRequest() instead.#ifndef USE_ASYNC_IO kr = (*intf)->WritePipe(intf, 2, kTestMessage, strlen(kTestMessage)); if (kIOReturnSuccess != kr) { printf("unable to do bulk write (%08x)/n", kr); (void) (*intf)->USBInterfaceClose(intf); (void) (*intf)->Release(intf); break; } printf("Wrote /"%s/" (%ld bytes) to bulk endpoint/n", kTestMessage, (UInt32) strlen(kTestMessage)); numBytesRead = sizeof(gBuffer) - 1; // leave one byte at the end for NUL termination kr = (*intf)->ReadPipe(intf, 9, gBuffer, &numBytesRead); if (kIOReturnSuccess != kr) { printf("unable to do bulk read (%08x)/n", kr); (void) (*intf)->USBInterfaceClose(intf); (void) (*intf)->Release(intf); break; } // The firmware we downloaded echoes the 1's complement of what we wrote, so // complement the buffer contents to see if we get the original data for (i = 0; i < numBytesRead; i++) gBuffer[i] = ~gBuffer[i]; printf("Read /"%s/" (%ld bytes) from bulk endpoint/n", gBuffer, numBytesRead);#else // Just like with service matching notifications, we need to create an event source and add it // to our run loop in order to receive async completion notifications. kr = (*intf)->CreateInterfaceAsyncEventSource(intf, &runLoopSource); if (kIOReturnSuccess != kr) { printf("unable to create async event source (%08x)/n", kr); (void) (*intf)->USBInterfaceClose(intf); (void) (*intf)->Release(intf); break; } CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode); printf("Async event source added to run loop./n"); bzero(gBuffer, sizeof(gBuffer)); strcpy(gBuffer, kTestMessage); kr = (*intf)->WritePipeAsync(intf, 2, gBuffer, strlen(gBuffer), WriteCompletion, (void *) intf); if (kIOReturnSuccess != kr) { printf("unable to do async bulk write (%08x)/n", kr); (void) (*intf)->USBInterfaceClose(intf); (void) (*intf)->Release(intf); break; }#endif // For this test we just want to use the first interface, so exit the loop. break; } return kr;}
开发者ID:aosm,项目名称:IOUSBFamily,代码行数:101,
示例15: main//================================================================================================// main//================================================================================================int main(int argc, const char *argv[]){ CFMutableDictionaryRef matchingDict; CFRunLoopSourceRef runLoopSource; CFNumberRef numberRef; kern_return_t kr; long usbVendor = kMyVendorID; long usbProduct = kMyProductID; sig_t oldHandler; // pick up command line arguments if (argc > 1) { usbVendor = atoi(argv[1]); } if (argc > 2) { usbProduct = atoi(argv[2]); } // Set up a signal handler so we can clean up when we're interrupted from the command line // Otherwise we stay in our run loop forever. oldHandler = signal(SIGINT, SignalHandler); if (oldHandler == SIG_ERR) { fprintf(stderr, "Could not establish new signal handler."); } fprintf(stderr, "Looking for devices matching vendor ID=%ld and product ID=%ld./n", usbVendor, usbProduct); // Set up the matching criteria for the devices we're interested in. The matching criteria needs to follow // the same rules as kernel drivers: mainly it needs to follow the USB Common Class Specification, pp. 6-7. // See also Technical Q&A QA1076 "Tips on USB driver matching on Mac OS X" // <http://developer.apple.com/qa/qa2001/qa1076.html>. // One exception is that you can use the matching dictionary "as is", i.e. without adding any matching // criteria to it and it will match every IOUSBDevice in the system. IOServiceAddMatchingNotification will // consume this dictionary reference, so there is no need to release it later on. matchingDict = IOServiceMatching(kIOUSBDeviceClassName); // Interested in instances of class // IOUSBDevice and its subclasses if (matchingDict == NULL) { fprintf(stderr, "IOServiceMatching returned NULL./n"); return -1; } // We are interested in all USB devices (as opposed to USB interfaces). The Common Class Specification // tells us that we need to specify the idVendor, idProduct, and bcdDevice fields, or, if we're not interested // in particular bcdDevices, just the idVendor and idProduct. Note that if we were trying to match an // IOUSBInterface, we would need to set more values in the matching dictionary (e.g. idVendor, idProduct, // bInterfaceNumber and bConfigurationValue. // Create a CFNumber for the idVendor and set the value in the dictionary numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor); CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), numberRef); CFRelease(numberRef); // Create a CFNumber for the idProduct and set the value in the dictionary numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct); CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID), numberRef); CFRelease(numberRef); numberRef = NULL; // Create a notification port and add its run loop event source to our run loop // This is how async notifications get set up. gNotifyPort = IONotificationPortCreate(kIOMasterPortDefault); runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort); gRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddSource(gRunLoop, runLoopSource, kCFRunLoopDefaultMode); // Now set up a notification to be called when a device is first matched by I/O Kit. kr = IOServiceAddMatchingNotification(gNotifyPort, // notifyPort kIOFirstMatchNotification, // notificationType matchingDict, // matching DeviceAdded, // callback NULL, // refCon &gAddedIter // notification ); // Iterate once to get already-present devices and arm the notification DeviceAdded(NULL, gAddedIter); // Start the run loop. Now we'll receive notifications. fprintf(stderr, "Starting run loop./n/n"); CFRunLoopRun(); // We should never get here fprintf(stderr, "Unexpectedly back from CFRunLoopRun()!/n"); return 0;}
开发者ID:seanwhitsell,项目名称:Pressure,代码行数:95,
示例16: main//.........这里部分代码省略......... current_ps = IOPSGetProvidingPowerSourceType(ps_info); /* On success, store the active power source */ } else { printf("Failed to get the power source information/n"); /* On failure: quit */ return 1; } if (debug) printf("target power source: %s/n", CFStringGetCStringPtr(current_ps, kCFStringEncodingMacRoman)); active_prof = IOPMCopyActivePowerProfiles(); /* Get the power profiles */ if (!active_prof) { printf("Failed to get the active profile/n"); CFCleanup(); return 1; } if (CFDictionaryContainsKey(active_prof, current_ps)) { /* Get the active profile corresponding to the current power source */ profile_ref = (CFNumberRef) CFDictionaryGetValue(active_prof, current_ps); profile_type = CFNumberGetType(profile_ref); CFNumberGetValue(profile_ref, profile_type, &original_profile); /* On succes, store its value */ if (debug) printf("original profile: %d/n", original_profile); } else { printf("Failed to get the power management settings/n"); /* On failure: quit */ CFCleanup(); return 1; } ds = SCDynamicStoreCreate(NULL, CFSTR("deepsleep"), NULL, NULL); /* Create a new dynamic store */ live_settings = SCDynamicStoreCopyValue(ds, CFSTR(kIOPMDynamicStoreSettingsKey)); /* Read current settings */ if(!isA_CFDictionary(live_settings)) { /* We did not get the settings: quit */ printf("Failed to get the power management settings/n"); CFCleanup(); return 1; } if (CFDictionaryContainsKey(live_settings, CFSTR("Hibernate Mode"))) { /* Check if the hibernate mode key exists */ hm_ref = (CFNumberRef) CFDictionaryGetValue(live_settings, CFSTR("Hibernate Mode")); /* On success, get its value */ hm_type = CFNumberGetType(hm_ref); CFNumberGetValue(hm_ref, hm_type, &original_mode); if (debug) printf("original mode: %d/n", original_mode); } else { /* On failure, cleanup and quit */ printf("Failed to get the hibernation mode/n"); CFCleanup(); return 1; } if (repair && original_mode == target_mode) { /* If the original mode is the same as the target mode */ original_mode = default_mode; /* A crash has probably happened during hibernation: we will set back the hibernation mode to its default value after wakeup */ if (debug) printf("repair mode to: %d/n", default_mode); } root_power_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, PowerCallBack, ¬ifierObject); /* Register to the Root Power Domain IOService: notifications will be handled by the PowerCallBack functions */ if (!root_power_port) { /* Registering failed: quit */ printf("Failed to register to the Root Power Domain IOService/n"); CFCleanup(); return 1; } CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes); /* Add the notification port to the run loop */ if (SetActiveProfile(target_profile, current_ps, active_prof)) { /* Set the active power profile to custom (-1) */ printf("Failed to set the active profile/n"); PortsCleanup(); CFCleanup(); return 1; } if (SetHibernateMode(target_mode, current_ps)) { /* Set the hibernate mode to target mode */ printf("Failed to set the hibernation mode/n"); SetActiveProfile(original_profile, current_ps, active_prof); PortsCleanup(); CFCleanup(); return 1; } if (do_sleep) { /* If we are not in simulation mode */ sleep(3); /* Wait for 3s to allow settings to settle down */ if (IOPMSleepSystem(root_power_port) == kIOReturnSuccess) /* Request the system to sleep */ CFRunLoopRun(); /* On success, start the run loop */ else perror("Failed to send the sleep request/n"); /* On failure, do not start it */ } /* The run loop has stopped: system has woken up */ if (restore) { /* If we are asked to restore the original hibernate mode */ if (SetHibernateMode(original_mode, current_ps)) { /* Restore the original hibernate mode */ printf("Failed to set the hibernation mode/n"); SetActiveProfile(original_profile, current_ps, active_prof); PortsCleanup(); CFCleanup(); return 1; } if (SetActiveProfile(original_profile, current_ps, active_prof)) { /* Restore the original power profile */ printf("Failed to set the active profile/n"); PortsCleanup(); CFCleanup(); return 1; } } PortsCleanup(); /* Cleanup */ CFCleanup(); return 0;}
开发者ID:toshiya240,项目名称:DeepSleep,代码行数:101,
示例17: open_intfstatic int open_intf (brick_t *brick) { IOUSBInterfaceInterface182 **intf = (IOUSBInterfaceInterface182 **) brick->handle; IOReturn r; assert (intf != NULL); r = (*intf)->USBInterfaceOpen (intf); if (!r) { UInt8 n_endpoints = 0; int i; brick->in_ep = -1; brick->out_ep = -1; brick->ep_type = kUSBBulk; (*intf)->GetNumEndpoints (intf, &n_endpoints); for (i = 1; i <= n_endpoints; ++i) { UInt16 maxPacketSize; UInt8 direction, number, transferType, interval; (*intf)->GetPipeProperties ( intf, (UInt8) i, &direction, &number, &transferType, &maxPacketSize, &interval ); switch (direction) { case kUSBIn: if (brick->in_ep < 0) { brick->in_ep = i; brick->ep_type = transferType; } break; case kUSBOut: if (brick->out_ep < 0) { brick->out_ep = i; brick->ep_type = transferType; } break; } } /* defaults */ if (brick->in_ep < 0) brick->in_ep = 2; if (brick->out_ep < 0) brick->out_ep = 1; if (brick->ep_type == kUSBInterrupt) { CFRunLoopSourceRef runLoop; r = (*intf)->CreateInterfaceAsyncEventSource (intf, &runLoop); if (r == kIOReturnSuccess) { CFRunLoopAddSource (CFRunLoopGetCurrent(), runLoop, kCFRunLoopDefaultMode); } else { fprintf (stderr, "Warning; unable to create asynchronous event source (%08x)/n", r); } } return 0; } else { fprintf (stderr, "intf error = %08x/n", r); return -1; }}
开发者ID:bsmr-misc-forks,项目名称:kroc,代码行数:67,
示例18: installMacNetworkInterfaceChangeTrackervoid installMacNetworkInterfaceChangeTracker() { CreateIPAddressListChangeCallbackSCF(MacInterfacesChangedCallback, NULL, &storeRef, &interfaceChangeRunLoopSourceRef); CFRunLoopAddSource(CFRunLoopGetCurrent(), interfaceChangeRunLoopSourceRef, kCFRunLoopCommonModes);}
开发者ID:kouis3940,项目名称:kinomajs,代码行数:5,
示例19: mainint main(){ if (geteuid()) { syslog(LOG_ERR,"Error: Daemon must run as root."); exit(geteuid()); } encrypt_buffer = CFDataCreateMutable(kCFAllocatorDefault,8); /*********Set up File**********/ if (!(pathName = (CFStringRef)CFPreferencesCopyAppValue(PATHNAME_PREF_KEY,PREF_DOMAIN))) { pathName = CFSTR(DEFAULT_PATHNAME); CFPreferencesSetAppValue(PATHNAME_PREF_KEY,pathName,PREF_DOMAIN); } CFURLRef logPathURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,pathName,kCFURLPOSIXPathStyle,false); logStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault,logPathURL); CFRelease(logPathURL); if (!logStream) { syslog(LOG_ERR,"Error: Couldn't open file stream at start."); return 1; }/*********Check encryption & keymap**********/ updateEncryption(); updateKeymap();/*********Check space**********/ if (outOfSpace(pathName)) { stamp_file(CFSTR("Not enough disk space remaining!")); CFRunLoopStop(CFRunLoopGetCurrent()); }/*********Connect to kernel extension**********/ if (!connectToKext()) { if (load_kext()) { stamp_file(CFSTR("Could not load KEXT")); return 1; } if (!connectToKext()) { stamp_file(CFSTR("Could not connect with KEXT")); return 1; } } sleep(1); // just a little time to let the kernel notification handlers finish stamp_file(CFSTR("LogKext Daemon starting up")); // stamp login file with initial user LoginLogoutCallBackFunction(NULL, NULL, NULL); CFPreferencesAppSynchronize(PREF_DOMAIN); /*********Create Daemon Timer source**********/ CFRunLoopTimerContext timerContext = { 0 }; CFRunLoopSourceRef loginLogoutSource; if (InstallLoginLogoutNotifiers(&loginLogoutSource)) syslog(LOG_ERR,"Error: could not install login notifier"); else CFRunLoopAddSource(CFRunLoopGetCurrent(),loginLogoutSource, kCFRunLoopDefaultMode); CFRunLoopTimerRef daemonTimer = CFRunLoopTimerCreate(NULL, 0, TIME_TO_SLEEP, 0, 0, DaemonTimerCallback, &timerContext); CFRunLoopAddTimer(CFRunLoopGetCurrent(), daemonTimer, kCFRunLoopCommonModes); CFRunLoopRun(); stamp_file(CFSTR("Server error: closing Daemon")); CFWriteStreamClose(logStream);}
开发者ID:ChaseJohnson,项目名称:LogKext,代码行数:82,
示例20: Tcl_InitNotifierClientDataTcl_InitNotifier(void){ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); tsdPtr->eventReady = 0; /* * Initialize CFRunLoopSource and add it to CFRunLoop of this thread */ if (!tsdPtr->runLoop) { CFRunLoopRef runLoop = CFRunLoopGetCurrent(); CFRunLoopSourceRef runLoopSource; CFRunLoopSourceContext runLoopSourceContext; bzero(&runLoopSourceContext, sizeof(CFRunLoopSourceContext)); runLoopSourceContext.info = tsdPtr; runLoopSource = CFRunLoopSourceCreate(NULL, 0, &runLoopSourceContext); if (!runLoopSource) { Tcl_Panic("Tcl_InitNotifier: could not create CFRunLoopSource."); } CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopCommonModes); tsdPtr->runLoopSource = runLoopSource; tsdPtr->runLoop = runLoop; } /* * Initialize trigger pipe and start the Notifier thread if necessary. */ LOCK_NOTIFIER_INIT; if (notifierCount == 0) { int fds[2], status, result; pthread_attr_t attr; if (pipe(fds) != 0) { Tcl_Panic("Tcl_InitNotifier: could not create trigger pipe."); } status = fcntl(fds[0], F_GETFL); status |= O_NONBLOCK; if (fcntl(fds[0], F_SETFL, status) < 0) { Tcl_Panic("Tcl_InitNotifier: could not make receive pipe non blocking."); } status = fcntl(fds[1], F_GETFL); status |= O_NONBLOCK; if (fcntl(fds[1], F_SETFL, status) < 0) { Tcl_Panic("Tcl_InitNotifier: could not make trigger pipe non blocking."); } receivePipe = fds[0]; triggerPipe = fds[1]; pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_attr_setstacksize(&attr, 60 * 1024); result = pthread_create(¬ifierThread, &attr, (void * (*)(void *))NotifierThreadProc, NULL); pthread_attr_destroy(&attr); if (result) { Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread."); } } notifierCount++; UNLOCK_NOTIFIER_INIT; return (ClientData) tsdPtr;}
开发者ID:SASfit,项目名称:SASfit,代码行数:70,
示例21: CFMessagePortSendRequestSInt32 CFMessagePortSendRequest(CFMessagePortRef remote, SInt32 msgid, CFDataRef data, CFTimeInterval sendTimeout, CFTimeInterval rcvTimeout, CFStringRef replyMode, CFDataRef *returnDatap) { struct __CFMessagePortMachMessage *sendmsg; CFRunLoopRef currentRL = CFRunLoopGetCurrent(); CFRunLoopSourceRef source = NULL; CFDataRef reply = NULL; int64_t termTSR; uint32_t sendOpts = 0, sendTimeOut = 0; int32_t desiredReply; Boolean didRegister = false; kern_return_t ret;//#warning CF: This should be an assert // if (!__CFMessagePortIsRemote(remote)) return -999; if (!__CFMessagePortIsValid(remote)) return kCFMessagePortIsInvalid; __CFMessagePortLock(remote); if (NULL == remote->_replyPort) { CFMachPortContext context; context.version = 0; context.info = remote; context.retain = (const void *(*)(const void *))CFRetain; context.release = (void (*)(const void *))CFRelease; context.copyDescription = (CFStringRef (*)(const void *))__CFMessagePortCopyDescription; remote->_replyPort = CFMachPortCreate(CFGetAllocator(remote), __CFMessagePortReplyCallBack, &context, NULL); } remote->_convCounter++; desiredReply = -remote->_convCounter; CFDictionarySetValue(remote->_replies, (void *)desiredReply, NULL); sendmsg = __CFMessagePortCreateMessage(CFGetAllocator(remote), false, CFMachPortGetPort(remote->_port), (replyMode != NULL ? CFMachPortGetPort(remote->_replyPort) : MACH_PORT_NULL), -desiredReply, msgid, (data ? CFDataGetBytePtr(data) : NULL), (data ? CFDataGetLength(data) : 0)); __CFMessagePortUnlock(remote); if (replyMode != NULL) { source = CFMachPortCreateRunLoopSource(CFGetAllocator(remote), remote->_replyPort, -100); didRegister = !CFRunLoopContainsSource(currentRL, source, replyMode); if (didRegister) { CFRunLoopAddSource(currentRL, source, replyMode); } } if (sendTimeout < 10.0*86400) { // anything more than 10 days is no timeout! sendOpts = MACH_SEND_TIMEOUT; sendTimeout *= 1000.0; if (sendTimeout < 1.0) sendTimeout = 0.0; sendTimeOut = floor(sendTimeout); } ret = mach_msg((mach_msg_header_t *)sendmsg, MACH_SEND_MSG|sendOpts, sendmsg->head.msgh_size, 0, MACH_PORT_NULL, sendTimeOut, MACH_PORT_NULL); CFAllocatorDeallocate(CFGetAllocator(remote), sendmsg); if (KERN_SUCCESS != ret) { if (didRegister) { CFRunLoopRemoveSource(currentRL, source, replyMode); CFRelease(source); } if (MACH_SEND_TIMED_OUT == ret) return kCFMessagePortSendTimeout; return kCFMessagePortTransportError; } if (replyMode == NULL) { return kCFMessagePortSuccess; } CFRetain(remote); // retain during run loop to avoid invalidation causing freeing _CFMachPortInstallNotifyPort(currentRL, replyMode); termTSR = mach_absolute_time() + __CFTimeIntervalToTSR(rcvTimeout); for (;;) { CFRunLoopRunInMode(replyMode, __CFTSRToTimeInterval(termTSR - mach_absolute_time()), true); // warning: what, if anything, should be done if remote is now invalid? reply = CFDictionaryGetValue(remote->_replies, (void *)desiredReply); if (NULL != reply || termTSR < (int64_t)mach_absolute_time()) { break; } if (!CFMessagePortIsValid(remote)) { // no reason that reply port alone should go invalid so we don't check for that break; } } // Should we uninstall the notify port? A complex question... if (didRegister) { CFRunLoopRemoveSource(currentRL, source, replyMode); CFRelease(source); } if (NULL == reply) { CFDictionaryRemoveValue(remote->_replies, (void *)desiredReply); CFRelease(remote); return CFMessagePortIsValid(remote) ? kCFMessagePortReceiveTimeout : -5; } if (NULL != returnDatap) { *returnDatap = ((void *)0xffffffff == reply) ? NULL : reply; } else if ((void *)0xffffffff != reply) { CFRelease(reply); } CFDictionaryRemoveValue(remote->_replies, (void *)desiredReply); CFRelease(remote); return kCFMessagePortSuccess;}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:90,
示例22: ListenUsingCoreFoundationstatic int ListenUsingCoreFoundation(size_t noteCount, const char **noteNames) // Implements the "listenCF" command. Register for the noteCount // notifications whose names are in the noteNames array. Then wrap the // notification Mach port in a CFMachPort and use CF to read the notification // messages, printing the information about any notifications that arrive // from our CFMachPort callback.{ int retVal; uint32_t noteErr; size_t noteIndex; int noteTokens[noteCount]; mach_port_t port = MACH_PORT_NULL; // Register. The first time around this loop fd == -1 and so we don't // specify NOTIFY_REUSE. notify_register_mach_port then allocates // a Mach port and returns it in port. For subsequent iterations // we /do/ specify NOTIFY_REUSE and notify_register_mach_port just // reuses the existing port. noteErr = NOTIFY_STATUS_OK; for (noteIndex = 0; noteIndex < noteCount; noteIndex++) { noteErr = notify_register_mach_port( noteNames[noteIndex], &port, (port == MACH_PORT_NULL) ? 0 : NOTIFY_REUSE, ¬eTokens[noteIndex] ); if (noteErr != NOTIFY_STATUS_OK) { break; } } if (noteErr != NOTIFY_STATUS_OK) { PrintNotifyError("registration failed", noteNames[noteIndex], noteErr); retVal = EXIT_FAILURE; } else { MyCFMachPortCallBackInfo myInfo; CFMachPortContext context = { 0 }; CFMachPortRef cfPort; Boolean shouldFreeInfo; CFRunLoopSourceRef rls; // Set up the context structure for MyCFMachPortCallBack. myInfo.magic = 'CFpI'; myInfo.noteCount = noteCount; myInfo.noteTokens = noteTokens; myInfo.noteNames = noteNames; // Create the CFMachPort. context.info = &myInfo; cfPort = CFMachPortCreateWithPort( NULL, port, MyCFMachPortCallBack, &context, &shouldFreeInfo ); assert(cfPort != NULL); // There can only be one CFMachPort for a given Mach port name. Thus, // if someone had already created a CFMachPort for "port", CFMachPort // would not create a new CFMachPort but, rather, return the existing // CFMachPort with the retain count bumped. In that case it hasn't // taken any 'reference' on the data in context; the context.info // on the /previous/ CFMachPort is still in use, but the context.info // that we supply is now superfluous. In that case it returns // shouldFreeInfo, telling us that we don't need to hold on to this // information. // // In this specific case no one should have already created a CFMachPort // for "port", so shouldFreeInfo should never be true. If it is, it's // time to worry! assert( ! shouldFreeInfo ); // Add it to the run loop. rls = CFMachPortCreateRunLoopSource(NULL, cfPort, 0); assert(rls != NULL); CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode); CFRelease(rls); // Run the run loop. fprintf(stdout, "Listening using Core Foundation:/n"); fflush(stdout); CFRunLoopRun(); fprintf(stderr, "CFRunLoopRun returned/n"); retVal = EXIT_FAILURE; } return retVal;}
开发者ID:fruitsamples,项目名称:NotifyTool,代码行数:98,
示例23: startKicker/* * startKicker() * * The first argument is a dictionary representing the keys * which need to be monitored for a given "target" and what * action should be taken if a change in one of those keys * is detected. */static voidstartKicker(const void *value, void *context){ CFMutableStringRef name; CFArrayRef keys; CFArrayRef patterns; kickeeRef target = CFAllocatorAllocate(NULL, sizeof(kickee), 0); SCDynamicStoreContext targetContext = { 0, (void *)target, NULL, NULL, NULL }; target->active = FALSE; target->needsKick = FALSE; target->dict = CFRetain((CFDictionaryRef)value); target->store = NULL; target->rl = NULL; target->rls = NULL; target->changedKeys = NULL; name = CFStringCreateMutableCopy(NULL, 0, CFDictionaryGetValue(target->dict, CFSTR("name"))); SCLog(TRUE, LOG_DEBUG, CFSTR("Starting kicker for %@"), name); CFStringAppend(name, CFSTR(" /"Kicker/"")); target->store = SCDynamicStoreCreate(NULL, name, kicker, &targetContext); CFRelease(name); if (!target->store) { SCLog(TRUE, LOG_NOTICE, CFSTR("SCDynamicStoreCreate() failed: %s"), SCErrorString(SCError())); goto error; } keys = isA_CFArray(CFDictionaryGetValue(target->dict, CFSTR("keys"))); patterns = isA_CFArray(CFDictionaryGetValue(target->dict, CFSTR("regexKeys"))); if (!SCDynamicStoreSetNotificationKeys(target->store, keys, patterns)) { SCLog(TRUE, LOG_NOTICE, CFSTR("SCDynamicStoreSetNotifications() failed: %s"), SCErrorString(SCError())); goto error; } target->rl = CFRunLoopGetCurrent(); target->rls = SCDynamicStoreCreateRunLoopSource(NULL, target->store, 0); if (!target->rls) { SCLog(TRUE, LOG_NOTICE, CFSTR("SCDynamicStoreCreateRunLoopSource() failed: %s"), SCErrorString(SCError())); goto error; } CFRunLoopAddSource(target->rl, target->rls, kCFRunLoopDefaultMode); return; error : CFRelease(target->dict); if (target->store) CFRelease(target->store); CFAllocatorDeallocate(NULL, target); return;}
开发者ID:aosm,项目名称:configd_plugins,代码行数:71,
示例24: __SCPreferencesScheduleWithRunLoopstatic Boolean__SCPreferencesScheduleWithRunLoop(SCPreferencesRef prefs, CFRunLoopRef runLoop, CFStringRef runLoopMode, dispatch_queue_t queue){ Boolean ok = FALSE; SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs; pthread_mutex_lock(&prefsPrivate->lock); if ((prefsPrivate->dispatchQueue != NULL) || // if we are already scheduled on a dispatch queue ((queue != NULL) && prefsPrivate->scheduled)) { // if we are already scheduled on a CFRunLoop _SCErrorSet(kSCStatusInvalidArgument); goto done; } if (!prefsPrivate->scheduled) { CFMutableArrayRef keys; if (prefsPrivate->session == NULL) { ok = __SCPreferencesAddSession(prefs); if (!ok) { goto done; } } CFRetain(prefs); // hold a reference to the prefs keys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); CFArrayAppendValue(keys, prefsPrivate->sessionKeyCommit); CFArrayAppendValue(keys, prefsPrivate->sessionKeyApply); (void) SCDynamicStoreSetNotificationKeys(prefsPrivate->session, keys, NULL); CFRelease(keys); if (runLoop != NULL) { prefsPrivate->rls = SCDynamicStoreCreateRunLoopSource(NULL, prefsPrivate->session, 0); prefsPrivate->rlList = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } prefsPrivate->scheduled = TRUE; } if (queue != NULL) { ok = SCDynamicStoreSetDispatchQueue(prefsPrivate->session, queue); if (!ok) { prefsPrivate->scheduled = FALSE; (void) SCDynamicStoreSetNotificationKeys(prefsPrivate->session, NULL, NULL); CFRelease(prefs); goto done; } prefsPrivate->dispatchQueue = queue; dispatch_retain(prefsPrivate->dispatchQueue); } else { if (!_SC_isScheduled(NULL, runLoop, runLoopMode, prefsPrivate->rlList)) { /* * if we do not already have notifications scheduled with * this runLoop / runLoopMode */ CFRunLoopAddSource(runLoop, prefsPrivate->rls, runLoopMode); } _SC_schedule(prefs, runLoop, runLoopMode, prefsPrivate->rlList); } ok = TRUE; done : pthread_mutex_unlock(&prefsPrivate->lock); return ok;}
开发者ID:010001111,项目名称:darling,代码行数:73,
示例25: iokit_poll_notificationsstatic void iokit_poll_notifications(void *opaque) { int phase = 0; Semaphore *handshake = opaque; IONotificationPortRef notification_port; io_object_t notifier; io_connect_t root_port; CFRunLoopSourceRef notification_run_loop_source; log_debug("Started notification poll thread"); // need to register this PThread with the Objective-C garbage collector, // because CoreFoundation uses Objective-C#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 objc_registerThreadWithCollector();#endif // register for system sleep/wake notifications root_port = IORegisterForSystemPower(&root_port, ¬ification_port, iokit_handle_notifications, ¬ifier); if (root_port == MACH_PORT_NULL) { log_error("Could not register for root power domain"); goto cleanup; } phase = 1; // get notification run loop source notification_run_loop_source = IONotificationPortGetRunLoopSource(notification_port); if (notification_run_loop_source == NULL) { log_error("Could not get notification run loop source"); goto cleanup; } CFRunLoopAddSource(CFRunLoopGetCurrent(), notification_run_loop_source, kCFRunLoopDefaultMode); phase = 2; // start loop _run_loop = (CFRunLoopRef)CFRetain(CFRunLoopGetCurrent()); _running = true; semaphore_release(handshake); CFRunLoopRun(); log_debug("Stopped notification poll thread");cleanup: if (!_running) { // need to release the handshake in all cases, otherwise iokit_init // will block forever in semaphore_acquire semaphore_release(handshake); } switch (phase) { // no breaks, all cases fall through intentionally case 2: CFRunLoopRemoveSource(CFRunLoopGetCurrent(), notification_run_loop_source, kCFRunLoopDefaultMode); case 1: IODeregisterForSystemPower(¬ifier); IOServiceClose(root_port); IONotificationPortDestroy(notification_port); default: break; } _running = false;}
开发者ID:Loremipsum1988,项目名称:brickd,代码行数:75,
示例26: sysEventThreadEntrystatic void * /* O - Return status/value */sysEventThreadEntry(void){ io_object_t powerNotifierObj; /* Power notifier object */ IONotificationPortRef powerNotifierPort; /* Power notifier port */ SCDynamicStoreRef store = NULL;/* System Config dynamic store */ CFRunLoopSourceRef powerRLS = NULL,/* Power runloop source */ storeRLS = NULL;/* System Config runloop source */ CFStringRef key[6], /* System Config keys */ pattern[2]; /* System Config patterns */ CFArrayRef keys = NULL, /* System Config key array*/ patterns = NULL;/* System Config pattern array */ SCDynamicStoreContext storeContext; /* Dynamic store context */ CFRunLoopTimerContext timerContext; /* Timer context */ cupsd_thread_data_t threadData; /* Thread context data for the * * runloop notifiers */ /* * Register for power state change notifications */ bzero(&threadData, sizeof(threadData)); threadData.sysevent.powerKernelPort = IORegisterForSystemPower(&threadData, &powerNotifierPort, sysEventPowerNotifier, &powerNotifierObj); if (threadData.sysevent.powerKernelPort) { powerRLS = IONotificationPortGetRunLoopSource(powerNotifierPort); CFRunLoopAddSource(CFRunLoopGetCurrent(), powerRLS, kCFRunLoopDefaultMode); } else DEBUG_puts("sysEventThreadEntry: error registering for system power " "notifications"); /* * Register for system configuration change notifications */ bzero(&storeContext, sizeof(storeContext)); storeContext.info = &threadData; store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("cupsd"), sysEventConfigurationNotifier, &storeContext); if (!ComputerNameKey) ComputerNameKey = SCDynamicStoreKeyCreateComputerName(kCFAllocatorDefault); if (!BTMMKey) BTMMKey = SCDynamicStoreKeyCreate(kCFAllocatorDefault, CFSTR("Setup:/Network/BackToMyMac")); if (!NetworkGlobalKeyIPv4) NetworkGlobalKeyIPv4 = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv4); if (!NetworkGlobalKeyIPv6) NetworkGlobalKeyIPv6 = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetIPv6); if (!NetworkGlobalKeyDNS) NetworkGlobalKeyDNS = SCDynamicStoreKeyCreateNetworkGlobalEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCEntNetDNS); if (!HostNamesKey) HostNamesKey = SCDynamicStoreKeyCreateHostNames(kCFAllocatorDefault); if (!NetworkInterfaceKeyIPv4) NetworkInterfaceKeyIPv4 = SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4); if (!NetworkInterfaceKeyIPv6) NetworkInterfaceKeyIPv6 = SCDynamicStoreKeyCreateNetworkInterfaceEntity(kCFAllocatorDefault, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6); if (store && ComputerNameKey && HostNamesKey && NetworkGlobalKeyIPv4 && NetworkGlobalKeyIPv6 && NetworkGlobalKeyDNS && NetworkInterfaceKeyIPv4 && NetworkInterfaceKeyIPv6) { key[0] = ComputerNameKey; key[1] = BTMMKey; key[2] = NetworkGlobalKeyIPv4; key[3] = NetworkGlobalKeyIPv6; key[4] = NetworkGlobalKeyDNS;//.........这里部分代码省略.........
开发者ID:thangap,项目名称:tizen-release,代码行数:101,
示例27: StartDebuggingAndDetachvoid StartDebuggingAndDetach(char *udid, char *app_path) { SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid); if (device) { CFStringRef bundleId = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *)app_path, strlen(app_path), kCFStringEncodingUTF8, false); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, bundleId, kCFURLPOSIXPathStyle, false); CFURLRef disk_app_url = CFURLCopyAbsoluteURL(relative_url); CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url); SDMMD_AMDebugConnectionRef debug = SDMMD_AMDebugConnectionCreateForDevice(device); SDMMD_AMDebugConnectionStart(debug); uintptr_t socket = SDMMD_AMDServiceConnectionGetSocket(debug->connection); CFSocketContext context = { 0, (void*)socket, NULL, NULL, NULL }; CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &socket_callback, &context); int yes = 1; setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); struct sockaddr_un address; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, SDM_LLDB_SOCKET); address.sun_len = SUN_LEN(&address); CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address)); unlink(SDM_LLDB_SOCKET); CFSocketSetAddress(fdvendor, address_data); CFRelease(address_data); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); SDMMD_AMDeviceRef device = SDMMD_AMDServiceConnectionGetDevice(debug->connection); CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS); CFRange range = { 0, CFStringGetLength(cmds) }; CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier); CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{DEVICE_PATH}"), device_app_path, range, 0); range.length = CFStringGetLength(cmds); CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{APP_PATH}"), disk_app_path, range, 0); range.length = CFStringGetLength(cmds); CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url); CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle); CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path); range.length = CFStringGetLength(dcp_noprivate); CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0); range.length = CFStringGetLength(cmds); CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0); range.length = CFStringGetLength(cmds); CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url); CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0); CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0); FILE *out = fopen(PREP_CMDS_PATH, "w"); fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out); fclose(out); CFSafeRelease(cmds); CFSafeRelease(bundle_identifier); CFSafeRelease(device_app_url); CFSafeRelease(device_app_path); CFSafeRelease(disk_app_path); CFSafeRelease(device_container_url); CFSafeRelease(device_container_path); CFSafeRelease(dcp_noprivate); CFSafeRelease(disk_container_url); CFSafeRelease(disk_container_path); CFSafeRelease(cmds_data); signal(SIGHUP, exit); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system("xcrun -sdk iphoneos lldb /tmp/sdmmd-lldb-prep"); kill(parent, SIGHUP); _exit(0); } CFRunLoopRun(); }}
开发者ID:JeremyAgost,项目名称:SDMMobileDevice,代码行数:88,
示例28: ReceiveReportsPsychError ReceiveReports(int deviceIndex){ long error=0; pRecDevice device; IOHIDDeviceInterface122** interface=NULL; int reason; // kCFRunLoopRunFinished, kCFRunLoopRunStopped, kCFRunLoopRunTimedOut, kCFRunLoopRunHandledSource CountReports("ReceiveReports beginning."); if(freeReportsPtr==NULL)PrintfExit("No free reports."); PsychHIDVerifyInit(); device=PsychHIDGetDeviceRecordPtrFromIndex(deviceIndex); if(!HIDIsValidDevice(device))PrintfExit("PsychHID: Invalid device./n"); interface=device->interface; if(interface==NULL)PrintfExit("PsychHID: No interface for device./n"); if(deviceIndex<0 || deviceIndex>MAXDEVICEINDEXS-1)PrintfExit("Sorry. Can't cope with deviceNumber %d (more than %d). Please tell [email C++ CFRunLoopGetCurrent函数代码示例 C++ CFRetain函数代码示例
|