• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <rights/Constraint.h>
18 
19 /** see Constraint.h */
Constraint()20 Constraint::Constraint()
21 {
22     mCount = INIT_VALUE;
23     mTimedCount = INIT_VALUE;
24     mTimer = INIT_VALUE;
25     mStart = INIT_VALUE;
26     mEnd = INIT_VALUE;
27     mInterval = INIT_VALUE;
28     mAccumulated = INIT_VALUE;
29     mExport = NONE;
30 }
31 
32 /** see Constraint.h */
~Constraint()33 Constraint::~Constraint()
34 {}
35 
36 /** see Constraint.h */
isUnConstraint() const37 bool Constraint::isUnConstraint() const
38 {
39     return (mCount == INIT_VALUE && mTimedCount == INIT_VALUE &&
40             mTimer == INIT_VALUE && mStart == INIT_VALUE &&
41             mEnd == INIT_VALUE && mInterval == INIT_VALUE &&
42             mAccumulated == INIT_VALUE && mExport == NONE &&
43             mSystemList.empty());
44 }
45 
46 /** see Constraint.h */
isDateTimeConstraint() const47 bool Constraint::isDateTimeConstraint() const
48 {
49     return !(mStart == INIT_VALUE && mEnd == INIT_VALUE);
50 }
51 
52 /** see Constraint.h */
isIntervalConstraint() const53 bool Constraint::isIntervalConstraint() const
54 {
55     return !(mInterval == INIT_VALUE);
56 }
57 
58 /** see Constraint.h */
isTimedCountConstraint() const59 bool Constraint::isTimedCountConstraint() const
60 {
61     return !(mTimedCount == INIT_VALUE);
62 }
63 
64 /** see Constraint.h */
isValid(long time) const65 bool Constraint::isValid(long time) const
66 {
67     if (isUnConstraint())
68     {
69         return true;
70     }
71 
72     if (isDateTimeConstraint())
73     {
74         if (time < mStart || time > mEnd)
75         {
76             return false;
77         }
78     }
79 
80     if (mInterval == 0 || mCount == 0 ||
81         mTimedCount == 0 || mAccumulated == 0)
82     {
83         return false;
84     }
85 
86     return true;
87 }
88 
89 /** see Constraint.h */
setStartTime(long time)90 void Constraint::setStartTime(long time)
91 {
92     mStart = time;
93 }
94 
95 /** see Constraint.h */
getStartTime() const96 long Constraint::getStartTime() const
97 {
98     return mStart;
99 }
100 
101 /** see Constraint.h */
setEndTime(long time)102 void Constraint::setEndTime(long time)
103 {
104     mEnd = time;
105 }
106 
107 /** see Constraint.h */
getEndTime() const108 long Constraint::getEndTime() const
109 {
110     return mEnd;
111 }
112 
113 /** see Constraint.h */
setAccumulated(long time)114 void Constraint::setAccumulated(long time)
115 {
116     mAccumulated = time;
117 }
118 
119 /** see Constraint.h */
getAccumulated() const120 long Constraint::getAccumulated() const
121 {
122     return mAccumulated;
123 }
124 
125 /** see Constraint.h */
setCount(int count)126 void Constraint::setCount(int count)
127 {
128     mCount = count;
129 }
130 
131 /** see Constraint.h */
getCount() const132 int Constraint::getCount() const
133 {
134     return mCount;
135 }
136 
137 /** see Constraint.h */
setTimer(int timer)138 void Constraint::setTimer(int timer)
139 {
140     mTimer = timer;
141 }
142 
143 /** see Constraint.h */
getTimer() const144 int Constraint::getTimer() const
145 {
146     return mTimer;
147 }
148 
149 /** see Constraint.h */
setTimedCount(int timedCount)150 void Constraint::setTimedCount(int timedCount)
151 {
152     mTimedCount = timedCount;
153 }
154 
155 /** see Constraint.h */
getTimedCount() const156 int Constraint::getTimedCount() const
157 {
158     return mTimedCount;
159 }
160 
161 /** see Constraint.h */
setInterval(int interval)162 void Constraint::setInterval(int interval)
163 {
164     mInterval = interval;
165 }
166 
167 /** see Constraint.h */
getInterval() const168 int Constraint::getInterval() const
169 {
170     return mInterval;
171 }
172 
173 /** see Constraint.h */
setExportMode(MODE mode)174 void Constraint::setExportMode(MODE mode)
175 {
176     mExport = mode;
177 }
178 
179 /** see Constraint.h */
getExportMode() const180 Constraint::MODE Constraint::getExportMode() const
181 {
182     return mExport;
183 }
184 
185 /** see Constraint.h */
consume()186 bool Constraint::consume()
187 {
188     if (isUnConstraint())
189     {
190         return true;
191     }
192 
193     if (mCount > 0)
194     {
195         mCount--;
196         return true;
197     }
198 
199     if (mAccumulated > 0)
200     {
201         mAccumulated--;
202         return true;
203     }
204 
205     if (mTimedCount > 0)
206     {
207 
208     }
209     return false;
210 }
211