SleepHelper
|
Class for ShouldConnect application callback. More...
#include <SleepHelper.h>
Public Member Functions | |
bool | shouldConnect () |
Determine if a cloud connection should occur. More... | |
![]() | |
void | add (std::function< bool(Types... args)> callback) |
Adds a callback function. Zero or more callbacks can be defined. More... | |
void | forEach (Types... args) |
Calls all callbacks, regardless of return value returned. More... | |
bool | untilTrue (bool defaultResult, Types... args) |
Calls callbacks until the first one returns true. The others are not called. More... | |
bool | whileAnyTrue (bool defaultResult, Types... args) |
Calls all callbacks. Returns true if any returns true, but all are still called. More... | |
bool | untilFalse (bool defaultResult, Types... args) |
Calls all callbacks until the first one returns false, then returns without calling others. More... | |
bool | whileAnyFalse (bool defaultResult, Types... args) |
Calls all callbacks. If any returns false then returns false, but all are still called. More... | |
void | removeAll () |
Remove all registered callbacks. More... | |
Additional Inherited Members | |
![]() | |
std::vector< std::function< bool(Types... args)> > | callbackFunctions |
Vector of all callbacks, limited only by available RAM. | |
Class for ShouldConnect application callback.
The prototype for the function or lambda is:
bool callback(int &connectConviction, int &noConnectConviction)
If you believe you should connect set connectConviction to a value between 1 and 100. The value defaults 0 which means "I don't care". If you absolutely must connect to the cloud now, set the value to a high value.
If you do not want to connect, set the noConnectConviction to a value between 1 and 100. For example, if you definitely do not have enough battery power to successfully connect a high value is used.
All of the ShouldConnect callbacks are called, and the maximum values for connectConviction and noConnectConviction are saved. If connectConviction >= noConnectConviction then a connection is attempted.
The bool result is ignored by this callback.
|
inline |
Determine if a cloud connection should occur.
This is determined by calling all of the shouldConnect functions. Each function is passed a connectConviction and a noConnectConviction, both initialized to true.
If the callback believes a connection should be made, the connectConviction should be set to a value from 1 to 100. A typical value would be 60. This would encourage connection but still could be overridden for other reasons, such as insufficient battery power.
If the callback believes a connection should not be made, it sets noConnectConviction to a value from 1 to 100, 100 being definitely do not connect.
If the highest connection conviction is greater than the highest no connection conviction, then a connection will be attempted.
Callback prototype:
bool shouldConnectCallback(int &connectConviction, int &noConnectConviction);
Return true from the function in all cases.