12#ifndef OPENVPN_APPLE_MACLIFE_H
13#define OPENVPN_APPLE_MACLIFE_H
73 State(
bool net_up_arg,
const std::string &iface_arg,
bool sleep_arg)
92 std::ostringstream
os;
122 dstore.reset(SCDynamicStoreCreate(kCFAllocatorDefault,
123 CFSTR(
"OpenVPN_MacLifeCycle"),
149 catch (
const std::exception &e)
151 OPENVPN_LOG(
"MacLifeCycle exception: " << e.what());
175 SCDynamicStoreContext context = {0,
this,
nullptr,
nullptr,
nullptr};
176 CF::DynamicStore ds(SCDynamicStoreCreate(kCFAllocatorDefault,
177 CFSTR(
"OpenVPN_MacLifeCycle_iface_watch"),
181 throw mac_lifecycle_error(
"SCDynamicStoreCreate");
185 if (!watched_keys.defined())
186 throw mac_lifecycle_error(
"watched_keys is undefined");
187 if (!SCDynamicStoreSetNotificationKeys(ds(),
190 throw mac_lifecycle_error(
"SCDynamicStoreSetNotificationKeys failed");
191 CF::RunLoopSource rls(SCDynamicStoreCreateRunLoopSource(kCFAllocatorDefault, ds(), 0));
193 throw mac_lifecycle_error(
"SCDynamicStoreCreateRunLoopSource failed");
194 CFRunLoopAddSource(CFRunLoopGetCurrent(), rls(), kCFRunLoopDefaultMode);
238 if (seconds || force_runloop)
240 CFRunLoopTimerContext context = {0,
this,
nullptr,
nullptr,
nullptr};
243 CFRunLoopAddTimer(CFRunLoopGetCurrent(),
action_timer(), kCFRunLoopCommonModes);
245 OPENVPN_LOG(
"MacLifeCycle::schedule_action_timer: failed to create timer");
308 catch (
const std::exception &e)
310 OPENVPN_LOG(
"MacLifeCycle::action_timer_callback exception: " << e.what());
static void action_timer_callback_static(CFRunLoopTimerRef timer, void *info)
void cancel_action_timer()
void reachability_tracker_event(const ReachabilityBase &rb, SCNetworkReachabilityFlags flags) override
void notify_sleep() override
void action_timer_callback(CFRunLoopTimerRef timer)
static void iface_watch_callback_static(SCDynamicStoreRef store, CFArrayRef changedKeys, void *arg)
bool network_available() override
void start(NotifyCallback *nc_arg) override
void schedule_action_timer(const int seconds, bool force_runloop=false)
void notify_wakeup() override
Log::Context::Wrapper logwrap
std::string primary_interface()
OPENVPN_EXCEPTION(mac_lifecycle_error)
void iface_watch_callback(SCDynamicStoreRef store, CFArrayRef changedKeys)
virtual Status vstatus(const SCNetworkReachabilityFlags flags) const =0
SCNetworkReachabilityFlags flags() const
static std::string render_flags(const SCNetworkReachabilityFlags flags)
virtual Type vtype() const =0
static std::string render_status(const Status status)
void reachability_tracker_schedule()
void reachability_tracker_cancel()
static Status status_from_flags(const SCNetworkReachabilityFlags flags)
#define OPENVPN_LOG(args)
MutableArray mutable_array(const CFIndex capacity=0)
Dict DynamicStoreCopyDict(const DynamicStore &ds, const KEY &key)
void array_append_str(MutableArray &array, const VALUE &value)
std::string dict_get_str(const DICT &dict, const KEY &key)
virtual void cln_reconnect(int seconds)=0
virtual void cln_resume()=0
virtual void cln_pause(const std::string &reason)=0
Argument to construct a Context in a different thread.
Scoped RAII for the global_log pointer.
bool operator==(const State &other) const
bool operator!=(const State &other) const
std::string to_string() const
State(bool net_up_arg, const std::string &iface_arg, bool sleep_arg)