Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / things-manager / sdk / src / ActionSet.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "ActionSet.h"
22 using namespace std;
23
24 namespace OIC
25 {
26 Time::Time() : mTime()
27 {
28     setTime(0, 0, 0, 0, 0, 0, 0);
29 }
30
31 Time::~Time()
32 {
33 }
34
35 void Time::setTime(OCTime t)
36 {
37     mTime = t;
38 }
39 void Time::setTime(unsigned int yy, unsigned int mm, unsigned int dd,
40         unsigned int h, unsigned int m, unsigned int s,
41         int dayoftheweek = 0)
42 {
43     mDelay = 0;
44     mTime.tm_year = (int)yy - 1900;
45     mTime.tm_mon = (int)mm - 1;
46     mTime.tm_mday = dd;
47
48     mTime.tm_hour = h;
49     mTime.tm_min = m;
50     mTime.tm_sec = s;
51
52     mTime.tm_wday = (unsigned int) dayoftheweek;
53     type = NONE;
54 }
55 void Time::setDayOfWeekForRecursive(int day)
56 {
57     if (day != -1)
58         type = RECURSIVE;
59     else
60         return;
61
62     setTime(0, 0, 0, 0, 0, 0, day);
63 }
64 unsigned int Time::getYear()
65 {
66     return mTime.tm_year;
67 }
68 unsigned int Time::getMonth()
69 {
70     return mTime.tm_mon;
71 }
72 unsigned int Time::getDay()
73 {
74     return mTime.tm_mday;
75 }
76 unsigned int Time::getHour()
77 {
78     return mTime.tm_hour;
79 }
80 unsigned int Time::getMin()
81 {
82     return mTime.tm_min;
83 }
84 unsigned int Time::getSec()
85 {
86     return mTime.tm_sec;
87 }
88 long int Time::getSecondsFromAbsoluteTime()
89 {
90     if(mTime.tm_year > 1900)
91         mTime.tm_year -= 1900;
92
93     mTime.tm_mon -= 1;
94
95     return getSecondsFromAbsTime(&mTime);
96 }
97 long int Time::getSecAbsTime()
98 {
99     return getSeconds(&mTime);
100 }
101 long int Time::getSecondsForWeeklySchedule()
102 {
103     if(mTime.tm_year > 1900)
104         mTime.tm_year -= 1900;
105
106     mTime.tm_mon -= 1;
107     return getRelativeIntervalOfWeek(&mTime);
108 }
109
110 void Time::setDelay(long int seconds)
111 {
112     if(type != NONE)
113     {
114         mDelay = seconds;
115     }
116 }
117
118 std::string Time::toString() const
119 {
120     char temp[25] = { 0 };
121     // It is shown format which required of scheduled/recursive group action time.
122     // " [delay] [type of actionset] "
123     snprintf(temp, sizeof(temp) / sizeof(char),
124             "%ld %d", mDelay, (unsigned int) type);
125     return std::string(temp);
126 }
127
128
129
130
131
132
133
134
135
136
137 Action::Action() :
138         target("")
139 {
140 }
141 Action::~Action()
142 {
143     listOfCapability.clear();
144 }
145
146
147
148
149
150
151
152
153
154 ActionSet::ActionSet() :
155         actionsetName("")
156 {
157 }
158 ActionSet::~ActionSet()
159 {
160     listOfAction.clear();
161 }
162 }