[HAM] change start() to enable to set options - interval and period
authorPiotr Czaja <p.czaja@samsung.com>
Wed, 13 Jan 2016 14:01:30 +0000 (15:01 +0100)
committerPiotr Czaja <p.czaja@samsung.com>
Thu, 14 Jan 2016 13:58:24 +0000 (14:58 +0100)
Note:
This changes weren't tested yet.
There is no Tizen 3.0 emulator available now.

Change-Id: I23b2600dd9b67f39d03405f69f68a8aa863951f6
Signed-off-by: Piotr Czaja <p.czaja@samsung.com>
src/humanactivitymonitor/humanactivitymonitor_api.js
src/humanactivitymonitor/humanactivitymonitor_instance.cc
src/humanactivitymonitor/humanactivitymonitor_manager.cc
src/humanactivitymonitor/humanactivitymonitor_manager.h

index b99ec9605e1008c1cfdfcd6701df580731690bf6..5e2e0ac7eaa480238d0828b65a0810eae196f207 100755 (executable)
@@ -139,17 +139,50 @@ function stopListener(listenerId, method, data) {
 HumanActivityMonitorManager.prototype.start = function(type, changedCallback) {
   var args = validator_.validateArgs(arguments, [
     {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)},
-    {name: 'changedCallback', type: types_.FUNCTION, optional: true, nullable: true}
+    {name: 'changedCallback', type: types_.FUNCTION, optional: true, nullable: true},
+    {name : 'option', type : types_.DICTIONARY, optional : true, nullable : true}
   ]);
 
   var listenerId = 'HumanActivityMonitor_'  + args.type;
+  var callbackInterval = null, sampleInterval = null;
+
+  switch (args.type) {
+  case HumanActivityType.GPS:
+    callbackInterval = !type_.isNullOrUndefined(args.option) ?
+        args.option.callbackInterval : 120000;
+    sampleInterval = !type_.isNullOrUndefined(args.option) ?
+        args.option.sampleInterval : 1000;
+    if (callbackInterval < 120000 || callbackInterval > 600000) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
+                                'callbackInterval is out of range');
+    }
+    if (sampleInterval < 1000 || sampleInterval > 120000) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
+                                'sampleInterval is out of range');
+    }
+    break
+  case HumanActivityType.HRM:
+    callbackInterval = !type_.isNullOrUndefined(args.option) ?
+        args.option.callbackInterval : 100;
+    if (callbackInterval < 10 || callbackInterval > 1000) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
+                                'callbackInterval is out of range');
+    }
+    break
+  }
 
+  console.log("callbackInterval = " + callbackInterval + ", sampleInterval = " + sampleInterval);
   startListener(listenerId,
                 function(result) {
                   native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result));
                 },
                 'HumanActivityMonitorManager_start',
