firebase::remote_config::RemoteConfig

#include <remote_config.h>

Entry point for the Firebase C++ SDK for Remote Config.

Summary

To use the SDK, call firebase::remote_config::RemoteConfig::GetInstance() to obtain an instance of RemoteConfig, then call operations on that instance. The instance contains the complete set of FRC parameter values available to your app. The instance also stores values fetched from the FRC Server until they are made available for use with a call to Activate().

Constructors and Destructors

~RemoteConfig()

Public functions

Activate()
Future< bool >
Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect.
ActivateLastResult()
Future< bool >
Get the (possibly still pending) results of the most recent Activate() call.
AddOnConfigUpdateListener(std::function< void(ConfigUpdate &&, RemoteConfigError)> config_update_listener)
Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.
EnsureInitialized()
Returns a Future that contains ConfigInfo representing the initialization status of this Firebase Remote Config instance.
EnsureInitializedLastResult()
Get the (possibly still pending) results of the most recent EnsureInitialized() call.
Fetch()
Future< void >
Fetches config data from the server.
Fetch(uint64_t cache_expiration_in_seconds)
Future< void >
Fetches config data from the server.
FetchAndActivate()
Future< bool >
Asynchronously fetches and then activates the fetched configs.
FetchAndActivateLastResult()
Future< bool >
Get the (possibly still pending) results of the most recent FetchAndActivate() call.
FetchLastResult()
Future< void >
Get the (possibly still pending) results of the most recent Fetch() call.
GetAll()
std::map< std::string, Variant >
Returns a Map of Firebase Remote Config key value pairs.
GetBoolean(const char *key)
bool
Returns the value associated with a key, converted to a bool.
GetBoolean(const char *key, ValueInfo *info)
bool
Returns the value associated with a key, converted to a bool.
GetConfigSettings()
Gets the current settings of the RemoteConfig object.
GetData(const char *key)
std::vector< unsigned char >
Returns the value associated with a key, as a vector of raw byte-data.
GetData(const char *key, ValueInfo *info)
std::vector< unsigned char >
Returns the value associated with a key, as a vector of raw byte-data.
GetDouble(const char *key)
double
Returns the value associated with a key, converted to a double.
GetDouble(const char *key, ValueInfo *info)
double
Returns the value associated with a key, converted to a double.
GetInfo()
const ConfigInfo
Returns information about the last fetch request, in the form of a ConfigInfo struct.
GetKeys()
std::vector< std::string >
Gets the set of all keys.
GetKeysByPrefix(const char *prefix)
std::vector< std::string >
Gets the set of keys that start with the given prefix.
GetLong(const char *key)
int64_t
Returns the value associated with a key, converted to a 64-bit integer.
GetLong(const char *key, ValueInfo *info)
int64_t
Returns the value associated with a key, converted to a 64-bit integer.
GetString(const char *key)
std::string
Returns the value associated with a key, converted to a string.
GetString(const char *key, ValueInfo *info)
std::string
Returns the value associated with a key, converted to a string.
SetConfigSettings(ConfigSettings settings)
Future< void >
Asynchronously changes the settings for this Remote Config instance.
SetConfigSettingsLastResult()
Future< void >
Get the (possibly still pending) results of the most recent SetConfigSettings() call.
SetDefaults(const ConfigKeyValueVariant *defaults, size_t number_of_defaults)
Future< void >
Sets the default values based on a mapping of string to Variant.
SetDefaults(const ConfigKeyValue *defaults, size_t number_of_defaults)
Future< void >
Sets the default values based on a string map.
SetDefaultsLastResult()
Future< void >
Get the (possibly still pending) results of the most recent SetDefaults() call.
app()
App *
Gets the App this remote config object is connected to.

Public static functions

GetInstance(App *app)
Returns the RemoteConfig object for an App.

Public functions

Activate

Future< bool > Activate()

Asynchronously activates the most recently fetched configs, so that the fetched key value pairs take effect.

Details
Returns
A Future that contains true if fetched configs were activated. The future will contain false if the configs were already activated.

ActivateLastResult

Future< bool > ActivateLastResult()

Get the (possibly still pending) results of the most recent Activate() call.

Details
Returns
The future result from the last call to Activate().

AddOnConfigUpdateListener

ConfigUpdateListenerRegistration AddOnConfigUpdateListener(
  std::function< void(ConfigUpdate &&, RemoteConfigError)> config_update_listener
)

Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.

