[Systeminfo] added array properties handling
authorPiotr Kosko <p.kosko@samsung.com>
Wed, 17 Dec 2014 10:44:16 +0000 (11:44 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 18 Dec 2014 08:49:56 +0000 (09:49 +0100)
[Feature] Added getPropertyValueArray, setPropertyValueArrayChangeListener implemented.

[Verification] Code compiles without errors.
  Tested in console. All methods work fine.

Change-Id: Ibbc5788198104579b78941acda0a9bde1c97f0be
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/systeminfo/systeminfo-utils.cpp
src/systeminfo/systeminfo-utils.h
src/systeminfo/systeminfo_api.js
src/systeminfo/systeminfo_instance.cc
src/systeminfo/systeminfo_instance.h

index ca887cff55f2a1456d3aa6ab2286e9c4fe870563..037ec9d0683cea111fd6a6a001b0f6af6f32c75e 100644 (file)
@@ -1133,7 +1133,7 @@ void SystemInfoListeners::OnBatteryChangedCallback(keynode_t* /*node*/, void* /*
 void SystemInfoListeners::OnCpuChangedCallback(void* /*event_ptr*/)
 {
     LOGD("");
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, false);
 
     if (m_cpu_load == m_last_cpu_load) {
         return;
@@ -1147,7 +1147,7 @@ void SystemInfoListeners::OnCpuChangedCallback(void* /*event_ptr*/)
 void SystemInfoListeners::OnStorageChangedCallback(void* /*event_ptr*/)
 {
     LOGD("");
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false);
 
     if (m_available_capacity_internal == m_last_available_capacity_internal) {
         return;
@@ -1162,7 +1162,7 @@ void SystemInfoListeners::OnStorageChangedCallback(void* /*event_ptr*/)
 void SystemInfoListeners::OnMmcChangedCallback(keynode_t* /*node*/, void* /*event_ptr*/)
 {
     LOGD("");
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false);
 
     if (m_available_capacity_mmc == m_last_available_capacity_mmc) {
         return;
@@ -1563,40 +1563,57 @@ unsigned long SysteminfoUtils::GetCount(const std::string& property)
     return count;
 }
 
-picojson::value SysteminfoUtils::GetPropertyValue(const std::string& property)
+picojson::value SysteminfoUtils::GetPropertyValue(const std::string& property, bool is_array_type)
 {
     LOGD("Entered getPropertyValue");
-    picojson::value result = picojson::value(picojson::object());
-    picojson::object& result_obj = result.get<picojson::object>();
-    if ("BATTERY" == property){
-        ReportBattery(result_obj);
-    } else if ("CPU" == property) {
-        ReportCpu(result_obj);
-    } else if ("STORAGE" == property) {
-        ReportStorage(result_obj);
-    } else if ("DISPLAY" == property) {
-        ReportDisplay(result_obj);
-    } else if ("DEVICE_ORIENTATION" == property) {
-        ReportDeviceOrientation(result_obj);
-    } else if ("BUILD" == property) {
-        ReportBuild(result_obj);
-    } else if ("LOCALE" == property) {
-        ReportLocale(result_obj);
-    } else if ("NETWORK" == property) {
-        ReportNetwork(result_obj);
-    } else if ("WIFI_NETWORK" == property) {
-        ReportWifiNetwork(result_obj);
-    } else if ("CELLULAR_NETWORK" == property) {
-        ReportCellularNetwork(result_obj);
-    } else if ("SIM" == property) {
-        ReportSim(result_obj);
-    } else if ("PERIPHERAL" == property) {
-        ReportPeripheral(result_obj);
-    } else {
-        LOGD("Property with given id is not supported");
-        throw NotSupportedException("Property with given id is not supported");
+
+    picojson::value array_result = picojson::value(picojson::object());
+    picojson::object& array_result_obj = array_result.get<picojson::object>();
+    picojson::array& array = array_result_obj.insert(
+            std::make_pair("array", picojson::value(picojson::array()))).
+                    first->second.get<picojson::array>();
+
+    unsigned long property_count = SysteminfoUtils::GetCount(property);
+
+    for (int i = 0; i < property_count; i++) {
+        picojson::value result = picojson::value(picojson::object());
+        picojson::object& result_obj = result.get<picojson::object>();
+
+        if ("BATTERY" == property){
+            ReportBattery(result_obj);
+        } else if ("CPU" == property) {
+            ReportCpu(result_obj);
+        } else if ("STORAGE" == property) {
+            ReportStorage(result_obj);
+        } else if ("DISPLAY" == property) {
+            ReportDisplay(result_obj);
+        } else if ("DEVICE_ORIENTATION" == property) {
+            ReportDeviceOrientation(result_obj);
+        } else if ("BUILD" == property) {
+            ReportBuild(result_obj);
+        } else if ("LOCALE" == property) {
+            ReportLocale(result_obj);
+        } else if ("NETWORK" == property) {
+            ReportNetwork(result_obj);
+        } else if ("WIFI_NETWORK" == property) {
+            ReportWifiNetwork(result_obj);
+        } else if ("CELLULAR_NETWORK" == property) {
+            ReportCellularNetwork(result_obj);
+        } else if ("SIM" == property) {
+            ReportSim(result_obj, i);
+        } else if ("PERIPHERAL" == property) {
+            ReportPeripheral(result_obj);
+        } else {
+            LOGD("Property with given id is not supported");
+            throw NotSupportedException("Property with given id is not supported");
+        }
+        if (!is_array_type) {
+            return result;
+        } else {
+            array.push_back(result);
+        }
     }
-    return result;
+    return array_result;
 }
 
 void SysteminfoUtils::ReportBattery(picojson::object& out) {
@@ -2180,9 +2197,9 @@ void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void */
     sim_mgr.TryReturn();
 }
 
-void SysteminfoUtils::ReportSim(picojson::object& out) {
+void SysteminfoUtils::ReportSim(picojson::object& out, unsigned long count) {
 
-    sim_mgr.GatherSimInformation(system_info_listeners.GetTapiHandle(), &out);
+    sim_mgr.GatherSimInformation(system_info_listeners.GetTapiHandles()[count], &out);
 }
 
 void SysteminfoUtils::ReportPeripheral(picojson::object& out) {
index b61a5d9acbba0f4ecb9bb335758d372eafb5a77e..33a25f830ef6ff03b6ab84a2f684b849c4ad5b9e 100644 (file)
@@ -39,7 +39,7 @@ public:
     static long long GetTotalMemory();
     static long long GetAvailableMemory();
     static unsigned long GetCount(const std::string& property);
-    static picojson::value GetPropertyValue(const std::string& prop);
+    static picojson::value GetPropertyValue(const std::string& prop, bool is_array_type);
 
     static void RegisterBatteryListener(const SysteminfoUtilsCallback& callback);
     static void UnregisterBatteryListener();
@@ -74,7 +74,7 @@ private:
     static void ReportNetwork(picojson::object& out);
     static void ReportWifiNetwork(picojson::object& out);
     static void ReportCellularNetwork(picojson::object& out);
-    static void ReportSim(picojson::object& out);
+    static void ReportSim(picojson::object& out, unsigned long count);
     static void ReportPeripheral(picojson::object& out);
 
     static void ReportStorage(picojson::object& out);
index 25cdb0a0e91c2fa9cfc5824bf59ae80891ebb442..0a9c8ca9627f492978fa2731f080ff9b4a9083af 100644 (file)
@@ -213,7 +213,7 @@ var _call = C.getCall('SystemInfo');
 
 /**
  * It is singleton object to keep and invoke callbacks.
- * 
+ *
  */
 var Callbacks = (function () {
     var _collection = {};
@@ -851,43 +851,76 @@ SystemInfo.prototype.getCapability = function() {
     }
 };
 
-SystemInfo.prototype.getPropertyValue = function() {
-    var args = AV.validateMethod(arguments, [
-             {
-                 name : 'property',
-                 type : AV.Types.ENUM,
-                 values : T.getValues(SystemInfoPropertyId)
-             },
-             {
-                 name : 'successCallback',
-                 type : AV.Types.FUNCTION
-             },
-             {
-                 name : 'errorCallback',
-                 type : AV.Types.FUNCTION,
-                 optional : true,
-                 nullable : true
-             }
-             ]);
 
-    var propObject = _propertyContainer[args.property];
-    if (!propObject) {
-        C.throwTypeMismatch('Property with id: ' + args.property + ' is not supported.');
+var _createProperty = function (property, data) {
+    if (_propertyContainer[property]){
+        return new _propertyContainer[property].constructor(data);
+    } else {
+        C.throwTypeMismatch('Property with id: ' + property + ' is not supported.');
     }
+};
 
-    var callback = function(result) {
-        if (C.isFailure(result)) {
-            setTimeout(function() {
-                C.callIfPossible(args.errorCallback, C.getErrorObject(result));
-            }, 0);
-        } else {
-            var resultProp = _createProperty(args.property, C.getResultObject(result));
-            args.successCallback(resultProp);
+var _createPropertyArray = function (property, data) {
+    var jsonArray = data.array;
+    var propertyArray = [];
+    if (_propertyContainer[property]){
+        var arrayLength = jsonArray.length;
+        for (var i = 0; i < arrayLength; i++) {
+            propertyArray.push(new _propertyContainer[property].constructor(jsonArray[i]));
         }
+    } else {
+        C.throwTypeMismatch('Property with id: ' + property + ' is not supported.');
+    }
+    return propertyArray;
+};
+
+
+var getPropertyFunction = function(cppLabel, objectCreateFunction) {
+    return function() {
+        var args = AV.validateMethod(arguments, [
+                 {
+                     name : 'property',
+                     type : AV.Types.ENUM,
+                     values : T.getValues(SystemInfoPropertyId)
+                 },
+                 {
+                     name : 'successCallback',
+                     type : AV.Types.FUNCTION
+                 },
+                 {
+                     name : 'errorCallback',
+                     type : AV.Types.FUNCTION,
+                     optional : true,
+                     nullable : true
+                 }
+                 ]);
+
+        var propObject = _propertyContainer[args.property];
+        if (!propObject) {
+            C.throwTypeMismatch('Property with id: ' + args.property + ' is not supported.');
+        }
+
+        var callback = function(result) {
+            if (C.isFailure(result)) {
+                setTimeout(function() {
+                    C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+                }, 0);
+            } else {
+                var resultProp = objectCreateFunction(args.property, C.getResultObject(result));
+                args.successCallback(resultProp);
+            }
+        };
+
+        _call(cppLabel, {property: args.property}, callback);
     };
+}
+
+SystemInfo.prototype.getPropertyValue =
+    getPropertyFunction('SystemInfo_getPropertyValue', _createProperty);
+
+SystemInfo.prototype.getPropertyValueArray =
+    getPropertyFunction('SystemInfo_getPropertyValueArray', _createPropertyArray);
 
-    _call('SystemInfo_getPropertyValue', {property: args.property}, callback);
-};
 
 //SystemInfo helpers ///////////////////////////////////////////////////
 var _batteryStr = SystemInfoPropertyId.BATTERY;
@@ -905,18 +938,10 @@ var _peripheralStr = SystemInfoPropertyId.PERIPHERAL;
 
 var _nextId = 0;
 
-var _createProperty = function (property, data) {
-    if (_propertyContainer[property]){
-        return new _propertyContainer[property].constructor(data);
-    } else {
-        C.throwTypeMismatch('Property with id: ' + property + ' is not supported.');
-    }
-};
 
 function _systeminfoBatteryListenerCallback(event) {
     var property = _batteryStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
@@ -926,6 +951,9 @@ function _systeminfoBatteryListenerCallback(event) {
                     (propObj.level <= listener.lowThreshold)) ||
                     (T.isUndefined(listener.highThreshold) ||
                             (propObj.level >= listener.highThreshold));
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             if (executeCall) {
                 listener.callback(propObj);
             }
@@ -936,7 +964,6 @@ function _systeminfoBatteryListenerCallback(event) {
 function _systeminfoCpuListenerCallback(event) {
     var property = _cpuStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
@@ -946,6 +973,9 @@ function _systeminfoCpuListenerCallback(event) {
                     (propObj.load <= listener.lowThreshold)) ||
                     (T.isUndefined(listener.highThreshold) ||
                             (propObj.load >= listener.highThreshold));
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             if (executeCall) {
                 listener.callback(propObj);
             }
@@ -956,11 +986,14 @@ function _systeminfoCpuListenerCallback(event) {
 function _systeminfoStorageListenerCallback(event) {
     var property = _storageStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -969,7 +1002,6 @@ function _systeminfoStorageListenerCallback(event) {
 function _systeminfoDisplayListenerCallback(event) {
     var property = _displayStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
@@ -979,6 +1011,9 @@ function _systeminfoDisplayListenerCallback(event) {
                     (propObj.brightness <= listener.lowThreshold)) ||
                     (T.isUndefined(listener.highThreshold) ||
                             (propObj.brightness >= listener.highThreshold));
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             if (executeCall) {
                 listener.callback(propObj);
             }
@@ -989,11 +1024,14 @@ function _systeminfoDisplayListenerCallback(event) {
 function _systeminfoDeviceOrientationListenerCallback(event) {
     var property = _deviceOrientationStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1002,11 +1040,14 @@ function _systeminfoDeviceOrientationListenerCallback(event) {
 function _systeminfoLocaleListenerCallback(event) {
     var property = _localeStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1015,11 +1056,14 @@ function _systeminfoLocaleListenerCallback(event) {
 function _systeminfoNetworkListenerCallback(event) {
     var property = _networkStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1028,11 +1072,14 @@ function _systeminfoNetworkListenerCallback(event) {
 function _systeminfoWifiNetworkListenerCallback(event) {
     var property = _wifiNetworkStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1041,11 +1088,14 @@ function _systeminfoWifiNetworkListenerCallback(event) {
 function _systeminfoCellularNetworkListenerCallback(event) {
     var property = _cellularNetworkStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1054,11 +1104,14 @@ function _systeminfoCellularNetworkListenerCallback(event) {
 function _systeminfoSimListenerCallback(event) {
     var property = _simStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1067,11 +1120,14 @@ function _systeminfoSimListenerCallback(event) {
 function _systeminfoPeripheralListenerCallback(event) {
     var property = _peripheralStr;
     var eventObj = JSON.parse(event);
-    var propObj = _createProperty(property, eventObj.result);
     var callbacks = _propertyContainer[property].callbacks;
 
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
             callbacks[watchId].callback(propObj);
         }
     }
@@ -1226,47 +1282,54 @@ var _unregisterListener = function (watchId, isTimeout) {
     }
 };
 
-SystemInfo.prototype.addPropertyValueChangeListener = function() {
-    var args = AV.validateMethod(arguments, [
-             {
-                 name : 'property',
-                 type : AV.Types.ENUM,
-                 values : T.getValues(SystemInfoPropertyId)
-             },
-             {
-                 name : 'successCallback',
-                 type : AV.Types.FUNCTION
-             },
-             {
-                 name : 'options',
-                 type : AV.Types.DICTIONARY,
-                 optional : true,
-                 nullable : true
-             },
-             {
-                 name : 'errorCallback',
-                 type : AV.Types.FUNCTION,
-                 optional : true,
-                 nullable : true
-             }
-             ]);
+var getListenerFunction = function (isArray) {
+    return function() {
+        var args = AV.validateMethod(arguments, [
+                 {
+                     name : 'property',
+                     type : AV.Types.ENUM,
+                     values : T.getValues(SystemInfoPropertyId)
+                 },
+                 {
+                     name : 'successCallback',
+                     type : AV.Types.FUNCTION
+                 },
+                 {
+                     name : 'options',
+                     type : AV.Types.DICTIONARY,
+                     optional : true,
+                     nullable : true
+                 },
+                 {
+                     name : 'errorCallback',
+                     type : AV.Types.FUNCTION,
+                     optional : true,
+                     nullable : true
+                 }
+                 ]);
+
+        var listener = {
+                callback      : args.successCallback,
+                isArrayType     : isArray,
+                highThreshold : !T.isNullOrUndefined(args.options) ?
+                        args.options.highThreshold : undefined,
+                        lowThreshold  : !T.isNullOrUndefined(args.options) ?
+                                args.options.lowThreshold : undefined
+        };
+        var watchId = _registerListener(args.property, listener, args.errorCallback);
+
+        var timeout = !T.isNullOrUndefined(args.options) ? args.options.timeout : undefined;
+        if (!T.isUndefined(timeout) ){
+            setTimeout(function(){_unregisterListener(watchId, true);}, timeout);
+        }
 
-    var listener = {
-            callback      : args.successCallback,
-            highThreshold : !T.isNullOrUndefined(args.options) ?
-                    args.options.highThreshold : undefined,
-                    lowThreshold  : !T.isNullOrUndefined(args.options) ?
-                            args.options.lowThreshold : undefined
+        return watchId;
     };
-    var watchId = _registerListener(args.property, listener, args.errorCallback);
+};
 
-    var timeout = !T.isNullOrUndefined(args.options) ? args.options.timeout : undefined;
-    if (!T.isUndefined(timeout) ){
-        setTimeout(function(){_unregisterListener(watchId, true);}, timeout);
-    }
+SystemInfo.prototype.addPropertyValueChangeListener = getListenerFunction(false);
 
-    return watchId;
-};
+SystemInfo.prototype.addPropertyValueArrayChangeListener = getListenerFunction(true);
 
 SystemInfo.prototype.removePropertyValueChangeListener = function() {
     var args = AV.validateMethod(arguments, [
index 932cddb30cd248bb4e8ccf9de85d523c111e5f6b..a95866d4477d77d8f2b20f82b05a3e05de7856d1 100644 (file)
@@ -67,6 +67,7 @@ SysteminfoInstance::SysteminfoInstance() {
   #define REGISTER_ASYNC(c,x) \
     RegisterHandler(c, std::bind(&SysteminfoInstance::x, this, _1, _2));
   REGISTER_ASYNC("SystemInfo_getPropertyValue", GetPropertyValue);
+  REGISTER_ASYNC("SystemInfo_getPropertyValueArray", GetPropertyValueArray);
   #undef REGISTER_ASYNC
 }
 
@@ -238,7 +239,36 @@ void SysteminfoInstance::GetPropertyValue(const picojson::value& args, picojson:
     auto get = [this, prop_id, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
         LoggerD("Getting");
         try {
-            picojson::value result = SysteminfoUtils::GetPropertyValue(prop_id);
+            picojson::value result = SysteminfoUtils::GetPropertyValue(prop_id, false);
+            ReportSuccess(result, response->get<picojson::object>());
+        } catch (const PlatformException& e) {
+            ReportError(e,response->get<picojson::object>());
+        }
+    };
+
+    auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+        LoggerD("Getting response");
+        picojson::object& obj = response->get<picojson::object>();
+        obj.insert(std::make_pair("callbackId", callback_id));
+        obj.insert(std::make_pair("cmd", picojson::value("SystemInfo_getPropertyValue")));
+        PostMessage(response->serialize().c_str());
+    };
+
+    TaskQueue::GetInstance().Queue<picojson::value>
+        (get, get_response, std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
+}
+
+void SysteminfoInstance::GetPropertyValueArray(const picojson::value& args, picojson::object& out) {
+    LoggerD("");
+    const double callback_id = args.get("callbackId").get<double>();
+
+    const std::string& prop_id = args.get("property").get<std::string>();
+    LoggerD("Getting property arrray with id: %s ", prop_id.c_str());
+
+    auto get = [this, prop_id, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+        LoggerD("Getting");
+        try {
+            picojson::value result = SysteminfoUtils::GetPropertyValue(prop_id, true);
             ReportSuccess(result, response->get<picojson::object>());
         } catch (const PlatformException& e) {
             ReportError(e,response->get<picojson::object>());
@@ -400,7 +430,7 @@ void OnBatteryChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdBattery);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdBattery);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdBattery, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -413,7 +443,7 @@ void OnCpuChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdCpu);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -426,7 +456,7 @@ void OnStorageChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdStorage);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -439,7 +469,7 @@ void OnDisplayChangedCallback()
                 std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdDisplay);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdDisplay);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdDisplay, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -452,7 +482,7 @@ void OnDeviceOrientationChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdDeviceOrientation);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdDeviceOrientation);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdDeviceOrientation, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -465,7 +495,7 @@ void OnLocaleChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdLocale);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdLocale);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdLocale, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -478,7 +508,7 @@ void OnNetworkChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdNetwork);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdNetwork);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdNetwork, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -491,7 +521,7 @@ void OnWifiNetworkChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdWifiNetwork);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdWifiNetwork);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdWifiNetwork, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -504,7 +534,7 @@ void OnCellularNetworkChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdCellularNetwork);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCellularNetwork);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdCellularNetwork, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
@@ -517,7 +547,7 @@ void OnPeripheralChangedCallback()
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
     response->get<picojson::object>()["propertyId"] = picojson::value(kPropertyIdPeripheral);
 
-    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdPeripheral);
+    picojson::value result = SysteminfoUtils::GetPropertyValue(kPropertyIdPeripheral, true);
     ReportSuccess(result,response->get<picojson::object>());
 
     SysteminfoInstance::getInstance().PostMessage(response->serialize().c_str());
index 53233d68f7fd4aec127e14cf8f12aee8a8b32c1c..f2b961589c81d8ac49ad323d188eb68347a3bc58 100644 (file)
@@ -23,6 +23,7 @@ private:
     void GetCapabilities(const picojson::value& args, picojson::object& out);
     void GetCapability(const picojson::value& args, picojson::object& out);
     void GetPropertyValue(const picojson::value& args, picojson::object& out);
+    void GetPropertyValueArray(const picojson::value& args, picojson::object& out);
     void AddPropertyValueChangeListener(const picojson::value& args, picojson::object& out);
     void RemovePropertyValueChangeListener(const picojson::value& args, picojson::object& out);
     void GetTotalMemory(const picojson::value& args, picojson::object& out);