5816523d1d543a7dc80f3c12a4d971fbdfbc2f22
[platform/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
25 namespace DeviceAPI {
26 namespace Alarm {
27
28 AlarmAbsolute::AlarmAbsolute()
29 {
30     m_isRecurrence = false;
31     service_create(&m_service_handle);
32     service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_ABSOLUTE_VALUE);
33     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE);
34     m_recurrenceType = AbsoluteRecurrence::NoRecurrence;
35     m_id = -1;
36 }
37
38 AlarmAbsolute::AlarmAbsolute(service_h handle)
39 {
40     service_clone(&m_service_handle, handle);
41     m_id = -1;
42 }
43
44 AlarmAbsolute::~AlarmAbsolute()
45 {
46     service_destroy(m_service_handle);
47 }
48
49 int AlarmAbsolute::getId() const
50 {
51     return m_id;
52 }
53
54 void AlarmAbsolute::setId(const int id)
55 {
56     m_id = id;
57 }
58
59 bool AlarmAbsolute::isRecurrence()
60 {
61     return m_isRecurrence;
62 }
63
64 void AlarmAbsolute::setIsRecurrence(bool value)
65 {
66     m_isRecurrence = value;
67 }
68
69 void AlarmAbsolute::setDate(struct tm date)
70 {
71     char strDate[19]; 
72     m_date = date;
73
74     snprintf(strDate, sizeof(strDate),  "%d %d %d %d %d %d",m_date.tm_year, m_date.tm_mon, 
75                 m_date.tm_mday,  m_date.tm_hour, m_date.tm_min,  m_date.tm_sec);
76
77     LogInfo("setDate encrypted string = " << strDate);
78     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_DATE_KEY, strDate);
79
80     LogInfo("AlarmAbsolute Date = " << " Sec: " << m_date.tm_sec << ", Min: "<< m_date.tm_min
81     << ", Hour:" << m_date.tm_hour << ", Day: " << m_date.tm_mday << ", MON: " << m_date.tm_mon 
82     << ", Year: " <<  m_date.tm_year);
83 }
84
85 struct tm AlarmAbsolute::getDate()
86 {
87     return m_date;
88 }
89
90 void AlarmAbsolute::setInterval(int interval)
91 {
92     m_interval = interval;
93     m_recurrenceType = AbsoluteRecurrence::Interval;
94     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL);
95 }
96
97 int AlarmAbsolute::getInterval()
98 {
99     return m_interval;
100 }
101
102 void AlarmAbsolute::setByDayRecurrence(std::vector<std::string> &daysOfTheWeek)
103 {
104     m_recurrenceType = AbsoluteRecurrence::ByDayValue;
105     m_daysOfTheWeek = daysOfTheWeek;
106     service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE);
107 }
108
109 std::vector<std::string> AlarmAbsolute::getByDayRecurrence()
110 {
111     return m_daysOfTheWeek;
112 }
113
114 AbsoluteRecurrence::Type AlarmAbsolute::getRecurrenceType()
115 {
116     return m_recurrenceType;
117 }
118
119 service_h AlarmAbsolute::getService() {
120     return m_service_handle;
121 }
122
123 }
124 }
125