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 #ifndef REALM_OS_SYSTEM_CONFIGURATION_HPP
20 #define REALM_OS_SYSTEM_CONFIGURATION_HPP
22 #include "sync/impl/network_reachability.hpp"
24 #if NETWORK_REACHABILITY_AVAILABLE
26 #include <SystemConfiguration/SystemConfiguration.h>
31 class SystemConfiguration {
33 static SystemConfiguration& shared();
35 SCNetworkReachabilityRef network_reachability_create_with_name(CFAllocatorRef allocator,
36 const char *hostname);
37 SCNetworkReachabilityRef network_reachability_create_with_address(CFAllocatorRef allocator,
38 const sockaddr *address);
39 bool network_reachability_set_dispatch_queue(SCNetworkReachabilityRef target,
40 dispatch_queue_t queue);
41 bool network_reachability_set_callback(SCNetworkReachabilityRef target,
42 SCNetworkReachabilityCallBack callback,
43 SCNetworkReachabilityContext *context);
44 bool network_reachability_get_flags(SCNetworkReachabilityRef target,
45 SCNetworkReachabilityFlags *flags);
48 using create_with_name_t = SCNetworkReachabilityRef(*)(CFAllocatorRef, const char*);
49 using create_with_address_t = SCNetworkReachabilityRef(*)(CFAllocatorRef, const sockaddr*);
50 using set_dispatch_queue_t = bool(*)(SCNetworkReachabilityRef, dispatch_queue_t);
51 using set_callback_t = bool(*)(SCNetworkReachabilityRef,
52 SCNetworkReachabilityCallBack,
53 SCNetworkReachabilityContext*);
54 using get_flags_t = bool(*)(SCNetworkReachabilityRef, SCNetworkReachabilityFlags*);
56 SystemConfiguration();
58 void* m_framework_handle;
60 create_with_name_t m_create_with_name = nullptr;
61 create_with_address_t m_create_with_address = nullptr;
62 set_dispatch_queue_t m_set_dispatch_queue = nullptr;
63 set_callback_t m_set_callback = nullptr;
64 get_flags_t m_get_flags = nullptr;
70 #endif // NETWORK_REACHABILITY_AVAILABLE
72 #endif // REALM_OS_SYSTEM_CONFIGURATION_HPP