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;
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;
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;
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) {
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) {
/**
* It is singleton object to keep and invoke callbacks.
- *
+ *
*/
var Callbacks = (function () {
var _collection = {};
}
};
-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;
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) {
(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);
}
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) {
(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);
}
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);
}
}
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) {
(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);
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
};
-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, [
#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
}
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>());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());