[Alarm] Stubs and ported JS layer.
authorTomasz Marciniak <t.marciniak@samsung.com>
Fri, 6 Mar 2015 14:14:44 +0000 (15:14 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 10 Mar 2015 08:39:23 +0000 (17:39 +0900)
Change-Id: Id4a2c9c4bae6b24f7d81696316c6c360f5de69f3
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
12 files changed:
packaging/webapi-plugins.spec
src/alarm/alarm.gyp [new file with mode: 0644]
src/alarm/alarm_api.js [new file with mode: 0644]
src/alarm/alarm_extension.cc [new file with mode: 0644]
src/alarm/alarm_extension.h [new file with mode: 0644]
src/alarm/alarm_instance.cc [new file with mode: 0644]
src/alarm/alarm_instance.h [new file with mode: 0644]
src/alarm/alarm_manager.cc [new file with mode: 0644]
src/alarm/alarm_manager.h [new file with mode: 0644]
src/alarm/alarm_utils.cc [new file with mode: 0644]
src/alarm/alarm_utils.h [new file with mode: 0644]
src/tizen-wrt.gyp

index 0ecb6eecc76a67fe7349525c8dda264878029868..bd747ddb12a87b2da50f199e199fa90bcc034063 100755 (executable)
@@ -19,6 +19,7 @@ Source0:    %{name}-%{version}.tar.gz
 %if "%{?profile}" == "mobile"
 
 %define tizen_feature_account_support             1
+%define tizen_feature_alarm_support               1
 %define tizen_feature_application_support         1
 %define tizen_feature_archive_support             1
 %define tizen_feature_badge_support               1
@@ -65,6 +66,7 @@ Source0:    %{name}-%{version}.tar.gz
 %if "%{?profile}" == "wearable"
 
 %define tizen_feature_account_support             0
+%define tizen_feature_alarm_support               0
 %define tizen_feature_application_support         0
 %define tizen_feature_archive_support             0
 %define tizen_feature_badge_support               0
@@ -111,6 +113,7 @@ Source0:    %{name}-%{version}.tar.gz
 %if "%{?profile}" == "tv"
 
 %define tizen_feature_account_support             0
+%define tizen_feature_alarm_support               0
 %define tizen_feature_application_support         1
 %define tizen_feature_archive_support             1
 %define tizen_feature_badge_support               0
@@ -191,6 +194,10 @@ BuildRequires: pkgconfig(capi-media-metadata-extractor)
 BuildRequires: pkgconfig(accounts-svc)
 %endif
 
+%if 0%{?tizen_feature_alarm_support}
+BuildRequires: pkgconfig(capi-appfw-alarm)
+%endif
+
 %if 0%{?tizen_feature_application_support}
 BuildRequires: pkgconfig(wrt-plugins-ipc-message)
 %endif
@@ -306,6 +313,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=x11"
 
 # feature flags
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_feature_account_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_alarm_support=%{?tizen_feature_alarm_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_application_support=%{?tizen_feature_application_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_archive_support=%{?tizen_feature_archive_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_badge_support=%{?tizen_feature_badge_support}"
diff --git a/src/alarm/alarm.gyp b/src/alarm/alarm.gyp
new file mode 100644 (file)
index 0000000..1ef284d
--- /dev/null
@@ -0,0 +1,31 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_alarm',
+      'type': 'loadable_module',
+      'sources': [
+        'alarm_api.js',
+        'alarm_extension.cc',
+        'alarm_extension.h',
+        'alarm_instance.cc',
+        'alarm_instance.h',
+        'alarm_manager.cc',
+        'alarm_manager.h',
+        'alarm_utils.cc',
+        'alarm_utils.h',
+      ],
+      'conditions': [
+        ['tizen == 1', {
+          'variables': {
+            'packages': [
+              'capi-appfw-alarm',
+            ]
+          },
+        }],
+      ],
+    },
+  ],
+}
\ No newline at end of file
diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js
new file mode 100644 (file)
index 0000000..85c3b48
--- /dev/null
@@ -0,0 +1,271 @@
+// Copyright 2014 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 T = xwalk.utils.type;
+var Converter = xwalk.utils.converter;
+var AV = xwalk.utils.validator;
+
+var native = new xwalk.utils.NativeManager(extension);
+
+var AlarmManager = function () {
+    Object.defineProperties(this, {
+        PERIOD_MINUTE:  { value: 60, writable: false, enumerable: true},
+        PERIOD_HOUR:    { value: 3600, writable: false, enumerable: true},
+        PERIOD_DAY:     { value: 86400, writable: false, enumerable: true},
+        PERIOD_WEEK:    { value: 604800, writable: false, enumerable: true},
+    });
+};
+
+//internal /////////////////////////////////////////////////////////////
+//this function should be kept in internal scope
+function InternalData(id) {
+    this.id = id;
+}
+
+//class AlarmManager ////////////////////////////////////////////////////
+AlarmManager.prototype.add = function () {
+    var args = AV.validateMethod(arguments, [
+        {
+            name : 'alarm',
+            type : AV.Types.PLATFORM_OBJECT,
+            values : [tizen.AlarmRelative, tizen.AlarmAbsolute]
+        },
+        {
+            name : 'applicationId',
+            type : AV.Types.STRING,
+        },
+        {
+            name : 'appControl',
+            type : AV.Types.PLATFORM_OBJECT,
+            values : tizen.ApplicationControl,
+            optional : true,
+            nullable : true
+        },
+    ]);
+
+    var type = null, seconds = 0;
+    if (args.alarm instanceof tizen.AlarmRelative) {
+        type = 'AlarmRelative';
+    } else if (args.alarm instanceof tizen.AlarmAbsolute) {
+        type = 'AlarmAbsolute';
+        seconds = args.alarm.date.getTime();
+    }
+
+    var callArgs = {};
+    callArgs.alarm = args.alarm;
+    callArgs.applicationId = args.applicationId;
+    if (args.has.appControl) {
+        callArgs.appControl = args.appControl;
+    }
+
+    callArgs.type = type;
+    callArgs.seconds = Converter.toString(seconds);
+
+    var result = native.callSync('AlarmManager_add', callArgs);
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    } else {
+        Object.defineProperties(args.alarm, {
+            id: {
+                value: Converter.toString(native.getResultObject(result).alarm_id),
+                writable: false, enumerable: true, configurable: true}
+        });
+    }
+};
+
+AlarmManager.prototype.remove = function () {
+    var args = AV.validateMethod(arguments, [
+        {
+            name : 'id',
+            type : AV.Types.STRING,
+        }
+    ]);
+
+    var result = native.callSync('AlarmManager_remove', {id: Number(args.id)});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    }
+};
+
+AlarmManager.prototype.removeAll = function () {
+    var result = native.callSync('AlarmManager_removeAll', {});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    }
+};
+
+AlarmManager.prototype.get = function () {
+    var args = AV.validateMethod(arguments, [
+        {
+            name : 'id',
+            type : AV.Types.STRING,
+        }
+    ]);
+
+    var result = native.callSync('AlarmManager_get', {id: Number(args.id)});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    } else {
+        result = native.getResultObject(result);
+        if ('AlarmRelative' === result.type) {
+            return new tizen.AlarmRelative(result.delay, result.period,
+                    new InternalData(result.id));
+        } else {
+            var date = new Date(result.year, result.month, result.day,
+                    result.hour, result.min, result.sec);
+
+            return new tizen.AlarmAbsolute(date, result.second,
+                    new InternalData(result.id));
+        }
+    }
+};
+
+AlarmManager.prototype.getAll = function () {
+    var result = native.callSync('AlarmManager_getAll', {});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    } else {
+        var data = native.getResultObject(result);
+        var md = [];
+        data.forEach(function (i) {
+            if ('AlarmRelative'=== i.type) {
+                md.push(new tizen.AlarmRelative(i.delay, i.period,
+                        new InternalData(i.id)));
+            } else {
+                var date = new Date(i.year, i.month, i.day,
+                        i.hour, i.min, i.sec);
+                md.push(new tizen.AlarmAbsolute(date, i.second,
+                        new InternalData(i.id)));
+            }
+        });
+        return md;
+    }
+};
+
+//class Alarm //////////////////////////////////////////////////////////
+function Alarm(id) {
+    var m_id = null;
+
+    if (!T.isNullOrUndefined(id)) {
+        m_id = Converter.toString(id);
+    }
+
+    Object.defineProperties(this, {
+        id:    { value: m_id, writable: false, enumerable: true, configurable: true}
+    });
+}
+//class AlarmRelative //////////////////////////////////////////////////
+
+tizen.AlarmRelative = function(delay, period, internal) {
+    AV.validateConstructorCall(this, tizen.AlarmRelative);
+
+    var m_period = null;
+
+    var m_delay = Converter.toLong(delay);
+
+    if (arguments.length >= 2) {
+        m_period = Converter.toLong(period, true);
+    }
+    if (internal instanceof InternalData) {
+        Alarm.call(this, internal.id);
+    }
+
+    Object.defineProperties(this, {
+        delay:     { value: m_delay, writable: false, enumerable: true},
+        period:    { value: m_period, writable: false, enumerable: true}
+    });
+}
+
+tizen.AlarmRelative.prototype = new Alarm();
+
+tizen.AlarmRelative.prototype.constructor = tizen.AlarmRelative;
+
+tizen.AlarmRelative.prototype.getRemainingSeconds = function () {
+    var result = native.callSync('AlarmRelative_getRemainingSeconds', {id: Number(this.id)});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    } else {
+        return Converter.toLong(native.getResultObject(result).seconds, true);
+    }
+};
+
+function makeDateConst(obj) {
+    console.log('Enter MakeConst');
+    obj.setDate = function() {};
+    obj.setFullYear = function() {};
+    obj.setHours = function() {};
+    obj.setMilliseconds = function() {};
+    obj.setMinutes = function() {};
+    obj.setMonth = function() {};
+    obj.setSeconds = function() {};
+    obj.setTime = function() {};
+    obj.setUTCDate = function() {};
+    obj.setUTCFullYear = function() {};
+    obj.setUTCHours = function() {};
+    obj.setUTCMilliseconds = function() {};
+    obj.setUTCMinutes = function() {};
+    obj.setUTCMonth = function() {};
+    obj.setUTCSeconds = function() {};
+    obj.setYear = function() {};
+    console.log('Leave MakeConst');
+}
+
+//class AlarmAbsolute //////////////////////////////////////////////////
+
+tizen.AlarmAbsolute = function(date, second, internal) {
+    AV.validateConstructorCall(this, tizen.AlarmAbsolute);
+
+    var m_period = null, m_daysOfWeek = [], m_date;
+
+    if (T.isDate(date)) {
+        m_date = date;
+        if (arguments.length >= 2) {
+            if(T.isArray(second)){
+                m_daysOfWeek = second;
+            } else {
+                m_period = Converter.toLong(second);
+            }
+        }
+
+        if (internal instanceof InternalData) {
+            Alarm.call(this, internal.id);
+        }
+    } else {
+        m_period = undefined;
+    }
+    makeDateConst(m_date);
+    Object.defineProperties(this, {
+        date:       { value: m_date, writable: false, enumerable: true},
+        period:     { value: m_period, writable: false, enumerable: true},
+        daysOfTheWeek: { value: m_daysOfWeek, writable: false, enumerable: true}
+    });
+}
+
+tizen.AlarmAbsolute.prototype = new Alarm();
+
+tizen.AlarmAbsolute.prototype.constructor = tizen.AlarmAbsolute;
+
+tizen.AlarmAbsolute.prototype.getNextScheduledDate = function () {
+    var result = native.callSync('AlarmAbsolute_getNextScheduledDate', {id: Number(this.id)});
+
+    if (native.isFailure(result)) {
+        throw native.getErrorObject(result);
+    } else {
+        var d = native.getResultObject(result);
+        if (T.isNull(d.year)) {
+            return null;
+        } else {
+            var date = new Date(d.year, d.month, d.day, d.hour, d.min, d.sec);
+            return date;
+        }
+    }
+};
+
+//exports //////////////////////////////////////////////////////////////
+exports = new AlarmManager();
diff --git a/src/alarm/alarm_extension.cc b/src/alarm/alarm_extension.cc
new file mode 100644 (file)
index 0000000..2da84bf
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright 2014 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 "alarm_extension.h"
+#include "alarm_instance.h"
+
+namespace {
+const char* kAlarm = "tizen.alarm";
+const char* kAlarmRelative = "tizen.AlarmRelative";
+const char* kAlarmAbsolute = "tizen.AlarmAbsolute";
+}
+
+// This will be generated from alarm_api.js.
+extern const char kSource_alarm_api[];
+
+common::Extension* CreateExtension() {
+  return new AlarmExtension;
+}
+
+AlarmExtension::AlarmExtension() {
+  SetExtensionName(kAlarm);
+  SetJavaScriptAPI(kSource_alarm_api);
+  const char* entry_points[] = {
+      kAlarmRelative,
+      kAlarmAbsolute,
+      NULL
+  };
+  SetExtraJSEntryPoints(entry_points);
+}
+
+AlarmExtension::~AlarmExtension() {}
+
+common::Instance* AlarmExtension::CreateInstance() {
+  return &extension::alarm::AlarmInstance::GetInstance();
+}
diff --git a/src/alarm/alarm_extension.h b/src/alarm/alarm_extension.h
new file mode 100644 (file)
index 0000000..e808c1e
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2014 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 ALARM_ALARM_EXTENSION_H_
+#define ALARM_ALARM_EXTENSION_H_
+
+#include "common/extension.h"
+
+class AlarmExtension : public common::Extension {
+ public:
+  AlarmExtension();
+  virtual ~AlarmExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif // ALARM_ALARM_EXTENSION_H_
diff --git a/src/alarm/alarm_instance.cc b/src/alarm/alarm_instance.cc
new file mode 100644 (file)
index 0000000..82bd3df
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2014 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 "alarm_instance.h"
+
+#include "alarm_manager.h"
+#include "common/picojson.h"
+#include "common/logger.h"
+
+namespace extension {
+namespace alarm {
+
+using namespace common;
+
+namespace {
+AlarmManager* alarm_manager = &AlarmManager::GetInstance();
+}
+
+AlarmInstance& AlarmInstance::GetInstance() {
+  static AlarmInstance instance;
+  return instance;
+}
+
+AlarmInstance::AlarmInstance() {
+  LoggerD("Entered");
+  using namespace std::placeholders;
+
+  RegisterSyncHandler("AlarmManager_add",
+                      std::bind(&AlarmManager::Add, alarm_manager, _1, _2));
+  RegisterSyncHandler("AlarmManager_remove",
+                      std::bind(&AlarmManager::Remove, alarm_manager, _1, _2));
+  RegisterSyncHandler("AlarmManager_removeAll",
+                      std::bind(&AlarmManager::RemoveAll, alarm_manager, _1, _2));
+  RegisterSyncHandler("AlarmManager_get",
+                      std::bind(&AlarmManager::Get, alarm_manager, _1, _2));
+  RegisterSyncHandler("AlarmManager_getAll",
+                      std::bind(&AlarmManager::GetAll, alarm_manager, _1, _2));
+  //AlarmRelative
+  RegisterSyncHandler("AlarmRelative_getRemainingSeconds",
+                      std::bind(&AlarmManager::GetRemainingSeconds, alarm_manager, _1, _2));
+  //AlarmAbsolute
+  RegisterSyncHandler("AlarmAbsolute_getNextScheduledDate",
+                      std::bind(&AlarmManager::GetNextScheduledDate, alarm_manager, _1, _2));
+}
+
+AlarmInstance::~AlarmInstance() {
+  LoggerD("Entered");
+}
+
+} // namespace Alarm
+} // namespace extension
diff --git a/src/alarm/alarm_instance.h b/src/alarm/alarm_instance.h
new file mode 100644 (file)
index 0000000..cd7ee19
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2014 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 ALARM_ALARM_INSTANCE_H_
+#define ALARM_ALARM_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace alarm {
+
+class AlarmInstance: public common::ParsedInstance {
+ public:
+  static AlarmInstance& GetInstance();
+ private:
+  AlarmInstance();
+  virtual ~AlarmInstance();
+};
+
+} // namespace alarm
+} // namespace extension
+
+#endif // ALARM_ALARM_INSTANCE_H_
diff --git a/src/alarm/alarm_manager.cc b/src/alarm/alarm_manager.cc
new file mode 100644 (file)
index 0000000..be1ca1d
--- /dev/null
@@ -0,0 +1,63 @@
+// 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 "alarm_manager.h"
+
+#include <app.h>
+#include <app_alarm.h>
+
+#include "common/logger.h"
+#include "common/converter.h"
+#include "common/platform_result.h"
+
+#include "alarm_instance.h"
+#include "alarm_utils.h"
+
+using namespace common;
+using namespace common::tools;
+
+namespace extension {
+namespace alarm {
+
+AlarmManager::AlarmManager() {
+}
+
+AlarmManager::~AlarmManager() {
+}
+
+AlarmManager& AlarmManager::GetInstance() {
+  static AlarmManager instance;
+  return instance;
+}
+
+void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::Remove(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::RemoveAll(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::Get(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::GetAll(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::GetRemainingSeconds(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+void AlarmManager::GetNextScheduledDate(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+}
+
+} // namespace alarm
+} // namespace extension
diff --git a/src/alarm/alarm_manager.h b/src/alarm/alarm_manager.h
new file mode 100644 (file)
index 0000000..00a5c43
--- /dev/null
@@ -0,0 +1,39 @@
+// 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 ALARM_ALARM_MANAGER_H_
+#define ALARM_ALARM_MANAGER_H_
+
+#include "common/picojson.h"
+
+namespace extension {
+namespace alarm {
+
+class AlarmManager {
+ public:
+  static AlarmManager& GetInstance();
+  virtual ~AlarmManager();
+
+  void Add(const picojson::value& args, picojson::object& out);
+  void Remove(const picojson::value& args, picojson::object& out);
+  void RemoveAll(const picojson::value& args, picojson::object& out);
+  void Get(const picojson::value& args, picojson::object& out);
+  void GetAll(const picojson::value& args, picojson::object& out);
+
+  //AlarmRelative
+  void GetRemainingSeconds(const picojson::value& args, picojson::object& out);
+  //AlarmAbsolute
+  void GetNextScheduledDate(const picojson::value& args, picojson::object& out);
+
+ private:
+  AlarmManager();
+  AlarmManager(const AlarmManager&) = delete;
+  AlarmManager& operator=(const AlarmManager&) = delete;
+
+};
+
+} // namespace alarm
+} // namespace extension
+
+#endif // ALARM_ALARM_MANAGER_H_
diff --git a/src/alarm/alarm_utils.cc b/src/alarm/alarm_utils.cc
new file mode 100644 (file)
index 0000000..cfc52c4
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2014 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 "alarm_utils.h"
+
+#include "common/logger.h"
+
+namespace extension {
+namespace alarm {
+namespace util {
+
+using namespace common;
+
+void CheckAccess(const std::string& privilege) {
+  // TODO: check access to privilege, throw exception on failure
+}
+
+PlatformResult AppControlToService(const picojson::object& obj, app_control_h *app_control) {
+  LoggerD("Entered");
+}
+
+PlatformResult AppControlToServiceExtraData(const picojson::object& app_obj,
+                                            app_control_h *app_control) {
+  LoggerD("Entered");
+}
+
+} // util
+} // alarm
+} // extension
diff --git a/src/alarm/alarm_utils.h b/src/alarm/alarm_utils.h
new file mode 100644 (file)
index 0000000..9927d62
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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 ALARM_ALARM_UTILS_H_
+#define ALARM_ALARM_UTILS_H_
+
+#include <app_control.h>
+
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace alarm {
+namespace util {
+
+void CheckAccess(const std::string& privilege);
+
+common::PlatformResult AppControlToService(const picojson::object& obj, app_control_h *app_control);
+common::PlatformResult AppControlToServiceExtraData(const picojson::object& app_obj,
+                                                           app_control_h *app_control);
+} // util
+} // alarm
+} // extension
+
+#endif // ALARM_ALARM_UTILS_H_
index 71dcedaad930c29f1626bde9f586183edbda584f..9883326ae77cf81528d8c3b598933689ed1d4800 100755 (executable)
             ],
           },
         ],
+        [
+          'tizen_feature_alarm_support==1', {
+            'dependencies': [
+              'alarm/alarm.gyp:*',
+            ],
+          },
+        ],
         [
           'tizen_feature_application_support==1', {
             'dependencies': [