1 /***************************************************************************
2 *
3 * Copyright 2012 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 #include "ilm_control.h"
21 #include "LMControl.h"
22
23 #include <iostream>
24 using std::cout;
25 using std::cin;
26 using std::endl;
27
28 #include <iomanip>
29 using std::dec;
30 using std::hex;
31
32 #include <stdlib.h>
33 #include <map>
34 using std::map;
35
36 #include <vector>
37 using std::vector;
38
39
printArray(const char * text,unsigned int * array,int count)40 void printArray(const char* text, unsigned int* array, int count)
41 {
42 cout << count << " " << text << "(s):\n";
43 for (int i = 0; i < count; ++i)
44 {
45 cout << "- " << text << " " << dec << array[i] << hex << " (0x"
46 << array[i] << ")" << dec << "\n";
47 }
48 }
49
50 template<typename T>
printArray(const char * text,T * array,int count)51 void printArray(const char* text, T* array, int count)
52 {
53 cout << count << " " << text << "(s):\n";
54 for (int i = 0; i < count; ++i)
55 {
56 cout << "- " << text << " " << "[" << array[i] << "]" << "\n";
57 }
58 }
59
60 template<typename T>
printVector(const char * text,vector<T> v)61 void printVector(const char* text, vector<T> v)
62 {
63 cout << v.size() << " " << text << "(s) Vector:\n";
64 for (int i = 0; i < v.size(); ++i)
65 {
66 cout << "- " << text << " " << v[i] << endl;
67 }
68 }
69
70 template<typename K, typename V>
printMap(const char * text,std::map<K,V> m)71 void printMap(const char* text, std::map<K, V> m)
72 {
73 cout << m.size() << " " << text << endl;
74
75 for (typename map<K, V>::iterator it = m.begin(); it != m.end(); ++it)
76 {
77 cout << "- " << (*it).first << " -> " << (*it).second << endl;
78 }
79 }
80
printScreenProperties(unsigned int screenid,const char * prefix)81 void printScreenProperties(unsigned int screenid, const char* prefix)
82 {
83 cout << prefix << "screen " << screenid << " (0x" << hex << screenid << dec
84 << ")\n";
85 cout << prefix << "---------------------------------------\n";
86
87 ilmScreenProperties screenProperties;
88
89 ilmErrorTypes callResult = ilm_getPropertiesOfScreen(screenid, &screenProperties);
90 if (ILM_SUCCESS != callResult)
91 {
92 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
93 cout << "Failed to get properties of screen with ID " << screenid << " found\n";
94 return;
95 }
96
97 cout << prefix << "- connector name: " << screenProperties.connectorName << "\n";
98
99 cout << prefix << "- resolution: x=" << screenProperties.screenWidth << ", y="
100 << screenProperties.screenHeight << "\n";
101
102 cout << prefix << "- layer render order: ";
103
104 for (t_ilm_uint layerIndex = 0; layerIndex < screenProperties.layerCount; ++layerIndex)
105 {
106 t_ilm_layer layerid = screenProperties.layerIds[layerIndex];
107 cout << layerid << "(0x" << hex << layerid << dec << "), ";
108 }
109 cout << "\n";
110
111 free(screenProperties.layerIds);
112 }
113
printLayerProperties(unsigned int layerid,const char * prefix)114 void printLayerProperties(unsigned int layerid, const char* prefix)
115 {
116 cout << prefix << "layer " << layerid << " (0x" << hex << layerid << dec
117 << ")\n";
118 cout << prefix << "---------------------------------------\n";
119
120 ilmLayerProperties p;
121
122 ilmErrorTypes callResult = ilm_getPropertiesOfLayer(layerid, &p);
123 if (ILM_SUCCESS != callResult)
124 {
125 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
126 cout << "Failed to get properties of layer with ID " << layerid << " found\n";
127 return;
128 }
129
130 cout << prefix << "- destination region: x=" << p.destX << ", y="
131 << p.destY << ", w=" << p.destWidth << ", h=" << p.destHeight
132 << "\n";
133 cout << prefix << "- source region: x=" << p.sourceX << ", y="
134 << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
135 << "\n";
136
137 cout << prefix << "- opacity: " << p.opacity << "\n";
138 cout << prefix << "- visibility: " << p.visibility << "\n";
139
140 cout << prefix << "- surface render order: ";
141
142 int surfaceCount = 0;
143 unsigned int* surfaceArray = NULL;
144
145 callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
146 if (ILM_SUCCESS != callResult)
147 {
148 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
149 cout << "Failed to get surfaces on layer with ID " << layerid << " \n";
150 return;
151 }
152
153 for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
154 {
155 cout << surfaceArray[surfaceIndex] << "(0x" << hex
156 << surfaceArray[surfaceIndex] << dec << "), ";
157 }
158 cout << "\n";
159 free(surfaceArray);
160
161 cout << prefix << "- on screen: ";
162
163 unsigned int screenCount = 0;
164 unsigned int* screenArray = NULL;
165
166 callResult = ilm_getScreenIDs(&screenCount, &screenArray);
167 if (ILM_SUCCESS != callResult)
168 {
169 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
170 cout << "Failed to get available screens\n";
171 return;
172 }
173
174 for (unsigned int screenIndex = 0; screenIndex < screenCount;
175 ++screenIndex)
176 {
177 unsigned int screenid = screenArray[screenIndex];
178 int layerCount = 0;
179 unsigned int* layerArray = NULL;
180
181 callResult = ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
182 if (ILM_SUCCESS != callResult)
183 {
184 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
185 cout << "Failed to get available layers on screen with ID" << screenid << "\n";
186 return;
187 }
188
189 for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
190 {
191 unsigned int id = layerArray[layerIndex];
192 if (id == layerid)
193 {
194 cout << screenid << "(0x" << hex << screenid << dec << ") ";
195 }
196 }
197
198 free(layerArray);
199 }
200 cout << "\n";
201
202 free(screenArray);
203 }
204
printSurfaceProperties(unsigned int surfaceid,const char * prefix)205 void printSurfaceProperties(unsigned int surfaceid, const char* prefix)
206 {
207 cout << prefix << "surface " << surfaceid << " (0x" << hex << surfaceid
208 << dec << ")\n";
209 cout << prefix << "---------------------------------------\n";
210
211 ilmSurfaceProperties p;
212
213 ilmErrorTypes callResult = ilm_getPropertiesOfSurface(surfaceid, &p);
214 if (ILM_SUCCESS != callResult)
215 {
216 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
217 cout << "No surface with ID " << surfaceid << " found\n";
218 return;
219 }
220
221 cout << prefix << "- created by pid: " << p.creatorPid << "\n";
222
223 cout << prefix << "- original size: x=" << p.origSourceWidth << ", y="
224 << p.origSourceHeight << "\n";
225 cout << prefix << "- destination region: x=" << p.destX << ", y=" << p.destY
226 << ", w=" << p.destWidth << ", h=" << p.destHeight << "\n";
227 cout << prefix << "- source region: x=" << p.sourceX << ", y="
228 << p.sourceY << ", w=" << p.sourceWidth << ", h=" << p.sourceHeight
229 << "\n";
230
231 cout << prefix << "- opacity: " << p.opacity << "\n";
232 cout << prefix << "- visibility: " << p.visibility << "\n";
233
234 cout << prefix << "- frame counter: " << p.frameCounter << "\n";
235
236 cout << prefix << "- on layer: ";
237 int layerCount = 0;
238 unsigned int* layerArray = NULL;
239
240 callResult = ilm_getLayerIDs(&layerCount, &layerArray);
241 if (ILM_SUCCESS != callResult)
242 {
243 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
244 cout << "Failed to get available layer IDs\n";
245 return;
246 }
247
248 for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
249 {
250 unsigned int layerid = layerArray[layerIndex];
251 int surfaceCount = 0;
252 unsigned int* surfaceArray = NULL;
253
254 callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
255 if (ILM_SUCCESS != callResult)
256 {
257 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
258 cout << "Failed to get surface IDs on layer" << layerid << "\n";
259 return;
260 }
261
262 for (int surfaceIndex = 0; surfaceIndex < surfaceCount;
263 ++surfaceIndex)
264 {
265 unsigned int id = surfaceArray[surfaceIndex];
266 if (id == surfaceid)
267 {
268 cout << layerid << "(0x" << hex << layerid << dec << ") ";
269 }
270 }
271
272 free(surfaceArray);
273 }
274 cout << "\n";
275
276 free(layerArray);
277 }
278
printScene()279 void printScene()
280 {
281 unsigned int screenCount = 0;
282 unsigned int* screenArray = NULL;
283
284 ilmErrorTypes callResult = ilm_getScreenIDs(&screenCount, &screenArray);
285 if (ILM_SUCCESS != callResult)
286 {
287 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
288 cout << "Failed to get available screen IDs\n";
289 return;
290 }
291
292 for (unsigned int screenIndex = 0; screenIndex < screenCount; ++screenIndex)
293 {
294 unsigned int screenid = screenArray[screenIndex];
295 printScreenProperties(screenid);
296 cout << "\n";
297
298 int layerCount = 0;
299 unsigned int* layerArray = NULL;
300
301 callResult = ilm_getLayerIDsOnScreen(screenid, &layerCount, &layerArray);
302 if (ILM_SUCCESS != callResult)
303 {
304 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
305 cout << "Failed to get available layers on screen with ID" << screenid << "\n";
306 return;
307 }
308
309 for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
310 {
311 unsigned int layerid = layerArray[layerIndex];
312 printLayerProperties(layerid, " ");
313 cout << "\n";
314
315 int surfaceCount = 0;
316 unsigned int* surfaceArray = NULL;
317
318 callResult = ilm_getSurfaceIDsOnLayer(layerid, &surfaceCount, &surfaceArray);
319 if (ILM_SUCCESS != callResult)
320 {
321 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
322 cout << "Failed to get available surfaces on layer with ID" << layerid << "\n";
323 return;
324 }
325
326 for (int surfaceIndex = 0; surfaceIndex < surfaceCount; ++surfaceIndex)
327 {
328 unsigned int surfaceid = surfaceArray[surfaceIndex];
329 printSurfaceProperties(surfaceid, " ");
330 cout << "\n";
331 }
332
333 free(surfaceArray);
334 }
335
336 free(layerArray);
337 }
338
339 free(screenArray);
340 }
341