Details
Parameters
config_update_listener
An event handler callback that can be used to respond to config updates when they're fetched
Returns
A registration object that allows the listener to remove the associated listener.

EnsureInitialized

Future< ConfigInfo > EnsureInitialized()

Returns a Future that contains ConfigInfo representing the initialization status of this Firebase Remote Config instance.

Use this method to ensure Set/Get call not being blocked.

EnsureInitializedLastResult

Future< ConfigInfo > EnsureInitializedLastResult()

Get the (possibly still pending) results of the most recent EnsureInitialized() call.

Details
Returns
The future result from the last call to EnsureInitialized().

Fetch

Future< void > Fetch()

Fetches config data from the server.

Note that this function is asynchronous, and will normally take an unspecified amount of time before completion.

Details
Returns
A Future which can be used to determine when the fetch is complete.

Fetch

Future< void > Fetch(
  uint64_t cache_expiration_in_seconds
)

Fetches config data from the server.

Details
Parameters
cache_expiration_in_seconds
The number of seconds to keep previously fetch data available. If cached data is available that is newer than cache_expiration_in_seconds, then the function returns immediately and does not fetch any data. A cache_expiration_in_seconds of zero will always cause a fetch.
Returns
A Future which can be used to determine when the fetch is complete.

FetchAndActivate

Future< bool > FetchAndActivate()

Asynchronously fetches and then activates the fetched configs.

If the time elapsed since the last fetch from the Firebase Remote Config backend is more than the default minimum fetch interval, configs are fetched from the backend.

After the fetch is complete, the configs are activated so that the fetched key value pairs take effect.

Details
Returns
A Future that contains true if the current call activated the fetched configs; if no configs were fetched from the backend and the local fetched configs have already been activated, the future will contain false.

FetchAndActivateLastResult

Future< bool > FetchAndActivateLastResult()

Get the (possibly still pending) results of the most recent FetchAndActivate() call.

Details
Returns
The future result from the last call to FetchAndActivate().

FetchLastResult

Future< void > FetchLastResult()

Get the (possibly still pending) results of the most recent Fetch() call.

Details
Returns
The future result from the last call to Fetch().

GetAll

std::map< std::string, Variant > GetAll()

Returns a Map of Firebase Remote Config key value pairs.

Evaluates the values of the parameters in the following order: The activated value, if the last successful Activate() contained the key. The default value, if the key was set with SetDefaults().

GetBoolean

bool GetBoolean(
  const char *key
)

Returns the value associated with a key, converted to a bool.

Values of "1", "true", "t", "yes", "y" and "on" are interpreted (case insensitive) as true and "0", "false", "f", "no", "n", "off", and empty strings are interpreted (case insensitive) as false.

Details
Parameters
key
Key of the value to be retrieved.
Returns
Value associated with the specified key converted to a boolean value.

GetBoolean

bool GetBoolean(
  const char *key,
  ValueInfo *info
)

Returns the value associated with a key, converted to a bool.

Values of "1", "true", "t", "yes", "y" and "on" are interpreted (case insensitive) as true and "0", "false", "f", "no", "n", "off", and empty strings are interpreted (case insensitive) as false.

Details
Parameters
key
Key of the value to be retrieved.
info
A return value, specifying the source of the returned value.
Returns
Value associated with the specified key converted to a boolean value.

GetConfigSettings

ConfigSettings GetConfigSettings()

Gets the current settings of the RemoteConfig object.

Details
Returns
A ConfigSettings struct.

GetData

std::vector< unsigned char > GetData(
  const char *key
)

Returns the value associated with a key, as a vector of raw byte-data.

Details
Parameters
key
Key of the value to be retrieved.
Returns
Vector of bytes.

GetData

std::vector< unsigned char > GetData(
  const char *key,
  ValueInfo *info
)

Returns the value associated with a key, as a vector of raw byte-data.

Details
Parameters
key
Key of the value to be retrieved.
info
A return value, specifying the source of the returned value.
Returns
Vector of bytes.

GetDouble

double GetDouble(
  const char *key
)

Returns the value associated with a key, converted to a double.

Details
Parameters
key
Key of the value to be retrieved.
Returns
Value associated with the specified key converted to a double.

GetDouble

double GetDouble(
  const char *key,
  ValueInfo *info
)

Returns the value associated with a key, converted to a double.

