All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WebConnectivityValidator.h
1 // Copyright eeGeo Ltd (2015), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Web.h"
6 #include "IWebLoadRequest.h"
7 #include "ICallback.h"
8 #include "WebLoadRequestCompletionCallback.h"
9 #include "PendingWebRequestsContainer.h"
10 #include "CallbackCollection.h"
11 #include <string>
12 
13 namespace Eegeo
14 {
15  namespace Web
16  {
17  namespace WebConnectivityStates
18  {
19  enum VALUES
20  {
21  Unknown = 0,
22  Offline,
23  Validating,
24  Portal,
25  Online
26  };
27  }
28 
29  /*
30  Validates the current web connectivity by calling a known response. This may be invalid due to no connection
31  enabled, or due to captive portal redirects.
32  */
34  {
35  public:
36 
38  IWebLoadRequestFactory& webRequestFactory);
40 
41  void PerformValidation();
42 
43  const WebConnectivityStates::VALUES GetCurrentState() const { return m_validationState; }
44  const bool IsValid() const { return m_validationState == WebConnectivityStates::Online; }
45  const bool IsValidating() const { return m_validationState == WebConnectivityStates::Validating; }
46 
47  void RegisterStateChangedCallback(Helpers::ICallback0& callback);
48  void UnregisterStateChangedCallback(Helpers::ICallback0& callback);
49 
50  private:
51 
52  void HandleConnectionChanged(const bool &connected);
53  void HandleCaptivePortalCheckResponse(IWebResponse& webResponse);
54  void SetState(WebConnectivityStates::VALUES state);
55 
56  IConnectivityService& m_connectivityService;
57  IWebLoadRequestFactory& m_webRequestFactory;
58  PendingWebRequestsContainer m_pendingWebRequestsContainer;
59 
62  WebConnectivityStates::VALUES m_validationState;
63 
64  Helpers::CallbackCollection0 m_stateChangedCallbacks;
65  };
66  }
67 }