summaryrefslogtreecommitdiff
path: root/wearable_src/Alarm
diff options
context:
space:
mode:
Diffstat (limited to 'wearable_src/Alarm')
-rw-r--r--wearable_src/Alarm/AlarmAbsolute.cpp130
-rwxr-xr-xwearable_src/Alarm/AlarmAbsolute.h72
-rw-r--r--wearable_src/Alarm/AlarmConverter.cpp256
-rwxr-xr-xwearable_src/Alarm/AlarmConverter.h65
-rw-r--r--wearable_src/Alarm/AlarmRelative.cpp101
-rwxr-xr-xwearable_src/Alarm/AlarmRelative.h73
-rw-r--r--wearable_src/Alarm/CMakeLists.txt60
-rw-r--r--wearable_src/Alarm/JSAlarmAbsolute.cpp363
-rwxr-xr-xwearable_src/Alarm/JSAlarmAbsolute.h84
-rw-r--r--wearable_src/Alarm/JSAlarmManager.cpp516
-rwxr-xr-xwearable_src/Alarm/JSAlarmManager.h66
-rw-r--r--wearable_src/Alarm/JSAlarmRelative.cpp314
-rwxr-xr-xwearable_src/Alarm/JSAlarmRelative.h78
-rwxr-xr-xwearable_src/Alarm/alarm_common.h61
-rwxr-xr-xwearable_src/Alarm/config.xml11
-rwxr-xr-xwearable_src/Alarm/plugin_config.cpp109
-rwxr-xr-xwearable_src/Alarm/plugin_config.h44
-rw-r--r--wearable_src/Alarm/plugin_initializer.cpp100
18 files changed, 2503 insertions, 0 deletions
diff --git a/wearable_src/Alarm/AlarmAbsolute.cpp b/wearable_src/Alarm/AlarmAbsolute.cpp
new file mode 100644
index 0000000..7dadf3b
--- /dev/null
+++ b/wearable_src/Alarm/AlarmAbsolute.cpp
@@ -0,0 +1,130 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "AlarmAbsolute.h"
+#include "alarm_common.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+AlarmAbsolute::AlarmAbsolute()
+{
+ m_isRecurrence = false;
+ service_create(&m_service_handle);
+ service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_ABSOLUTE_VALUE);
+ service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE);
+ m_recurrenceType = AbsoluteRecurrence::NoRecurrence;
+ m_id = -1;
+ m_interval = -1;
+ is_registered = false;
+}
+
+AlarmAbsolute::AlarmAbsolute(service_h handle)
+{
+ service_clone(&m_service_handle, handle);
+ m_id = -1;
+ m_interval = -1;
+ is_registered = false;
+}
+
+AlarmAbsolute::~AlarmAbsolute()
+{
+ service_destroy(m_service_handle);
+}
+
+int AlarmAbsolute::getId() const
+{
+ return m_id;
+}
+
+void AlarmAbsolute::setId(const int id)
+{
+ m_id = id;
+ is_registered = true;
+}
+
+bool AlarmAbsolute::isRecurrence()
+{
+ return m_isRecurrence;
+}
+
+void AlarmAbsolute::setIsRecurrence(bool value)
+{
+ m_isRecurrence = value;
+}
+
+void AlarmAbsolute::setDate(struct tm date)
+{
+ char strDate[19];
+ m_date = date;
+
+ snprintf(strDate, sizeof(strDate), "%d %d %d %d %d %d",m_date.tm_year, m_date.tm_mon,
+ m_date.tm_mday, m_date.tm_hour, m_date.tm_min, m_date.tm_sec);
+
+ service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_DATE_KEY, strDate);
+
+ LoggerI("AlarmAbsolute Date = " << " Sec: " << m_date.tm_sec << ", Min: "<< m_date.tm_min
+ << ", Hour:" << m_date.tm_hour << ", Day: " << m_date.tm_mday << ", MON: " << m_date.tm_mon
+ << ", Year: " << m_date.tm_year);
+}
+
+struct tm AlarmAbsolute::getDate()
+{
+ return m_date;
+}
+
+void AlarmAbsolute::setInterval(int interval)
+{
+ m_interval = interval;
+ m_recurrenceType = AbsoluteRecurrence::Interval;
+ service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL);
+}
+
+int AlarmAbsolute::getInterval()
+{
+ return m_interval;
+}
+
+void AlarmAbsolute::setByDayRecurrence(std::vector<std::string> &daysOfTheWeek)
+{
+ m_recurrenceType = AbsoluteRecurrence::ByDayValue;
+ m_daysOfTheWeek = daysOfTheWeek;
+ service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE);
+}
+
+std::vector<std::string> AlarmAbsolute::getByDayRecurrence()
+{
+ return m_daysOfTheWeek;
+}
+
+AbsoluteRecurrence::Type AlarmAbsolute::getRecurrenceType()
+{
+ return m_recurrenceType;
+}
+
+service_h AlarmAbsolute::getService() {
+ return m_service_handle;
+}
+
+}
+}
+
diff --git a/wearable_src/Alarm/AlarmAbsolute.h b/wearable_src/Alarm/AlarmAbsolute.h
new file mode 100755
index 0000000..fec12cd
--- /dev/null
+++ b/wearable_src/Alarm/AlarmAbsolute.h
@@ -0,0 +1,72 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_ALARMABSOLUTE_H_
+#define TIZENAPIS_API_ALARMABSOLUTE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <time.h>
+#include <app.h>
+#include "alarm_common.h"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+class AlarmAbsolute;
+typedef DPL::SharedPtr<AlarmAbsolute> AlarmAbsolutePtr;
+typedef std::vector<AlarmAbsolutePtr> AlarmAbsoluteArrayPtr;
+
+class AlarmAbsolute
+{
+ public:
+ AlarmAbsolute();
+ AlarmAbsolute(service_h handle);
+ ~AlarmAbsolute();
+ int getId() const;
+ void setId(const int id);
+ void setDate(struct tm date);
+ struct tm getDate();
+ void setInterval(int interval);
+ int getInterval();
+ bool isRecurrence();
+ void setIsRecurrence(bool value);
+ void setByDayRecurrence(std::vector<std::string> &daysOfTheWeek);
+ std::vector<std::string> getByDayRecurrence();
+ AbsoluteRecurrence::Type getRecurrenceType();
+ service_h getService();
+
+ public:
+ bool is_registered;
+
+ private:
+ int m_id;
+ struct tm m_date;
+ bool m_isRecurrence;
+ int m_interval;
+ service_h m_service_handle;
+ std::vector<std::string> m_daysOfTheWeek;
+ AbsoluteRecurrence::Type m_recurrenceType;
+
+};
+
+}
+}
+
+#endif
diff --git a/wearable_src/Alarm/AlarmConverter.cpp b/wearable_src/Alarm/AlarmConverter.cpp
new file mode 100644
index 0000000..53c93b4
--- /dev/null
+++ b/wearable_src/Alarm/AlarmConverter.cpp
@@ -0,0 +1,256 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <vector>
+#include <app.h>
+#include <time.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "AlarmConverter.h"
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+AlarmConverter::AlarmConverter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context)
+{
+
+}
+
+AlarmConverter::~AlarmConverter()
+{
+
+}
+
+int AlarmConverter::toNativeAlarmValue(std::vector<std::string> daysOfTheWeek)
+{
+ int nativeValue = 0;
+
+ for( unsigned int i=0; i<daysOfTheWeek.size(); i++ )
+ {
+ if( daysOfTheWeek[i]=="SU" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_SUNDAY;
+ else if( daysOfTheWeek[i]=="MO" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_MONDAY ;
+ else if( daysOfTheWeek[i]=="TU" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_TUESDAY ;
+ else if( daysOfTheWeek[i]=="WE" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_WEDNESDAY;
+ else if( daysOfTheWeek[i]=="TH" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_THURSDAY ;
+ else if( daysOfTheWeek[i]=="FR" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_FRIDAY ;
+ else if( daysOfTheWeek[i]=="SA" )
+ nativeValue = nativeValue | ALARM_WEEK_FLAG_SATURDAY ;
+ }
+ return nativeValue;
+}
+
+std::vector<std::string> AlarmConverter::convertFlagToDaysOfTheWeek(int byDayValue)
+{
+ std::vector<std::string> daysOfTheWeek;
+
+ if(byDayValue & ALARM_WEEK_FLAG_SUNDAY)
+ daysOfTheWeek.push_back("SU");
+ if(byDayValue & ALARM_WEEK_FLAG_MONDAY)
+ daysOfTheWeek.push_back("MO");
+ if(byDayValue & ALARM_WEEK_FLAG_TUESDAY)
+ daysOfTheWeek.push_back("TU");
+ if(byDayValue & ALARM_WEEK_FLAG_WEDNESDAY)
+ daysOfTheWeek.push_back("WE");
+ if(byDayValue & ALARM_WEEK_FLAG_THURSDAY)
+ daysOfTheWeek.push_back("TH");
+ if(byDayValue & ALARM_WEEK_FLAG_FRIDAY)
+ daysOfTheWeek.push_back("FR");
+ if(byDayValue & ALARM_WEEK_FLAG_SATURDAY)
+ daysOfTheWeek.push_back("SA");
+
+ return daysOfTheWeek;
+}
+
+service_h AlarmConverter::toService(std::string id)
+{
+ service_h service;
+ service_create(&service);
+
+ service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+ service_set_package(service, id.c_str());
+ return service;
+}
+service_h AlarmConverter::toService(std::string id, std::string page)
+{
+ service_h service;
+ service_create(&service);
+
+ service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+ service_set_package(service, id.c_str());
+ return service;
+}
+
+bool AlarmConverter::toAlarmAbsolutePtr(int id, service_h handle, AlarmAbsolutePtr privateData)
+{
+ char* dateString;
+ char* alarmType;
+ struct tm date;
+ memset(&date, 0, sizeof(tm));
+ int error = ALARM_ERROR_NONE;
+
+ error = service_get_extra_data(handle, ALARM_ALSOLUTE_DATE_KEY, &dateString);
+
+ LoggerI("Date Strng = " << dateString);
+ if(error != SERVICE_ERROR_NONE)
+ {
+ LoggerE("Fail to get AlarmDelay");
+ return false;
+ }
+ sscanf(dateString, "%d %d %d %d %d %d", &date.tm_year, &date.tm_mon,
+ &date.tm_mday, &date.tm_hour, &date.tm_min, &date.tm_sec);
+ mktime(&date);
+
+ LoggerI("Converter AlarmAbsolute Date = " << " Sec: " << date.tm_sec << ", Min: "<< date.tm_min
+ << ", Hour: " << date.tm_hour << ", Day: " << date.tm_mday << ", MON: " << date.tm_mon
+ << ", Year: " << date.tm_year);
+
+ service_get_extra_data(handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, &alarmType);
+
+ if(!strcmp(alarmType, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL)) {
+ int interval = 0;
+ alarm_get_scheduled_period(id, &interval);
+ LoggerI("interval type alarm: "<<interval);
+ privateData->setInterval(interval);
+ } else if(!strcmp(alarmType, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE)) {
+ int byDayValue =0;
+ error = alarm_get_scheduled_recurrence_week_flag(id, &byDayValue);
+ LoggerI("daysOfWeek type alarm: "<<byDayValue<<", error: "<<error);
+ if(error==ALARM_ERROR_NONE && byDayValue>0) {
+ std::vector<std::string> result;
+ result = convertFlagToDaysOfTheWeek(byDayValue);
+ privateData->setByDayRecurrence(result);
+ } else {
+ LoggerE("Can't get the recurrence week flag.");
+ }
+ }
+
+ privateData->setId(id);
+ privateData->setDate(date);
+
+ return true;
+}
+
+bool AlarmConverter::toAlarmRelativePtr(int id, service_h handle, AlarmRelativePtr privateData)
+{
+ int interval = 0;
+ char* delayString;
+ int delay;
+
+ int error = ALARM_ERROR_NONE;
+ error = alarm_get_scheduled_period(id, &interval);
+ if(error != ALARM_ERROR_NONE) {
+ interval = 0;
+ }
+
+ error = service_get_extra_data(handle, ALARM_RELATIVE_DELAY_KEY, &delayString);
+ if(error != SERVICE_ERROR_NONE)
+ {
+ LoggerE("Fail to get AlarmDelay");
+ return false;
+ }
+ delay = atoi(delayString);
+ free(delayString);
+
+ privateData->setId(id);
+ privateData->setDelay(delay);
+ privateData->setPeriod(interval);
+
+ return true;
+}
+
+int AlarmConverter::toNativeInterval(std::string freq, std::string interval)
+{
+ int freqInSecond = 0;
+ int intervalValue = toInt(interval);
+
+ if (!freq.compare(ALARM_PROPERTY_MINUTELY_RECURRENCE))
+ freqInSecond = 60;
+ else if (!freq.compare(ALARM_PROPERTY_HOURLY_RECURRENCE))
+ freqInSecond = 3600;
+ else if (!freq.compare(ALARM_PROPERTY_DAILY_RECURRENCE))
+ freqInSecond = 3600*24;
+ else if (!freq.compare(ALARM_PROPERTY_WEEKLY_RECURRENCE))
+ freqInSecond = 3600 * 24 * 7;
+
+ return freqInSecond * intervalValue;
+}
+
+bool AlarmConverter::toAlarmService(service_h service, DeviceAPI::Application::ApplicationControlPtr appservice)
+ {
+ if (appservice->getOperation().compare("") != 0) {
+ service_set_operation(service, appservice->getOperation().c_str() );
+ } else {
+ LoggerD("Error. operation is madatory field. cannot be null");
+ return false;
+ }
+
+ if (appservice->getUri().compare("") != 0) {
+ service_set_uri(service, appservice->getUri().c_str() );
+ }
+
+ if (appservice->getMime().compare("") != 0) {
+ service_set_mime(service, appservice->getMime().c_str() );
+ }
+
+ std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = appservice->getAppControlDataArray();
+
+ if (!appControlDataArray.empty()) {
+ std::string key;
+ const char** arr = NULL;
+
+ for (size_t i = 0; i < appControlDataArray.size(); ++i) {
+ key = appControlDataArray.at(i)->getKey();
+ if (key.empty()) {
+ return false;
+ }
+ std::vector<std::string> valueArray = appControlDataArray.at(i)->getValue();
+ size_t size = valueArray.size();
+
+ arr = (const char**)calloc(sizeof(char*), size);
+
+ for (size_t j = 0; j < size; j++) {
+ arr[j] = valueArray.at(j).c_str();
+ }
+
+ service_add_extra_data_array(service, key.c_str(), arr, size);
+
+ if (arr)
+ free(arr);
+ }
+ }
+ return true;
+}
+
+}
+}
+
diff --git a/wearable_src/Alarm/AlarmConverter.h b/wearable_src/Alarm/AlarmConverter.h
new file mode 100755
index 0000000..cf9ada5
--- /dev/null
+++ b/wearable_src/Alarm/AlarmConverter.h
@@ -0,0 +1,65 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef _JS_TIZEN_ALARM_CONVERTER_H_
+#define _JS_TIZEN_ALARM_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <app.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <JSApplicationControl.h>
+#include <ApplicationControl.h>
+#include <ApplicationConverter.h>
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+class AlarmConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+ using Converter::toJSValueRef;
+ explicit AlarmConverter(JSContextRef context);
+ virtual ~AlarmConverter();
+
+ int toNativeAlarmValue(std::vector<std::string> daysOfTheWeek);
+ std::vector<std::string> convertFlagToDaysOfTheWeek(int byDayValue);
+ int toNativeValue(int interval);
+ std::vector<std::string> toPrivateValue(int byDayValue);
+ service_h toService(std::string id);
+ service_h toService(std::string id, std::string page);
+ bool toAlarmAbsolutePtr(int id, service_h handle, AlarmAbsolutePtr ptr);
+ bool toAlarmRelativePtr(int id, service_h handle, AlarmRelativePtr ptr);
+ int toNativeInterval(std::string freq, std::string interval);
+ bool toAlarmService(service_h alarm_service, DeviceAPI::Application::ApplicationControlPtr ptr);
+};
+
+typedef ConverterFactory<AlarmConverter> AlarmConverterFactory;
+
+}
+}
+
+#endif /* _JS_TIZEN_ALARM_CONVERTER_H_ */
diff --git a/wearable_src/Alarm/AlarmRelative.cpp b/wearable_src/Alarm/AlarmRelative.cpp
new file mode 100644
index 0000000..f58366d
--- /dev/null
+++ b/wearable_src/Alarm/AlarmRelative.cpp
@@ -0,0 +1,101 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "AlarmRelative.h"
+#include "alarm_common.h"
+#include <JSTimeDuration.h>
+#include <app.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+AlarmRelative::AlarmRelative()
+{
+ m_isRecurrence = false;
+ service_create(&m_service_handle);
+ service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_RELATIVE_VALUE);
+ m_Period = -1;
+ m_id = -1;
+ is_registered = false;
+}
+
+AlarmRelative::AlarmRelative(service_h handle)
+{
+ service_clone(&m_service_handle, handle);
+ m_Period = -1;
+ m_id = -1;
+ is_registered = false;
+}
+
+AlarmRelative::~AlarmRelative()
+{
+ service_destroy(m_service_handle);
+}
+
+int AlarmRelative::getId() const
+{
+ return m_id;
+}
+
+void AlarmRelative::setId(const int id)
+{
+ m_id = id;
+ is_registered = true;
+}
+
+bool AlarmRelative::isRecurrence()
+{
+ return m_isRecurrence;
+}
+
+void AlarmRelative::setIsRecurrence(bool value)
+{
+ m_isRecurrence = value;
+}
+
+void AlarmRelative::setDelay(int delay)
+{
+ char result[12];
+ snprintf(result, sizeof(result), "%d", delay);
+ service_add_extra_data(m_service_handle, ALARM_RELATIVE_DELAY_KEY, result);
+ m_delay = delay;
+}
+
+int AlarmRelative::getDelay()
+{
+ return m_delay;
+}
+
+void AlarmRelative::setPeriod(int value)
+{
+ m_Period = value;
+}
+
+int AlarmRelative::getPeriod()
+{
+ return m_Period;
+}
+
+service_h AlarmRelative::getService()
+{
+ return m_service_handle;
+}
+
+}
+}
+
diff --git a/wearable_src/Alarm/AlarmRelative.h b/wearable_src/Alarm/AlarmRelative.h
new file mode 100755
index 0000000..e8a4839
--- /dev/null
+++ b/wearable_src/Alarm/AlarmRelative.h
@@ -0,0 +1,73 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_ALARMRELATIVE_H_
+#define TIZENAPIS_API_ALARMRELATIVE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <time.h>
+#include <app.h>
+#include "alarm_common.h"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+class AlarmRelative;
+typedef DPL::SharedPtr<AlarmRelative> AlarmRelativePtr;
+typedef std::vector<AlarmRelativePtr> AlarmRelativeArrayPtr;
+
+class AlarmRelative
+{
+ public:
+ typedef enum {
+ ALARM_TYPE_DELAY,
+ ALARM_TYPE_DATE,
+ ALARM_TYPE_INVALID,
+ } alarm_type_e;
+
+ AlarmRelative();
+ AlarmRelative(service_h handle);
+ ~AlarmRelative();
+ void setIsRecurrence(bool value);
+ int getId() const;
+ void setId(const int id);
+ void setDelay(int delay);
+ int getDelay();
+ bool isRecurrence();
+ void setPeriod(int value);
+ int getPeriod();
+ service_h getService();
+
+ public:
+ bool is_registered;
+
+ private:
+ int m_id;
+ int m_delay;
+ bool m_isRecurrence;
+ int m_Period;
+ service_h m_service_handle;
+
+};
+
+}
+}
+
+#endif
diff --git a/wearable_src/Alarm/CMakeLists.txt b/wearable_src/Alarm/CMakeLists.txt
new file mode 100644
index 0000000..e3ce625
--- /dev/null
+++ b/wearable_src/Alarm/CMakeLists.txt
@@ -0,0 +1,60 @@
+SET(TARGET_NAME ${alarm_target})
+SET(DESTINATION_NAME ${alarm_dest})
+SET(TARGET_IMPL_NAME ${alarm_impl})
+
+PKG_CHECK_MODULES(platform_pkgs_alarm REQUIRED capi-appfw-application)
+
+ADD_DEFINITIONS("-fvisibility=hidden")
+
+INCLUDE_DIRECTORIES(
+ ${platform_pkgs_alarm_INCLUDE_DIRS}
+ ${INCLUDE_COMMON}
+ ${TOP}/Application
+ ${TOP}/TimeUtil
+)
+
+SET(CMAKE_INSTALL_RPATH
+ ${CMAKE_INSTALL_RPATH}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${tizen_dest}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${timeutil_dest}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${application_dest}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}
+)
+
+SET(SRCS_IMPL
+ AlarmAbsolute.cpp
+ AlarmConverter.cpp
+ AlarmRelative.cpp
+ JSAlarmAbsolute.cpp
+ JSAlarmManager.cpp
+ JSAlarmRelative.cpp
+)
+
+ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
+ ${LIBS_COMMON}
+ ${platform_pkgs_alarm_LIBRARIES}
+ ${tizen_impl}
+ ${application_impl}
+ ${timeutil_impl}
+)
+
+SET(SRCS
+ plugin_config.cpp
+ plugin_initializer.cpp
+)
+
+ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ${TARGET_IMPL_NAME}
+ "-Wl,--no-as-needed" ${application_config}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(
+ DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/alarm
+ FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
+)
diff --git a/wearable_src/Alarm/JSAlarmAbsolute.cpp b/wearable_src/Alarm/JSAlarmAbsolute.cpp
new file mode 100644
index 0000000..e0f8507
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmAbsolute.cpp
@@ -0,0 +1,363 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <ArgumentValidator.h>
+
+#include <Commons/Exception.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+
+#include "AlarmAbsolute.h"
+#include "AlarmConverter.h"
+#include <app.h>
+#include <time.h>
+#include <JSUtil.h>
+
+#include <TimeTracer.h>
+#include "plugin_config.h"
+#include "JSAlarmAbsolute.h"
+#include "JSAlarmManager.h"
+#include <Export.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+JSClassRef JSAlarmAbsolute::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmAbsolute::m_jsClassInfo = {
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_ALARM_ABSOLUTE_INTERFACE,
+ NULL,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //getProperty,
+ NULL, //setProperty,
+ NULL, //deleteProperty,Geolocation
+ NULL, //getPropertyNames,
+ NULL,
+ NULL, // constructor
+ NULL,
+ NULL
+};
+
+JSStaticFunction JSAlarmAbsolute::m_function[] = {
+ { ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE, JSAlarmAbsolute::getNextScheduledDate, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSStaticValue JSAlarmAbsolute::m_property[] = {
+ { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DATE, getDate, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_PERIOD, getInterval, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DAYSOFTHEWEEK, getDaysOfTheWeek, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+const JSClassRef DLL_EXPORT JSAlarmAbsolute::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmAbsolute::getClassInfo()
+{
+ return &m_jsClassInfo;
+}
+
+void JSAlarmAbsolute::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+void JSAlarmAbsolute::finalize(JSObjectRef object)
+{
+ JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ LoggerE("Private object is null");
+ }
+ delete priv;
+
+}
+
+
+JSObjectRef DLL_EXPORT JSAlarmAbsolute::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+
+ AlarmAbsolutePtr priv = AlarmAbsolutePtr(new AlarmAbsolute());
+
+ try {
+ time_t date = validator.toTimeT(0);
+ struct tm *startDate = localtime(&date);
+ mktime(startDate);
+
+ priv->setDate(*startDate);
+
+ if (argumentCount >= 2) {
+ if (JSIsArrayValue(ctx, arguments[1])) {
+ std::vector<std::string> daysOfTheWeek = validator.toStringVector(1);
+
+ for (size_t i = 0; i < daysOfTheWeek.size(); i++ ) {
+ if ( (daysOfTheWeek[i]!="SU") && (daysOfTheWeek[i]!="MO") &&
+ (daysOfTheWeek[i]!="TU") && (daysOfTheWeek[i]!="WE") &&
+ (daysOfTheWeek[i]!="TH") && (daysOfTheWeek[i]!="FR") &&
+ (daysOfTheWeek[i]!="SA") ) {
+ // remove unacceptable data from vector
+ daysOfTheWeek.erase(std::remove(daysOfTheWeek.begin(), daysOfTheWeek.end(), daysOfTheWeek[i]), daysOfTheWeek.end());
+ }
+ }
+
+ if(daysOfTheWeek.size() > 0) {
+ priv->setByDayRecurrence(daysOfTheWeek);
+ }
+ } else {
+ long interval = validator.toLong(1);
+ if (interval < 0) {
+ throw InvalidValuesException("period can not be negative value");
+ }
+
+ priv->setInterval(interval);
+ }
+ }
+ } catch (const BasePlatformException& err) {
+ LoggerE("Exception occured while creating constructor : " << err.getMessage());
+ }
+
+ JSAlarmAbsolutePriv *jspriv = new JSAlarmAbsolutePriv(ctx, priv);
+ JSObjectRef obj = JSObjectMake(ctx, getClassRef(), jspriv);
+
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, obj, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+
+ return obj;
+}
+
+AlarmAbsolutePtr JSAlarmAbsolute::getPrivData(JSObjectRef object)
+{
+ JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ throw TypeMismatchException("Private object is null");
+ }
+ AlarmAbsolutePtr result = priv->getObject();
+ if (!result) {
+ throw TypeMismatchException("Private object is null");
+ }
+ return result;
+}
+
+
+JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, AlarmAbsolutePtr privateData)
+{
+ JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
+ if (!priv) {
+ throw TypeMismatchException("Private object is null");
+ }
+ return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmAbsolute::getNextScheduledDate( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ try {
+ struct tm date;
+ Converter converter(ctx);
+
+ AlarmAbsolutePtr privateData = getPrivData(thisObject);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ if(!privateData->is_registered) {
+ return JSValueMakeNull(ctx);
+ }
+
+ int id = privateData->getId();
+ TIME_TRACER_ITEM_BEGIN("(getNextScheduledDate)alarm_get_scheduled_date", 0);
+ int err = alarm_get_scheduled_date(id, &date);
+ TIME_TRACER_ITEM_END("(getNextScheduledDate)alarm_get_scheduled_date", 0);
+ if(err != ALARM_ERROR_NONE) {
+ return JSValueMakeNull(ctx);
+ }
+
+ // check wheter the alarm is expired or not
+ struct tm curr_date;
+ TIME_TRACER_ITEM_BEGIN("(getNextScheduledDate)alarm_get_current_time", 0);
+ err = alarm_get_current_time(&curr_date);
+ TIME_TRACER_ITEM_END("(getNextScheduledDate)alarm_get_current_time", 0);
+ if(err != ALARM_ERROR_NONE) {
+ return JSValueMakeNull(ctx);
+ }
+
+ if (mktime(&date) < mktime(&curr_date)) {
+ return JSValueMakeNull(ctx);
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+
+ return converter.toJSValueRef(date);
+
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Converter converter(ctx);
+ struct tm date;
+
+ try {
+ AlarmAbsolutePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ date = privateData->getDate();
+ LoggerI("JSAlarmAbsolute Date = " << " Sec : " << date.tm_sec << " Min : "<< date.tm_min
+ << " Hour" << date.tm_hour << "Day : " << date.tm_mday << " MON : " << date.tm_mon
+ << " Year : " << date.tm_year);
+
+ JSValueRef args[6];
+ args[0] = JSValueMakeNumber(ctx, date.tm_year + 1900);
+ args[1] = JSValueMakeNumber(ctx, date.tm_mon);
+ args[2] = JSValueMakeNumber(ctx, date.tm_mday);
+ args[3] = JSValueMakeNumber(ctx, date.tm_hour);
+ args[4] = JSValueMakeNumber(ctx, date.tm_min);
+ args[5] = JSValueMakeNumber(ctx, date.tm_sec);
+
+ JSObjectRef result = JSObjectMakeDate(ctx, 6, args, exception);
+ return result;
+ } catch (...) {
+ LoggerE("Exception: occured");
+ }
+
+ return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getId(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ try {
+ AlarmAbsolutePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ Converter converter(ctx);
+ if (privateData->is_registered) {
+ std::string strId = converter.toString(privateData->getId());
+ return converter.toJSValueRef(strId);
+ } else {
+ return JSValueMakeNull(ctx);
+ }
+ } catch (...) {
+ LoggerE("Exception: occured");
+ }
+
+ return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getInterval(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ try {
+ AlarmAbsolutePtr privateData = getPrivData(object);
+ AbsoluteRecurrence::Type alarmType = privateData->getRecurrenceType();
+
+ if(alarmType == AbsoluteRecurrence::Interval) {
+ long interval = privateData->getInterval();
+ if (interval == -1 ) {
+ return JSValueMakeNull(ctx);
+ } else {
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, interval);
+ }
+ } else {
+ return JSValueMakeNull(ctx);
+ }
+ } catch (...) {
+ LoggerI("Exception: occured");
+ }
+
+ return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getDaysOfTheWeek(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Converter converter(ctx);
+
+ try {
+ AlarmAbsolutePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+ if (jsResult == NULL) {
+ throw UnknownException("Could not create js array object");
+ }
+
+ std::vector<std::string> daysOfTheWeek = privateData->getByDayRecurrence();
+
+ if(daysOfTheWeek.size() > 0) {
+ for(size_t i = 0; i<daysOfTheWeek.size(); i++) {
+ JSValueRef val = converter.toJSValueRef(daysOfTheWeek.at(i));
+ if(!JSSetArrayElement(ctx, jsResult, i, val)) {
+ throw UnknownException("Could not insert value into js array");
+ }
+ }
+ }
+
+ return jsResult;
+ } catch (...) {
+ LoggerI("Exception: occured");
+ }
+
+ return JSValueMakeUndefined(ctx);
+}
+
+} // Alarm
+} // TizenApis
+
+
diff --git a/wearable_src/Alarm/JSAlarmAbsolute.h b/wearable_src/Alarm/JSAlarmAbsolute.h
new file mode 100755
index 0000000..b9ee64f
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmAbsolute.h
@@ -0,0 +1,84 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef _JS_TIZEN_JSALARMABSOLUTE
+#define _JS_TIZEN_JSALARMABSOLUTE
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <IApplicationManager.h>
+#include "AlarmAbsolute.h"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+#define TIZEN_ALARM_ABSOLUTE_INTERFACE "AlarmAbsolute"
+
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_ID "id"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DATE "date"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_PERIOD "period"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DAYSOFTHEWEEK "daysOfTheWeek"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<AlarmAbsolutePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAlarmAbsolutePriv;
+
+class JSAlarmAbsolute {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+ static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+ static JSValueRef createJSObject(JSContextRef context, AlarmAbsolutePtr privateData);
+
+protected:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static JSValueRef getNextScheduledDate(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+private:
+ static AlarmAbsolutePtr getPrivData(JSObjectRef object);
+
+ static JSValueRef getDate(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getId(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getInterval(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getDaysOfTheWeek(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+
+ static JSClassDefinition m_jsClassInfo;
+ static JSClassRef m_jsClassRef;
+ static JSStaticFunction m_function[];
+ static JSStaticValue m_property[];
+};
+
+}// Alarm
+} // TizenApis
+
+#endif
diff --git a/wearable_src/Alarm/JSAlarmManager.cpp b/wearable_src/Alarm/JSAlarmManager.cpp
new file mode 100644
index 0000000..e572cc4
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmManager.cpp
@@ -0,0 +1,516 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <vector>
+#include <app.h>
+#include <time.h>
+#include <string>
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
+#include <SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include <JSWebAPIErrorFactory.h>
+#include <JSApplicationControl.h>
+#include <ApplicationControl.h>
+#include <ApplicationConverter.h>
+
+#include <ail.h>
+
+#include "plugin_config.h"
+#include "AlarmConverter.h"
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+#include "JSAlarmManager.h"
+
+#include <TimeTracer.h>
+#include <Export.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+static bool alarm_iterate_callback(int alarm_id, void *user_data)
+{
+ std::vector<int> *alarmIds = reinterpret_cast<std::vector<int>*>(user_data);
+
+ alarmIds->push_back(alarm_id);
+ return true;
+}
+
+JSClassRef JSAlarmManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmManager::m_jsClassInfo = {
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_ALARM_INTERFACE,
+ NULL,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //getProperty,
+ NULL, //setProperty,
+ NULL, //deleteProperty,Geolocation
+ NULL, //getPropertyNames,
+ NULL,
+ NULL, // constructor
+ NULL,
+ NULL
+};
+
+JSStaticFunction JSAlarmManager::m_function[] = {
+ { ALARM_FUNCTION_API_ADD, JSAlarmManager::add,kJSPropertyAttributeNone },
+ { ALARM_FUNCTION_API_REMOVE, JSAlarmManager::remove,kJSPropertyAttributeNone },
+ { ALARM_FUNCTION_API_REMOVE_ALL, JSAlarmManager::removeAll,kJSPropertyAttributeNone },
+ { ALARM_FUNCTION_API_GET_ALL, JSAlarmManager::getAll,kJSPropertyAttributeNone },
+ { ALARM_FUNCTION_API_GET, JSAlarmManager::get,kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSStaticValue JSAlarmManager::m_property[] = {
+ { TIZEN_ALARM_CONSTANT_PERIOD_MINUTE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_CONSTANT_PERIOD_HOUR, getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_CONSTANT_PERIOD_DAY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_CONSTANT_PERIOD_WEEK, getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+const JSClassRef DLL_EXPORT JSAlarmManager::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmManager::getClassInfo()
+{
+ return &m_jsClassInfo;
+}
+
+JSContextRef JSAlarmManager::gContext = NULL;
+
+void JSAlarmManager::initialize(JSContextRef ctx, JSObjectRef object)
+{
+ gContext = ctx;
+}
+
+void JSAlarmManager::finalize(JSObjectRef object)
+{
+}
+
+JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ service_h service;
+ struct tm startDate;
+ int delay = 0;
+ int alarm_id;
+ std::string applicationId;
+ std::string page;
+
+ TIME_TRACER_ITEM_BEGIN("(add)ace_check", 0);
+ AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_ADD);
+ TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
+ TIME_TRACER_ITEM_END("(add)ace_check", 0);
+
+ try {
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+ AlarmConverter converter(ctx);
+
+ // applicationId
+ std::string appId = validator.toString(1);
+
+ // alarm
+ JSObjectRef alarmObj = validator.toObject(0);
+ if (JSValueIsObjectOfClass(ctx, alarmObj, JSAlarmAbsolute::getClassRef())) {
+
+ JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(alarmObj));
+ if (!priv) {
+ throw TypeMismatchException("Object is null.");
+ }
+ AlarmAbsolutePtr alarmPtr = priv->getObject();
+ if (!alarmPtr) {
+ throw TypeMismatchException("Private object is null.");
+ }
+
+ startDate = alarmPtr->getDate();
+ service = alarmPtr->getService();
+ service_set_app_id(service, appId.c_str());
+
+ // appControl
+ JSObjectRef appControlObj = validator.toObject(2, true);
+ if (appControlObj) {
+ if(!JSValueIsObjectOfClass(ctx, appControlObj, DeviceAPI::Application::JSApplicationControl::getClassRef())) {
+ throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+ }
+ DeviceAPI::Application::ApplicationConverter applicationConverter(ctx);
+ DeviceAPI::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(appControlObj);
+ if(converter.toAlarmService(service, appService) == false) {
+ throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+ }
+ } else {
+ service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+ }
+
+ AbsoluteRecurrence::Type alarmType = alarmPtr->getRecurrenceType();
+
+ int err = ALARM_ERROR_NONE;
+ if(alarmType == AbsoluteRecurrence::ByDayValue) {
+ int bydayValue = converter.toNativeAlarmValue(alarmPtr->getByDayRecurrence());
+ LoggerI("Native bydayValue = " << bydayValue);
+ TIME_TRACER_ITEM_BEGIN("(add)alarm_schedule_with_recurrence_week_flag", 0);
+ err = alarm_schedule_with_recurrence_week_flag(service, &startDate, bydayValue, &alarm_id);
+ TIME_TRACER_ITEM_END("(add)alarm_schedule_with_recurrence_week_flag", 0);
+
+ } else if(alarmType == AbsoluteRecurrence::Interval) {
+ int interval = alarmPtr->getInterval();
+ TIME_TRACER_ITEM_BEGIN("(add)alarm_schedule_at_date", 0);
+ err = alarm_schedule_at_date(service, &startDate, interval, &alarm_id);
+ TIME_TRACER_ITEM_END("(add)alarm_schedule_at_date", 0);
+ } else {
+ TIME_TRACER_ITEM_BEGIN("(add)alarm_schedule_at_date", 0);
+ err = alarm_schedule_at_date(service, &startDate, 0, &alarm_id);
+ TIME_TRACER_ITEM_END("(add)alarm_schedule_at_date", 0);
+ }
+
+ if(err == ALARM_ERROR_NONE) {
+ alarmPtr->setId(alarm_id);
+ } else {
+ throw UnknownException("Alarm scheduling failed.");
+ }
+
+ } else if (JSValueIsObjectOfClass(ctx, alarmObj, JSAlarmRelative::getClassRef())) {
+
+ JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(alarmObj));
+ if (!priv) {
+ throw TypeMismatchException("Object is null.");
+ }
+ AlarmRelativePtr alarmPtr = priv->getObject();
+ if (!alarmPtr) {
+ throw TypeMismatchException("Private object is null.");
+ }
+
+ delay = alarmPtr->getDelay();
+ if (delay < 0) {
+ throw InvalidValuesException("Alarm scheduling failed : delay cannot be negative value.");
+ }
+
+ long interval = alarmPtr->getPeriod();
+ service = alarmPtr->getService();
+ service_set_app_id(service, appId.c_str());
+
+ // appControl
+ JSObjectRef appControlObj = validator.toObject(2, true);
+ if (appControlObj) {
+ if(!JSValueIsObjectOfClass(ctx, appControlObj, DeviceAPI::Application::JSApplicationControl::getClassRef())) {
+ throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+ }
+ DeviceAPI::Application::ApplicationConverter applicationConverter(ctx);
+ DeviceAPI::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(appControlObj);
+ if(converter.toAlarmService(service, appService) == false) {
+ throw TypeMismatchException("Third parameter is not a ApplicationControl object");
+ }
+ } else {
+ service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+ }
+
+ TIME_TRACER_ITEM_BEGIN("(add)alarm_schedule_after_delay", 0);
+ int err = alarm_schedule_after_delay(service, delay, interval, &alarm_id);
+ TIME_TRACER_ITEM_END("(add)alarm_schedule_after_delay", 0);
+
+ if(err == ALARM_ERROR_NONE) {
+ alarmPtr->setId(alarm_id);
+ } else {
+ throw UnknownException("Alarm scheduling failed.");
+ }
+
+ } else {
+ LoggerE("First parameter is not a Alarm object");
+ throw TypeMismatchException("First parameter is not a Alarm object");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(ctx);
+
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmManager::remove(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ TIME_TRACER_ITEM_BEGIN("(add)ace_check", 0);
+ AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_REMOVE);
+ TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
+ TIME_TRACER_ITEM_END("(add)ace_check", 0);
+
+ try {
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+
+ // id
+ std::string id = validator.toString(0);
+
+ int alarmId = 0;
+ std::stringstream(id) >> alarmId;
+
+ if (alarmId <= 0) {
+ throw InvalidValuesException("Invalid ID");
+ }
+
+ TIME_TRACER_ITEM_BEGIN("(remove)alarm_cancel", 0);
+ int ret = alarm_cancel(alarmId);
+ TIME_TRACER_ITEM_END("(remove)alarm_cancel", 0);
+
+ if (ret != ALARM_ERROR_NONE) {
+ throw NotFoundException("Alarm not found");
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(ctx);
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmManager::removeAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ TIME_TRACER_ITEM_BEGIN("(add)ace_check", 0);
+ AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_REMOVE_ALL);
+ TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
+ TIME_TRACER_ITEM_END("(add)ace_check", 0);
+
+ TIME_TRACER_ITEM_BEGIN("(removeAll)alarm_cancel_all", 0);
+ int returnVal = alarm_cancel_all();
+ TIME_TRACER_ITEM_END("(removeAll)alarm_cancel_all", 0);
+
+ if (ALARM_ERROR_NONE != returnVal) {
+ LoggerE("Error while removing all alarms: "<< returnVal);
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ try {
+ service_h service = NULL;
+ char* alarmType = NULL;
+ JSValueRef result = NULL;
+
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+ AlarmConverter converter(ctx);
+
+ // id
+ std::string id = validator.toString(0);
+ int alarmId = 0;
+ std::stringstream(id) >> alarmId;
+
+ if (alarmId <= 0) {
+ LoggerE("Wrong Alarm ID");
+ throw InvalidValuesException("Invalid ID");
+ }
+
+ TIME_TRACER_ITEM_BEGIN("(get)alarm_get_service", 0);
+ int ret = alarm_get_service(alarmId, &service);
+
+ if (ret != ALARM_ERROR_NONE) {
+ throw NotFoundException("Alarm not found");
+ }
+
+ ret = service_get_extra_data(service, ALARM_TYPE_KEY, &alarmType);
+ if (ret != SERVICE_ERROR_NONE) {
+ LoggerE("Getting data failed: " << ret);
+ service_destroy(service);
+ throw UnknownException("Unknown error occurred.");
+ }
+ TIME_TRACER_ITEM_END("(get)alarm_get_service", 0);
+
+ if (strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE) == 0) {
+ AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(service));
+
+ if(!converter.toAlarmAbsolutePtr(alarmId, service, privateData)) {
+ service_destroy(service);
+ throw TypeMismatchException("Alarm not found");
+ }
+
+ result = JSAlarmAbsolute::createJSObject(ctx, privateData);
+
+ } else if(strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE) == 0) {
+ AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(service));
+
+ if(!converter.toAlarmRelativePtr(alarmId, service, privateData)) {
+ service_destroy(service);
+ throw TypeMismatchException("Alarm not found");
+ }
+
+ result = JSAlarmRelative::createJSObject(ctx, privateData);
+ } else {
+ service_destroy(service);
+ throw UnknownException("Unknown error occurred.");
+ }
+
+ service_destroy(service);
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return result;
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+
+JSValueRef JSAlarmManager::getAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ try {
+ AlarmConverter converter(ctx);
+ std::vector<int> alarmIds;
+
+ TIME_TRACER_ITEM_BEGIN("(getAll)alarm_foreach_registered_alarm", 0);
+ int error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds);
+ TIME_TRACER_ITEM_END("(getAll)alarm_foreach_registered_alarm", 0);
+ if (error == ALARM_ERROR_CONNECTION_FAIL) {
+ LoggerE("Alarm system may not be ready yet.");
+ alarmIds.clear();
+ } else if(error != ALARM_ERROR_NONE) {
+ LoggerE("Error occurred while getting all alarms : " << error);
+ throw UnknownException("Unknown error occurred.");
+ }
+
+ JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+ if (jsResult == NULL) {
+ throw TypeMismatchException("Could not create js array object.");
+ }
+
+ for (size_t i = 0 ; i < alarmIds.size(); i++) {
+
+ service_h handle = NULL;
+ char* alarmType = NULL;
+
+ TIME_TRACER_ITEM_BEGIN("(getAll)alarm_get_service", 0);
+ error = alarm_get_service(alarmIds.at(i), &handle);
+ TIME_TRACER_ITEM_END("(getAll)alarm_get_service", 0);
+ if(error != ALARM_ERROR_NONE) {
+ LoggerE("Getting service failed: " << error);
+ throw NotFoundException("Alarm not found");
+ }
+
+ TIME_TRACER_ITEM_BEGIN("(getAll)service_get_extra_data", 0);
+ error = service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
+ TIME_TRACER_ITEM_END("(getAll)service_get_extra_data", 0);
+ if(error != SERVICE_ERROR_NONE) {
+ LoggerI("Getting data failed: " << error);
+ service_destroy(handle);
+ throw UnknownException("Unknown error occurred.");
+ }
+
+ JSValueRef obj = NULL;
+ if (strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE) == 0) {
+ AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
+
+ if(!converter.toAlarmAbsolutePtr(alarmIds.at(i), handle, privateData)) {
+ service_destroy(handle);
+ throw TypeMismatchException("Absolute alarm conversion failed.");
+ }
+
+ obj = JSAlarmAbsolute::createJSObject(ctx, privateData);
+
+ } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
+ AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
+
+ if(!converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData)) {
+ service_destroy(handle);
+ throw TypeMismatchException("Relative alarm conversion failed.");
+ }
+ obj = JSAlarmRelative::createJSObject(ctx, privateData);
+
+ } else {
+ service_destroy(handle);
+ throw UnknownException("Unknown error occurred.");
+ }
+
+ service_destroy(handle);
+
+ if(!JSSetArrayElement(ctx, jsResult, i, obj)) {
+ service_destroy(handle);
+ throw UnknownException("JS array creation failed.");
+ }
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return jsResult;
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmManager::getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ try {
+ if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_MINUTE)) {
+ return JSUtil::toJSValueRef(context, (long)60);
+ } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_HOUR)) {
+ return JSUtil::toJSValueRef(context, (long)3600);
+ } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_DAY)) {
+ return JSUtil::toJSValueRef(context, (long)86400);
+ } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ALARM_CONSTANT_PERIOD_WEEK)) {
+ return JSUtil::toJSValueRef(context, (long)604800);
+ }
+ } catch (const BasePlatformException &err) {
+ LoggerE("Getting property is failed. %s", err.getMessage().c_str());
+ }
+
+ return NULL;
+}
+
+} // Alarm
+} // TizenApis
+
diff --git a/wearable_src/Alarm/JSAlarmManager.h b/wearable_src/Alarm/JSAlarmManager.h
new file mode 100755
index 0000000..7100030
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmManager.h
@@ -0,0 +1,66 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef _JS_TIZEN_ALARM_MANAGER
+#define _JS_TIZEN_ALARM_MANAGER
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+#define TIZEN_ALARM_INTERFACE "AlarmManager"
+
+#define TIZEN_ALARM_CONSTANT_PERIOD_MINUTE "PERIOD_MINUTE"
+#define TIZEN_ALARM_CONSTANT_PERIOD_HOUR "PERIOD_HOUR"
+#define TIZEN_ALARM_CONSTANT_PERIOD_DAY "PERIOD_DAY"
+#define TIZEN_ALARM_CONSTANT_PERIOD_WEEK "PERIOD_WEEK"
+
+class JSAlarmManager {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+ static JSContextRef gContext;
+
+protected:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static JSValueRef add(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+ static JSValueRef remove(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+ static JSValueRef removeAll(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+ static JSValueRef get(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+ static JSValueRef getAll(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+private:
+ static JSValueRef getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSClassDefinition m_jsClassInfo;
+ static JSClassRef m_jsClassRef;
+ static JSStaticFunction m_function[];
+ static JSStaticValue m_property[];
+
+};
+
+}
+} // TizenApis
+
+#endif
diff --git a/wearable_src/Alarm/JSAlarmRelative.cpp b/wearable_src/Alarm/JSAlarmRelative.cpp
new file mode 100644
index 0000000..9fd962c
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmRelative.cpp
@@ -0,0 +1,314 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include <ArgumentValidator.h>
+
+#include <Commons/Exception.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+
+#include "plugin_config.h"
+
+#include "AlarmRelative.h"
+#include "AlarmConverter.h"
+#include "JSAlarmRelative.h"
+#include "JSAlarmManager.h"
+
+#include <JSUtil.h>
+
+#include <TimeTracer.h>
+#include <app.h>
+#include <time.h>
+#include <Export.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+JSClassRef JSAlarmRelative::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmRelative::m_jsClassInfo = {
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_ALARM_RELATIVE_INTERFACE,
+ NULL,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //getProperty,
+ NULL, //setProperty,
+ NULL, //deleteProperty,Geolocation
+ NULL, //getPropertyNames,
+ NULL,
+ NULL, // constructor
+ NULL,
+ NULL
+};
+
+JSStaticFunction JSAlarmRelative::m_function[] = {
+ { ALARM_FUNCTION_API_GET_REMAINING_SECONDS, JSAlarmRelative::getRemainingSeconds, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSStaticValue JSAlarmRelative::m_property[] = {
+ { TIZEN_ALARM_RELATIVE_ATTRIBUTE_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_RELATIVE_ATTRIBUTE_DELAY, getDelay, NULL, kJSPropertyAttributeReadOnly },
+ { TIZEN_ALARM_RELATIVE_ATTRIBUTE_PERIOD, getPeriod, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+const JSClassRef DLL_EXPORT JSAlarmRelative::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmRelative::getClassInfo()
+{
+ return &m_jsClassInfo;
+}
+
+void JSAlarmRelative::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+void JSAlarmRelative::finalize(JSObjectRef object)
+{
+ JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ LoggerE("Private object is null");
+ }
+ delete priv;
+}
+
+
+JSObjectRef DLL_EXPORT JSAlarmRelative::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+
+ AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative());
+
+ try {
+ long delay = validator.toLong(0);
+ privateData->setDelay(delay);
+
+ long period = validator.toLong(1, true, -1);
+ privateData->setPeriod(period);
+
+ } catch (const BasePlatformException& err) {
+ LoggerE("Exception occured while creating constructor : " << err.getMessage());
+ }
+
+ JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(ctx, privateData);
+ JSObjectRef obj = JSObjectMake(ctx, getClassRef(), priv);
+
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, obj, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+
+ return obj;
+}
+
+AlarmRelativePtr JSAlarmRelative::getPrivData(JSObjectRef object)
+{
+ JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ throw TypeMismatchException("Private object is null");
+ }
+ AlarmRelativePtr result = priv->getObject();
+ if (!result) {
+ throw TypeMismatchException("Private object is null");
+ }
+ return result;
+}
+
+JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, AlarmRelativePtr privateData)
+{
+ JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
+ if (!priv) {
+ throw TypeMismatchException("Private object is null");
+ }
+ return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+
+JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int interval)
+{
+ AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative());
+ privateData->setDelay(delay);
+ privateData->setPeriod(interval);
+
+ JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
+ if (!priv) {
+ throw TypeMismatchException("Private object is null");
+ }
+ return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception)
+{
+ struct tm date;
+ struct tm current;
+ time_t currentTime;
+ time_t nextTime;
+ int id;
+
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ try {
+ AlarmRelativePtr privateData = getPrivData(thisObject);
+
+ if(!privateData->is_registered) {
+ return JSValueMakeNull(ctx);
+ }
+
+ id = privateData->getId();
+
+ TIME_TRACER_ITEM_BEGIN("(getRemainingSeconds)alarm_get_scheduled_date", 0);
+ int err = alarm_get_scheduled_date(id, &date);
+ TIME_TRACER_ITEM_END("(getRemainingSeconds)alarm_get_scheduled_date", 0);
+ if(err != ALARM_ERROR_NONE)
+ {
+ LoggerI("alarm_get_scheduled_date error =" << err);
+ if(err == ALARM_ERROR_INVALID_PARAMETER || err== ALARM_ERROR_CONNECTION_FAIL) {
+ return JSValueMakeNull(ctx);
+ } else {
+ throw UnknownException("Unknown exception occurred. fail to get scheduled date");
+ }
+ }
+
+ TIME_TRACER_ITEM_BEGIN("(getRemainingSeconds)alarm_get_current_time", 0);
+ alarm_get_current_time(&current);
+
+ nextTime = mktime(&date);
+ currentTime = mktime(&current);
+ TIME_TRACER_ITEM_END("(getRemainingSeconds)alarm_get_current_time", 0);
+
+ long result = nextTime - currentTime;
+
+ LoggerI("nextTime: "<<nextTime<<", currentTime: "<<currentTime<<", result: "<<result);
+
+ if(result < 0) {
+ return JSValueMakeNull(ctx);
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, result);
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppSharedURI().");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmRelative::getId(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Converter converter(ctx);
+
+ try {
+ AlarmRelativePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ if(privateData->is_registered) {
+ std::string strId = converter.toString(privateData->getId());
+ return converter.toJSValueRef(strId);
+ } else {
+ return JSValueMakeNull(ctx);
+ }
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmRelative::getDelay(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ long delay;
+
+ try {
+ AlarmRelativePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ delay = privateData->getDelay();
+ LoggerI("JSAlarmRelative delay = " << delay);
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, delay);
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+JSValueRef JSAlarmRelative::getPeriod(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ long period =0;
+
+ try {
+ AlarmRelativePtr privateData = getPrivData(object);
+ if (!privateData) {
+ throw TypeMismatchException("Private object is null");
+ }
+
+ period = privateData->getPeriod();
+ LoggerI("JSAlarmRelative interval = " << period);
+ if(period == -1) {
+ return JSValueMakeNull(ctx);
+ } else {
+ return DeviceAPI::Common::JSUtil::toJSValueRef(ctx, period);
+ }
+ } catch (const BasePlatformException &err) {
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ } catch (...) {
+ DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
+ return JSWebAPIErrorFactory::postException(ctx, exception, err);
+ }
+}
+
+} // Alarm
+} // TizenApis
+
+
diff --git a/wearable_src/Alarm/JSAlarmRelative.h b/wearable_src/Alarm/JSAlarmRelative.h
new file mode 100755
index 0000000..fee01ff
--- /dev/null
+++ b/wearable_src/Alarm/JSAlarmRelative.h
@@ -0,0 +1,78 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef _JS_TIZEN_ALARMRELATIVE
+#define _JS_TIZEN_ALARMRELATIVE
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <IApplicationManager.h>
+#include "AlarmRelative.h"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+#define TIZEN_ALARM_RELATIVE_INTERFACE "AlarmRelative"
+
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_ID "id"
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_DELAY "delay"
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_PERIOD "period"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<AlarmRelativePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAlarmRelativePriv;
+
+class JSAlarmRelative {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+ static JSValueRef createJSObject(JSContextRef context, AlarmRelativePtr privateData);
+ static JSValueRef createJSObject(JSContextRef context, int delay, int interval);
+ static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+protected:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static JSValueRef getRemainingSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+
+private:
+ static AlarmRelativePtr getPrivData(JSObjectRef object);
+
+ static JSValueRef getId(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getDelay(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef getPeriod(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSClassDefinition m_jsClassInfo;
+ static JSClassRef m_jsClassRef;
+ static JSStaticFunction m_function[];
+ static JSStaticValue m_property[];
+};
+
+}// Alarm
+} // TizenApis
+
+#endif
diff --git a/wearable_src/Alarm/alarm_common.h b/wearable_src/Alarm/alarm_common.h
new file mode 100755
index 0000000..bd38edf
--- /dev/null
+++ b/wearable_src/Alarm/alarm_common.h
@@ -0,0 +1,61 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_API_ALARM_COMMON_H_
+#define TIZENAPIS_API_ALARM_COMMON_H_
+
+namespace DeviceAPI {
+namespace Alarm {
+
+// Alarm Type
+#define ALARM_TYPE_KEY "TYPE"
+#define ALARM_TYPE_ABSOLUTE_VALUE "ABSOLUTE"
+#define ALARM_TYPE_RELATIVE_VALUE "RELATIVE"
+
+// Absolute Alarm Recurrence
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY "RECURRENCE"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL "INTERVAL"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE "BYDAYVALUE"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE "NONE"
+#define ALARM_ABSOLUTE_FREQUENCY_KEY "FREQUENCY"
+#define ALARM_ABSOLUTE_FREQUENCY_INTERVAL "FREQUENCY_INTERVAL"
+#define ALARM_ALSOLUTE_DATE_KEY "DATE"
+
+// Relative Alarm Delay
+#define ALARM_RELATIVE_DELAY_KEY "RELATIVE_DELAY"
+
+// Frequency
+#define ALARM_PROPERTY_MINUTELY_RECURRENCE "MINUTELY"
+#define ALARM_PROPERTY_HOURLY_RECURRENCE "HOURLY"
+#define ALARM_PROPERTY_DAILY_RECURRENCE "DAILY"
+#define ALARM_PROPERTY_WEEKLY_RECURRENCE "WEEKLY"
+#define ALARM_PROPERTY_MONTHLY_RECURRENCE "MONTHLY"
+#define ALARM_PROPERTY_YEARLY_RECURRENCE "YEARLY"
+
+namespace AbsoluteRecurrence
+{
+ typedef enum
+ {
+ NoRecurrence,
+ ByDayValue,
+ Interval,
+ }Type;
+}
+
+}
+}
+#endif
diff --git a/wearable_src/Alarm/config.xml b/wearable_src/Alarm/config.xml
new file mode 100755
index 0000000..05f5f62
--- /dev/null
+++ b/wearable_src/Alarm/config.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+ <library-name>libwrt-plugins-tizen-alarm.so</library-name>
+ <feature-install-uri>alarm.install.uri</feature-install-uri>
+ <api-feature>
+ <name>http://tizen.org/privilege/alarm</name>
+ <device-capability>alarm</device-capability>
+ </api-feature>
+
+</plugin-properties>
diff --git a/wearable_src/Alarm/plugin_config.cpp b/wearable_src/Alarm/plugin_config.cpp
new file mode 100755
index 0000000..856b58a
--- /dev/null
+++ b/wearable_src/Alarm/plugin_config.cpp
@@ -0,0 +1,109 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <iostream>
+#include <Commons/Exception.h>
+#include <dpl/exception.h>
+#include <map>
+
+#include "plugin_config.h"
+
+#define ALARM_FEATURE_API "http://tizen.org/privilege/alarm"
+
+#define ALARM_DEVICE_CAP "alarm"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace DeviceAPI {
+namespace Alarm {
+
+static FunctionMapping createAlarmFunctions();
+
+static FunctionMapping AlarmFunctions =
+ createAlarmFunctions();
+
+#pragma GCC visibility push(default)
+
+DEFINE_FUNCTION_GETTER(Alarm, AlarmFunctions);
+
+#pragma GCC visibility pop
+
+static FunctionMapping createAlarmFunctions()
+{
+ /**
+ * Device capabilities
+ */
+ ACE_CREATE_DEVICE_CAP(DEVICE_CAP_ALARM, ALARM_DEVICE_CAP);
+
+ ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_ALARM);
+ ACE_ADD_DEVICE_CAP(DEVICE_LIST_ALARM, DEVICE_CAP_ALARM);
+
+ /**
+ * Api Features
+ */
+ ACE_CREATE_FEATURE(FEATURE_ALARM, ALARM_FEATURE_API);
+
+ ACE_CREATE_FEATURE_LIST(ALARM_FEATURES);
+ ACE_ADD_API_FEATURE(ALARM_FEATURES, FEATURE_ALARM);
+
+ /**
+ * Functions
+ */
+ FunctionMapping alarmMapping;
+
+ // add
+ AceFunction addFunc = ACE_CREATE_FUNCTION(
+ FUNCTION_ADD,
+ ALARM_FUNCTION_API_ADD,
+ ALARM_FEATURES,
+ DEVICE_LIST_ALARM);
+
+ alarmMapping.insert(std::make_pair(
+ ALARM_FUNCTION_API_ADD,
+ addFunc));
+
+ // remove
+ AceFunction removeFunc = ACE_CREATE_FUNCTION(
+ FUNCTION_REMOVE,
+ ALARM_FUNCTION_API_REMOVE,
+ ALARM_FEATURES,
+ DEVICE_LIST_ALARM);
+
+ alarmMapping.insert(std::make_pair(
+ ALARM_FUNCTION_API_REMOVE,
+ removeFunc));
+
+
+ // removeAll
+ AceFunction removeAllFunc = ACE_CREATE_FUNCTION(
+ FUNCTION_REMOVE_ALL,
+ ALARM_FUNCTION_API_REMOVE_ALL,
+ ALARM_FEATURES,
+ DEVICE_LIST_ALARM);
+
+ alarmMapping.insert(std::make_pair(
+ ALARM_FUNCTION_API_REMOVE_ALL,
+ removeAllFunc));
+
+ return alarmMapping;
+}
+
+}
+}
diff --git a/wearable_src/Alarm/plugin_config.h b/wearable_src/Alarm/plugin_config.h
new file mode 100755
index 0000000..796e37b
--- /dev/null
+++ b/wearable_src/Alarm/plugin_config.h
@@ -0,0 +1,44 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _ALARM_PLUGIN_CONFIG_H_
+#define _ALARM_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+#define ALARM_FUNCTION_API_GET_ALL "getAll"
+#define ALARM_FUNCTION_API_GET "get"
+#define ALARM_FUNCTION_API_ADD "add"
+#define ALARM_FUNCTION_API_REMOVE "remove"
+#define ALARM_FUNCTION_API_REMOVE_ALL "removeAll"
+#define ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE "getNextScheduledDate"
+#define ALARM_FUNCTION_API_GET_REMAINING_SECONDS "getRemainingSeconds"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+DECLARE_FUNCTION_GETTER(Alarm);
+
+#define ALARM_CHECK_ACCESS(functionName) \
+ aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+ getAlarmFunctionData, \
+ functionName)
+}
+}
+#endif
+
diff --git a/wearable_src/Alarm/plugin_initializer.cpp b/wearable_src/Alarm/plugin_initializer.cpp
new file mode 100644
index 0000000..2951641
--- /dev/null
+++ b/wearable_src/Alarm/plugin_initializer.cpp
@@ -0,0 +1,100 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include <TimeTracer.h>
+#include "JSAlarmManager.h"
+#include "JSAlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include <Logger.h>
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+namespace DeviceAPI {
+namespace Alarm {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+class_definition_options_t ConstructorClassOptions =
+{
+ JS_INTERFACE,
+ CREATE_INSTANCE,
+ NONE_NOTICE,
+ USE_OVERLAYED, //ignored
+ NULL,
+ NULL,
+ NULL
+};
+
+void on_widget_start_callback(int widgetId)
+{
+ LoggerI("[Tizen\\AlarmManager ] on_widget_start_callback (" << widgetId << ")");
+ Try
+ {
+ TIME_TRACER_INIT();
+ WrtAccessSingleton::Instance().initialize(widgetId);
+ }
+ Catch(Commons::Exception)
+ {
+ LoggerE("WrtAccess initialization failed");
+ }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+ LoggerI("[Tizen\\AlarmManager ] on_widget_stop_callback (" << widgetId << ")");
+ Try
+ {
+ TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"Alarm");
+ TIME_TRACER_RELEASE();
+ WrtAccessSingleton::Instance().deinitialize(widgetId);
+ }
+ Catch(Commons::Exception)
+ {
+ LoggerE("WrtAccess deinitialization failed");
+ }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(
+ WRT_JS_EXTENSION_OBJECT_TIZEN,
+ "alarm",
+ (js_class_template_getter)DeviceAPI::Alarm::JSAlarmManager::getClassRef,
+ NULL)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
+ WRT_JS_EXTENSION_OBJECT_TIZEN,
+ TIZEN_ALARM_ABSOLUTE_INTERFACE,
+ (js_class_template_getter)DeviceAPI::Alarm::JSAlarmAbsolute::getClassRef,
+ reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmAbsolute::constructor),
+ &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
+ WRT_JS_EXTENSION_OBJECT_TIZEN,
+ TIZEN_ALARM_RELATIVE_INTERFACE,
+ (js_class_template_getter)DeviceAPI::Alarm::JSAlarmRelative::getClassRef,
+ reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmRelative::constructor),
+ &ConstructorClassOptions)
+PLUGIN_CLASS_MAP_END
+
+} // Alarm
+} // DeviceAPI