1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2017 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #include "sync/impl/apple/system_configuration.hpp"
21 #if NETWORK_REACHABILITY_AVAILABLE
26 using namespace realm;
27 using namespace realm::_impl;
29 SystemConfiguration::SystemConfiguration()
31 m_framework_handle = dlopen("/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", RTLD_LAZY);
33 if (m_framework_handle) {
34 m_create_with_name = (create_with_name_t)dlsym(m_framework_handle, "SCNetworkReachabilityCreateWithName");
35 m_create_with_address = (create_with_address_t)dlsym(m_framework_handle, "SCNetworkReachabilityCreateWithAddress");
36 m_set_dispatch_queue = (set_dispatch_queue_t)dlsym(m_framework_handle, "SCNetworkReachabilitySetDispatchQueue");
37 m_set_callback = (set_callback_t)dlsym(m_framework_handle, "SCNetworkReachabilitySetCallback");
38 m_get_flags = (get_flags_t)dlsym(m_framework_handle, "SCNetworkReachabilityGetFlags");
40 #pragma clang diagnostic push
41 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
42 asl_log(nullptr, nullptr, ASL_LEVEL_WARNING, "network reachability is not available");
43 #pragma clang diagnostic pop
47 SystemConfiguration& SystemConfiguration::shared()
49 static SystemConfiguration system_configuration;
51 return system_configuration;
54 SCNetworkReachabilityRef SystemConfiguration::network_reachability_create_with_name(CFAllocatorRef allocator,
57 if (m_create_with_name)
58 return m_create_with_name(allocator, hostname);
63 SCNetworkReachabilityRef SystemConfiguration::network_reachability_create_with_address(CFAllocatorRef allocator,
64 const sockaddr *address)
66 if (m_create_with_address)
67 return m_create_with_address(allocator, address);
72 bool SystemConfiguration::network_reachability_set_dispatch_queue(SCNetworkReachabilityRef target, dispatch_queue_t queue)
74 if (m_set_dispatch_queue)
75 return m_set_dispatch_queue(target, queue);
80 bool SystemConfiguration::network_reachability_set_callback(SCNetworkReachabilityRef target,
81 SCNetworkReachabilityCallBack callback,
82 SCNetworkReachabilityContext *context)
85 return m_set_callback(target, callback, context);
90 bool SystemConfiguration::network_reachability_get_flags(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags *flags)
93 return m_get_flags(target, flags);
98 #endif // NETWORK_REACHABILITY_AVAILABLE