}
}
+var GPSListener = null;
+function GPSCallback(result) {
+ if (GPSListener) {
+ GPSListener(result);
+ }
+}
+
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: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true},
{name : 'option', type : types_.DICTIONARY, optional : true, nullable : true}
]);
break;
}
- var listener = HumanActivityType.PEDOMETER === args.type ? pedometerCallback : function(result) {
- native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result));
- };
+ var listener = null;
+ switch (args.type) {
+ case HumanActivityType.PEDOMETER:
+ listener = pedometerCallback;
+ break;
+ case HumanActivityType.GPS:
+ listener = GPSCallback;
+ break;
+ default:
+ listener = function(result) {
+ native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result));
+ };
+ }
console.log("callbackInterval = " + callbackInterval + ", sampleInterval = " + sampleInterval);
startListener(listenerId,
if (HumanActivityType.PEDOMETER === args.type) {
pedometerListener = args.changedCallback;
}
+
+ if (HumanActivityType.GPS === args.type) {
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ } else {
+ native_.callIfPossible(args.changedCallback, convertActivityData(args.type, result));
+ }
+ };
+
+ GPSListener = callback;
+ }
};
HumanActivityMonitorManager.prototype.stop = function(type) {
if (HumanActivityType.PEDOMETER === args.type) {
pedometerListener = null;
}
+
+ if (HumanActivityType.GPS === args.type) {
+ GPSListener = null;
+ }
};
HumanActivityMonitorManager.prototype.setAccumulativePedometerListener = function() {
int sample_interval = static_cast<int>(args.get(kSampleInterval).get<double>() / 1000);
LoggerD("callbackInterval: %d, sampleInterval: %d", callback_interval, sample_interval);
+ ret = location_manager_set_setting_changed_cb(LOCATIONS_METHOD_GPS,
+ OnGpsSettingEvent,
+ this);
+ if (LOCATIONS_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Failed to set setting listener",
+ ("Failed to set setting listener, error: %d (%s)", ret, get_error_message(ret)));
+ }
+
ret = location_manager_set_location_batch_cb(handle_,
OnGpsEvent,
sample_interval, // batch_interval
}
private:
+ static void OnGpsSettingEvent(location_method_e method, bool enable, void *user_data) {
+ ScopeLogger();
+
+ if (LOCATIONS_METHOD_GPS != method) {
+ LoggerD("Location method different from GPS");
+ return;
+ }
+
+ auto monitor = static_cast<GpsMonitor*>(user_data);
+ auto& callback = monitor->event_callback();
+
+ if (!callback) {
+ LOGGER(ERROR) << "No GPS event callback registered, skipping.";
+ return;
+ }
+
+ if (!enable) {
+ picojson::value val{picojson::object{}};
+ auto& obj = val.get<picojson::object>();
+
+ LogAndReportError(
+ PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "GPS service is not available"),
+ &obj, ("GPS service is not available"));
+
+ callback(&val);
+ }
+ }
+
static void OnGpsEvent(int num_of_location, void* user_data) {
ScopeLogger();