• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ilm_control.h"
20 #include "LMControl.h"
21 #include "Expression.h"
22 #include "ExpressionInterpreter.h"
23 #include <iostream>
24 #include <sstream>
25 #include <iomanip>
26 #include <vector>
27 #include <map>
28 #include <algorithm>
29 #include <iterator>
30 #include <cstring>
31 #include <signal.h> // signal
32 #include <unistd.h> // alarm
33 
34 using namespace std;
35 
36 
37 #define COMMAND(text) COMMAND2(__COUNTER__,text)
38 
39 #define COMMAND2(x,y) COMMAND3(x,y)
40 
41 #define COMMAND3(funcNumber, text) \
42     void func_ ## funcNumber(Expression* input); \
43     static const bool reg_ ## funcNumber = \
44         ExpressionInterpreter::addExpression(func_ ## funcNumber, text); \
45     void func_ ## funcNumber(Expression* input)
46 
47 
48 
49 //=============================================================================
50 COMMAND("help")
51 //=============================================================================
52 {
53     (void)input;
54     cout << "help: supported commands:\n\n";
55     ExpressionInterpreter::printExpressionList();
56     cout << "\n";
57 }
58 
59 //=============================================================================
60 COMMAND("tree")
61 //=============================================================================
62 {
63     (void)input;
64     cout << "help: supported commands:\n\n";
65     ExpressionInterpreter::printExpressionTree();
66     cout << "\n";
67 }
68 
69 //=============================================================================
70 COMMAND("get scene|screens|layers|surfaces")
71 //=============================================================================
72 {
73     if (input->contains("scene"))
74     {
75         printScene();
76     }
77     else if (input->contains("screens"))
78     {
79         (void)input;
80         unsigned int count = 0;
81         unsigned int* array = NULL;
82 
83         ilmErrorTypes callResult = ilm_getScreenIDs(&count, &array);
84         if (ILM_SUCCESS != callResult)
85         {
86             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
87             cout << "Failed to get screen IDs\n";
88             return;
89         }
90 
91         printArray("Screen", array, count);
92         free(array);
93     }
94     else if (input->contains("layers"))
95     {
96         (void)input;
97         int count = 0;
98         unsigned int* array = NULL;
99 
100         ilmErrorTypes callResult = ilm_getLayerIDs(&count, &array);
101         if (ILM_SUCCESS != callResult)
102         {
103             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
104             cout << "Failed to get layer IDs\n";
105             return;
106         }
107 
108         printArray("Layer", array, count);
109         free(array);
110     }
111     else if (input->contains("surfaces"))
112     {
113         (void)input;
114         int count = 0;
115         unsigned int* array = NULL;
116 
117         ilmErrorTypes callResult = ilm_getSurfaceIDs(&count, &array);
118         if (ILM_SUCCESS != callResult)
119         {
120             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
121             cout << "Failed to get surface IDs\n";
122             return;
123         }
124 
125         printArray("Surface", array, count);
126         free(array);
127     }
128 }
129 
130 //=============================================================================
131 COMMAND("get screen|layer|surface <id>")
132 //=============================================================================
133 {
134     if (input->contains("screen"))
135     {
136         printScreenProperties(input->getUint("id"));
137     }
138     else if (input->contains("layer"))
139     {
140         printLayerProperties(input->getUint("id"));
141     }
142     else if (input->contains("surface"))
143     {
144         printSurfaceProperties(input->getUint("id"));
145     }
146 }
147 
148 //=============================================================================
149 COMMAND("dump screen|surface <id> to <file>")
150 //=============================================================================
151 {
152     if (input->contains("screen"))
153     {
154         ilmErrorTypes callResult = ilm_takeScreenshot(input->getUint("id"),
155                                                         input->getString("file").c_str());
156         if (ILM_SUCCESS != callResult)
157         {
158             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
159             cout << "Failed to take screenshot of screen with ID " << input->getUint("id") << "\n";
160             return;
161         }
162     }
163     else if (input->contains("surface"))
164     {
165         ilmErrorTypes callResult = ilm_takeSurfaceScreenshot(input->getString("file").c_str(),
166                                                                 input->getUint("id"));
167         if (ILM_SUCCESS != callResult)
168         {
169             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
170             cout << "Failed to take screenshot of surface with ID " << input->getUint("id") << "\n";
171             return;
172         }
173     }
174 }
175 
176 //=============================================================================
177 COMMAND("set layer|surface <id> source region <x> <y> <w> <h>")
178 //=============================================================================
179 {
180     t_ilm_uint id = input->getUint("id");
181     t_ilm_int x = input->getInt("x");
182     t_ilm_int y = input->getInt("y");
183     t_ilm_int w = input->getInt("w");
184     t_ilm_int h = input->getInt("h");
185 
186     if (input->contains("layer"))
187     {
188         ilmErrorTypes callResult = ilm_layerSetSourceRectangle(id, x, y, w, h);
189         if (ILM_SUCCESS != callResult)
190         {
191             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
192             cout << "Failed to set source rectangle (" << x << "," << y << ", " << w << ", " << h << ") for layer with ID " << id << "\n";
193             return;
194         }
195 
196         ilm_commitChanges();
197     }
198     else if (input->contains("surface"))
199     {
200         ilmErrorTypes callResult = ilm_surfaceSetSourceRectangle(id, x, y, w, h);
201         if (ILM_SUCCESS != callResult)
202         {
203             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
204             cout << "Failed to set source rectangle (" << x << ", " << y << ", " << w << ", " << h << ") for surface with ID " << id << "\n";
205             return;
206         }
207 
208         ilm_commitChanges();
209     }
210 }
211 
212 //=============================================================================
213 COMMAND("set layer|surface <id> destination region <x> <y> <w> <h>")
214 //=============================================================================
215 {
216     t_ilm_uint id = input->getUint("id");
217     t_ilm_int x = input->getInt("x");
218     t_ilm_int y = input->getInt("y");
219     t_ilm_int w = input->getInt("w");
220     t_ilm_int h = input->getInt("h");
221 
222     if (input->contains("layer"))
223     {
224         ilmErrorTypes callResult = ilm_layerSetDestinationRectangle(id, x, y, w, h);
225         if (ILM_SUCCESS != callResult)
226         {
227             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
228             cout << "Failed to set destination rectangle (" << x << ", " << y << ", " << w << ", " << h << ") for layer with ID " << id << "\n";
229             return;
230         }
231 
232         ilm_commitChanges();
233     }
234     else if (input->contains("surface"))
235     {
236         ilmErrorTypes callResult = ilm_surfaceSetDestinationRectangle(id, x, y, w, h);
237         if (ILM_SUCCESS != callResult)
238         {
239             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
240             cout << "Failed to set destination rectangle (" << x << ", " << y << ", " << w << ", " << h << ") for surface with ID " << id << "\n";
241             return;
242         }
243 
244         ilm_commitChanges();
245     }
246 }
247 
248 //=============================================================================
249 COMMAND("set layer|surface <id> opacity <opacity>")
250 //=============================================================================
251 {
252     t_ilm_uint id = input->getUint("id");
253     double opacity = input->getDouble("opacity");
254 
255     if (input->contains("layer"))
256     {
257         ilmErrorTypes callResult = ilm_layerSetOpacity(id, opacity);
258         if (ILM_SUCCESS != callResult)
259         {
260             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
261             cout << "Failed to set opacity " << opacity << " for layer with ID " << id << "\n";
262             return;
263         }
264 
265         ilm_commitChanges();
266     }
267     else if (input->contains("surface"))
268     {
269         ilmErrorTypes callResult = ilm_surfaceSetOpacity(id, opacity);
270         if (ILM_SUCCESS != callResult)
271         {
272             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
273             cout << "Failed to set opacity " << opacity << " for surface with ID " << id << "\n";
274             return;
275         }
276 
277         ilm_commitChanges();
278     }
279 }
280 
281 //=============================================================================
282 COMMAND("set layer|surface <id> visibility <visibility>")
283 //=============================================================================
284 {
285     t_ilm_uint id = input->getUint("id");
286     t_ilm_bool visibility = input->getBool("visibility");
287 
288     if (input->contains("layer"))
289     {
290         ilmErrorTypes callResult = ilm_layerSetVisibility(id, visibility);
291         if (ILM_SUCCESS != callResult)
292         {
293             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
294             cout << "Failed to set visibility " << visibility << " for layer with ID " << id << "\n";
295             return;
296         }
297 
298         ilm_commitChanges();
299     }
300     else if (input->contains("surface"))
301     {
302         ilmErrorTypes callResult = ilm_surfaceSetVisibility(id, visibility);
303         if (ILM_SUCCESS != callResult)
304         {
305             cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
306             cout << "Failed to set visibility " << visibility << " for surface with ID " << id << "\n";
307             return;
308         }
309 
310         ilm_commitChanges();
311     }
312 }
313 
314 //=============================================================================
315 //=============================================================================
316 COMMAND("set surface <surfaceid> type <type>")
317 //=============================================================================
318 {
319     t_ilm_uint id = input->getUint("surfaceid");
320     ilmSurfaceType type = (ilmSurfaceType)input->getInt("type");
321 
322     ilmErrorTypes callResult = ilm_surfaceSetType(id, type);
323     if (ILM_SUCCESS != callResult)
324     {
325         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
326         cout << "Failed to set type " << type << " for surface with ID " << id << "\n";
327         return;
328     }
329 
330     ilm_commitChanges();
331 }
332 
333 //=============================================================================
334 COMMAND("set screen|layer <id> render order [<idarray>]")
335 //=============================================================================
336 {
337     if (input->contains("screen"))
338     {
339         if (input->contains("idarray"))
340         {
341             unsigned int count = 0;
342             unsigned int* array = NULL;
343             unsigned int screenid = input->getUint("id");
344             input->getUintArray("idarray", &array, &count);
345 
346             ilmErrorTypes callResult = ilm_displaySetRenderOrder(screenid, array, count);
347             if (ILM_SUCCESS != callResult)
348             {
349                 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
350                 cout << "Failed to set render order for screen with ID " << screenid << "\n";
351                 return;
352             }
353 
354             ilm_commitChanges();
355             delete[] array;
356         }
357         else
358         {
359             unsigned int screenid = input->getUint("id");
360 
361             ilmErrorTypes callResult = ilm_displaySetRenderOrder(screenid, NULL, 0);
362             if (ILM_SUCCESS != callResult)
363             {
364                 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
365                 cout << "Failed to set render order for screen with ID " << screenid << "\n";
366                 return;
367             }
368 
369             ilm_commitChanges();
370         }
371     }
372     else if (input->contains("layer"))
373     {
374         if (input->contains("idarray"))
375         {
376             unsigned int count = 0;
377             unsigned int* array = NULL;
378             unsigned int layerid = input->getUint("id");
379             input->getUintArray("idarray", &array, &count);
380 
381             ilmErrorTypes callResult = ilm_layerSetRenderOrder(layerid, array, count);
382             if (ILM_SUCCESS != callResult)
383             {
384                 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
385                 cout << "Failed to set render order for layer with ID " << layerid << "\n";
386                 return;
387             }
388 
389             ilm_commitChanges();
390             delete[] array;
391         }
392         else
393         {
394             unsigned int layerid = input->getUint("id");
395 
396             ilmErrorTypes callResult = ilm_layerSetRenderOrder(layerid, NULL, 0);
397             if (ILM_SUCCESS != callResult)
398             {
399                 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
400                 cout << "Failed to set render order for layer with ID " << layerid << "\n";
401                 return;
402             }
403 
404             ilm_commitChanges();
405         }
406     }
407 }
408 
409 //=============================================================================
410 COMMAND("create layer <layerid> <width> <height>")
411 //=============================================================================
412 {
413     unsigned int layerid = input->getUint("layerid");
414     unsigned int width = input->getUint("width");
415     unsigned int height = input->getUint("height");
416 
417     ilmErrorTypes callResult = ilm_layerCreateWithDimension(&layerid, width, height);
418     if (ILM_SUCCESS != callResult)
419     {
420         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
421         cout << "Failed to create layer with ID " << layerid << "\n";
422         return;
423     }
424 }
425 
426 //=============================================================================
427 COMMAND("destroy layer <id>")
428 //=============================================================================
429 {
430     unsigned int layerid = input->getUint("id");
431 
432     ilmErrorTypes callResult = ilm_layerRemove(layerid);
433     if (ILM_SUCCESS != callResult)
434     {
435         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
436         cout << "Failed to remove layer with ID " << layerid << "\n";
437         return;
438     }
439 
440     ilm_commitChanges();
441 }
442 
443 //=============================================================================
444 COMMAND("add surface <sid> to layer <lid>")
445 //=============================================================================
446 {
447     t_ilm_uint sid = input->getUint("sid");
448     t_ilm_uint lid = input->getUint("lid");
449 
450     ilmErrorTypes callResult = ilm_layerAddSurface(lid, sid);
451     if (ILM_SUCCESS != callResult)
452     {
453         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
454         cout << "Failed to add surface (" << sid << " ) to layer (" << lid << " ) " << "\n";
455         return;
456     }
457 
458     ilm_commitChanges();
459 }
460 
461 //=============================================================================
462 COMMAND("remove surface <sid> from layer <lid>")
463 //=============================================================================
464 {
465     t_ilm_uint sid = input->getUint("sid");
466     t_ilm_uint lid = input->getUint("lid");
467 
468     ilmErrorTypes callResult = ilm_layerRemoveSurface(lid, sid);
469     if (ILM_SUCCESS != callResult)
470     {
471         cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
472         cout << "Failed to remove surface (" << sid << " ) from layer (" << lid << " ) " << "\n";
473         return;
474     }
475 
476     ilm_commitChanges();
477 }
478 
479 //=============================================================================
480 COMMAND("test notification layer <layerid>")
481 //=============================================================================
482 {
483     unsigned int layerid = input->getUint("layerid");
484 
485     testNotificationLayer(layerid);
486 }
487 
488 //=============================================================================
489 COMMAND("watch layer|surface <idarray>")
490 //=============================================================================
491 {
492     if (input->contains("layer"))
493     {
494         unsigned int* layerids = NULL;
495         unsigned int layeridCount;
496         input->getUintArray("idarray", &layerids, &layeridCount);
497 
498         watchLayer(layerids, layeridCount);
499         delete[] layerids;
500     }
501     else if (input->contains("surface"))
502     {
503         unsigned int* surfaceids = NULL;
504         unsigned int surfaceidCount;
505         input->getUintArray("idarray", &surfaceids, &surfaceidCount);
506 
507         watchSurface(surfaceids, surfaceidCount);
508         delete[] surfaceids;
509     }
510 }
511 
512 //=============================================================================
513 COMMAND("analyze surface <surfaceid>")
514 //=============================================================================
515 {
516     t_ilm_surface targetSurfaceId = (t_ilm_uint) input->getUint("surfaceid");
517     analyzeSurface(targetSurfaceId);
518 }
519 
520 //=============================================================================
521 COMMAND("export scene to <filename>")
522 //=============================================================================
523 {
524     string filename = (string) input->getString("filename");
525     exportSceneToFile(filename);
526 }
527 
528 //=============================================================================
529 COMMAND("export xtext to <filename> <grammar> <url>")
530 //=============================================================================
531 {
532     string filename = (string) input->getString("filename");
533     string grammar = (string) input->getString("grammar");
534     string url = (string) input->getString("url");
535     exportXtext(filename, grammar, url);
536 }
537