Skip to content

Commit 796c6c9

Browse files
committed
features for remote configs v3
1 parent f4f36eb commit 796c6c9

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

include/GameAnalytics/GameAnalytics.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ namespace gameanalytics
102102
static void startSession();
103103
static void endSession();
104104

105+
/*
106+
template<typename T>
107+
static T getRemoteConfigsValue(std::string const& key, T const& defaultValue);
108+
*/
109+
105110
static std::string getRemoteConfigsValueAsString(std::string const& key, std::string const& defaultValue = "");
111+
static int64_t getRemoteConfigsValueAsInt(std::string const& key, int64_t defaultValue = 0);
112+
static uint64_t getRemoteConfigsValueAsUInt(std::string const& key, uint64_t defaultValue = 0);
113+
static bool getRemoteConfigsValueAsBool(std::string const& key, bool defaultValue = false);
114+
static double getRemoteConfigsValueAsFloat(std::string const& key, double defaultValue = 0.0);
115+
static std::string getRemoteConfigsValueAsJson(std::string const& key);
106116

107117
static bool isRemoteConfigsReady();
108118
static void addRemoteConfigsListener(const std::shared_ptr<IRemoteConfigsListener> &listener);
@@ -134,4 +144,5 @@ namespace gameanalytics
134144
static bool isSdkReady(bool needsInitialized, bool warn);
135145
static bool isSdkReady(bool needsInitialized, bool warn, std::string const& message);
136146
};
147+
137148
} // namespace gameanalytics

source/gameanalytics/GameAnalytics.cpp

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,78 @@ namespace gameanalytics
740740

741741
std::string GameAnalytics::getRemoteConfigsValueAsString(std::string const& key, std::string const& defaultValue)
742742
{
743-
return state::GAState::getRemoteConfigsStringValue(key, defaultValue);
743+
return state::GAState::getRemoteConfigsValue<std::string>(key, defaultValue);
744+
}
745+
746+
int64_t GameAnalytics::getRemoteConfigsValueAsInt(std::string const& key, int64_t defaultValue)
747+
{
748+
try
749+
{
750+
std::string s = getRemoteConfigsValueAsString(key);
751+
if(!s.empty())
752+
{
753+
return std::stoll(s);
754+
}
755+
}
756+
catch(std::exception& e)
757+
{
758+
(void)e;
759+
}
760+
761+
return defaultValue;
762+
}
763+
764+
uint64_t GameAnalytics::getRemoteConfigsValueAsUInt(std::string const& key, uint64_t defaultValue)
765+
{
766+
try
767+
{
768+
std::string s = getRemoteConfigsValueAsString(key);
769+
if(!s.empty())
770+
{
771+
return std::stoull(s);
772+
}
773+
}
774+
catch(std::exception& e)
775+
{
776+
(void)e;
777+
}
778+
779+
return defaultValue;
780+
}
781+
782+
double GameAnalytics::getRemoteConfigsValueAsFloat(std::string const& key, double defaultValue)
783+
{
784+
try
785+
{
786+
std::string s = getRemoteConfigsValueAsString(key);
787+
if(!s.empty())
788+
{
789+
return std::stod(s);
790+
}
791+
}
792+
catch(std::exception& e)
793+
{
794+
(void)e;
795+
}
796+
797+
return defaultValue;
798+
}
799+
800+
bool GameAnalytics::getRemoteConfigsValueAsBool(std::string const& key, bool defaultValue)
801+
{
802+
std::string s = getRemoteConfigsValueAsString(key, "false");
803+
return utilities::toLowerCase(s) == "true";
804+
}
805+
806+
std::string GameAnalytics::getRemoteConfigsValueAsJson(std::string const& key)
807+
{
808+
std::string jsonString = getRemoteConfigsValueAsString(key);
809+
if(!json::accept(jsonString))
810+
{
811+
return "";
812+
}
813+
814+
return jsonString;
744815
}
745816

746817
bool GameAnalytics::isRemoteConfigsReady()
@@ -874,8 +945,9 @@ namespace gameanalytics
874945
std::this_thread::sleep_for(std::chrono::milliseconds(100));
875946
}
876947
}
877-
catch (const std::exception&)
948+
catch (const std::exception& e)
878949
{
950+
logging::GALogger::e(e.what());
879951
}
880952
}
881953

@@ -906,7 +978,7 @@ namespace gameanalytics
906978
{
907979
if (warn)
908980
{
909-
logging::GALogger::w("%sDatastore not initialized", m.c_str());
981+
logging::GALogger::w("%s; Datastore not initialized", m.c_str());
910982
}
911983
return false;
912984
}
@@ -915,7 +987,7 @@ namespace gameanalytics
915987
{
916988
if (warn)
917989
{
918-
logging::GALogger::w("%sSDK is not initialized", m.c_str());
990+
logging::GALogger::w("%s; SDK is not initialized", m.c_str());
919991
}
920992
return false;
921993
}
@@ -924,7 +996,7 @@ namespace gameanalytics
924996
{
925997
if (warn)
926998
{
927-
logging::GALogger::w("%s;SDK is disabled", m.c_str());
999+
logging::GALogger::w("%s; SDK is disabled", m.c_str());
9281000
}
9291001
return false;
9301002
}
@@ -934,7 +1006,7 @@ namespace gameanalytics
9341006
{
9351007
if (warn)
9361008
{
937-
logging::GALogger::w("%s;Session has not started yet", m.c_str());
1009+
logging::GALogger::w("%s; Session has not started yet", m.c_str());
9381010
}
9391011
return false;
9401012
}

0 commit comments

Comments
 (0)