A class used to perform active network connectivity checks.
This class allows for active network connectivity checks to be performed, either on a per-request basis, or on a periodic basis. This differs from the CYINetworkInformationBridge class, which only performs passive checks.
Three 'levels' of network connectivity can be checked:
If the reported connectivity is INTERNET, it also implies that connectivity to the local network is available. Similarly, connectivity to application servers imply connectivity to internet and local network.
The periodic connectivity checks are enabled by the StartPeriodicChecker() function, and are stopped by the StopPeriodicChecker() function.
Whether the periodic checkers are running or not, the user can request a 'one shot' connectivity check using the ProbeState function. When the probe completes, the ProbeCompleted signal is emitted with the connectivity state. The signal will be emitted even if the connectivity state has not changed.
When the connectivity state is detected as having changed (either due to periodic check or due to a manually-requested check), the StateChanged is called with the new connectivity state.
#include <network/YiConnectivity.h>
Public Types | |
| enum | TYPE { NO_CONNECTIVITY = 0x00, LOCAL_NETWORK = 0x01, INTERNET = 0x02, APPLICATION_SERVER = 0x04 } |
Public Attributes | |
| CYISignal< TYPE > | StateChanged |
| CYISignal< TYPE > | ProbeCompleted |
An enum representing the various possible network connectivity states.
| CYIConnectivity::CYIConnectivity | ( | ) |
|
virtual |
| TYPE CYIConnectivity::GetState | ( | ) | const |
Returns the current connectivity state.
| bool CYIConnectivity::IsCheckerRunning | ( | ) | const |
Returns true if the periodic checks for connectivity are active.
| bool CYIConnectivity::IsWaitingOnNetwork | ( | ) | const |
Returns true if a network connectivity check is currently in progress. Both periodic connectivity checks and state probes can cause this function to return true.
| void CYIConnectivity::ProbeState | ( | ) |
Requests that a network connectivity check be performed. Once the check has been performed, the ProbeComplete signal is emitted with the connectivity state.
| void CYIConnectivity::SetApplicationURL | ( | const CYIUrl & | url | ) |
Sets the URL to be used for performing application server connectivity checks. If a blank URL is provided, no application server checks are performed. By default, no application server checks are performed.
| void CYIConnectivity::SetNetworkCheckTimeout | ( | uint64_t | uTimeoutMs | ) |
Sets how long HTTP requests are allowed to run before timing out.
| void CYIConnectivity::SetPeriodicCheckInterval | ( | uint64_t | uIntervalMs | ) |
Sets the frequency at which periodic network connectivity checks are made. For example, calling this function with a value of 5000 will result in periodic checks being performed every 5 seconds.
| void CYIConnectivity::StartPeriodicChecker | ( | ) |
Starts performing periodic checks for connectivity. This will result in 1-2 HTTP requests being performed every 5 seconds (by default). Has no effect if periodic checks are already running.
When the network connectivity state is detected as having changed, the StateChanged signal is emitted with the new connectivity state.
The check interval can be configured using the SetPeriodicCheckInterval function.
| void CYIConnectivity::StopPeriodicChecker | ( | ) |
Stops performing periodic checks for connectivity. Has no effect if periodic checks are not currently running.
A signal emitted when a state probe requested by the user (through the ProbeState() function) has completed. This signal is emitted even if the probe revealed no change in the network connectivity state.
A signal emitted when a network connectivity change is detected (either through periodic checks or through a user-triggered state probe).