You.i Engine
YiConnectivity.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_CONNECTIVITY_H_
3 #define _YI_CONNECTIVITY_H_
4 
6 #include "network/YiUrl.h"
7 #include "signal/YiSignal.h"
9 #include "utility/YiTimer.h"
10 
41 {
42 public:
46  enum class Type
47  {
49  NoConnectivity = 0x00,
51  LocalNetwork = 0x01,
53  Internet = 0x02,
55  ApplicationServer = 0x04
56  };
57 
59  virtual ~CYIConnectivity();
60 
68  void StartPeriodicChecker();
69 
75  void StopPeriodicChecker();
76 
80  bool IsCheckerRunning() const;
81 
87  bool IsWaitingOnNetwork() const;
88 
92  void ProbeState();
93 
102  Type GetState() const;
103 
107  const CYIUrl &GetInternetURL() const;
108 
113  const CYIUrl &GetApplicationURL() const;
114 
118  void SetApplicationURL(const CYIUrl &url);
119 
123  void SetPeriodicCheckInterval(uint64_t intervalMs);
124 
130  void SetNetworkCheckTimeout(uint64_t timeoutMs);
131 
136 
141 
142 private:
143  void SendRequests();
144  void CancelRequests();
145  void CancelInternetRequest();
146  void CancelAppRequest();
147  void OnCheckerTimeout();
148 
149  void OnInternetRequestSucceeded();
150  void OnInternetRequestFailed(const std::shared_ptr<CYIHTTPRequest> &pRequest, const CYIHTTPService::HTTPStatusCode code);
151  void OnAppRequestSucceeded();
152  void OnAppRequestFailed(const std::shared_ptr<CYIHTTPRequest> &pRequest, const CYIHTTPService::HTTPStatusCode code);
153 
154  void OnConnectionPartChecked();
155 
156  CYITimer m_periodicCheckerTimer;
157 
158  Type m_state;
159  CYIUrl m_appURL;
160  uint64_t m_checkIntervalMs;
161  uint64_t m_checkTimeoutMs;
162  bool m_probeRequested;
163  Type m_checkedBits;
164  Type m_connectivityBits;
165 
166  std::shared_ptr<CYIHTTPRequest> m_pInternetRequest;
167  std::shared_ptr<CYIHTTPRequest> m_pAppRequest;
168 };
169 
174 template<>
176 {
177  static const bool enable = true;
178 };
179 
180 #endif // _YI_CONNECTIVITY_H_
void SetNetworkCheckTimeout(uint64_t timeoutMs)
Type
Definition: YiConnectivity.h:46
virtual ~CYIConnectivity()
bool IsWaitingOnNetwork() const
void SetApplicationURL(const CYIUrl &url)
Type GetState() const
void StopPeriodicChecker()
A struct used to enable bitmask operators for an enum class type.
Definition: YiEnumBitmaskOperators.h:26
void SetPeriodicCheckInterval(uint64_t intervalMs)
A low-precision timer driven by the update loop.
Definition: YiTimer.h:27
CYISignal< Type > ProbeCompleted
Definition: YiConnectivity.h:140
const CYIUrl & GetApplicationURL() const
void StartPeriodicChecker()
HTTPStatusCode
Definition: YiHTTPService.h:29
A class used to encapsulate an URL.
Definition: YiUrl.h:24
bool IsCheckerRunning() const
Definition: YiSignalHandler.h:175
const CYIUrl & GetInternetURL() const
A class used to perform active network connectivity checks.
Definition: YiConnectivity.h:40
CYISignal< Type > StateChanged
Definition: YiConnectivity.h:135