RDK Documentation (Open Sourced RDK Components)
Activity.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 <map>
30 #include <iostream>
31 #include <vector>
32 #include "trm/Activity.h"
33 
34 LOCAL_BEGIN_NAMESPACE
35 enum {
36  None,
37  Live,
38  Record,
39  EAS,
40 
41  MAX_ENUM_NUMBER,
42  };
43 
44 LOCAL_END_NAMESPACE
45 
46 TRM_BEGIN_NAMESPACE
47 
48 const Enum<Activity> Activity::kNone (MAKE_PAIR(None));
49 const Enum<Activity> Activity::kLive (MAKE_PAIR(Live));
50 const Enum<Activity> Activity::kRecord (MAKE_PAIR(Record));
51 const Enum<Activity> Activity::kEAS (MAKE_PAIR(EAS));
52 
53 const std::vector<const Enum<Activity> * > & Activity::getEnums(void)
54 {
55  static std::vector<const Enum<Activity> * > enums_;
56  if (enums_.size() == 0) {
57  enums_.push_back(&Activity::kNone);
58  enums_.push_back(&Activity::kLive);
59  enums_.push_back(&Activity::kRecord);
60  enums_.push_back(&Activity::kEAS);
61 
62  Assert(enums_.size() == MAX_ENUM_NUMBER);
63 
64  };
65 
66  return enums_;
67 }
68 
69 Activity::Activity(const Enum<Activity> &activity)
70 : activity(activity)
71 {
72 }
73 
74 Activity::Activity(const char *name)
75 : activity(Enum<Activity>::at(name))
76 {
77 }
78 
79 Activity::~Activity(void)
80 {
81 }
82 
83 /**
84  * @brief This function is used to return the request or granted usage of tuner. The Activity
85  * field represents the intended use of the tuner.
86  *
87  * @return Supported tuner activity name are Live, Recording, or EAS.
88  */
90 {
91  return activity;
92 }
93 
94 
95 /**
96  * @brief This function is used to return true if the activity has the detailed field describing the
97  * activity, otherwise the function will return false.
98  *
99  * @return Returns true if the tuner activity has a detailed field else will return false.
100  */
101 bool Activity::hasDetails(void) const
102 {
103  return details.size() != 0;
104 }
105 
106 
107 /**
108  * @brief This function will get the details of the recording.
109  * Each activity may be associated with a set of details describing the tuner activity.
110  *
111  * @param[in] key recording Id for which details to be extracted from the list.
112  * @return
113  */
114 const std::string & Activity::getDetail(const std::string &key) const
115 {
116  static const std::string emptyDetail = "";
117  std::map<KeyT,ValT>::const_iterator it = details.find(key);
118  if (it != details.end()) {
119  return it->second;
120  }
121  else {
122  return emptyDetail;
123  }
124 }
125 
126 const std::map<Activity::KeyT,Activity::ValT> & Activity::getDetails(void) const
127 {
128  return details;
129 }
130 
131 
132 /**
133  * @brief This API is used to add the details describing the activity in to a list.
134  *
135  * The field specified here are required for the associated activity. The requestor is
136  * allowed to insert unspecified fields in the details. These unspecified fields are ignored by TRM,
137  * and echoed back in response message that have the activity field.
138  * @n The defined fields are:
139  * - recordingId : required when requesting Record activity for a tuner.
140  * - hot : flag (true or false) indicating of the recording is scheduled or hot.
141  *
142  * @param[in] key it could be "recordingId" or "hot" when requesting Record activity for a tuner.
143  * @param[in] value value associated for recording.
144  * @return None.
145  * @ingroup TRM_API
146  */
147 void Activity::addDetail(const std::string &key, const std::string &value)
148 {
149  details.insert(std::pair<KeyT,ValT>(key,value));
150 }
151 
152 bool Activity::operator == (const Activity &that) const
153 {
154  return (this->activity == that.activity);
155  //&& (this->details == that.details);
156 }
157 
158 
159 /**
160  * @brief Print the list of recording(s) details which are being scheduled. The defined fields are,
161  * - recordingId : required when requesting Record activity for a tuner.
162  * - hot : flag (true or false) indicating of the recording is scheduled or hot.
163  * This function is used for debugging.
164  * @return None.
165  */
166 void Activity::print(void) const
167 {
168  activity.print();
169  for (std::map<KeyT,ValT>::const_iterator it=details.begin(); it!=details.end(); ++it) {
170  std::cout << "[OBJ][" << klassName() << "][Details] " << it->first << " => " << it->second << '\n';
171  }
172 }
173 
174 TRM_END_NAMESPACE
175 
176 
177 /** @} */
178 /** @} */
TRM::Activity::hasDetails
bool hasDetails(void) const
This function is used to return true if the activity has the detailed field describing the activity,...
Definition: Activity.cpp:101
TRM::Enum
Definition: Enum.h:42
TRM::Activity
The Activity class represents the request or granted usage of a tuner. The activity field in the clas...
Definition: Activity.h:92
TRM::Activity::getDetail
const std::string & getDetail(const std::string &key) const
This function will get the details of the recording. Each activity may be associated with a set of de...
Definition: Activity.cpp:114
TRM::Activity::print
void print(void) const
Print the list of recording(s) details which are being scheduled. The defined fields are,...
Definition: Activity.cpp:166
TRM::Activity::addDetail
void addDetail(const std::string &key, const std::string &value)
This API is used to add the details describing the activity in to a list.
Definition: Activity.cpp:147
TRM::Activity::getActivity
const Enum< Activity > & getActivity(void) const
This function is used to return the request or granted usage of tuner. The Activity field represents ...
Definition: Activity.cpp:89