[Sensor] Initial commit with stubs.
authorPiotr Kosko <p.kosko@samsung.com>
Wed, 11 Feb 2015 10:50:59 +0000 (11:50 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 12 Feb 2015 12:38:55 +0000 (21:38 +0900)
[Verification] Code compiles without errors.

Change-Id: I842792ca7c06570b06a2c5128b15a145847477a9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
packaging/webapi-plugins.spec
src/sensor/sensor.gyp [new file with mode: 0644]
src/sensor/sensor_api.js [new file with mode: 0644]
src/sensor/sensor_extension.cc [new file with mode: 0644]
src/sensor/sensor_extension.h [new file with mode: 0644]
src/sensor/sensor_instance.cc [new file with mode: 0644]
src/sensor/sensor_instance.h [new file with mode: 0644]
src/tizen-wrt.gyp

index 97d25be3a59d6f0db241231ffa3ba7028d3ccc1c..208b8bd93da119611f4f106eaf449c68fe2ed14c 100644 (file)
@@ -46,7 +46,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_push_support                0
 %define tizen_feature_sap_support                 0
 %define tizen_feature_se_support                  1
-%define tizen_feature_sensor_support              0
+%define tizen_feature_sensor_support              1
 %define tizen_feature_sound_support               1
 %define tizen_feature_system_setting_support      1
 %define tizen_feature_telephony_support           0
@@ -272,6 +272,10 @@ BuildRequires: pkgconfig(notification)
 BuildRequires:  pkgconfig(capi-media-sound-manager)
 %endif
 
+%if 0%{?tizen_feature_sensor_support}
+BuildRequires: pkgconfig(capi-system-sensor)
+%endif
+
 
 %description
 Tizen Web APIs implemented.
diff --git a/src/sensor/sensor.gyp b/src/sensor/sensor.gyp
new file mode 100644 (file)
index 0000000..dead302
--- /dev/null
@@ -0,0 +1,30 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_sensor',
+      'type': 'loadable_module',
+      'sources': [
+        'sensor_api.js',
+        'sensor_extension.cc',
+        'sensor_extension.h',
+        'sensor_instance.cc',
+        'sensor_instance.h',
+      ],
+      'includes': [
+        '../common/pkg-config.gypi',
+      ],
+      'conditions': [
+        ['tizen == 1', {
+          'variables': {
+            'packages': [
+              'capi-system-sensor',
+            ]
+          },
+        }],
+      ],
+    },
+  ],
+}
\ No newline at end of file
diff --git a/src/sensor/sensor_api.js b/src/sensor/sensor_api.js
new file mode 100644 (file)
index 0000000..52870da
--- /dev/null
@@ -0,0 +1,366 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var validator_ = xwalk.utils.validator;
+var converter_ = xwalk.utils.converter;
+var types_ = validator_.Types;
+var T_ = xwalk.utils.type;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+// Enums
+var SensorType = {
+    LIGHT : 'LIGHT',
+    MAGNETIC : 'MAGNETIC',
+    PRESSURE : 'PRESSURE',
+    PROXIMITY : 'PROXIMITY',
+    ULTRAVIOLET : 'ULTRAVIOLET'
+};
+
+var ProximityState = {
+    FAR : 'FAR',
+    NEAR : 'NEAR'
+};
+
+var MagneticSensorAccuracy = {
+    UNDEFINED : 'ACCURACY_UNDEFINED',
+    BAD : 'ACCURACY_BAD',
+    NORMAL : 'ACCURACY_NORMAL',
+    GOOD : 'ACCURACY_GOOD',
+    VERYGOOD : 'ACCURACY_VERYGOOD'
+};
+
+function SensorService() {
+};
+
+SensorService.prototype.getDefaultSensor = function() {
+    var args = validator_.validateArgs(arguments, [
+        {
+            name : 'type',
+            type : types_.ENUM,
+            values : T_.getValues(SensorType)
+        }
+    ]);
+
+    var result = native_.callSync('SensorService_getDefaultSensor', {});
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
+SensorService.prototype.getAvailableSensors = function() {
+    var result = native_.callSync('SensorService_getAvailableSensors', {});
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+    return [];
+};
+
+//////////////////////Sensor classes//////////////////////////////////////////////////////////
+//// Base Sensor class
+var Sensor = function (type) {
+    Object.defineProperties(this, {
+        sensorType : {value: type, writable: false, enumerable: true}
+    });
+};
+
+Sensor.prototype.start = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+   ]);
+
+    native_.call('Sensor_start', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+Sensor.prototype.stop = function() {
+    var result = native_.callSync('Sensor_stop', {});
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
+Sensor.prototype.setChangeListener = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type: types_.FUNCTION
+       }
+   ]);
+
+    var result = native_.callSync('Sensor_setChangeListener', {});
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
+Sensor.prototype.unsetChangeListener = function() {
+    var result = native_.callSync('Sensor_unsetChangeListener', {});
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
+//// LightSensor
+var LightSensor = function(data) {
+    Sensor.call(this, SensorType.LIGHT);
+};
+
+LightSensor.prototype = new Sensor();
+
+LightSensor.prototype.constructor = Sensor;
+
+LightSensor.prototype.getLightSensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+    native_.call('LightSensor_getData', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+//// MagneticSensor
+var MagneticSensor = function(data) {
+    Sensor.call(this, SensorType.MAGNETIC);
+};
+
+MagneticSensor.prototype = new Sensor();
+
+MagneticSensor.prototype.constructor = Sensor;
+
+MagneticSensor.prototype.getMagneticSensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+    native_.call('MagneticSensor_getData', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+//// PressureSensor
+var PressureSensor = function(data) {
+    Sensor.call(this, SensorType.PRESSURE);
+};
+
+PressureSensor.prototype = new Sensor();
+
+PressureSensor.prototype.constructor = Sensor;
+
+PressureSensor.prototype.getPressureSensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+    native_.call('PressureSensor_getData', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+//// ProximitySensor
+var ProximitySensor = function(data) {
+    Sensor.call(this, SensorType.PROXIMITY);
+};
+
+ProximitySensor.prototype = new Sensor();
+
+ProximitySensor.prototype.constructor = Sensor;
+
+ProximitySensor.prototype.getProximitySensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+    native_.call('ProximitySensor_getData', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+//// UltravioletSensor
+var UltravioletSensor = function(data) {
+    Sensor.call(this, SensorType.ULTRAVIOLET);
+};
+
+UltravioletSensor.prototype = new Sensor();
+
+UltravioletSensor.prototype.constructor = Sensor;
+
+UltravioletSensor.prototype.getUltravioletSensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+    native_.call('UltravioletSensor_getData', {},
+        function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(args.errorCallback)) {
+                    args.errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                args.successCallback();
+            }
+        }
+    );
+};
+
+////////////////////// Sensor Data classes/////////////////////////////////////////////////////
+////Base SensorData class
+var SensorData = function () {
+};
+
+//// SensorLightData
+var SensorLightData = function(data) {
+    SensorData.call(this);
+    Object.defineProperties(this, {
+        lightLevel : {value: data.lightLevel, writable: false, enumerable: true}
+    });
+};
+
+SensorLightData.prototype = new SensorData();
+
+SensorLightData.prototype.constructor = SensorData;
+
+//// SensorMagneticData
+var SensorMagneticData = function(data) {
+    SensorData.call(this);
+    Object.defineProperties(this, {
+        x : {value: data.x, writable: false, enumerable: true},
+        y : {value: data.y, writable: false, enumerable: true},
+        z : {value: data.z, writable: false, enumerable: true},
+        accuracy : {value: data.accuracy, writable: false, enumerable: true}
+    });
+};
+
+SensorMagneticData.prototype = new SensorData();
+
+SensorMagneticData.prototype.constructor = SensorData;
+
+//// SensorPressureData
+var SensorPressureData = function(data) {
+    SensorData.call(this);
+    Object.defineProperties(this, {
+        pressure : {value: data.pressure, writable: false, enumerable: true}
+    });
+};
+
+SensorPressureData.prototype = new SensorData();
+
+SensorPressureData.prototype.constructor = SensorData;
+
+//// SensorProximityData
+var SensorProximityData = function(data) {
+    SensorData.call(this);
+    Object.defineProperties(this, {
+        proximityState : {value: data.proximityState, writable: false, enumerable: true}
+    });
+};
+
+SensorProximityData.prototype = new SensorData();
+
+SensorProximityData.prototype.constructor = SensorData;
+
+//// SensorUltravioletData
+var SensorUltravioletData = function(data) {
+    SensorData.call(this);
+    Object.defineProperties(this, {
+        ultravioletLevel : {value: data.ultravioletLevel, writable: false, enumerable: true}
+    });
+};
+
+SensorUltravioletData.prototype = new SensorData();
+
+SensorUltravioletData.prototype.constructor = SensorData;
+
+// Exports
+exports = new SensorService();
diff --git a/src/sensor/sensor_extension.cc b/src/sensor/sensor_extension.cc
new file mode 100644 (file)
index 0000000..7b06fb6
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sensor/sensor_extension.h"
+#include "sensor/sensor_instance.h"
+
+// This will be generated from sensor_api.js
+extern const char kSource_sensor_api[];
+
+common::Extension* CreateExtension() {
+  return new SensorExtension;
+}
+
+SensorExtension::SensorExtension() {
+  SetExtensionName("tizen.sensorservice");
+  SetJavaScriptAPI(kSource_sensor_api);
+}
+
+SensorExtension::~SensorExtension() {}
+
+common::Instance* SensorExtension::CreateInstance() {
+  return &extension::sensor::SensorInstance::getInstance();
+}
diff --git a/src/sensor/sensor_extension.h b/src/sensor/sensor_extension.h
new file mode 100644 (file)
index 0000000..6fc7c1a
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SENSOR_SENSOR_EXTENSION_H_
+#define SENSOR_SENSOR_EXTENSION_H_
+
+#include "common/extension.h"
+
+class SensorExtension : public common::Extension {
+ public:
+  SensorExtension();
+  virtual ~SensorExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif // SENSOR_SENSOR_EXTENSION_H_
diff --git a/src/sensor/sensor_instance.cc b/src/sensor/sensor_instance.cc
new file mode 100644 (file)
index 0000000..685ad70
--- /dev/null
@@ -0,0 +1,102 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sensor/sensor_instance.h"
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/platform_exception.h"
+
+namespace extension {
+namespace sensor {
+
+using namespace common;
+
+SensorInstance& SensorInstance::getInstance() {
+  static SensorInstance instance;
+  return instance;
+}
+
+SensorInstance::SensorInstance() {
+  using namespace std::placeholders;
+#define REGISTER_SYNC(c,x) \
+    RegisterSyncHandler(c, std::bind(&SensorInstance::x, this, _1, _2));
+  REGISTER_SYNC("SensorService_getDefaultSensor", GetDefaultSensor);
+  REGISTER_SYNC("SensorService_getAvailableSensors", GetAvailableSensors);
+  REGISTER_SYNC("Sensor_stop", SensorStop);
+  REGISTER_SYNC("Sensor_setChangeListener", SensorSetChangeListener);
+  REGISTER_SYNC("Sensor_unsetChangeListener", SensorUnsetChangeListener);
+#undef REGISTER_SYNC
+#define REGISTER_ASYNC(c,x) \
+    RegisterHandler(c, std::bind(&SensorInstance::x, this, _1, _2));
+  REGISTER_ASYNC("Sensor_start", SensorStart);
+  REGISTER_ASYNC("LightSensor_getData", LightSensorGetData);
+  REGISTER_ASYNC("MagneticSensor_getData", MagneticSensorGetData);
+  REGISTER_ASYNC("PressureSensor_getData", PressureSensorGetData);
+  REGISTER_ASYNC("ProximitySensor_getData", ProximitySensorGetData);
+  REGISTER_ASYNC("UltravioletSensor_getData", UltravioletSensorGetData);
+
+#undef REGISTER_ASYNC
+}
+
+SensorInstance::~SensorInstance() {
+}
+
+void SensorInstance::GetDefaultSensor(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::GetAvailableSensors(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::SensorStop(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::SensorSetChangeListener(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::SensorUnsetChangeListener(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::SensorStart(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::LightSensorGetData(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::MagneticSensorGetData(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::PressureSensorGetData(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::ProximitySensorGetData(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+void SensorInstance::UltravioletSensorGetData(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+  //empty stub
+}
+
+} // namespace sensor
+} // namespace extension
diff --git a/src/sensor/sensor_instance.h b/src/sensor/sensor_instance.h
new file mode 100644 (file)
index 0000000..28f82a2
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SENSOR_SENSOR_INSTANCE_H_
+#define SENSOR_SENSOR_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace sensor {
+
+class SensorInstance : public common::ParsedInstance {
+ public:
+  static SensorInstance& getInstance();
+
+ private:
+  SensorInstance();
+  virtual ~SensorInstance();
+
+  void GetDefaultSensor(const picojson::value& args, picojson::object& out);
+  void GetAvailableSensors(const picojson::value& args, picojson::object& out);
+  void SensorStop(const picojson::value& args, picojson::object& out);
+  void SensorSetChangeListener(const picojson::value& args, picojson::object& out);
+  void SensorUnsetChangeListener(const picojson::value& args, picojson::object& out);
+  void SensorStart(const picojson::value& args, picojson::object& out);
+  void LightSensorGetData(const picojson::value& args, picojson::object& out);
+  void MagneticSensorGetData(const picojson::value& args, picojson::object& out);
+  void PressureSensorGetData(const picojson::value& args, picojson::object& out);
+  void ProximitySensorGetData(const picojson::value& args, picojson::object& out);
+  void UltravioletSensorGetData(const picojson::value& args, picojson::object& out);
+};
+
+} // namespace sensor
+} // namespace extension
+
+#endif // SENSOR_SENSOR_INSTANCE_H_
index 3b45a469259f86aeafdb3067a9bd4649fea90448..21ea3139b5ad4c9f29e63bbcfe7b5b55068ef01a 100644 (file)
@@ -10,7 +10,7 @@
       'dependencies': [
         'tizen/tizen.gyp:*',
         'application/application.gyp:*',
-       'package/package.gyp:*',
+        'package/package.gyp:*',
         'time/time.gyp:*',
         'utils/utils.gyp:*',
         'messageport/messageport.gyp:*',
@@ -41,6 +41,7 @@
               'secureelement/secureelement.gyp:*',
               'sound/sound.gyp:*',
               'notification/notification.gyp:*',
+              'sensor/sensor.gyp:*',
             ],
           },
         ], # end mobile