Tizen 2.0 Release
[framework/web/wrt-commons.git] / modules / utils / src / wrt_global_settings.cpp
index 8695e8a..9428fb3 100644 (file)
  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
  * @brief       runtime
  */
-#include <dpl/assert.h>
-#include <dpl/log/log.h>
-#include <string.h>
-#include <stdlib.h>
-#include <wrt_global_settings_internal.h>
+#include <stddef.h>
+#include <cstdlib>
+#include <cstring>
+#include <string>
+#include <sstream>
+#include <sys/utsname.h>
+#include <dpl/utils/wrt_global_settings.h>
+
+namespace GlobalSettings {
 
 namespace {
-bool GetPopupsEnabledFlag()
+const int ROAMING_TEST = 0x00000001;
+const int POPUPS_TEST =  0x00000002;
+const int OCSP_TEST = 0x00000004;
+const int WARP_TEST = 0x00000008;
+const int CRL_TEST = 0x00000010;
+const int SCREEN_SHOT_TEST = 0x00000020;
+const int ALL_TEST = (ROAMING_TEST | POPUPS_TEST | OCSP_TEST | WARP_TEST
+                      | CRL_TEST | SCREEN_SHOT_TEST);
+const char* WRT_TEST_MODE = "WRT_TEST_MODE";
+const char* MACHINE_NAME_EMUL = "emulated"; // "arch_emulated"
+enum MachineType
 {
-    //TODO : env var. will be removed after UX guide for POWDER is enabled.
-    const char *env = getenv("WRT_POPUP_ENABLE");
-    if (env && 0 == strcmp(env, "1")) {
-        return true;
-    } else {
-        return false;
-    }
-}
+    MACHINE_TYPE_TARGET,
+    MACHINE_TYPE_EMULATOR,
+    MACHINE_TYPE_UNKNOWN
+};
+
+struct Settings {
+    bool isEmulator;
+    int testModes;
 
-static bool initializeGlobalSettings();
+    Settings()
+    : isEmulator(false), testModes(0)
+    {}
+};
 
-static bool initHelper = initializeGlobalSettings();
+Settings gSettings;
+
+bool initializeGlobalSettings();
+bool initHelper = initializeGlobalSettings();
+
+MachineType getMachineType()
+{
+    // get current machine name
+    struct utsname u;
+    if (0 == uname(&u)) {
+        if (0 == strlen(u.machine)) {
+            return MACHINE_TYPE_UNKNOWN;
+        } else {
+            // If current machine is emul,
+            // machine name include "<arch>_emulated"
+            std::string machine = u.machine;
+            // find "emulated" string in the u.machine
+            if (std::string::npos != machine.find(MACHINE_NAME_EMUL)) {
+                return MACHINE_TYPE_EMULATOR;
+            } else {
+                return MACHINE_TYPE_TARGET;
+            }
+        }
+    }
+
+    return MACHINE_TYPE_UNKNOWN;
+}
 
 bool initializeGlobalSettings()
 {
     (void)initHelper;
-    LogDebug("Initializing globall settings");
-    GlobalSettings::IGlobalSettingsFunctions functions;
-    functions.getPopupsEnabledFlag = &GetPopupsEnabledFlag;
-    GlobalSettings::SetPredefinedGlobalSettings(functions);
+
+    // ignore environment variables if this flag is not set
+#ifdef GLOBAL_SETTINGS_CONTROL
+    char * envStr = getenv(WRT_TEST_MODE);
+    int testMode = 0;
+    if (NULL != envStr) {
+        std::string env = envStr;
+        if ("1" == env) {
+            testMode = ALL_TEST;
+        } else {
+            std::istringstream str(envStr);
+            while (std::getline(str, env, '|')) {
+                if ("popups" == env) {
+                        testMode |= POPUPS_TEST;
+                } else if ("roaming" == env) {
+                        testMode |= ROAMING_TEST;;
+                } else if ("ocsp" == env) {
+                        testMode |= OCSP_TEST;;
+                } else if ("warp" == env) {
+                        testMode |= WARP_TEST;;
+                } else if ("crl" == env) {
+                        testMode |= CRL_TEST;
+                } else if ("screen" == env) {
+                        testMode |= SCREEN_SHOT_TEST;;
+                }
+            }
+        }
+        gSettings.testModes = testMode;
+    }
+    // TODO other settings initialization
+
+#endif
+    gSettings.isEmulator = (MACHINE_TYPE_EMULATOR == getMachineType());
     return false;
 }
+} // namespace
+
+bool TestModeEnabled()
+{
+    return ((gSettings.testModes & ALL_TEST) == ALL_TEST);
+}
+
+bool PopupsTestModeEnabled() {
+    return (gSettings.testModes & POPUPS_TEST);
+}
+bool WarpTestModeEnabled() {
+    return (gSettings.testModes & WARP_TEST);
+}
+bool RoamingTestModeEnabled() {
+    return (gSettings.testModes & ROAMING_TEST);
+}
+bool OCSPTestModeEnabled() {
+    return (gSettings.testModes & OCSP_TEST);
 }
+bool CrlTestModeEnabled() {
+    return (gSettings.testModes & CRL_TEST);
+}
+bool MakeScreenTestModeEnabled() {
+    return (gSettings.testModes & SCREEN_SHOT_TEST);
+}
+
+bool IsEmulator()
+{
+    return gSettings.isEmulator;
+}
+
+} // GlobalSettings