RDK Documentation (Open Sourced RDK Components)
frontPanelConfig.cpp
Go to the documentation of this file.
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  * @file frontPanelConfig.cpp
23  * @brief A manager module for the front panel.
24  */
25 
26 
27 
28 /**
29 * @defgroup devicesettings
30 * @{
31 * @defgroup ds
32 * @{
33 **/
34 
35 
36 #include <iostream>
37 #include "dsError.h"
38 #include "dsUtl.h"
39 #include "frontPanelConfig.hpp"
40 #include "frontPanelSettings.hpp"
41 #include "illegalArgumentException.hpp"
42 #include "dslogger.h"
43 
44 using namespace std;
45 
46 namespace device {
47 
48 /**
49  * @fn FrontPanelConfig::FrontPanelConfig()
50  * @brief This function initializes the underlying front panel sub-system. It loads
51  * the platform supported configurations of all the front panel indicator and text display.
52  *
53  * @return None
54  */
55 FrontPanelConfig::FrontPanelConfig()
56 {
57  dsFPInit();
58  load();
59 }
60 
61 
62 /**
63  * @fn FrontPanelConfig::~FrontPanelConfig()
64  * @brief This function is the default destructor for FrontPanelConfig.
65  *
66  * @return None
67  */
68 FrontPanelConfig::~FrontPanelConfig()
69 {
70  //dsFPTerm();
71 }
72 
73 
74 /**
75  * @fn FrontPanelConfig::getInstance()
76  * @brief This API gets the instance of the FrontPanelConfig. When called for the first time,
77  * it creates an instance of FrontPanelConfig where the front panel indicators
78  * and text display are initialized and loaded with supported colours and text by the default constructor.
79  *
80  * @return _singleton An instance of FrontPanelConfig is returned.
81  */
82 FrontPanelConfig & FrontPanelConfig::getInstance()
83 {
84  static FrontPanelConfig _singleton;
85  return _singleton;
86 }
87 
88 
89 /**
90  * @fn FrontPanelConfig::getIndicator(const string &name)
91  * @brief This API gets the FrontPanelndicator instance corresponding to the name parameter returned by the get supported frontpanel indicator device.
92  * <ul>
93  * <li> The valid indicator names are Message, Power, Record, Remote and RfByPass.
94  * </ul>
95  *
96  * @param[in] name Indicates the name of the FrontPanelIndicator whose instance should be returned.
97  *
98  * @return Returns an instance of FrontPanelIndicator corresponding to the name parameter else throws
99  * an IllegalArgumentException if the instance corresponding to the name parameter was not found.
100  */
101 FrontPanelIndicator &FrontPanelConfig::getIndicator(const string &name)
102 {
103  std::vector<FrontPanelIndicator>::iterator it = _indicators.begin();
104  while (it != _indicators.end()) {
105  if (it->getName() == name) {
106  return *it;
107  }
108  it++;
109  }
110 
111  throw IllegalArgumentException("Bad indicator name");
112 }
113 
114 /**
115  * @fn FrontPanelConfig::fPInit()
116  * @brief This API is used to Initialize front panel.
117  *
118  * @return None
119  */
120 void FrontPanelConfig::fPInit()
121 {
122  dsFPInit();
123 }
124 
125 
126 /**
127  * @fn FrontPanelConfig::fPTerm()
128  * @brief This API is used to terminate front panel.
129  *
130  * @return None
131  */
132 void FrontPanelConfig::fPTerm()
133 {
134  dsFPTerm();
135 }
136 
137 /**
138  * @fn FrontPanelConfig::getIndicator(int id)
139  * @brief This function gets an instance of the FrontPanelndicator with the specified id, only if the id
140  * passed is valid.
141  *
142  * @param[in] id Indicates the id of front panel indicator whose instance is required.
143  *
144  * @return Returns an instance of FrontPanelIndicator corresponding to the id parameter else throws an
145  * IllegalArgumentException indicating that the instance corresponding to the id parameter was not found.
146  */
147 FrontPanelIndicator &FrontPanelConfig::getIndicator(int id)
148 {
149  std::vector<FrontPanelIndicator>::iterator it = _indicators.begin();
150  while (it != _indicators.end()) {
151  if (it->getId() == id) {
152  return *it;
153  }
154  it++;
155  }
156 
157  throw IllegalArgumentException();
158 
159 
160 }
161 
162 
163 /**
164  * @fn FrontPanelConfig::getColor(const string &name)
165  * @brief This function gets an instance of the front panel indicator Color with the specified name,
166  * only if the name passed is valid.
167  *
168  * @param[in] name Indicates the name of the color whose instance is required.
169  *
170  * @return Returns an instance of Color corresponding to the name parameter else throws an
171  * IllegalArgumentException indicating that the instance corresponding to the name parameter was
172  * not found.
173  */
175 {
176  std::vector<FrontPanelIndicator::Color>::iterator it = _colors.begin();
177  while (it != _colors.end()) {
178  if (it->getName() == name) {
179  return *it;
180  }
181  it++;
182  }
183 
184  throw IllegalArgumentException("Bad color name");
185 }
186 
187 
188 /**
189  * @fn FrontPanelConfig::getColor(int id)
190  * @brief This function gets an instance of the front panel indicator Color with the specified id,
191  * only if the id passed is valid.
192  *
193  * @param[in] id Indicates the id of the color whose instance is required.
194  *
195  * @return Returns an instance of Color corresponding to the id parameter else throws an
196  * IllegalArgumentException indicating that the instance corresponding to the id parameter was
197  * not found.
198  */
200 {
201  std::vector<FrontPanelIndicator::Color>::iterator it = _colors.begin();
202  while (it != _colors.end()) {
203  if (it->getId() == id) {
204  return *it;
205  }
206  it++;
207  }
208 
209  throw IllegalArgumentException("Bad color id");
210 }
211 
212 
213 /**
214  * @fn FrontPanelConfig::getTextDisplay(int id)
215  * @brief This function gets the FrontPanelTextDisplay instance corresponding to the specified id,
216  * only if the id passed is valid.
217  *
218  * @param[in] id Indicates the id of the front panel display whose instance is required.
219  *
220  * @return Returns FrontPanelTextDisplay instance corresponding to the id parameter else throws an
221  * IllegalArgumentException indicating that the instance corresponding to the id parameter is not
222  * found
223  */
224 FrontPanelTextDisplay &FrontPanelConfig::getTextDisplay(int id)
225 {
226  std::vector<FrontPanelTextDisplay>::iterator it = _textDisplays.begin();
227  while (it != _textDisplays.end()) {
228  if (it->getId() == id) {
229  return *it;
230  }
231  it++;
232  }
233 
234  throw IllegalArgumentException();
235 
236 }
237 
238 
239 /**
240  * @fn FrontPanelConfig::getTextDisplay(const string &name)
241  * @brief This API gets the FrontPanelTextDisplay instance corresponding to the name parameter, only
242  * if the name passed is valid.
243  * <ul>
244  * <li> Valid name parameter is Text.
245  * </ul>
246  *
247  * @param[in] name Indicates the name of FrontPanelTextDisplay whose instance has to be returned.
248  *
249  * @return Returns FrontPanelTextDisplay instance corresponding to the name else throws an
250  * IllegalArgumentException if the instance corresponding to the name parameter is not found.
251  */
252 FrontPanelTextDisplay &FrontPanelConfig::getTextDisplay(const string &name)
253 {
254  std::vector<FrontPanelTextDisplay>::iterator it = _textDisplays.begin();
255  while (it != _textDisplays.end()) {
256  if (it->getName() == name) {
257  return *it;
258  }
259  it++;
260  }
261 
262  throw IllegalArgumentException();
263 
264 }
265 
266 
267 /**
268  * @fn FrontPanelConfig::getColors()
269  * @brief This API gets the list of colors supported by front panel indicators.
270  *
271  * @return rColors List of colors supported by the indicators.
272  */
273 List<FrontPanelIndicator::Color> FrontPanelConfig::getColors()
274 {
276 
277  for (size_t i = 0; i < _colors.size(); i++) {
278  rColors.push_back(_colors.at(i));
279  }
280 
281  return rColors;
282 }
283 
284 
285 /**
286  * @fn FrontPanelConfig::getIndicators()
287  * @brief This API gets a list of indicators on the front panel.
288  *
289  * @return rIndicators Contains list indicators on the front panel.
290  */
291 List<FrontPanelIndicator> FrontPanelConfig::getIndicators()
292 {
293  List <FrontPanelIndicator> rIndicators;
294 
295  for (size_t i = 0; i < _indicators.size(); i++) {
296  rIndicators.push_back(_indicators.at(i));
297  }
298 
299  return rIndicators;
300 }
301 
302 
303 /**
304  * @fn FrontPanelConfig::getTextDisplays()
305  * @brief This API gets a list of text display supported by the front panels.
306  *
307  * @return rIndicators Contains the list of text supported by the front panel display.
308  */
309 List<FrontPanelTextDisplay> FrontPanelConfig::getTextDisplays()
310 {
312 
313  for (size_t i = 0; i < _textDisplays.size(); i++) {
314  rTexts.push_back(_textDisplays.at(i));
315  }
316 
317  return rTexts;
318 }
319 
320 
321 /**
322  * @fn FrontPanelConfig::load()
323  * @brief This function creates instances of the front panel indicators and text display.
324  * It also loads the platform supported configurations.
325  *
326  * @return None
327  */
328 void FrontPanelConfig::load()
329 {
330  /*
331  * Create Indicators
332  * 1. Create Supported Colors.
333  * 2. Create Indicators.
334  */
335  {
336  for (size_t i = 0; i < dsUTL_DIM(kIndicatorColors); i++) {
337  _colors.push_back(FrontPanelIndicator::Color(kIndicatorColors[i].id));
338  }
339 
340  for (size_t i = 0; i < dsUTL_DIM(kIndicators); i++) {
341  /* All indicators support a same set of colors */
342  _indicators.push_back(FrontPanelIndicator(kIndicators[i].id,
343  kIndicators[i].maxBrightness,
344  kIndicators[i].maxCycleRate,
345  kIndicators[i].levels,
346  kIndicators[i].colorMode));
347  }
348 
349  }
350 
351  {
352  /*
353  * Create TextDisplays
354  * 1. Use Supported Colors created for indicators.
355  * 2. Create Text Displays.
356  */
357  for (size_t i = 0; i < dsUTL_DIM(kTextDisplays); i++) {
358  _textDisplays.push_back(
359  FrontPanelTextDisplay(kTextDisplays[i].id,
360  kTextDisplays[i].maxBrightness,
361  kTextDisplays[i].maxCycleRate,
362  kTextDisplays[i].levels,
363  kTextDisplays[i].maxHorizontalIterations,
364  kTextDisplays[i].maxVerticalIterations,
365  kTextDisplays[i].supportedCharacters,
366  kTextDisplays[i].colorMode));
367  }
368  }
369 }
370 
371 }
372 
373 
374 /** @} */
375 /** @} */
device::List
This class is implemented using templates and it is used to maintain a container with the list of sup...
Definition: list.hpp:51
getColor
static int getColor(gsw_CcAttribType attributeIndex, gsw_CcType ccType, std::string input, gsw_CcColor *colorOut)
Get color option from input string.
Definition: AampCCManager.cpp:95
dsFPTerm
dsError_t dsFPTerm(void)
Terminate the the Front Panel Display sub-system.
Definition: dsFPD.c:62
dsError.h
Device Settings HAL error codes.
dsUtl.h
Device Settings HAL utilities.
dsFPInit
dsError_t dsFPInit(void)
This function is used to initialize the underlying front panel display sub-system.
Definition: dsFPD.c:42
frontPanelConfig.hpp
Structures and classes to manage front panel are defined here.
device::FrontPanelIndicator
This class extents DSConstant to manage front panel indicators color, blink sequence and brightness.
Definition: frontPanelIndicator.hpp:55
device::FrontPanelTextDisplay
This class extents FrontPanelIndicator to manage front panel text display mode, scrolling and its bri...
Definition: frontPanelTextDisplay.hpp:53
device::List::push_back
void push_back(const T &x)
This is a template function used to push/store the ID of an instance x into the container.
Definition: list.hpp:108
device::IllegalArgumentException
This class extends Exception class to manage the expections caused due to illegal arguments.
Definition: illegalArgumentException.hpp:51
dsUTL_DIM
#define dsUTL_DIM(arr)
Device Settings general Array dimension calculation inline definition.
Definition: dsUtl.h:85
device::FrontPanelIndicator::Color
Definition: frontPanelIndicator.hpp:67
device::FrontPanelConfig
Definition: frontPanelConfig.hpp:55