Implement abstract tracker class

This commit is contained in:
Sergey Abramchuk 2017-07-17 20:22:03 +03:00
parent a9629cdf86
commit d2d46640db
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,21 @@
//
// OpenVPNReachabilityTracker.h
// OpenVPN Adapter
//
// Created by Sergey Abramchuk on 17.07.17.
//
//
#import <openvpn/apple/reachable.hpp>
using namespace openvpn;
class OpenVPNReachabilityTracker : public ReachabilityTracker {
OpenVPNReachabilityTracker(const bool enable_internet, const bool enable_wifi, void* handler);
virtual void reachability_tracker_event(const ReachabilityBase& rb, SCNetworkReachabilityFlags flags) override;
private:
void* handler;
};

View File

@ -0,0 +1,33 @@
//
// OpenVPNReachabilityTracker.m
// OpenVPN Adapter
//
// Created by Sergey Abramchuk on 17.07.17.
//
//
#import "OpenVPNReachability+Internal.h"
#import "OpenVPNReachabilityTracker.h"
OpenVPNReachabilityTracker::OpenVPNReachabilityTracker(const bool enable_internet, const bool enable_wifi, void* handler) : ReachabilityTracker(enable_internet, enable_wifi) {
this->handler = handler;
}
void OpenVPNReachabilityTracker::reachability_tracker_event(const ReachabilityBase& rb, SCNetworkReachabilityFlags flags) {
OpenVPNReachability* handler = (__bridge OpenVPNReachability* )this->handler;
ReachabilityInterface::Status status = rb.status();
switch (status) {
case ReachabilityInterface::NotReachable:
[handler updateReachabilityStatus:OpenVPNReachabilityStatusNotReachable];
break;
case ReachabilityInterface::ReachableViaWiFi:
[handler updateReachabilityStatus:OpenVPNReachabilityStatusReachableViaWiFi];
break;
case ReachabilityInterface::ReachableViaWWAN:
[handler updateReachabilityStatus:OpenVPNReachabilityStatusReachableViaWWAN];
break;
}
}