RDK Documentation (Open Sourced RDK Components)
manager.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 /**
23 * @defgroup devicesettings
24 * @{
25 * @defgroup ds
26 * @{
27 **/
28 
29 
30 #include "manager.hpp"
31 #include <iostream>
32 #include "audioOutputPortConfig.hpp"
33 #include "videoOutputPortConfig.hpp"
34 #include "host.hpp"
35 #include "videoDeviceConfig.hpp"
36 #include "dsVideoPort.h"
37 #include "dsVideoDevice.h"
38 #include "dsAudio.h"
39 #include "dsDisplay.h"
40 #include "dsFPD.h"
41 #include "dslogger.h"
42 #include <mutex>
43 #include <pthread.h>
44 
45 /**
46  * @file manager.cpp
47  * @brief RDK Device Settings module is a cross-platform device for controlling the following hardware configurations:
48  * Audio Output Ports (Volume, Mute, etc.)
49  * Video Ouptut Ports (Resolutions, Aspect Ratio, etc.)
50  * Front Panel Indicators
51  * DFC[zoom] Settings
52  * Display (Aspect Ratio, EDID data etc.)
53  * General Host configuration (Power managements, event management etc.)
54  *
55  */
56 
57 using namespace std;
58 
59 namespace device {
60 
61 int Manager::IsInitialized = 0; //!< Indicates the application has initialized with devicettings modules.
62 static std::mutex gManagerInitMutex;
63 
64 Manager::Manager() {
65  // TODO Auto-generated constructor stub
66 
67 }
68 
69 Manager::~Manager() {
70  // TODO Auto-generated destructor stub
71 }
72 
73 /**
74  * @addtogroup dssettingsmanagerapi
75  * @{
76  */
77 /**
78  * @fn Manager::Initialize()
79  * @brief This API is used to initialize the Device Setting module.
80  * Each API should be called by any client of device settings before it start device settings service.
81  * <ul>
82  * <li> dsDisplayInit() function must initialize all underlying the video display modules and associated data structures.
83  * <li> dsAudioPortInit() function must be used to initialize all the audio output ports.
84  * Must return NOT_SUPPORTED when no audio port present in the device (ex., Gateway)
85  * <li> dsVideoPortInit() function must initialize all the video specific output ports.
86  * <li> dsVideoDeviceInit() function must initialize all the video devices that exists in the system.
87  * <li> AudioOutputPortConfig::getInstance().load() function will load constants first and initialize Audio portTypes (encodings, compressions etc.)
88  * and its port instances (db, level etc).
89  * <li> VideoOutputPortConfig::getInstance().load() function will load constants first and initialize a set of supported resolutions.
90  * Initialize Video portTypes (Only Enable Ports) and its port instances (current resolution)
91  * <li> VideoDeviceConfig::getInstance().load() function will load constants first and initialize Video Devices (supported DFCs etc.).
92  * </ul>
93  * IllegalStateException will be thrown by the APIs if the module is not yet initialized.
94  *
95  * @return None
96  */
97 void Manager::Initialize()
98 {
99  printf("Entering %s count %d with thread id %lu\n",__FUNCTION__,IsInitialized,pthread_self());
100 
101  if (0 == IsInitialized) {
102 
103  dsDisplayInit();
104  dsAudioPortInit();
105  dsVideoPortInit();
107 
108  {std::lock_guard<std::mutex> lock(gManagerInitMutex);
109  AudioOutputPortConfig::getInstance().load();
110  VideoOutputPortConfig::getInstance().load();
111  VideoDeviceConfig::getInstance().load();
112  }
113  }
114  IsInitialized++;
115  printf("Exiting %s with thread %lu\n",__FUNCTION__,pthread_self());
116 }
117 
118 
119 /**
120  * @fn void Manager::DeInitialize()
121  * @brief This API is used to deinitialize the device settings module.
122  * DeInitialize() must be called to release all resource used by the Device Setting module.
123  * After DeInitialize(), the device will return to a state as if the Initialize() was never called.
124  * <ul>
125  * <li> dsVideoDeviceTerm() function will reset the data structures used within this module and release the handles specific to video devices.
126  * <li> dsVideoPortTerm() function will reset the data structures used within this module and release the video port specific handles.
127  * <li> dsAudioPortTerm() function will terminate the usage of audio output ports by resetting the data structures used within this module
128  * and release the audio port specific handles.
129  * <li> dsDisplayTerm() function will reset the data structures used within this module and release the video display specific handles.
130  * <li> VideoDeviceConfig::getInstance().release() function releases the DFCs and video device instance.
131  * <li> VideoOutputPortConfig::getInstance().release() function clears the instance of video pixel resolution, aspect ratio, stereoscopic mode, frameRate,
132  * supported Resolution and video port types.
133  * <li> AudioOutputPortConfig::getInstance().release() function clears the instance of audio encoding, compression, stereo modes and audio port types.
134  * </ul>
135  *
136  * @return None
137  */
138 void Manager::DeInitialize()
139 {
140  printf("Entering %s count %d with thread id: %lu\n",__FUNCTION__,IsInitialized,pthread_self());
141  if(IsInitialized>0)IsInitialized--;
142  if (0 == IsInitialized) {
143 
144  VideoDeviceConfig::getInstance().release();
145  VideoOutputPortConfig::getInstance().release();
146  AudioOutputPortConfig::getInstance().release();
147 
148  {std::lock_guard<std::mutex> lock(gManagerInitMutex);
150  dsVideoPortTerm();
151  dsAudioPortTerm();
152  dsDisplayTerm();
153  }
154  }
155  printf("Exiting %s with thread %lu\n",__FUNCTION__,pthread_self());
156 
157 }
158 
159 }
160 
161 /** @} */
162 
163 /** @} */
164 /** @} */
dsVideoDeviceTerm
dsError_t dsVideoDeviceTerm()
This function deinitialize all the video devices in the system. It reset any data structures used wit...
Definition: dsVideoDevice.c:144
dsDisplayInit
dsError_t dsDisplayInit()
Initialize the Display sub-system.
Definition: dsDisplay.c:47
dsFPD.h
dsDisplayTerm
dsError_t dsDisplayTerm()
This function deinitialize the display sub-system. This function deallocates the data structures used...
Definition: dsDisplay.c:194
dsVideoPortTerm
dsError_t dsVideoPortTerm()
Terminate the Video Port sub-system.
Definition: dsVideoPort.c:511
manager.hpp
It contains class referenced by manager.cpp file.
dsVideoPort.h
dsVideoDeviceInit
dsError_t dsVideoDeviceInit()
This function initialize all the video devices in the system.
Definition: dsVideoDevice.c:46
dsVideoDevice.h
dsVideoPortInit
dsError_t dsVideoPortInit()
Initialize underlying Video Port sub-system.
Definition: dsVideoPort.c:45
dsAudioPortTerm
dsError_t dsAudioPortTerm()
Terminate the Audio Port sub-system.
Definition: dsAudio.c:591
dsDisplay.h
dsAudio.h
dsAudioPortInit
dsError_t dsAudioPortInit()
Initialize the underlying Audio Port sub-system.
Definition: dsAudio.c:47