Add profile util 52/109552/10 accepted/tizen/3.0/common/20170120.102118 accepted/tizen/3.0/ivi/20170119.225306 accepted/tizen/3.0/mobile/20170119.225218 accepted/tizen/3.0/tv/20170119.225234 accepted/tizen/3.0/wearable/20170119.225249 submit/tizen_3.0/20170118.065338
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 10 Jan 2017 11:01:27 +0000 (20:01 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 18 Jan 2017 02:14:10 +0000 (11:14 +0900)
- Add profile util to determine target profile at runtime

Change-Id: Ia66867a3d8516ace5277c4324f5fa15340bac6e8
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/utils/profile_util.cc [new file with mode: 0644]
src/common/utils/profile_util.h [new file with mode: 0644]

diff --git a/src/common/utils/profile_util.cc b/src/common/utils/profile_util.cc
new file mode 100644 (file)
index 0000000..2393ba6
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/utils/profile_util.h"
+
+#include <system_info.h>
+
+#include <cstdlib>
+#include <string>
+
+namespace common_installer {
+
+TizenProfile GetTizenProfile() {
+  static TizenProfile profile = TizenProfile::UNKNOWN;
+  char* profileName;
+
+  if (__builtin_expect(profile != TizenProfile::UNKNOWN, 1))
+    return profile;
+
+  system_info_get_platform_string("http://tizen.org/feature/profile",
+      &profileName);
+  switch (*profileName) {
+    case 'm':
+    case 'M':
+      profile = TizenProfile::MOBILE;
+      break;
+    case 'w':
+    case 'W':
+      profile = TizenProfile::WEARABLE;
+      break;
+    case 't':
+    case 'T':
+      profile = TizenProfile::TV;
+      break;
+    case 'i':
+    case 'I':
+      profile = TizenProfile::IVI;
+      break;
+    default:
+      profile = TizenProfile::COMMON;
+      break;
+  }
+  free(profileName);
+
+  return profile;
+}
+
+}  // namespace common_installer
diff --git a/src/common/utils/profile_util.h b/src/common/utils/profile_util.h
new file mode 100644 (file)
index 0000000..2384212
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_UTILS_PROFILE_UTIL_H_
+#define COMMON_UTILS_PROFILE_UTIL_H_
+
+namespace common_installer {
+
+enum class TizenProfile {
+  UNKNOWN = 0,
+  MOBILE = 0x1,
+  WEARABLE = 0x2,
+  TV = 0x4,
+  IVI = 0x8,
+  COMMON = 0x10,
+};
+
+TizenProfile GetTizenProfile();
+
+}  // namespace common_installer
+
+#endif  // COMMON_UTILS_PROFILE_UTIL_H_