wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Alarm / AlarmAbsolute.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 #include "AlarmAbsolute.h"
20 #include "alarm_common.h"
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <Logger.h>
25
26 namespace DeviceAPI {
27 namespace Alarm {
28
29 AlarmAbsolute::AlarmAbsolute()
30 {
31     m_isRecurrence = false;
32     service_create(&m_service_handle);
33     service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_ABSOLUTE_VALUE);
34     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE);
35     m_recurrenceType = AbsoluteRecurrence::NoRecurrence;
36     m_id = -1;
37         m_interval = -1;
38 }
39
40 AlarmAbsolute::AlarmAbsolute(service_h handle)
41 {
42     service_clone(&m_service_handle, handle);
43     m_id = -1;
44         m_interval = -1;
45 }
46
47 AlarmAbsolute::~AlarmAbsolute()
48 {
49     service_destroy(m_service_handle);
50 }
51
52 int AlarmAbsolute::getId() const
53 {
54     return m_id;
55 }
56
57 void AlarmAbsolute::setId(const int id)
58 {
59     m_id = id;
60 }
61
62 bool AlarmAbsolute::isRecurrence()
63 {
64     return m_isRecurrence;
65 }
66
67 void AlarmAbsolute::setIsRecurrence(bool value)
68 {
69     m_isRecurrence = value;
70 }
71
72 void AlarmAbsolute::setDate(struct tm date)
73 {
74     char strDate[19]; 
75     m_date = date;
76
77     snprintf(strDate, sizeof(strDate),  "%d %d %d %d %d %d",m_date.tm_year, m_date.tm_mon, 
78                 m_date.tm_mday,  m_date.tm_hour, m_date.tm_min,  m_date.tm_sec);
79
80     LoggerI("setDate encrypted string = " << strDate);
81     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_DATE_KEY, strDate);
82
83     LoggerI("AlarmAbsolute Date = " << " Sec: " << m_date.tm_sec << ", Min: "<< m_date.tm_min
84     << ", Hour:" << m_date.tm_hour << ", Day: " << m_date.tm_mday << ", MON: " << m_date.tm_mon 
85     << ", Year: " <<  m_date.tm_year);
86 }
87
88 struct tm AlarmAbsolute::getDate()
89 {
90     return m_date;
91 }
92
93 void AlarmAbsolute::setInterval(int interval)
94 {
95     m_interval = interval;
96     m_recurrenceType = AbsoluteRecurrence::Interval;
97     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL);
98 }
99
100 int AlarmAbsolute::getInterval()
101 {
102     return m_interval;
103 }
104
105 void AlarmAbsolute::setByDayRecurrence(std::vector<std::string> &daysOfTheWeek)
106 {
107     m_recurrenceType = AbsoluteRecurrence::ByDayValue;
108     m_daysOfTheWeek = daysOfTheWeek;
109     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE);
110 }
111
112 std::vector<std::string> AlarmAbsolute::getByDayRecurrence()
113 {
114     return m_daysOfTheWeek;
115 }
116
117 AbsoluteRecurrence::Type AlarmAbsolute::getRecurrenceType()
118 {
119     return m_recurrenceType;
120 }
121
122 service_h AlarmAbsolute::getService() {
123     return m_service_handle;
124 }
125
126 }
127 }
128