Merge Things Manager codes CA and Master branch.
[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()
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     yy -= 1900;
44     mm -= 1;
45
46     mDelay = 0;
47     mTime.tm_year = yy;
48     mTime.tm_mon = mm;
49     mTime.tm_mday = dd;
50
51     mTime.tm_hour = h;
52     mTime.tm_min = m;
53     mTime.tm_sec = s;
54
55     mTime.tm_wday = (unsigned int) dayoftheweek;
56     type = NONE;
57 }
58 void Time::setDayOfWeekForRecursive(int day)
59 {
60     if (day != -1)
61         type = RECURSIVE;
62     else
63         return;
64
65     setTime(0, 0, 0, 0, 0, 0, day);
66 }
67 unsigned int Time::getYear()
68 {
69     return mTime.tm_year;
70 }
71 unsigned int Time::getMonth()
72 {
73     return mTime.tm_mon;
74 }
75 unsigned int Time::getDay()
76 {
77     return mTime.tm_mday;
78 }
79 unsigned int Time::getHour()
80 {
81     return mTime.tm_hour;
82 }
83 unsigned int Time::getMin()
84 {
85     return mTime.tm_min;
86 }
87 unsigned int Time::getSec()
88 {
89     return mTime.tm_sec;
90 }
91 long int Time::getSecondsFromAbsoluteTime()
92 {
93     if(mTime.tm_year > 1900)
94         mTime.tm_year -= 1900;
95
96     mTime.tm_mon -= 1;
97
98     return getSecondsFromAbsTime(&mTime);
99 }
100 long int Time::getSecAbsTime()
101 {
102     return getSeconds(&mTime);
103 }
104 long int Time::getSecondsForWeeklySchedule()
105 {
106     if(mTime.tm_year > 1900)
107         mTime.tm_year -= 1900;
108
109     mTime.tm_mon -= 1;
110     return getRelativeIntervalOfWeek(&mTime);
111 }
112
113 void Time::setDelay(long int seconds)
114 {
115     if(type != NONE)
116     {
117         mDelay = seconds;
118     }
119 }
120
121 std::string Time::toString() const
122 {
123     char temp[25] = { 0 };
124     // It is shown format which required of scheduled/recursive group action time.
125     // " [delay] [type of actionset] "
126     snprintf(temp, sizeof(temp) / sizeof(char),
127             "%ld %d", mDelay, (unsigned int) type);
128     return std::string(temp);
129 }
130
131
132
133
134
135
136
137
138
139
140 Action::Action() :
141         target("")
142 {
143 }
144 Action::~Action()
145 {
146     listOfCapability.clear();
147 }
148
149
150
151
152
153
154
155
156
157 ActionSet::ActionSet() :
158         actionsetName("")
159 {
160 }
161 ActionSet::~ActionSet()
162 {
163     listOfAction.clear();
164 }
165 }