RDK Documentation (Open Sourced RDK Components)
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TunerState.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
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 /**
22 * @defgroup trm
23 * @{
24 * @defgroup common
25 * @{
26 **/
27 
28 
29 #include "trm/TunerState.h"
30 #include "trm/Activity.h"
31 
32 LOCAL_BEGIN_NAMESPACE
33 enum {
34  Free,
35  Live,
36  Record,
37  Hybrid,
38  EAS,
39 
40  MAX_ENUM_NUMBER
41 };
42 
43 LOCAL_END_NAMESPACE
44 
45 TRM_BEGIN_NAMESPACE
46 
47 const Enum<TunerState> TunerState::kFree (MAKE_PAIR(Free));
48 const Enum<TunerState> TunerState::kLive (MAKE_PAIR(Live));
49 const Enum<TunerState> TunerState::kRecord(MAKE_PAIR(Record));
50 const Enum<TunerState> TunerState::kHybrid(MAKE_PAIR(Hybrid));
51 const Enum<TunerState> TunerState::kEAS (MAKE_PAIR(EAS));
52 
53 const std::vector<const Enum<TunerState> * > & TunerState::getEnums(void)
54 {
55  static std::vector<const Enum<TunerState> * > enums_;
56  if (enums_.size() == 0) {
57  enums_.push_back(&TunerState::kFree);
58  enums_.push_back(&TunerState::kLive);
59  enums_.push_back(&TunerState::kRecord);
60  enums_.push_back(&TunerState::kHybrid);
61  enums_.push_back(&TunerState::kEAS);
62 
63  Assert(enums_.size() == MAX_ENUM_NUMBER);
64 
65  };
66 
67  return enums_;
68 }
69 
70 TunerState::TunerState(const Enum<TunerState> &state)
71 : state(state)
72 {
73 }
74 
75 TunerState::TunerState(const char *name)
76 : state((Enum<TunerState>::at(name)))
77 {
78 }
79 
80 TunerState::~TunerState(void)
81 {
82 }
83 
84 const Enum<TunerState> & TunerState::getState(void) const
85 {
86  return state;
87 }
88 
89 TunerState TunerState::operator + (const Enum<Activity> & activity)
90 {
91  const Enum<TunerState> origState = state;
92 
93  if (state == TunerState::kFree) {
94  if (activity == Activity::kLive) {
95  state = TunerState::kLive;
96  }
97  else if(activity == Activity::kRecord){
98  state = TunerState::kRecord;
99  }
100  else if(activity == Activity::kEAS){
101  state = TunerState::kEAS;
102  }
103  }
104  else
105  if (state == TunerState::kLive) {
106  if(activity == Activity::kRecord){
107  state = TunerState::kHybrid;
108  }
109  }
110  else
111  if (state == TunerState::kRecord) {
112  if(activity == Activity::kLive){
113  state = TunerState::kHybrid;
114  }
115  }
116 
117  if (state == origState) {
118  }
119 
120  return *this;
121 }
122 
123 #if 0
124 TunerState TunerState::operator - (const Enum<Activity> &activity)
125 {
126  const Enum<TunerState> origState = state;
127  std::cout << "State(" << (const char *) state << ") - Activity ("
128  << (const char *)activity << ")" << std::endl;
129 
130  if (state == TunerState::kHybrid) {
131  if (activity == Activity::kLive) {
132  state = TunerState::kRecord;
133  }
134  else if(activity == Activity::kRecord){
135  state = TunerState::kLive;
136  }
137  }
138  else
139  if (state == TunerState::kLive) {
140  if(activity == Activity::kLive){
141  state = TunerState::kFree;
142  }
143  }
144  else
145  if (state == TunerState::kRecord) {
146  if(activity == Activity::kRecord){
147  state = TunerState::kFree;
148  }
149  }
150 
151  if (state == origState) {
152  SafeAssert(0);
153  }
154 
155  return *this;
156 }
157 #endif
158 
159 bool TunerState::operator == (const TunerState &that) const
160 {
161  return ((this->state)) == ((that.state));
162 }
163 
164 bool TunerState::operator != (const TunerState &that) const
165 {
166  return (!(*this == that));
167 }
168 
169 void TunerState::print(void) const
170 {
171  (state).print();
172 }
173 
174 TRM_END_NAMESPACE
175 
176 
177 /** @} */
178 /** @} */