NetworkMonitor::NetworkMonitor(boost::asio::io_service& io) : m_impl(new Impl(io)) { m_impl->scheduleCfLoop(); // Potentially useful System Configuration regex patterns: // // State:/Network/Interface/.*/Link // State:/Network/Interface/.*/IPv4 // State:/Network/Interface/.*/IPv6 // // State:/Network/Global/DNS // State:/Network/Global/IPv4 // // Potentially useful notifications from Darwin Notify Center: // // com.apple.system.config.network_change // network change observations CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), static_cast<void*>(this), &NetworkMonitor::Impl::afterNotificationCenterEvent, CFSTR("com.apple.system.config.network_change"), nullptr, // object to observe CFNotificationSuspensionBehaviorDeliverImmediately); }
void CACFDistributedNotification::RemoveObserver(const void* inObserver, CFStringRef inName) { #if !TARGET_OS_IPHONE CFNotificationCenterRef theCenter = CFNotificationCenterGetDistributedCenter(); #else CFNotificationCenterRef theCenter = CFNotificationCenterGetDarwinNotifyCenter(); #endif CFNotificationCenterRemoveObserver(theCenter, inObserver, inName, NULL); }
void CACFDistributedNotification::AddObserver(const void* inObserver, CFNotificationCallback inCallback, CFStringRef inName, CFNotificationSuspensionBehavior inSuspensionBehavior) { #if !TARGET_OS_IPHONE CFNotificationCenterRef theCenter = CFNotificationCenterGetDistributedCenter(); CFNotificationSuspensionBehavior theSuspensionBehavior = inSuspensionBehavior; #else #pragma unused(inSuspensionBehavior) CFNotificationCenterRef theCenter = CFNotificationCenterGetDarwinNotifyCenter(); CFNotificationSuspensionBehavior theSuspensionBehavior = 0; #endif CFNotificationCenterAddObserver(theCenter, inObserver, inCallback, inName, NULL, theSuspensionBehavior); }
void shm_post_update(nmeaINFO* nmeaInfo, const char *buff, int buff_sz) { shm_append_ringbuf(buff, buff_sz); const int bestRatingResetTimeout = 3; static int lastSeenBestRatedSentence = 0; int currentRating = smask_rating(nmeaInfo->smask); static nmeaTIME lastTimestamp; // only do this for position sentences because // sentences without embedded UTC get local device time // which will vary with each sentence if (currentRating > 0 && 0 != memcmp(&lastTimestamp, &nmeaInfo->utc, sizeof(nmeaTIME))) { lastTimestamp = nmeaInfo->utc; ++lastSeenBestRatedSentence; #ifdef DEBUG LogMsg("shm_post_update DEBUG: incrementing lastSeenBestRatedSentence to %u, current rating %u", lastSeenBestRatedSentence, currentRating); #endif } static int bestRating = 0; if (lastSeenBestRatedSentence > bestRatingResetTimeout) { LogMsg("shm_post_update: resetting best rating (%u)", bestRating); bestRating = 0; } if (currentRating > bestRating) { bestRating = currentRating; LogMsg("shm_post_update: best rating set to (%u)", bestRating); } // always update shared mem to make it possible to show satellite positions before fix is available memcpy(&g_shm_info->nmeaInfo, nmeaInfo, sizeof(nmeaINFO)); if (currentRating == bestRating && lastSeenBestRatedSentence != 0) { lastSeenBestRatedSentence = 0; CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), BtGpsNotificationName, nil, nil, TRUE); } }
void CACFDistributedNotification::PostNotification(CFStringRef inName, CFDictionaryRef inUserInfo, bool inPostToAllSessions) { #if !TARGET_OS_IPHONE CFNotificationCenterRef theCenter = CFNotificationCenterGetDistributedCenter(); CFDictionaryRef theUserInfo = inUserInfo; CFOptionFlags theFlags = kCFNotificationDeliverImmediately; if(inPostToAllSessions) { theFlags += kCFNotificationPostToAllSessions; } #else // flag unsupported features Assert(inUserInfo == NULL, "CACFDistributedNotification::PostNotification: distributed notifications do not support a payload"); Assert(inPostToAllSessions, "CACFDistributedNotification::PostNotification: distributed notifications do not support per-session delivery"); CFNotificationCenterRef theCenter = CFNotificationCenterGetDarwinNotifyCenter(); CFDictionaryRef theUserInfo = NULL; CFOptionFlags theFlags = 0; #endif CFNotificationCenterPostNotificationWithOptions(theCenter, inName, NULL, theUserInfo, theFlags); }
NetworkMonitor::~NetworkMonitor() { CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), static_cast<void*>(this)); }