LayerManagerControl: added feature "demo"
[profile/ivi/layer-management.git] / LayerManagerExamples / LayerManagerControl / src / commands.cpp
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 in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either inputess or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19 #include "ilm_client.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 screens")
71 //=============================================================================
72 {
73     (void)input;
74     unsigned int count = 0;
75     unsigned int* array = NULL;
76     ilm_getScreenIDs(&count, &array);
77     printArray("Screen", array, count);
78 }
79
80 //=============================================================================
81 COMMAND("get layers")
82 //=============================================================================
83 {
84     (void)input;
85     int count = 0;
86     unsigned int* array = NULL;
87     ilm_getLayerIDs(&count, &array);
88     printArray("Layer", array, count);
89 }
90
91 //=============================================================================
92 COMMAND("get surfaces")
93 //=============================================================================
94 {
95     (void)input;
96     int count = 0;
97     unsigned int* array = NULL;
98     ilm_getSurfaceIDs(&count, &array);
99     printArray("Surface", array, count);
100 }
101
102 //=============================================================================
103 COMMAND("get screen <screenid>")
104 //=============================================================================
105 {
106     printScreenProperties(input->getUint("screenid"));
107 }
108
109 //=============================================================================
110 COMMAND("get layer <layerid>")
111 //=============================================================================
112 {
113     printLayerProperties(input->getUint("layerid"));
114 }
115
116 //=============================================================================
117 COMMAND("get surface <surfaceid>")
118 //=============================================================================
119 {
120     printSurfaceProperties(input->getUint("surfaceid"));
121 }
122
123 //=============================================================================
124 COMMAND("dump screen <screenid> to <file>")
125 //=============================================================================
126 {
127     ilm_takeScreenshot(input->getUint("screenid"),
128                        input->getString("file").c_str());
129 }
130
131 //=============================================================================
132 COMMAND("dump layer <layerid> to <file>")
133 //=============================================================================
134 {
135     ilm_takeLayerScreenshot(input->getString("file").c_str(),
136                             input->getUint("layerid"));
137 }
138
139 //=============================================================================
140 COMMAND("dump surface <surfaceid> to <file>")
141 //=============================================================================
142 {
143     ilm_takeSurfaceScreenshot(input->getString("file").c_str(),
144                               input->getUint("surfaceid"));
145 }
146
147 //=============================================================================
148 COMMAND("set layer <layerid> source region <x> <y> <w> <h>")
149 //=============================================================================
150 {
151     ilm_layerSetSourceRectangle(input->getUint("layerid"),
152                                 input->getUint("x"),
153                                 input->getUint("y"),
154                                 input->getUint("w"),
155                                 input->getUint("h"));
156     ilm_commitChanges();
157 }
158
159 //=============================================================================
160 COMMAND("set surface <surfaceid> source region <x> <y> <w> <h>")
161 //=============================================================================
162 {
163     ilm_surfaceSetSourceRectangle(input->getUint("surfaceid"),
164                                   input->getUint("x"),
165                                   input->getUint("y"),
166                                   input->getUint("w"),
167                                   input->getUint("h"));
168     ilm_commitChanges();
169 }
170
171 //=============================================================================
172 COMMAND("set layer <layerid> destination region <x> <y> <w> <h>")
173 //=============================================================================
174 {
175     ilm_layerSetDestinationRectangle(input->getUint("layerid"),
176                                      input->getUint("x"),
177                                      input->getUint("y"),
178                                      input->getUint("w"),
179                                      input->getUint("h"));
180     ilm_commitChanges();
181 }
182
183 //=============================================================================
184 COMMAND("set surface <surfaceid> destination region <x> <y> <w> <h>")
185 //=============================================================================
186 {
187     ilm_surfaceSetDestinationRectangle(input->getUint("surfaceid"),
188                                        input->getUint("x"),
189                                        input->getUint("y"),
190                                        input->getUint("w"),
191                                        input->getUint("h"));
192     ilm_commitChanges();
193 }
194
195 //=============================================================================
196 COMMAND("set layer <layerid> opacity <opacity>")
197 //=============================================================================
198 {
199     ilm_layerSetOpacity(input->getUint("layerid"),
200                         input->getDouble("opacity"));
201     ilm_commitChanges();
202 }
203
204 //=============================================================================
205 COMMAND("set surface <surfaceid> opacity <opacity>")
206 //=============================================================================
207 {
208     ilm_surfaceSetOpacity(input->getUint("surfaceid"),
209                           input->getDouble("opacity"));
210     ilm_commitChanges();
211 }
212
213 //=============================================================================
214 COMMAND("set layer <layerid> visibility <visibility>")
215 //=============================================================================
216 {
217     ilm_layerSetVisibility(input->getUint("layerid"),
218                            input->getBool("visibility"));
219     ilm_commitChanges();
220 }
221
222 //=============================================================================
223 COMMAND("set surface <surfaceid> visibility <visibility>")
224 //=============================================================================
225 {
226     ilm_surfaceSetVisibility(input->getUint("surfaceid"),
227                              input->getBool("visibility"));
228     ilm_commitChanges();
229 }
230
231 //=============================================================================
232 COMMAND("set layer <layerid> orientation <orientation>")
233 //=============================================================================
234 {
235     ilm_layerSetOrientation(input->getUint("layerid"),
236             (ilmOrientation)input->getInt("orientation"));
237     ilm_commitChanges();
238 }
239
240 //=============================================================================
241 COMMAND("set surface <surfaceid> orientation <orientation>")
242 //=============================================================================
243 {
244     ilm_surfaceSetOrientation(input->getUint("surfaceid"),
245               (ilmOrientation)input->getInt("orientation"));
246     ilm_commitChanges();
247 }
248
249 //=============================================================================
250 COMMAND("set screen <screenid> render order <layeridarray>")
251 //=============================================================================
252 {
253     unsigned int count = 0;
254     unsigned int* array = NULL;
255     unsigned int screenid = input->getUint("screenid");
256     input->getUintArray("layeridarray", &array, &count);
257     ilm_displaySetRenderOrder(screenid, array, count);
258     ilm_commitChanges();
259 }
260
261 //=============================================================================
262 COMMAND("set screen <screenid> render order")
263 //=============================================================================
264 {
265     unsigned int screenid = input->getUint("screenid");
266     ilm_displaySetRenderOrder(screenid, NULL, 0);
267     ilm_commitChanges();
268 }
269
270 //=============================================================================
271 COMMAND("set layer <layerid> render order <surfaceidarray>")
272 //=============================================================================
273 {
274     unsigned int count = 0;
275     unsigned int* array = NULL;
276     unsigned int layerid = input->getUint("layerid");
277     input->getUintArray("surfaceidarray", &array, &count);
278     ilm_layerSetRenderOrder(layerid, array, count);
279     ilm_commitChanges();
280 }
281
282 //=============================================================================
283 COMMAND("set layer <layerid> render order")
284 //=============================================================================
285 {
286     unsigned int layerid = input->getUint("layerid");
287     ilm_layerSetRenderOrder(layerid, NULL, 0);
288     ilm_commitChanges();
289 }
290
291 //=============================================================================
292 COMMAND("set layer <layerid> width <width>")
293 //=============================================================================
294 {
295     unsigned int dimension[2];
296     unsigned int layerid = input->getUint("layerid");
297     ilm_layerGetDimension(layerid, dimension);
298     dimension[0] = input->getUint("width");
299     ilm_layerSetDimension(layerid, dimension);
300     ilm_commitChanges();
301 }
302
303 //=============================================================================
304 COMMAND("set surface <surfaceid> width <width>")
305 //=============================================================================
306 {
307     unsigned int dimension[2];
308     unsigned int surfaceid = input->getUint("surfaceid");
309     ilm_surfaceGetDimension(surfaceid, dimension);
310     dimension[0] = input->getUint("width");
311     ilm_surfaceSetDimension(surfaceid, dimension);
312     ilm_commitChanges();
313 }
314
315 //=============================================================================
316 COMMAND("set layer <layerid> height <height>")
317 //=============================================================================
318 {
319     unsigned int dimension[2];
320     unsigned int layerid = input->getUint("layerid");
321     ilm_layerGetDimension(layerid, dimension);
322     dimension[1] = input->getUint("height");
323     ilm_layerSetDimension(layerid, dimension);
324     ilm_commitChanges();
325 }
326
327 //=============================================================================
328 COMMAND("set surface <surfaceid> height <height>")
329 //=============================================================================
330 {
331     unsigned int dimension[2];
332     unsigned int surfaceid = input->getUint("surfaceid");
333     ilm_surfaceGetDimension(surfaceid, dimension);
334     dimension[1] = input->getUint("height");
335     ilm_surfaceSetDimension(surfaceid, dimension);
336     ilm_commitChanges();
337 }
338
339 //=============================================================================
340 COMMAND("set layer <layerid> position <x> <y>")
341 //=============================================================================
342 {
343     unsigned int dimension[2];
344     unsigned int layerid = input->getUint("layerid");
345     dimension[0] = input->getUint("x");
346     dimension[1] = input->getUint("y");
347     ilm_layerSetPosition(layerid, dimension);
348     ilm_commitChanges();
349 }
350
351 //=============================================================================
352 COMMAND("set surface <surfaceid> position <x> <y>")
353 //=============================================================================
354 {
355     unsigned int dimension[2];
356     unsigned int surfaceid = input->getUint("surfaceid");
357     dimension[0] = input->getUint("x");
358     dimension[1] = input->getUint("y");
359     ilm_surfaceSetPosition(surfaceid, dimension);
360     ilm_commitChanges();
361 }
362
363 //=============================================================================
364 COMMAND("create layer <layerid>")
365 //=============================================================================
366 {
367     unsigned int layerid = input->getUint("layerid");
368     ilm_layerCreate(&layerid);
369 }
370
371 //=============================================================================
372 COMMAND("create layer <layerid> <width> <height>")
373 //=============================================================================
374 {
375     unsigned int layerid = input->getUint("layerid");
376     unsigned int width = input->getUint("width");
377     unsigned int height = input->getUint("height");
378     ilm_layerCreateWithDimension(&layerid, width, height);
379 }
380
381 //=============================================================================
382 COMMAND("create surface <surfaceid> <nativehandle> <width> <height> <pixelformat>")
383 //=============================================================================
384 {
385     unsigned int surfaceid = input->getUint("surfaceid");
386     unsigned int nativeHandle = input->getUint("nativehandle");
387     unsigned int width = input->getUint("width");
388     unsigned int height = input->getUint("height");
389     e_ilmPixelFormat pixelformat = (e_ilmPixelFormat)input->getUint("pixelformat");
390     ilm_surfaceCreate(nativeHandle, width, height, pixelformat, &surfaceid);
391 }
392
393 //=============================================================================
394 COMMAND("destroy layer <layerid>")
395 //=============================================================================
396 {
397     unsigned int layerid = input->getUint("layerid");
398     ilm_layerRemove(layerid);
399 }
400
401 //=============================================================================
402 COMMAND("destroy surface <surfaceid>")
403 //=============================================================================
404 {
405     unsigned int surfaceid = input->getUint("surfaceid");
406     ilm_surfaceRemove(surfaceid);
407 }
408
409 //=============================================================================
410 COMMAND("get scene")
411 //=============================================================================
412 {
413     printScene();
414 }
415
416 //=============================================================================
417 COMMAND("get communicator performance")
418 //=============================================================================
419 {
420    getCommunicatorPerformance();
421 }
422
423 //=============================================================================
424 COMMAND("set surface <surfaceid> keyboard focus")
425 //=============================================================================
426 {
427     t_ilm_surface surface = input->getUint("surfaceid");
428
429     setSurfaceKeyboardFocus(surface);
430 }
431
432 //=============================================================================
433 COMMAND("get keyboard focus")
434 //=============================================================================
435 {
436     getKeyboardFocus();
437 }
438
439 //=============================================================================
440 COMMAND("set surface <surfaceid> accept <acceptance> input events from devices <kbd:pointer:touch>")
441 //=============================================================================
442 {
443     t_ilm_surface surfaceId = input->getUint("surfaceid");
444     t_ilm_bool acceptance = input->getBool("acceptance");
445     string kbdPointerTouch = input->getString("kbd:pointer:touch");
446
447     setSurfaceAcceptsInput(surfaceId, kbdPointerTouch, acceptance);
448 }
449
450 //=============================================================================
451 COMMAND("set surface <surfaceid> chromakey <red> <green> <blue>")
452 //=============================================================================
453 {
454     t_ilm_surface surface = input->getUint("surfaceid");
455     t_ilm_int color[3] =
456     {
457         input->getInt("red"),
458         input->getInt("green"),
459         input->getInt("blue")
460     };
461     ilm_surfaceSetChromaKey(surface, color);
462     ilm_commitChanges();
463 }
464
465 //=============================================================================
466 COMMAND("set surface <surfaceid> chromakey disabled")
467 //=============================================================================
468 {
469     t_ilm_surface surface = input->getUint("surfaceid");
470     ilm_surfaceSetChromaKey(surface, NULL);
471     ilm_commitChanges();
472 }
473
474 //=============================================================================
475 COMMAND("set layer <layerid> chromakey <red> <green> <blue>")
476 //=============================================================================
477 {
478     t_ilm_surface surface = input->getUint("layerid");
479     t_ilm_int color[3] =
480     {
481         input->getInt("red"),
482         input->getInt("green"),
483         input->getInt("blue")
484     };
485
486     ilm_layerSetChromaKey(surface, color);
487     ilm_commitChanges();
488 }
489
490 //=============================================================================
491 COMMAND("test notification layer <layerid>")
492 //=============================================================================
493 {
494     unsigned int layerid = input->getUint("layerid");
495
496     testNotificationLayer(layerid);
497 }
498
499 //=============================================================================
500 COMMAND("watch layer <layeridarray>")
501 //=============================================================================
502 {
503     unsigned int* layerids = NULL;
504     unsigned int layeridCount;
505     input->getUintArray("layeridarray", &layerids, &layeridCount);
506
507     watchLayer(layerids, layeridCount);
508 }
509
510 //=============================================================================
511 COMMAND("watch surface <surfaceidarray>")
512 //=============================================================================
513 {
514     unsigned int* surfaceids = NULL;
515     unsigned int surfaceidCount;
516     input->getUintArray("surfaceidarray", &surfaceids, &surfaceidCount);
517
518     watchSurface(surfaceids, surfaceidCount);
519 }
520
521 //=============================================================================
522 COMMAND("set optimization <id> mode <mode>")
523 //=============================================================================
524 {
525     t_ilm_uint id = input->getUint("id");
526     t_ilm_uint mode = input->getUint("mode");
527     setOptimization(id, mode);
528 }
529
530 //=============================================================================
531 COMMAND("get optimization <id>")
532 //=============================================================================
533 {
534     t_ilm_uint id = input->getUint("id");
535     getOptimization(id);
536 }
537
538 //=============================================================================
539 COMMAND("analyze surface <surfaceid>")
540 //=============================================================================
541 {
542     t_ilm_surface targetSurfaceId = (t_ilm_uint) input->getUint("surfaceid");
543     analyzeSurface(targetSurfaceId);
544 }
545
546 //=============================================================================
547 COMMAND("scatter")
548 //=============================================================================
549 {
550     scatter();
551 }
552
553 //=============================================================================
554 COMMAND("scatter all")
555 //=============================================================================
556 {
557     scatterAll();
558 }
559
560 //=============================================================================
561 COMMAND("demo <animation_mode>")
562 //=============================================================================
563 {
564     int mode = (int) input->getInt("animation_mode");
565     demo(mode);
566 }