Details
Parameters
key
Key of the value to be retrieved.
info
A return value, specifying the source of the returned value.
Returns
Value associated with the specified key converted to a double.

GetInfo

const ConfigInfo GetInfo()

Returns information about the last fetch request, in the form of a ConfigInfo struct.

Details
Returns
A ConfigInfo struct, containing fields reflecting the state of the most recent fetch request.

GetKeys

std::vector< std::string > GetKeys()

Gets the set of all keys.

Details
Returns
Set of all Remote Config parameter keys.

GetKeysByPrefix

std::vector< std::string > GetKeysByPrefix(
  const char *prefix
)

Gets the set of keys that start with the given prefix.

Details
Parameters
prefix
The key prefix to look for. If empty or null, this method will return all keys.
Returns
Set of Remote Config parameter keys that start with the specified prefix. Will return an empty set if there are no keys with the given prefix.

GetLong

int64_t GetLong(
  const char *key
)

Returns the value associated with a key, converted to a 64-bit integer.

Details
Parameters
key
Key of the value to be retrieved.
Returns
Value associated with the specified key converted to a 64-bit integer.

GetLong

int64_t GetLong(
  const char *key,
  ValueInfo *info
)

Returns the value associated with a key, converted to a 64-bit integer.

Details
Parameters
key
Key of the value to be retrieved.
info
A return value, specifying the source of the returned value.
Returns
Value associated with the specified key converted to a 64-bit integer.

GetString

std::string GetString(
  const char *key
)

Returns the value associated with a key, converted to a string.

Details
Parameters
key
Key of the value to be retrieved.
Returns
Value as a string associated with the specified key.

GetString

std::string GetString(
  const char *key,
  ValueInfo *info
)

Returns the value associated with a key, converted to a string.

Details
Parameters
key
Key of the value to be retrieved.
info
A return value, specifying the source of the returned value.
Returns
Value as a string associated with the specified key.

SetConfigSettings

Future< void > SetConfigSettings(
  ConfigSettings settings
)

Asynchronously changes the settings for this Remote Config instance.

Details
Parameters
settings
The new settings to be applied.
Returns
a Future which can be used to determine when the operation is complete.

SetConfigSettingsLastResult

Future< void > SetConfigSettingsLastResult()

Get the (possibly still pending) results of the most recent SetConfigSettings() call.

Details
Returns
The future result from the last call to SetConfigSettings().

SetDefaults

Future< void > SetDefaults(
  const ConfigKeyValueVariant *defaults,
  size_t number_of_defaults
)

Sets the default values based on a mapping of string to Variant.

This allows you to specify defaults of type other than string.

The type of each Variant in the map determines the type of data for which you are providing a default. For example, boolean values can be retrieved with GetBool(), integer values can be retrieved with GetLong(), double values can be retrieved with GetDouble(), string values can be retrieved with GetString(), and binary data can be retrieved with GetData(). Aggregate Variant types are not allowed.

See also:firebase::Variant for more information on how to create a Variant of each type.

Details
Parameters
defaults
Array of ConfigKeyValueVariant, representing the new set of defaults to apply. If the same key is specified multiple times, the value associated with the last duplicate key is applied.
number_of_defaults
Number of elements in the defaults array.
Returns
a Future which can be used to determine when the operation is complete.

SetDefaults

Future< void > SetDefaults(
  const ConfigKeyValue *defaults,
  size_t number_of_defaults
)

Sets the default values based on a string map.

Details
Parameters
defaults
Array of ConfigKeyValue, representing the new set of defaults to apply. If the same key is specified multiple times, the value associated with the last duplicate key is applied.
number_of_defaults
Number of elements in the defaults array.
Returns
a Future which can be used to determine when the operation is complete.

SetDefaultsLastResult

Future< void > SetDefaultsLastResult()

Get the (possibly still pending) results of the most recent SetDefaults() call.

Details
Returns
The future result from the last call to SetDefaults().

app

App * app()

Gets the App this remote config object is connected to.

~RemoteConfig

 ~RemoteConfig()

Public static functions

GetInstance

RemoteConfig * GetInstance(
  App *app
)

Returns the RemoteConfig object for an App.

Creates the RemoteConfig if required.

To get the RemoteConfig object for the default app, use, GetInstance(GetDefaultFirebaseApp());

If the library RemoteConfig fails to initialize, init_result_out will be written with the result status (if a pointer is given).

Details
Parameters
app
The App to use for the RemoteConfig object.