LayerManagerService: added support for client specific command queues
[profile/ivi/layer-management.git] / LayerManagerService / include / Layermanager.h
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19
20 #ifndef _LAYERMANAGER_H_
21 #define _LAYERMANAGER_H_
22
23 #include "ICommandExecutor.h"
24 #include "NotificationQueue.h"
25 #include "CommandList.h"
26 #include <pthread.h>
27
28 class Scene;
29 class ICommand;
30 class IRenderer;
31 class ICommunicator;
32 class ISceneProvider;
33 class IApplicationReference;
34 class IHealth;
35 class IPlugin;
36 class Configuration;
37 class PluginManager;
38
39 typedef std::map<unsigned int, CommandList> CommandListMap;
40 typedef std::map<unsigned int, const char*> PidToProcessNameTable;
41 typedef std::list<IPlugin*> PluginList;
42
43
44 class Layermanager: public ICommandExecutor
45 {
46 public:
47     Layermanager(Configuration& config);
48     virtual ~Layermanager();
49
50     void signalRendererRedraw();
51
52     virtual bool execute(ICommand* commandToBeExecuted);
53     virtual uint getLayerTypeCapabilities(const LayerType layertype) const;
54     virtual uint getNumberOfHardwareLayers(const uint screenID) const;
55     virtual uint* getScreenResolution(const uint screenID) const;
56     virtual uint* getScreenIDs(uint* length) const;
57
58     virtual void addRenderer(IRenderer* renderer);
59     virtual void removeRenderer(IRenderer* renderer);
60
61     virtual void addCommunicator(ICommunicator* communicator);
62     virtual void removeCommunicator(ICommunicator* communicator);
63
64     virtual void addSceneProvider(ISceneProvider* sceneProvider);
65     virtual void removeSceneProvider(ISceneProvider* sceneProvider);
66
67     virtual void addApplicationReference(t_ilm_client_handle client, IApplicationReference* reference);
68     virtual void removeApplicationReference(t_ilm_client_handle client);
69     virtual t_ilm_uint getSenderPid(t_ilm_client_handle client);
70     const char* getSenderName(t_ilm_client_handle client);
71     const char* getSenderName(unsigned int pid);
72     
73     virtual bool startManagement();
74     virtual bool stopManagement();
75
76     virtual Scene* getScene(void);
77     virtual RendererList* getRendererList(void);
78     virtual CommunicatorList* getCommunicatorList(void);
79     virtual SceneProviderList* getSceneProviderList(void);
80
81     virtual void addClientNotification(GraphicalObject* object, t_ilm_notification_mask mask);
82     virtual NotificationQueue& getClientNotificationQueue();
83     virtual ApplicationReferenceMap* getApplicationReferenceMap(void);
84
85     virtual HealthCondition getHealth();
86
87     virtual CommandList& getEnqueuedCommands(unsigned int clientPid);
88
89 private:
90     void printDebugInformation() const;
91     bool startAllRenderers(const int width, const int height, const char *displayName);
92     bool startAllCommunicators();
93     bool delegateScene();
94     void stopAllRenderers();
95     void stopAllCommunicators();
96     bool executeCommand(ICommand* commandToBeExecuted);
97     bool enqueueCommand(ICommand* commandToBeExecuted);
98
99 private:
100     Scene* m_pScene;
101     RendererList* m_pRendererList;
102     CommunicatorList* m_pCommunicatorList;
103     SceneProviderList* m_pSceneProviderList;
104     NotificationQueue m_clientNotificationQueue;
105     ApplicationReferenceMap* m_pApplicationReferenceMap;
106     PidToProcessNameTable m_pidToProcessNameTable;
107     CommandListMap m_EnqueuedCommands;
108     IHealth* m_pHealth;
109     pthread_t m_pWatchdogThread;
110     bool mHealthState;
111     PluginList mMonitoredPlugins;
112     Configuration& mConfiguration;
113     PluginManager* m_pPluginManager;
114 };
115
116 inline Scene* Layermanager::getScene(void)
117 {
118     return m_pScene;
119 }
120
121 inline RendererList* Layermanager::getRendererList(void)
122 {
123     return m_pRendererList;
124 }
125
126 inline CommunicatorList* Layermanager::getCommunicatorList(void)
127 {
128     return m_pCommunicatorList;
129 }
130
131 inline SceneProviderList* Layermanager::getSceneProviderList(void)
132 {
133     return m_pSceneProviderList;
134 }
135
136 inline ApplicationReferenceMap* Layermanager::getApplicationReferenceMap(void)
137 {
138     return m_pApplicationReferenceMap;
139 }
140
141 inline void Layermanager::addClientNotification(GraphicalObject* object, t_ilm_notification_mask newMask)
142 {
143     if (m_clientNotificationQueue.find(object) != m_clientNotificationQueue.end())
144     {
145         m_clientNotificationQueue[object] = (t_ilm_notification_mask)(m_clientNotificationQueue[object] | newMask);
146     }
147     else
148     {
149         m_clientNotificationQueue[object] = newMask;
150     }
151 }
152
153 inline NotificationQueue& Layermanager::getClientNotificationQueue()
154 {
155     return m_clientNotificationQueue;
156 }
157
158 inline CommandList& Layermanager::getEnqueuedCommands(unsigned int clientPid)
159 {
160     return m_EnqueuedCommands[clientPid];
161 }
162
163 #endif /* _LAYERMANAGER_H_ */