[SystemInfo] Fix for systemInfo CameraFlash
[platform/core/api/webapi-plugins.git] / src / systeminfo / systeminfo-utils.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_UTILS_H__
18 #define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_UTILS_H__
19
20 #include <string>
21 #include <functional>
22 #include "common/picojson.h"
23 #include "common/platform_result.h"
24
25 namespace extension {
26 namespace systeminfo {
27
28 struct CpuInfo {
29   long long usr;
30   long long nice;
31   long long system;
32   long long idle;
33   double load;
34 };
35
36 class SysteminfoInstance;
37
38 typedef std::function<void(SysteminfoInstance& instance)> SysteminfoUtilsCallback;
39
40 class SysteminfoUtils {
41  public:
42   static common::PlatformResult GetTotalMemory(long long& result);
43   static common::PlatformResult GetAvailableMemory(long long& result);
44   static common::PlatformResult GetCount(const std::string& property, unsigned long& ret);
45   static common::PlatformResult GetPropertyValue(
46       const std::string& prop, bool is_array_type, picojson::value& res);
47
48   static common::PlatformResult RegisterBatteryListener(const SysteminfoUtilsCallback& callback,
49                                                         SysteminfoInstance& instance);
50   static common::PlatformResult UnregisterBatteryListener();
51   static common::PlatformResult RegisterCpuListener(const SysteminfoUtilsCallback& callback,
52                                                     SysteminfoInstance& instance);
53   static common::PlatformResult UnregisterCpuListener();
54   static common::PlatformResult RegisterStorageListener(const SysteminfoUtilsCallback& callback,
55                                                         SysteminfoInstance& instance);
56   static common::PlatformResult UnregisterStorageListener();
57   static common::PlatformResult RegisterDisplayListener(const SysteminfoUtilsCallback& callback,
58                                                         SysteminfoInstance& instance);
59   static common::PlatformResult UnregisterDisplayListener();
60   static common::PlatformResult RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback,
61                                                                   SysteminfoInstance& instance);
62   static common::PlatformResult UnregisterDeviceOrientationListener();
63   static common::PlatformResult RegisterLocaleListener(const SysteminfoUtilsCallback& callback,
64                                                        SysteminfoInstance& instance);
65   static common::PlatformResult UnregisterLocaleListener();
66   static common::PlatformResult RegisterNetworkListener(const SysteminfoUtilsCallback& callback,
67                                                         SysteminfoInstance& instance);
68   static common::PlatformResult UnregisterNetworkListener();
69   static common::PlatformResult RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback,
70                                                             SysteminfoInstance& instance);
71   static common::PlatformResult UnregisterWifiNetworkListener();
72   static common::PlatformResult RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback,
73                                                                 SysteminfoInstance& instance);
74   static common::PlatformResult UnregisterEthernetNetworkListener();
75   static common::PlatformResult RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback,
76                                                                 SysteminfoInstance& instance);
77   static common::PlatformResult UnregisterCellularNetworkListener();
78   static common::PlatformResult RegisterPeripheralListener(const SysteminfoUtilsCallback& callback,
79                                                            SysteminfoInstance& instance);
80   static common::PlatformResult UnregisterPeripheralListener();
81   static common::PlatformResult RegisterMemoryListener(const SysteminfoUtilsCallback& callback,
82                                                        SysteminfoInstance& instance);
83   static common::PlatformResult UnregisterMemoryListener();
84   static common::PlatformResult RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback,
85                                                        SysteminfoInstance& instance);
86   static common::PlatformResult UnregisterCameraFlashListener();
87
88  private:
89   static common::PlatformResult ReportProperty(const std::string& property, int index,
90                                                picojson::object& res_obj);
91   static common::PlatformResult ReportBattery(picojson::object& out);
92   static common::PlatformResult ReportCpu(picojson::object& out);
93
94   static common::PlatformResult ReportDisplay(picojson::object& out);
95   static common::PlatformResult ReportDeviceOrientation(picojson::object& out);
96
97   static common::PlatformResult ReportBuild(picojson::object& out);
98   static common::PlatformResult ReportLocale(picojson::object& out);
99   static common::PlatformResult ReportNetwork(picojson::object& out);
100   static common::PlatformResult ReportWifiNetwork(picojson::object& out);
101   static common::PlatformResult ReportEthernetNetwork(picojson::object& out);
102   static common::PlatformResult ReportCellularNetwork(picojson::object& out, unsigned long count);
103   static common::PlatformResult ReportSim(picojson::object& out, unsigned long count);
104   static common::PlatformResult ReportPeripheral(picojson::object& out);
105   static common::PlatformResult ReportMemory(picojson::object& out);
106   static common::PlatformResult ReportCameraFlash(picojson::object& out, unsigned long count);
107
108   static common::PlatformResult ReportStorage(picojson::object& out);
109 };
110
111 typedef unsigned char byte;
112
113 class SystemInfoDeviceCapability {
114  public:
115   static common::PlatformResult GetCapability(const std::string& key, picojson::value& result);
116   static common::PlatformResult GetValueBool(const char *key, bool* value);
117   static common::PlatformResult GetValueInt(const char *key, int* value);
118   static common::PlatformResult GetValueString(const char *key, std::string* str_value);
119
120   static common::PlatformResult IsInputKeyboardLayout(bool* result);
121   static common::PlatformResult GetOpenglesTextureFormat(std::string* result);
122   static common::PlatformResult GetPlatfomCoreCpuArch(std::string* return_value);
123   static common::PlatformResult GetPlatfomCoreFpuArch(std::string* return_value);
124   static common::PlatformResult GetProfile(std::string* return_value);
125   static common::PlatformResult GetPlatformCoreCpuFrequency(int* return_value);
126   static common::PlatformResult IsNativeOspCompatible(bool* result);
127   static common::PlatformResult GetNativeAPIVersion(std::string* return_value);
128   static common::PlatformResult GetPlatformVersionName(std::string* result);
129   static bool IsBluetoothAlwaysOn();
130   static bool IsScreen();
131 };
132
133 } // namespace systeminfo
134 } // namespace webapi
135
136 #endif // WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_UTILS_H__