-                { type: args.type, listenerId: listenerId });
+                { type: args.type,
+                  listenerId: listenerId,
+                  callbackInterval: callbackInterval,
+                  sampleInterval: sampleInterval
+                }
+               );
 };
 
 HumanActivityMonitorManager.prototype.stop = function(type) {
index 48af5e0b3c4e549ac6d3eed45cd337048bd9d0c3..2b6ca2242abab91797253ab9ae88b31f20aa9feb 100755 (executable)
@@ -165,7 +165,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStart(
     Instance::PostMessage(this, data->serialize().c_str());
   };
 
-  result = manager_->SetListener(type, cb);
+  result = manager_->SetListener(type, cb, args);
   if (result) {
     ReportSuccess(out);
   } else {
index 068f221ff253ecb2fa0a9b81af91dcac25e37b8c..ab29a61f07f059b747418948f44ec38a6480abfb 100755 (executable)
@@ -88,7 +88,7 @@ PlatformResult HumanActivityMonitorManager::IsSupported(
 }
 
 PlatformResult HumanActivityMonitorManager::SetListener(
-    const std::string& type, JsonCallback callback) {
+    const std::string& type , JsonCallback callback, const picojson::value& args) {
 
   PlatformResult result = IsSupported(type);
   if (!result) {
@@ -104,11 +104,11 @@ PlatformResult HumanActivityMonitorManager::SetListener(
   }
 
   if (type == kActivityTypeHrm) {
-    return SetHrmListener(callback);
+    return SetHrmListener(callback, args);
   }
 
   if (type == kActivityTypeGps) {
-    return SetGpsListener(callback);
+    return SetGpsListener(callback, args);
   }
 
   return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
@@ -234,7 +234,7 @@ void HumanActivityMonitorManager::OnWristUpEvent(gesture_type_e gesture,
 
 // HRM
 PlatformResult HumanActivityMonitorManager::SetHrmListener(
-    JsonCallback callback) {
+    JsonCallback callback, const picojson::value& args) {
   LoggerD("Enter");
   sensor_h hrm_sensor;
   int ret;
@@ -253,8 +253,11 @@ PlatformResult HumanActivityMonitorManager::SetHrmListener(
                           ("Failed to create HRM sensor listener, error: %d",ret));
   }
 
+  int callbackInterval = static_cast<int>(args.get("callbackInterval").get<double>());
+  LoggerD("callbackInterval: %d", callbackInterval);
+
   ret = sensor_listener_set_event_cb(hrm_sensor_listener_,
-                                     0,
+                                     callbackInterval,
                                      OnHrmSensorEvent,
                                      this);
   if (ret != SENSOR_ERROR_NONE) {
@@ -385,7 +388,7 @@ PlatformResult HumanActivityMonitorManager::GetHrmData(picojson::value* data) {
 
 // GPS
 PlatformResult HumanActivityMonitorManager::SetGpsListener(
-    JsonCallback callback) {
+    JsonCallback callback, const picojson::value& args) {
   LoggerD("Enter");
   int ret;
 
@@ -396,10 +399,14 @@ PlatformResult HumanActivityMonitorManager::SetGpsListener(
                           ("Failed to create location manager, error: %d",ret));
   }
 
+  int callbackInterval = static_cast<int>(args.get("callbackInterval").get<double>()/1000);
+  int sampleInterval = static_cast<int>(args.get("sampleInterval").get<double>()/1000);
+  LoggerD("callbackInterval: %d, sampleInterval: %d", callbackInterval, sampleInterval);
+
   ret = location_manager_set_location_batch_cb(location_handle_,
                                                OnGpsEvent,
-                                               1, // batch_interval
-                                               120, // batch_period
+                                               sampleInterval, // batch_interval
+                                               callbackInterval, // batch_period
                                                this);
   if (ret != LOCATIONS_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
index 38da4d3964bb4ba0e4dc4491d4668cfd177a306b..9d194683a0427e949ca9bc821be7ceefda4e37a6 100755 (executable)
@@ -46,7 +46,7 @@ class HumanActivityMonitorManager {
   common::PlatformResult Init();
 
   common::PlatformResult SetListener(const std::string& type,
-                                     JsonCallback callback);
+      JsonCallback callback, const picojson::value& args);
   common::PlatformResult UnsetListener(const std::string& type);
 
   common::PlatformResult GetHumanActivityData(const std::string& type,
@@ -64,14 +64,14 @@ class HumanActivityMonitorManager {
                              gesture_error_e error,
                              void* user_data);
   // HRM
-  common::PlatformResult SetHrmListener(JsonCallback callback);
+  common::PlatformResult SetHrmListener(JsonCallback callback, const picojson::value& args);
   common::PlatformResult UnsetHrmListener();
   static void OnHrmSensorEvent(sensor_h sensor,
                                sensor_event_s *event,
                                void *user_data);
   common::PlatformResult GetHrmData(picojson::value* data);
   // GPS
-  common::PlatformResult SetGpsListener(JsonCallback callback);
+  common::PlatformResult SetGpsListener(JsonCallback callback, const picojson::value& args);
   common::PlatformResult UnsetGpsListener();
   static void OnGpsEvent(int num_of_location, void *user_data);
   common::PlatformResult GetGpsData(picojson::value* data);