Example #1
0
def main():
    # Setup a dynamic store controller that monitors all keys:
    store = SCDynamicStoreCreate(None, "demo.controller", dynamicStoreChanged, None)
    SCDynamicStoreSetNotificationKeys(store, None, [".*"])
    source = SCDynamicStoreCreateRunLoopSource(None, store, 0)

    # Setup a preferences controller
    prefs = SCPreferencesCreate(None, "demo.prefs", None)
    SCPreferencesSetCallback(prefs, prefsChanged, None)

    # Set up a run loop and add all controllers to that.
    loop = CFRunLoopGetCurrent()
    CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)
    SCPreferencesScheduleWithRunLoop(prefs, loop, kCFRunLoopCommonModes)

    signal.signal(signal.SIGINT, sigint)
    CFRunLoopRun()
Example #2
0
def main():
    if len(sys.argv) >= 2:
        addr = socket.gethostbyname(sys.argv[1])
    else:
        addr = "82.94.237.218"  # www.python.org

    loop = CFRunLoopGetCurrent()

    target = SCNetworkReachabilityCreateWithAddress(None, (addr, 80))
    SCNetworkReachabilitySetCallback(target, resultAvailable, addr)

    ok, flags = SCNetworkReachabilityGetFlags(target, None)
    if ok:
        resultAvailable(target, flags, addr)

    else:
        ok = SCNetworkReachabilityScheduleWithRunLoop(target, loop,
                                                      kCFRunLoopCommonModes)

        CFRunLoopRun()
Example #3
0
 def run_forever(self):
     with self._running_loop():
         CFRunLoopRun()