Add new ipc for Input Events management from client
[profile/ivi/layer-management.git] / LayerManagerPlugins / Communicators / GenericCommunicator / src / GenericCommunicator.cpp
1 /***************************************************************************
2  * Copyright 2012 BMW Car IT GmbH
3  *
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  ****************************************************************************/
18
19 #include "GenericCommunicator.h"
20 #include "ilm_types.h"
21 #include "Log.h"
22
23 #include <stdbool.h>
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <string>
29
30 #define DEFAULT_SCREEN 0
31
32 const char* RESSOURCE_ALREADY_INUSE = "Ressource already in use";
33 const char* INVALID_ARGUMENT = "Invalid argument";
34 const char* RESSOURCE_NOT_FOUND = "Ressource not found";
35
36
37 //=============================================================================
38 // logging
39 //=============================================================================
40 #define LOG_ENTER_FUNCTION printf("      --> GenericCommunicator::%s()\n", __FUNCTION__)
41 //#define LOG_ENTER_FUNCTION
42
43 #include <sstream>
44 using std::stringstream;
45
46 #include <string>
47 using std::string;
48
49 GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
50 : ICommunicator(executor)
51 , m_running(ILM_FALSE)
52 {
53     LOG_ENTER_FUNCTION;
54
55     MethodTable manager_methods[] =
56     {
57         { "ServiceConnect",                   &GenericCommunicator::ServiceConnect },
58         { "ServiceDisconnect",                &GenericCommunicator::ServiceDisconnect },
59         { "Debug",                            &GenericCommunicator::Debug },
60         { "ScreenShot",                       &GenericCommunicator::ScreenShot },
61         { "ScreenShotOfLayer",                &GenericCommunicator::ScreenShotOfLayer },
62         { "ScreenShotOfSurface",              &GenericCommunicator::ScreenShotOfSurface },
63         { "GetScreenResolution",              &GenericCommunicator::GetScreenResolution },
64         { "GetNumberOfHardwareLayers",        &GenericCommunicator::GetNumberOfHardwareLayers },
65         { "GetScreenIDs",                     &GenericCommunicator::GetScreenIDs },
66         { "ListAllLayerIDS",                  &GenericCommunicator::ListAllLayerIDS },
67         { "ListAllLayerIDsOnScreen",          &GenericCommunicator::ListAllLayerIDsOnScreen },
68         { "ListAllSurfaceIDS",                &GenericCommunicator::ListAllSurfaceIDS },
69         { "ListAllLayerGroupIDS",             &GenericCommunicator::ListAllLayerGroupIDS },
70         { "ListAllSurfaceGroupIDS",           &GenericCommunicator::ListAllSurfaceGroupIDS },
71         { "ListSurfacesOfSurfacegroup",       &GenericCommunicator::ListSurfacesOfSurfacegroup },
72         { "ListLayersOfLayergroup",           &GenericCommunicator::ListLayersOfLayergroup },
73         { "ListSurfaceofLayer",               &GenericCommunicator::ListSurfaceofLayer },
74         { "GetPropertiesOfSurface",           &GenericCommunicator::GetPropertiesOfSurface },
75         { "GetPropertiesOfLayer",             &GenericCommunicator::GetPropertiesOfLayer },
76         { "CreateSurface",                    &GenericCommunicator::CreateSurface },
77         { "CreateSurfaceFromId",              &GenericCommunicator::CreateSurfaceFromId },
78         { "InitializeSurface",                &GenericCommunicator::InitializeSurface },
79         { "InitializeSurfaceFromId",          &GenericCommunicator::InitializeSurfaceFromId },
80         { "SetSurfaceNativeContent",          &GenericCommunicator::SetSurfaceNativeContent },
81         { "RemoveSurfaceNativeContent",       &GenericCommunicator::RemoveSurfaceNativeContent },
82         { "RemoveSurface",                    &GenericCommunicator::RemoveSurface },
83         { "CreateLayer",                      &GenericCommunicator::CreateLayer },
84         { "CreateLayerFromId",                &GenericCommunicator::CreateLayerFromId },
85         { "CreateLayerWithDimension",         &GenericCommunicator::CreateLayerWithDimension },
86         { "CreateLayerFromIdWithDimension",   &GenericCommunicator::CreateLayerFromIdWithDimension },
87         { "RemoveLayer",                      &GenericCommunicator::RemoveLayer },
88         { "AddSurfaceToSurfaceGroup",         &GenericCommunicator::AddSurfaceToSurfaceGroup },
89         { "RemoveSurfaceFromSurfaceGroup",    &GenericCommunicator::RemoveSurfaceFromSurfaceGroup },
90         { "AddLayerToLayerGroup",             &GenericCommunicator::AddLayerToLayerGroup },
91         { "RemoveLayerFromLayerGroup",        &GenericCommunicator::RemoveLayerFromLayerGroup },
92         { "AddSurfaceToLayer",                &GenericCommunicator::AddSurfaceToLayer },
93         { "RemoveSurfaceFromLayer",           &GenericCommunicator::RemoveSurfaceFromLayer },
94         { "CreateSurfaceGroup",               &GenericCommunicator::CreateSurfaceGroup },
95         { "CreateSurfaceGroupFromId",         &GenericCommunicator::CreateSurfaceGroupFromId },
96         { "RemoveSurfaceGroup",               &GenericCommunicator::RemoveSurfaceGroup },
97         { "CreateLayerGroup",                 &GenericCommunicator::CreateLayerGroup },
98         { "CreateLayerGroupFromId",           &GenericCommunicator::CreateLayerGroupFromId },
99         { "RemoveLayerGroup",                 &GenericCommunicator::RemoveLayerGroup },
100         { "SetSurfaceSourceRegion",           &GenericCommunicator::SetSurfaceSourceRegion },
101         { "SetLayerSourceRegion",             &GenericCommunicator::SetLayerSourceRegion },
102         { "SetSurfaceDestinationRegion",      &GenericCommunicator::SetSurfaceDestinationRegion },
103         { "SetSurfacePosition",               &GenericCommunicator::SetSurfacePosition },
104         { "GetSurfacePosition",               &GenericCommunicator::GetSurfacePosition },
105         { "SetSurfaceDimension",              &GenericCommunicator::SetSurfaceDimension },
106         { "SetLayerDestinationRegion",        &GenericCommunicator::SetLayerDestinationRegion },
107         { "SetLayerPosition",                 &GenericCommunicator::SetLayerPosition },
108         { "GetLayerPosition",                 &GenericCommunicator::GetLayerPosition },
109         { "SetLayerDimension",                &GenericCommunicator::SetLayerDimension },
110         { "GetLayerDimension",                &GenericCommunicator::GetLayerDimension },
111         { "GetSurfaceDimension",              &GenericCommunicator::GetSurfaceDimension },
112         { "SetSurfaceOpacity",                &GenericCommunicator::SetSurfaceOpacity },
113         { "SetLayerOpacity",                  &GenericCommunicator::SetLayerOpacity },
114         { "SetSurfacegroupOpacity",           &GenericCommunicator::SetSurfacegroupOpacity },
115         { "SetLayergroupOpacity",             &GenericCommunicator::SetLayergroupOpacity },
116         { "GetSurfaceOpacity",                &GenericCommunicator::GetSurfaceOpacity },
117         { "GetLayerOpacity",                  &GenericCommunicator::GetLayerOpacity },
118         { "SetSurfaceOrientation",            &GenericCommunicator::SetSurfaceOrientation },
119         { "GetSurfaceOrientation",            &GenericCommunicator::GetSurfaceOrientation },
120         { "SetLayerOrientation",              &GenericCommunicator::SetLayerOrientation },
121         { "GetLayerOrientation",              &GenericCommunicator::GetLayerOrientation },
122         { "GetSurfacePixelformat",            &GenericCommunicator::GetSurfacePixelformat },
123         { "SetSurfaceVisibility",             &GenericCommunicator::SetSurfaceVisibility },
124         { "SetLayerVisibility",               &GenericCommunicator::SetLayerVisibility },
125         { "GetSurfaceVisibility",             &GenericCommunicator::GetSurfaceVisibility },
126         { "GetLayerVisibility",               &GenericCommunicator::GetLayerVisibility },
127         { "SetSurfacegroupVisibility",        &GenericCommunicator::SetSurfacegroupVisibility },
128         { "SetLayergroupVisibility",          &GenericCommunicator::SetLayergroupVisibility },
129         { "SetRenderOrderOfLayers",           &GenericCommunicator::SetRenderOrderOfLayers },
130         { "SetSurfaceRenderOrderWithinLayer", &GenericCommunicator::SetSurfaceRenderOrderWithinLayer },
131         { "GetLayerType",                     &GenericCommunicator::GetLayerType },
132         { "GetLayertypeCapabilities",         &GenericCommunicator::GetLayertypeCapabilities },
133         { "GetLayerCapabilities",             &GenericCommunicator::GetLayerCapabilities },
134         { "Exit",                             &GenericCommunicator::Exit },
135         { "CommitChanges",                    &GenericCommunicator::CommitChanges },
136         { "CreateShader",                     &GenericCommunicator::CreateShader },
137         { "DestroyShader",                    &GenericCommunicator::DestroyShader },
138         { "SetShader",                        &GenericCommunicator::SetShader },
139         { "SetUniforms",                      &GenericCommunicator::SetUniforms },
140         { "SetKeyboardFocusOn",               &GenericCommunicator::SetKeyboardFocusOn },
141         { "GetKeyboardFocusSurfaceId",        &GenericCommunicator::GetKeyboardFocusSurfaceId },
142         { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn }
143     };
144
145     int entryCount = sizeof(manager_methods) / sizeof(MethodTable);
146
147     for (int index = 0; index < entryCount; ++index)
148     {
149         MethodTable* method = &manager_methods[index];
150         if (method->function)
151         {
152             m_callBackTable[method->name] = *method;
153             LOG_DEBUG("GenericCommunicator", "registered callback for " << method->name);
154         }
155     }
156 }
157
158 bool GenericCommunicator::start()
159 {
160     LOG_ENTER_FUNCTION;
161     LOG_DEBUG("GenericCommunicator", "Starting up dbus connector");
162
163     if (!loadIpcModule(&m_ipcModule))
164     {
165         LOG_ERROR("GenericCommunicator", "Loading IpcModule failed.");
166         return ILM_FALSE;
167     }
168     LOG_DEBUG("GenericCommunicator", "Loading IpcModule success.");
169
170     if (!m_ipcModule.init(ILM_FALSE))
171     {
172         LOG_ERROR("GenericCommunicator", "Initializing IpcModule failed.");
173         return ILM_FALSE;
174     }
175     LOG_DEBUG("GenericCommunicator", "Initializing IpcModule success.");
176
177     m_running = ILM_TRUE;
178
179     return ILM_TRUE;
180 }
181
182 void GenericCommunicator::stop()
183 {
184     LOG_ENTER_FUNCTION;
185     LOG_INFO("GenericCommunicator","stopping");
186
187     if (m_running)
188     {
189         m_ipcModule.destroy();
190     }
191 }
192
193 void GenericCommunicator::process(int timeout_ms)
194 {
195     enum IpcMessageType messageType = m_ipcModule.receiveMessage(timeout_ms);
196
197     t_ilm_const_string name = m_ipcModule.getMessageName();
198     t_ilm_const_string sender = m_ipcModule.getSenderName();
199
200     switch(messageType)
201     {
202     case IpcMessageTypeCommand:
203         if (m_callBackTable.count(name))
204         {
205             LOG_DEBUG("GenericCommunicator", "Received message " << name
206                       << " (type=command" << ", sender=" << sender << ")");
207             CallBackMethod method = m_callBackTable[name].function;
208             (this->*method)();
209         }
210         else
211         {
212             LOG_WARNING("GenericCommunicator", "Received unknown message " << name
213                         << " (type=command" << ", sender=" << sender << ")");
214         }
215         break;
216
217     case IpcMessageTypeDisconnect:
218         LOG_DEBUG("GenericCommunicator", "Received message " << name
219                   << " (type=disconnect" << ", sender=" << sender << ")");
220         ServiceDisconnect();
221         break;
222
223     case IpcMessageTypeNotification:
224         LOG_DEBUG("GenericCommunicator", "Received message " << name
225                   << " (type=notification" << ", sender=" << sender << ")");
226         break;
227
228     case IpcMessageTypeError:
229         LOG_DEBUG("GenericCommunicator", "Received message " << name
230                   << " (type=error" << ", sender=" << sender << ")");
231         break;
232
233     case IpcMessageTypeNone:
234         break;
235
236     default:
237         LOG_DEBUG("GenericCommunicator", "Received message " << name
238                   << " (type=unknown" << ", sender=" << sender << ")");
239         break;
240     }
241 }
242
243 void GenericCommunicator::setdebug(bool onoff)
244 {
245     (void)onoff; // TODO: remove, only prevents warning
246 }
247
248 void GenericCommunicator::ServiceConnect()
249 {
250     LOG_DEBUG("GenericCommunicator", "ServiceConnect called");
251     u_int32_t processId = 0;
252     m_ipcModule.getUint(&processId);
253     char* owner = strdup(m_ipcModule.getSenderName());
254     m_executor->addApplicationReference(new IApplicationReference(owner,processId));
255     m_ipcModule.createMessage((char*)__FUNCTION__);
256     m_ipcModule.sendMessage();
257 }
258
259 void GenericCommunicator::ServiceDisconnect()
260 {
261     LOG_DEBUG("GenericCommunicator", "ServiceDisconnect called");
262     char* owner = strdup(m_ipcModule.getSenderName());
263     long int ownerHash = IApplicationReference::generateApplicationHash(owner);
264     ApplicationReferenceMap* refmap = m_executor->getApplicationReferenceMap();
265
266     ApplicationReferenceMapIterator iter = refmap->find(ownerHash);
267     ApplicationReferenceMapIterator iterEnd = refmap->end();
268
269     for (; iter != iterEnd; ++iter)
270     {
271         IApplicationReference* registeredApp = (*iter).second;
272         m_executor->removeApplicationReference(registeredApp);
273     }
274
275     m_ipcModule.createMessage((char*)__FUNCTION__);
276     m_ipcModule.sendMessage();
277 }
278
279 void GenericCommunicator::Debug()
280 {
281     t_ilm_bool param = ILM_FALSE;
282     m_ipcModule.getBool(&param);
283
284     t_ilm_bool status = m_executor->execute(new DebugCommand(param));
285     if (status)
286     {
287         m_ipcModule.createMessage((char*)__FUNCTION__);
288         m_ipcModule.sendMessage();
289     }
290     else
291     {
292         m_ipcModule.sendError(INVALID_ARGUMENT);
293     }
294 }
295
296 void GenericCommunicator::GetScreenResolution()
297 {
298     uint screenid = 0;
299     m_ipcModule.getUint(&screenid);
300     uint* resolution = m_executor->getScreenResolution(screenid);
301     m_ipcModule.createMessage((char*)__FUNCTION__);
302     m_ipcModule.appendUint(resolution[0]);
303     m_ipcModule.appendUint(resolution[1]);
304     m_ipcModule.sendMessage();
305 }
306
307 void GenericCommunicator::GetNumberOfHardwareLayers()
308 {
309     uint screenid = 0;
310     m_ipcModule.getUint(&screenid);
311     uint numberOfHardwareLayers = m_executor->getNumberOfHardwareLayers(screenid);
312     m_ipcModule.createMessage((char*)__FUNCTION__);
313     m_ipcModule.appendUint(numberOfHardwareLayers);
314     m_ipcModule.sendMessage();
315 }
316
317 void GenericCommunicator::GetScreenIDs()
318 {
319     uint length = 0;
320     uint* IDs = m_executor->getScreenIDs(&length);
321     m_ipcModule.createMessage((char*)__FUNCTION__);
322     m_ipcModule.appendUintArray(IDs, length);
323     m_ipcModule.sendMessage();
324 }
325
326 void GenericCommunicator::ScreenShot()
327 {
328     uint screenid = 0;
329     m_ipcModule.getUint(&screenid);
330     char filename[1024];
331     m_ipcModule.getString(filename);
332
333     t_ilm_bool status = m_executor->execute(new ScreenDumpCommand(filename, screenid));
334     if (status)
335     {
336         m_ipcModule.createMessage((char*)__FUNCTION__);
337         m_ipcModule.sendMessage();
338     }
339     else
340     {
341         m_ipcModule.sendError(INVALID_ARGUMENT);
342     }
343 }
344
345 void GenericCommunicator::ScreenShotOfLayer()
346 {
347     char filename[1024];
348     m_ipcModule.getString(filename);
349     uint layerid = 0;
350     m_ipcModule.getUint(&layerid);
351
352     t_ilm_bool status = m_executor->execute(new LayerDumpCommand(filename, layerid));
353     if (status)
354     {
355         m_ipcModule.createMessage((char*)__FUNCTION__);
356         m_ipcModule.sendMessage();
357     }
358     else
359     {
360         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
361     }
362 }
363
364 void GenericCommunicator::ScreenShotOfSurface()
365 {
366     char filename[1024];
367     m_ipcModule.getString(filename);
368     uint id = 0;
369     m_ipcModule.getUint(&id);
370     t_ilm_bool status = m_executor->execute(new SurfaceDumpCommand(filename, id));
371     if (status)
372     {
373         m_ipcModule.createMessage((char*)__FUNCTION__);
374         m_ipcModule.sendMessage();
375     }
376     else
377     {
378         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
379     }
380 }
381
382 void GenericCommunicator::ListAllLayerIDS()
383 {
384     uint* array = NULL;
385     uint length = 0;
386     m_executor->getScene()->lockScene();
387     m_executor->getScene()->getLayerIDs(&length, &array);
388     m_ipcModule.createMessage((char*)__FUNCTION__);
389     m_ipcModule.appendUintArray(array, length);
390     m_ipcModule.sendMessage();
391     m_executor->getScene()->unlockScene();
392 }
393
394 void GenericCommunicator::ListAllLayerIDsOnScreen()
395 {
396     uint screenID = 0;
397     m_ipcModule.getUint(&screenID);
398
399     uint* array = NULL;
400     uint length = 0;
401     m_executor->getScene()->lockScene();
402     t_ilm_bool status = m_executor->getScene()->getLayerIDsOfScreen(screenID, &length, &array);
403     if (status)
404     {
405         m_ipcModule.createMessage((char*)__FUNCTION__);
406         m_ipcModule.appendUintArray(array, length);
407         m_ipcModule.sendMessage();
408     }
409     else
410     {
411         m_ipcModule.sendError(INVALID_ARGUMENT);
412     }
413     m_executor->getScene()->unlockScene();
414 }
415
416 void GenericCommunicator::ListAllSurfaceIDS()
417 {
418     uint* array = NULL;
419     uint length = 0;
420     m_executor->getScene()->lockScene();
421     m_executor->getScene()->getSurfaceIDs(&length, &array);
422     m_ipcModule.createMessage((char*)__FUNCTION__);
423     m_ipcModule.appendUintArray(array, length);
424     m_ipcModule.sendMessage();
425     m_executor->getScene()->unlockScene();
426 }
427
428 void GenericCommunicator::ListAllLayerGroupIDS()
429 {
430     uint* array = NULL;
431     uint length = 0;
432     m_executor->getScene()->lockScene();
433     m_executor->getScene()->getLayerGroupIDs(&length, &array);
434     m_ipcModule.createMessage((char*)__FUNCTION__);
435     m_ipcModule.appendUintArray(array, length);
436     m_ipcModule.sendMessage();
437     m_executor->getScene()->unlockScene();
438 }
439
440 void GenericCommunicator::ListAllSurfaceGroupIDS()
441 {
442     uint* array = NULL;
443     uint length = 0;
444     m_executor->getScene()->lockScene();
445     m_executor->getScene()->getSurfaceGroupIDs(&length, &array);
446     m_ipcModule.createMessage((char*)__FUNCTION__);
447     m_ipcModule.appendUintArray(array, length);
448     m_ipcModule.sendMessage();
449     m_executor->getScene()->unlockScene();
450 }
451
452 void GenericCommunicator::ListSurfacesOfSurfacegroup()
453 {
454     uint id = 0;
455     m_ipcModule.getUint(&id);
456     m_executor->getScene()->lockScene();
457     SurfaceGroup* sg = m_executor->getScene()->getSurfaceGroup(id);
458     if (NULL != sg)
459     {
460         std::list<Surface*> surfaces = sg->getList();
461         uint length = surfaces.size();
462         uint* array = new uint[length];
463         uint arrayPos = 0;
464         m_ipcModule.createMessage((char*)__FUNCTION__);
465
466         for (std::list<Surface*>::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
467         {
468             Surface* s = *it;
469             array[arrayPos] = s->getID();
470             ++arrayPos;
471         }
472
473         m_ipcModule.appendUintArray(array, length);
474
475         m_ipcModule.sendMessage();
476         m_executor->getScene()->unlockScene();
477     }
478     else
479     {
480         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
481     }
482 }
483
484 void GenericCommunicator::ListLayersOfLayergroup()
485 {
486     uint id = 0;
487     m_ipcModule.getUint(&id);
488     m_executor->getScene()->lockScene();
489     LayerGroup* sg = m_executor->getScene()->getLayerGroup(id);
490     if (NULL != sg)
491     {
492         std::list<Layer*> layers = sg->getList();
493
494         uint length = layers.size();
495         uint* array = new uint[length];
496         uint arrayPos = 0;
497
498         m_ipcModule.createMessage((char*)__FUNCTION__);
499         for (std::list<Layer*>::const_iterator it = layers.begin(); it != layers.end(); ++it)
500         {
501             Layer* l = *it;
502             array[arrayPos] = l->getID();
503             ++arrayPos;
504         }
505
506         m_ipcModule.appendUintArray(array, length);
507
508         m_ipcModule.sendMessage();
509         m_executor->getScene()->unlockScene();
510     }
511     else
512     {
513         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
514     }
515 }
516
517 void GenericCommunicator::ListSurfaceofLayer()
518 {
519     uint id = 0;
520     m_ipcModule.getUint(&id);
521     m_executor->getScene()->lockScene();
522     Layer* layer = m_executor->getScene()->getLayer(id);
523     if (layer != NULL)
524     {
525         std::list<Surface*> surfaces = layer->getAllSurfaces();
526
527         uint length = surfaces.size();
528         uint* array = new uint[length];
529         uint arrayPos = 0;
530
531         m_ipcModule.createMessage((char*)__FUNCTION__);
532
533         for (std::list<Surface*>::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
534         {
535             Surface* s = *it;
536             array[arrayPos] = s->getID();
537             ++arrayPos;
538         }
539
540         m_ipcModule.appendUintArray(array, length);
541
542         m_ipcModule.sendMessage();
543     }
544     else
545     {
546         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
547     }
548     m_executor->getScene()->unlockScene();
549 }
550
551 void GenericCommunicator::GetPropertiesOfSurface()
552 {
553     uint id = 0;
554     m_ipcModule.getUint(&id);
555
556     Surface* surface = m_executor->getScene()->getSurface(id);
557     if (surface != NULL)
558     {
559         Rectangle dest = surface->getDestinationRegion();
560         Rectangle src = surface->getSourceRegion();
561         OrientationType orientation = surface->getOrientation();
562
563         m_ipcModule.createMessage((char*)__FUNCTION__);
564         m_ipcModule.appendDouble(surface->getOpacity());
565         m_ipcModule.appendUint(src.x);
566         m_ipcModule.appendUint(src.y);
567         m_ipcModule.appendUint(src.width);
568         m_ipcModule.appendUint(src.height);
569         m_ipcModule.appendUint(surface->OriginalSourceWidth);
570         m_ipcModule.appendUint(surface->OriginalSourceHeight);
571         m_ipcModule.appendUint(dest.x);
572         m_ipcModule.appendUint(dest.y);
573         m_ipcModule.appendUint(dest.width);
574         m_ipcModule.appendUint(dest.height);
575         m_ipcModule.appendUint(orientation);
576         m_ipcModule.appendBool(surface->getVisibility());
577         m_ipcModule.appendUint(surface->frameCounter);
578         m_ipcModule.appendUint(surface->drawCounter);
579         m_ipcModule.appendUint(surface->updateCounter);
580         m_ipcModule.appendUint(surface->getPixelFormat());
581         m_ipcModule.appendUint(surface->getNativeContent());
582         m_ipcModule.appendUint(surface->getInputEventAcceptanceOnDevices());
583         m_ipcModule.sendMessage();
584     }
585     else
586     {
587         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
588     }
589 }
590
591 void GenericCommunicator::GetPropertiesOfLayer()
592 {
593     uint id = 0;
594     m_ipcModule.getUint(&id);
595
596     Layer* layer = m_executor->getScene()->getLayer(id);
597     if (layer != NULL)
598     {
599         Rectangle dest = layer->getDestinationRegion();
600         Rectangle src = layer->getSourceRegion();
601         OrientationType orientation = layer->getOrientation();
602
603         m_ipcModule.createMessage((char*)__FUNCTION__);
604         m_ipcModule.appendDouble(layer->getOpacity());
605         m_ipcModule.appendUint(src.x);
606         m_ipcModule.appendUint(src.y);
607         m_ipcModule.appendUint(src.width);
608         m_ipcModule.appendUint(src.height);
609         m_ipcModule.appendUint(layer->OriginalSourceWidth);
610         m_ipcModule.appendUint(layer->OriginalSourceHeight);
611         m_ipcModule.appendUint(dest.x);
612         m_ipcModule.appendUint(dest.y);
613         m_ipcModule.appendUint(dest.width);
614         m_ipcModule.appendUint(dest.height);
615         m_ipcModule.appendUint(orientation);
616         m_ipcModule.appendBool(layer->getVisibility());
617         m_ipcModule.appendUint(layer->getLayerType());
618         m_ipcModule.sendMessage();
619     }
620     else
621     {
622         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
623     }
624 }
625
626 void GenericCommunicator::CreateSurface()
627 {
628     uint handle = 0;
629     m_ipcModule.getUint(&handle);
630     uint width = 0;
631     m_ipcModule.getUint(&width);
632     uint height = 0;
633     m_ipcModule.getUint(&height);
634     uint pixelformat = 0;
635     m_ipcModule.getUint(&pixelformat);
636     PixelFormat pf = (PixelFormat) pixelformat;
637
638     //LOG_DEBUG("GenericCommunicator::CreateSurface","pixelformat: " << pixelformat);
639     uint id = GraphicalObject::INVALID_ID;
640     /* First of all create the surface */
641     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
642     /* after that apply the native content */
643     status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));    
644     if (status)
645     {
646         m_ipcModule.createMessage((char*)__FUNCTION__);
647         m_ipcModule.appendUint(id);
648         m_ipcModule.sendMessage();
649     }
650     else
651     {
652         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
653     }
654 }
655
656 void GenericCommunicator::CreateSurfaceFromId()
657 {
658     uint handle = 0;
659     m_ipcModule.getUint(&handle);
660     uint width = 0;
661     m_ipcModule.getUint(&width);
662     uint height = 0;
663     m_ipcModule.getUint(&height);
664     uint pixelformat = 0;
665     m_ipcModule.getUint(&pixelformat);
666     PixelFormat pf = (PixelFormat) pixelformat;
667
668     //LOG_DEBUG("GenericCommunicator::CreateSurface","pixelformat: " << pixelformat);
669     uint id = 0;
670     m_ipcModule.getUint(&id);
671
672     // First of all create the surface
673     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
674     // after that apply the native content
675     status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));    
676
677     if (status)
678     {
679         m_ipcModule.createMessage((char*)__FUNCTION__);
680         m_ipcModule.appendUint(id);
681         m_ipcModule.sendMessage();
682     }
683     else
684     {
685         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
686     }
687 }
688
689 void GenericCommunicator::InitializeSurface()
690 {
691     uint id = GraphicalObject::INVALID_ID;
692
693     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
694     if (status)
695     {
696         m_ipcModule.createMessage((char*)__FUNCTION__);
697         m_ipcModule.appendUint(id);
698         m_ipcModule.sendMessage();
699     }
700     else
701     {
702         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
703     }
704 }
705
706 void GenericCommunicator::InitializeSurfaceFromId()
707 {
708     uint id = 0;
709     m_ipcModule.getUint(&id);
710     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
711     if (status)
712     {
713         m_ipcModule.createMessage((char*)__FUNCTION__);
714         m_ipcModule.appendUint(id);
715         m_ipcModule.sendMessage();
716     }
717     else
718     {
719         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
720     }
721 }
722
723 void GenericCommunicator::SetSurfaceNativeContent()
724 {
725     uint id = 0;
726     m_ipcModule.getUint(&id);
727     uint handle = 0;
728     m_ipcModule.getUint(&handle);
729     uint width = 0;
730     m_ipcModule.getUint(&width);
731     uint height = 0;
732     m_ipcModule.getUint(&height);
733     uint pixelformat = 0;
734     m_ipcModule.getUint(&pixelformat);
735     PixelFormat pf = (PixelFormat) pixelformat;
736
737     t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));
738     if (status)
739     {
740         m_ipcModule.createMessage((char*)__FUNCTION__);
741         m_ipcModule.sendMessage();
742     }
743     else
744     {
745         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
746     }
747 }
748
749 void GenericCommunicator::RemoveSurfaceNativeContent()
750 {
751     uint id = 0;
752     m_ipcModule.getUint(&id);
753
754     t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(id));
755     if (status)
756     {
757         m_ipcModule.createMessage((char*)__FUNCTION__);
758         m_ipcModule.sendMessage();
759     }
760     else
761     {
762         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
763     }
764 }
765
766 void GenericCommunicator::RemoveSurface()
767 {
768     uint param = 0;
769     m_ipcModule.getUint(&param);
770     t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(param));
771     if (status)
772     {
773         m_ipcModule.createMessage((char*)__FUNCTION__);
774         m_ipcModule.sendMessage();
775     }
776     else
777     {
778         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
779     }
780 }
781
782 void GenericCommunicator::CreateLayer()
783 {
784     uint id = GraphicalObject::INVALID_ID;
785     // use resolution of default screen as default width and height of layers
786     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
787     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
788     if (status)
789     {
790         m_ipcModule.createMessage((char*)__FUNCTION__);
791         m_ipcModule.appendUint(id);
792         m_ipcModule.sendMessage();
793     }
794     else
795     {
796         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
797     }
798 }
799
800 void GenericCommunicator::CreateLayerFromId()
801 {
802     uint id = GraphicalObject::INVALID_ID;
803
804     m_ipcModule.getUint(&id);
805     // use resolution of default screen as default width and height of layers
806     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
807     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
808     if (status)
809     {
810         m_ipcModule.createMessage((char*)__FUNCTION__);
811         m_ipcModule.appendUint(id);
812         m_ipcModule.sendMessage();
813     }
814     else
815     {
816         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
817     }
818 }
819
820
821 void GenericCommunicator::CreateLayerWithDimension()
822 {
823     uint width = 0;
824     m_ipcModule.getUint(&width);
825     uint height = 0;
826     m_ipcModule.getUint(&height);
827
828     uint id = GraphicalObject::INVALID_ID;
829     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(width, height, &id));
830     if (status)
831     {
832         m_ipcModule.createMessage((char*)__FUNCTION__);
833         m_ipcModule.appendUint(id);
834         m_ipcModule.sendMessage();
835     }
836     else
837     {
838         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
839     }
840 }
841
842 void GenericCommunicator::CreateLayerFromIdWithDimension()
843 {
844     uint id = GraphicalObject::INVALID_ID;
845
846     m_ipcModule.getUint(&id);
847     uint width = 0;
848     m_ipcModule.getUint(&width);
849     uint height = 0;
850     m_ipcModule.getUint(&height);
851     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(width, height, &id));
852     if (status)
853     {
854         m_ipcModule.createMessage((char*)__FUNCTION__);
855         m_ipcModule.appendUint(id);
856         m_ipcModule.sendMessage();
857     }
858     else
859     {
860         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
861     }
862 }
863
864 void GenericCommunicator::RemoveLayer()
865 {
866     uint param = 0;
867     m_ipcModule.getUint(&param);
868     t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(param));
869     if (status)
870     {
871         m_ipcModule.createMessage((char*)__FUNCTION__);
872         m_ipcModule.sendMessage();
873     }
874     else
875     {
876         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
877     }
878 }
879
880 void GenericCommunicator::AddSurfaceToSurfaceGroup()
881 {
882     uint surfaceid = 0;
883     m_ipcModule.getUint(&surfaceid);
884     uint surfacegroupid = 0;
885     m_ipcModule.getUint(&surfacegroupid);
886
887     t_ilm_bool status = m_executor->execute(new SurfacegroupAddSurfaceCommand(surfacegroupid, surfaceid));
888     if (status)
889     {
890         m_ipcModule.createMessage((char*)__FUNCTION__);
891         m_ipcModule.sendMessage();
892     }
893     else
894     {
895         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
896     }
897 }
898
899 void GenericCommunicator::RemoveSurfaceFromSurfaceGroup()
900 {
901     uint surfaceid = 0;
902     m_ipcModule.getUint(&surfaceid);
903     uint surfacegroupid = 0;
904     m_ipcModule.getUint(&surfacegroupid);
905
906     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveSurfaceCommand(surfacegroupid, surfaceid));
907     if (status)
908     {
909         m_ipcModule.createMessage((char*)__FUNCTION__);
910         m_ipcModule.sendMessage();
911     }
912     else
913     {
914         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
915     }
916 }
917
918 void GenericCommunicator::AddLayerToLayerGroup()
919 {
920     uint layerid = 0;
921     m_ipcModule.getUint(&layerid);
922     uint layergroupid = 0;
923     m_ipcModule.getUint(&layergroupid);
924
925     t_ilm_bool status = m_executor->execute(new LayergroupAddLayerCommand(layergroupid, layerid));
926     if (status)
927     {
928         m_ipcModule.createMessage((char*)__FUNCTION__);
929         m_ipcModule.sendMessage();
930     }
931     else
932     {
933         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
934     }
935 }
936
937 void GenericCommunicator::RemoveLayerFromLayerGroup()
938 {
939     uint layerid = 0;
940     m_ipcModule.getUint(&layerid);
941     uint layergroupid = 0;
942     m_ipcModule.getUint(&layergroupid);
943
944     t_ilm_bool status = m_executor->execute(new LayergroupRemoveLayerCommand(layergroupid, layerid));
945     if (status)
946     {
947         m_ipcModule.createMessage((char*)__FUNCTION__);
948         m_ipcModule.sendMessage();
949     }
950     else
951     {
952         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
953     }
954 }
955
956 void GenericCommunicator::AddSurfaceToLayer()
957 {
958     uint surfaceid = 0;
959     m_ipcModule.getUint(&surfaceid);
960     uint layer = 0;
961     m_ipcModule.getUint(&layer);
962
963     t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(layer, surfaceid));
964     if (status)
965     {
966         m_ipcModule.createMessage((char*)__FUNCTION__);
967         m_ipcModule.sendMessage();
968     }
969     else
970     {
971         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
972     }
973 }
974
975 void GenericCommunicator::RemoveSurfaceFromLayer()
976 {
977     uint surfaceid = 0;
978     m_ipcModule.getUint(&surfaceid);
979     uint layerid = 0;
980     m_ipcModule.getUint(&layerid);
981
982     t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(layerid, surfaceid));
983     if (status)
984     {
985         m_ipcModule.createMessage((char*)__FUNCTION__);
986         m_ipcModule.sendMessage();
987     }
988     else
989     {
990         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
991     }
992 }
993
994 void GenericCommunicator::CreateSurfaceGroup()
995 {
996     uint newID = GraphicalObject::INVALID_ID;
997
998     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
999     if (status)
1000     {
1001         m_ipcModule.createMessage((char*)__FUNCTION__);
1002         m_ipcModule.appendUint(newID);
1003         m_ipcModule.sendMessage();
1004     }
1005     else
1006     {
1007         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1008     }
1009 }
1010
1011 void GenericCommunicator::CreateSurfaceGroupFromId()
1012 {
1013     uint newID = GraphicalObject::INVALID_ID;
1014
1015     m_ipcModule.getUint(&newID);
1016
1017     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
1018     if (status)
1019     {
1020         m_ipcModule.createMessage((char*)__FUNCTION__);
1021         m_ipcModule.appendUint(newID);
1022         m_ipcModule.sendMessage();
1023     }
1024     else
1025     {
1026         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1027     }
1028 }
1029
1030 void GenericCommunicator::RemoveSurfaceGroup()
1031 {
1032     uint param = 0;
1033     m_ipcModule.getUint(&param);
1034
1035     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveCommand(param));
1036     if (status)
1037     {
1038         m_ipcModule.createMessage((char*)__FUNCTION__);
1039         m_ipcModule.sendMessage();
1040     }
1041     else
1042     {
1043         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1044     }
1045 }
1046
1047 void GenericCommunicator::CreateLayerGroup()
1048 {
1049     uint newID = GraphicalObject::INVALID_ID;
1050
1051     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
1052     if (status)
1053     {
1054         m_ipcModule.createMessage((char*)__FUNCTION__);
1055         m_ipcModule.appendUint(newID);
1056         m_ipcModule.sendMessage();
1057     }
1058     else
1059     {
1060         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1061     }
1062 }
1063
1064 void GenericCommunicator::CreateLayerGroupFromId()
1065 {
1066     uint newID = GraphicalObject::INVALID_ID;
1067
1068     m_ipcModule.getUint(&newID);
1069
1070     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
1071     if (status)
1072     {
1073         m_ipcModule.createMessage((char*)__FUNCTION__);
1074         m_ipcModule.appendUint(newID);
1075         m_ipcModule.sendMessage();
1076     }
1077     else
1078     {
1079         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1080     }
1081 }
1082
1083 void GenericCommunicator::RemoveLayerGroup()
1084 {
1085     uint param = 0;
1086     m_ipcModule.getUint(&param);
1087
1088     t_ilm_bool status = m_executor->execute(new LayergroupRemoveCommand(param));
1089     if (status)
1090     {
1091         m_ipcModule.createMessage((char*)__FUNCTION__);
1092         m_ipcModule.sendMessage();
1093     }
1094     else
1095     {
1096         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1097     }
1098 }
1099
1100 void GenericCommunicator::SetSurfaceSourceRegion()
1101 {
1102     uint id = 0;
1103     m_ipcModule.getUint(&id);
1104     uint x = 0;
1105     m_ipcModule.getUint(&x);
1106     uint y = 0;
1107     m_ipcModule.getUint(&y);
1108     uint width = 0;
1109     m_ipcModule.getUint(&width);
1110     uint height = 0;
1111     m_ipcModule.getUint(&height);
1112
1113     t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(id, x, y, width, height));
1114     if (status)
1115     {
1116         m_ipcModule.createMessage((char*)__FUNCTION__);
1117         m_ipcModule.sendMessage();
1118     }
1119     else
1120     {
1121         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1122     }
1123 }
1124
1125 void GenericCommunicator::SetLayerSourceRegion()
1126 {
1127     uint id = 0;
1128     m_ipcModule.getUint(&id);
1129     uint x = 0;
1130     m_ipcModule.getUint(&x);
1131     uint y = 0;
1132     m_ipcModule.getUint(&y);
1133     uint width = 0;
1134     m_ipcModule.getUint(&width);
1135     uint height = 0;
1136     m_ipcModule.getUint(&height);
1137
1138     //LOG_DEBUG("DBUSC","new SetSourceRectangleCommand with arguments: " <<id <<" " << x <<" "<< y <<" "<< width <<" "<< height );
1139     t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(id, x, y, width, height));
1140     if (status)
1141     {
1142         m_ipcModule.createMessage((char*)__FUNCTION__);
1143         m_ipcModule.sendMessage();
1144     }
1145     else
1146     {
1147         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1148     }
1149 }
1150
1151 void GenericCommunicator::SetSurfaceDestinationRegion()
1152 {
1153     uint id = 0;
1154     m_ipcModule.getUint(&id);
1155     uint x = 0;
1156     m_ipcModule.getUint(&x);
1157     uint y = 0;
1158     m_ipcModule.getUint(&y);
1159     uint width = 0;
1160     m_ipcModule.getUint(&width);
1161     uint height = 0;
1162     m_ipcModule.getUint(&height);
1163
1164     t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(id, x, y, width, height));
1165     if (status)
1166     {
1167         m_ipcModule.createMessage((char*)__FUNCTION__);
1168         m_ipcModule.sendMessage();
1169     }
1170     else
1171     {
1172         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1173     }
1174 }
1175
1176 void GenericCommunicator::SetSurfacePosition()
1177 {
1178     uint id = 0;
1179     m_ipcModule.getUint(&id);
1180     uint x = 0;
1181     m_ipcModule.getUint(&x);
1182     uint y = 0;
1183     m_ipcModule.getUint(&y);
1184
1185     t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(id, x, y));
1186     if (status)
1187     {
1188         m_ipcModule.createMessage((char*)__FUNCTION__);
1189         m_ipcModule.sendMessage();
1190     }
1191     else
1192     {
1193         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1194     }
1195 }
1196
1197 void GenericCommunicator::GetSurfacePosition()
1198 {
1199     uint id = 0;
1200     m_ipcModule.getUint(&id);
1201     uint x = 0;
1202     uint y = 0;
1203
1204     t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(id, &x, &y));
1205     if (status)
1206     {
1207         m_ipcModule.createMessage((char*)__FUNCTION__);
1208         m_ipcModule.appendUint(x);
1209         m_ipcModule.appendUint(y);
1210         m_ipcModule.sendMessage();
1211     }
1212     else
1213     {
1214         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1215     }
1216 }
1217
1218 void GenericCommunicator::SetSurfaceDimension()
1219 {
1220     uint id = 0;
1221     m_ipcModule.getUint(&id);
1222     uint width = 0;
1223     m_ipcModule.getUint(&width);
1224     uint height = 0;
1225     m_ipcModule.getUint(&height);
1226
1227     t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(id, width, height));
1228     if (status)
1229     {
1230         m_ipcModule.createMessage((char*)__FUNCTION__);
1231         m_ipcModule.sendMessage();
1232     }
1233     else
1234     {
1235         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1236     }
1237 }
1238
1239 void GenericCommunicator::SetLayerDestinationRegion()
1240 {
1241     uint id = 0;
1242     m_ipcModule.getUint(&id);
1243     uint x = 0;
1244     m_ipcModule.getUint(&x);
1245     uint y = 0;
1246     m_ipcModule.getUint(&y);
1247     uint width = 0;
1248     m_ipcModule.getUint(&width);
1249     uint height = 0;
1250     m_ipcModule.getUint(&height);
1251
1252     t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(id, x, y, width, height));
1253     if (status)
1254     {
1255         m_ipcModule.createMessage((char*)__FUNCTION__);
1256         m_ipcModule.sendMessage();
1257     }
1258     else
1259     {
1260         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1261     }
1262 }
1263
1264 void GenericCommunicator::SetLayerPosition()
1265 {
1266     uint id = 0;
1267     m_ipcModule.getUint(&id);
1268     uint x = 0;
1269     m_ipcModule.getUint(&x);
1270     uint y = 0;
1271     m_ipcModule.getUint(&y);
1272
1273     t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(id, x, y));
1274     if (status)
1275     {
1276         m_ipcModule.createMessage((char*)__FUNCTION__);
1277         m_ipcModule.sendMessage();
1278     }
1279     else
1280     {
1281         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1282     }
1283 }
1284
1285 void GenericCommunicator::GetLayerPosition()
1286 {
1287     uint id = 0;
1288     m_ipcModule.getUint(&id);
1289     uint x = 0;
1290     uint y = 0;
1291
1292     t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(id, &x, &y));
1293     if (status)
1294     {
1295         m_ipcModule.createMessage((char*)__FUNCTION__);
1296         m_ipcModule.appendUint(x);
1297         m_ipcModule.appendUint(y);
1298         m_ipcModule.sendMessage();
1299     }
1300     else
1301     {
1302         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1303     }
1304 }
1305
1306 void GenericCommunicator::SetLayerDimension()
1307 {
1308     uint id = 0;
1309     m_ipcModule.getUint(&id);
1310     uint width = 0;
1311     m_ipcModule.getUint(&width);
1312     uint height = 0;
1313     m_ipcModule.getUint(&height);
1314
1315     t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(id, width, height));
1316     if (status)
1317     {
1318         m_ipcModule.createMessage((char*)__FUNCTION__);
1319         m_ipcModule.sendMessage();
1320     }
1321     else
1322     {
1323         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1324     }
1325 }
1326
1327 void GenericCommunicator::GetLayerDimension()
1328 {
1329     uint id = 0;
1330     m_ipcModule.getUint(&id);
1331     uint width = 0;
1332     uint height = 0;
1333
1334     t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(id, &width, &height));
1335     if (status)
1336     {
1337         m_ipcModule.createMessage((char*)__FUNCTION__);
1338         m_ipcModule.appendUint(width);
1339         m_ipcModule.appendUint(height);
1340         m_ipcModule.sendMessage();
1341     }
1342     else
1343     {
1344         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1345     }
1346 }
1347
1348 void GenericCommunicator::GetSurfaceDimension()
1349 {
1350     uint id = 0;
1351     m_ipcModule.getUint(&id);
1352     uint width = 0;
1353     uint height = 0;
1354
1355     t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(id, &width, &height));
1356     if (status)
1357     {
1358         m_ipcModule.createMessage((char*)__FUNCTION__);
1359         m_ipcModule.appendUint(width);
1360         m_ipcModule.appendUint(height);
1361         m_ipcModule.sendMessage();
1362     }
1363     else
1364     {
1365         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1366     }
1367 }
1368
1369 void GenericCommunicator::SetSurfaceOpacity()
1370 {
1371     uint id = 0;
1372     m_ipcModule.getUint(&id);
1373     double param = 0.0;
1374     m_ipcModule.getDouble(&param);
1375
1376     t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(id, param));
1377     if (status)
1378     {
1379         m_ipcModule.createMessage((char*)__FUNCTION__);
1380         m_ipcModule.sendMessage();
1381     }
1382     else
1383     {
1384         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1385     }
1386 }
1387
1388 void GenericCommunicator::SetLayerOpacity()
1389 {
1390     uint id = 0;
1391     m_ipcModule.getUint(&id);
1392     double param = 0.0;
1393     m_ipcModule.getDouble(&param);
1394
1395     t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(id, param));
1396     if (status)
1397     {
1398         m_ipcModule.createMessage((char*)__FUNCTION__);
1399         m_ipcModule.sendMessage();
1400     }
1401     else
1402     {
1403         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1404     }
1405 }
1406
1407 void GenericCommunicator::SetSurfacegroupOpacity()
1408 {
1409     uint id = 0;
1410     m_ipcModule.getUint(&id);
1411     double param = 0.0;
1412     m_ipcModule.getDouble(&param);
1413
1414     t_ilm_bool status = m_executor->execute(new SurfacegroupSetOpacityCommand(id, param));
1415     if (status)
1416     {
1417         m_ipcModule.createMessage((char*)__FUNCTION__);
1418         m_ipcModule.sendMessage();
1419     }
1420     else
1421     {
1422         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1423     }
1424 }
1425
1426 void GenericCommunicator::SetLayergroupOpacity()
1427 {
1428     uint id = 0;
1429     m_ipcModule.getUint(&id);
1430     double param = 0.0;
1431     m_ipcModule.getDouble(&param);
1432
1433     t_ilm_bool status = m_executor->execute(new LayergroupSetOpacityCommand(id, param));
1434     if (status)
1435     {
1436         m_ipcModule.createMessage((char*)__FUNCTION__);
1437         m_ipcModule.sendMessage();
1438     }
1439     else
1440     {
1441         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1442     }
1443 }
1444
1445 void GenericCommunicator::GetSurfaceOpacity()
1446 {
1447     uint id = 0;
1448     m_ipcModule.getUint(&id);
1449     double param = 0.0;
1450
1451     t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(id, &param));
1452     if (status)
1453     {
1454         m_ipcModule.createMessage((char*)__FUNCTION__);
1455         m_ipcModule.appendDouble(param);
1456         m_ipcModule.sendMessage();
1457     }
1458     else
1459     {
1460         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1461     }
1462 }
1463
1464 void GenericCommunicator::GetLayerOpacity()
1465 {
1466     uint id = 0;
1467     m_ipcModule.getUint(&id);
1468     double param = 0.0;
1469
1470     t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(id, &param));
1471     if (status)
1472     {
1473         m_ipcModule.createMessage((char*)__FUNCTION__);
1474         m_ipcModule.appendDouble(param);
1475         m_ipcModule.sendMessage();
1476     }
1477     else
1478     {
1479         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1480     }
1481 }
1482
1483 void GenericCommunicator::SetSurfaceOrientation()
1484 {
1485     uint id = 0;
1486     m_ipcModule.getUint(&id);
1487     uint param = 0;
1488     m_ipcModule.getUint(&param);
1489     OrientationType o = (OrientationType) param;
1490
1491     t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(id, o));
1492     if (status)
1493     {
1494         m_ipcModule.createMessage((char*)__FUNCTION__);
1495         m_ipcModule.sendMessage();
1496     }
1497     else
1498     {
1499         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1500     }
1501 }
1502
1503 void GenericCommunicator::GetSurfaceOrientation()
1504 {
1505     uint id = 0;
1506     m_ipcModule.getUint(&id);
1507     OrientationType o;
1508
1509     t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(id, &o));
1510     if (status)
1511     {
1512         m_ipcModule.createMessage((char*)__FUNCTION__);
1513         m_ipcModule.appendUint(o);
1514         m_ipcModule.sendMessage();
1515     }
1516     else
1517     {
1518         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1519     }
1520 }
1521
1522 void GenericCommunicator::SetLayerOrientation()
1523 {
1524     uint id = 0;
1525     m_ipcModule.getUint(&id);
1526     uint param = 0;
1527     m_ipcModule.getUint(&param);
1528     OrientationType o = (OrientationType) param;
1529
1530     t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(id, o));
1531     if (status)
1532     {
1533         m_ipcModule.createMessage((char*)__FUNCTION__);
1534         m_ipcModule.sendMessage();
1535     }
1536     else
1537     {
1538         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1539     }
1540 }
1541
1542 void GenericCommunicator::GetLayerOrientation()
1543 {
1544     uint id = 0;
1545     m_ipcModule.getUint(&id);
1546     OrientationType o;
1547
1548     t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(id, &o));
1549     if (status)
1550     {
1551         m_ipcModule.createMessage((char*)__FUNCTION__);
1552         m_ipcModule.appendUint(o);
1553         m_ipcModule.sendMessage();
1554     }
1555     else
1556     {
1557         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1558     }
1559 }
1560
1561 void GenericCommunicator::GetSurfacePixelformat()
1562 {
1563     uint id = 0;
1564     m_ipcModule.getUint(&id);
1565     PixelFormat param;
1566
1567     t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(id, &param));
1568     if (status)
1569     {
1570         m_ipcModule.createMessage((char*)__FUNCTION__);
1571         m_ipcModule.appendUint(param);
1572         m_ipcModule.sendMessage();
1573     }
1574     else
1575     {
1576         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1577     }
1578 }
1579
1580 void GenericCommunicator::SetSurfaceVisibility()
1581 {
1582     uint surfaceid = 0;
1583     m_ipcModule.getUint(&surfaceid);
1584     t_ilm_bool newVis = ILM_FALSE;
1585     m_ipcModule.getBool(&newVis);
1586
1587     t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(surfaceid, newVis));
1588     if (status)
1589     {
1590         m_ipcModule.createMessage((char*)__FUNCTION__);
1591         m_ipcModule.sendMessage();
1592     }
1593     else
1594     {
1595         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1596     }
1597 }
1598
1599 void GenericCommunicator::SetLayerVisibility()
1600 {
1601     uint layerid = 0;
1602     m_ipcModule.getUint(&layerid);
1603     t_ilm_bool myparam = ILM_FALSE;
1604     m_ipcModule.getBool(&myparam);
1605
1606     t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(layerid, myparam));
1607     if (status)
1608     {
1609         m_ipcModule.createMessage((char*)__FUNCTION__);
1610         m_ipcModule.sendMessage();
1611     }
1612     else
1613     {
1614         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1615     }
1616 }
1617
1618 void GenericCommunicator::GetSurfaceVisibility()
1619 {
1620     uint id = 0;
1621     m_ipcModule.getUint(&id);
1622     bool param;
1623
1624     t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(id, &param));
1625     if (status)
1626     {
1627         m_ipcModule.createMessage((char*)__FUNCTION__);
1628         //LOG_DEBUG("GenericCommunicator", "returning surfacevisibility: " << param);
1629         m_ipcModule.appendBool(param);
1630         m_ipcModule.sendMessage();
1631     }
1632     else
1633     {
1634         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1635     }
1636 }
1637
1638 void GenericCommunicator::GetLayerVisibility()
1639 {
1640     uint id = 0;
1641     m_ipcModule.getUint(&id);
1642     bool param;
1643
1644     t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(id, &param));
1645     if (status)
1646     {
1647         m_ipcModule.createMessage((char*)__FUNCTION__);
1648         m_ipcModule.appendBool(param);
1649         //LOG_DEBUG("GenericCommunicator", "returning layervisibility: " << param);
1650         m_ipcModule.sendMessage();
1651     }
1652     else
1653     {
1654         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1655     }
1656 }
1657
1658 void GenericCommunicator::SetSurfacegroupVisibility()
1659 {
1660     uint groupid = 0;
1661     m_ipcModule.getUint(&groupid);
1662     t_ilm_bool myparam = ILM_FALSE;
1663     m_ipcModule.getBool(&myparam);
1664
1665     t_ilm_bool status = m_executor->execute(new SurfacegroupSetVisibilityCommand(groupid, myparam));
1666     if (status)
1667     {
1668         m_ipcModule.createMessage((char*)__FUNCTION__);
1669         m_ipcModule.sendMessage();
1670     }
1671     else
1672     {
1673         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1674     }
1675 }
1676
1677 void GenericCommunicator::SetLayergroupVisibility()
1678 {
1679     uint groupid = 0;
1680     m_ipcModule.getUint(&groupid);
1681     t_ilm_bool myparam = ILM_FALSE;
1682     m_ipcModule.getBool(&myparam);
1683
1684     t_ilm_bool status = m_executor->execute(new LayergroupSetVisibilityCommand(groupid, myparam));
1685     if (status)
1686     {
1687         m_ipcModule.createMessage((char*)__FUNCTION__);
1688         m_ipcModule.sendMessage();
1689     }
1690     else
1691     {
1692         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1693     }
1694 }
1695
1696
1697 void GenericCommunicator::SetRenderOrderOfLayers()
1698 {
1699     uint* array = NULL;
1700     int length = 0;
1701
1702     m_ipcModule.getUintArray(&array, &length);
1703
1704     //LOG_DEBUG("GenericCommunicator","Renderorder: Got " << length << " ids.");
1705
1706     t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(array, length));
1707     if (status)
1708     {
1709         m_ipcModule.createMessage((char*)__FUNCTION__);
1710         m_ipcModule.sendMessage();
1711     }
1712     else
1713     {
1714         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1715     }
1716 }
1717
1718 void GenericCommunicator::SetSurfaceRenderOrderWithinLayer()
1719 {
1720     uint* array = NULL;
1721     int length = 0;
1722
1723     uint layerid = 0;
1724     m_ipcModule.getUint(&layerid);
1725
1726     m_ipcModule.getUintArray(&array, &length);
1727
1728     t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(layerid, array, length));
1729     if (status)
1730     {
1731         m_ipcModule.createMessage((char*)__FUNCTION__);
1732         m_ipcModule.sendMessage();
1733     }
1734     else
1735     {
1736         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1737     }
1738 }
1739
1740 void GenericCommunicator::GetLayerType()
1741 {
1742     uint id = 0;
1743     m_ipcModule.getUint(&id);
1744     Layer* l = m_executor->getScene()->getLayer(id);
1745     if (l != NULL)
1746     {
1747         m_ipcModule.createMessage((char*)__FUNCTION__);
1748         m_ipcModule.appendUint(l->getLayerType());
1749         m_ipcModule.sendMessage();
1750     }
1751     else
1752     {
1753         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1754     }
1755 }
1756
1757 void GenericCommunicator::GetLayertypeCapabilities()
1758 {
1759     uint id = 0;
1760     m_ipcModule.getUint(&id);
1761     LayerType type = (LayerType) id;
1762     uint capabilities = m_executor->getLayerTypeCapabilities(type);
1763     //LOG_DEBUG("GenericCommunicator", "GetLayertypeCapabilities: returning capabilities:" << capabilities);
1764     m_ipcModule.createMessage((char*)__FUNCTION__);
1765     m_ipcModule.appendUint(capabilities);
1766     m_ipcModule.sendMessage();
1767 }
1768
1769 void GenericCommunicator::GetLayerCapabilities()
1770 {
1771     uint id = 0;
1772     m_ipcModule.getUint(&id);
1773     Layer* l = m_executor->getScene()->getLayer(id);
1774     if (l != NULL)
1775     {
1776         m_ipcModule.createMessage((char*)__FUNCTION__);
1777         m_ipcModule.appendUint(l->getCapabilities());
1778         m_ipcModule.sendMessage();
1779     }
1780     else
1781     {
1782         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1783     }
1784 }
1785
1786 void GenericCommunicator::FadeIn()
1787 {
1788     m_ipcModule.createMessage((char*)__FUNCTION__);
1789     m_ipcModule.sendMessage();
1790 }
1791
1792 void GenericCommunicator::SynchronizedFade()
1793 {
1794     m_ipcModule.createMessage((char*)__FUNCTION__);
1795     m_ipcModule.sendMessage();
1796 }
1797
1798 void GenericCommunicator::FadeOut()
1799 {
1800     m_ipcModule.createMessage((char*)__FUNCTION__);
1801     m_ipcModule.sendMessage();
1802 }
1803
1804 void GenericCommunicator::Exit()
1805 {
1806     t_ilm_bool status = m_executor->execute(new ExitCommand());
1807     if (status)
1808     {
1809         m_ipcModule.createMessage((char*)__FUNCTION__);
1810         m_ipcModule.sendMessage();
1811     }
1812     else
1813     {
1814         m_ipcModule.sendError(INVALID_ARGUMENT);
1815     }
1816 }
1817
1818 void GenericCommunicator::CommitChanges()
1819 {
1820     t_ilm_bool status = m_executor->execute(new CommitCommand());
1821     if (status)
1822     {
1823         m_ipcModule.createMessage((char*)__FUNCTION__);
1824         m_ipcModule.sendMessage();
1825     }
1826     else
1827     {
1828         m_ipcModule.sendError(INVALID_ARGUMENT);
1829     }
1830 }
1831
1832 void GenericCommunicator::CreateShader()
1833 {
1834     char vertname[1024];
1835     char fragname[1024];
1836     m_ipcModule.getString(vertname);
1837     m_ipcModule.getString(fragname);
1838     uint id = 0;
1839
1840     t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(vertname, fragname, &id));
1841     if (status)
1842     {
1843         m_ipcModule.createMessage((char*)__FUNCTION__);
1844         m_ipcModule.appendUint(id);
1845         m_ipcModule.sendMessage();
1846     }
1847     else
1848     {
1849         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1850     }
1851 }
1852
1853 void GenericCommunicator::DestroyShader()
1854 {
1855     uint shaderid = 0;
1856     m_ipcModule.getUint(&shaderid);
1857
1858     t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(shaderid));
1859     if (status)
1860     {
1861         m_ipcModule.createMessage((char*)__FUNCTION__);
1862         m_ipcModule.sendMessage();
1863     }
1864     else
1865     {
1866         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1867     }
1868 }
1869
1870 void GenericCommunicator::SetShader()
1871 {
1872     uint surfaceId = 0;
1873     uint shaderid = 0;
1874     m_ipcModule.getUint(&surfaceId);
1875     m_ipcModule.getUint(&shaderid);
1876
1877     t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(surfaceId, shaderid));
1878     if (status)
1879     {
1880         m_ipcModule.createMessage((char*)__FUNCTION__);
1881         m_ipcModule.sendMessage();
1882     }
1883     else
1884     {
1885         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1886     }
1887 }
1888
1889 void GenericCommunicator::SetUniforms()
1890 {
1891     uint id = 0; m_ipcModule.getUint(&id);
1892
1893     std::vector<string> uniforms;
1894
1895     // TODO
1896     //m_ipcModule.getStringArray(&uniforms);
1897
1898     t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(id, uniforms));
1899     if (status)
1900     {
1901         m_ipcModule.createMessage((char*)__FUNCTION__);
1902         m_ipcModule.sendMessage();
1903     }
1904     else
1905     {
1906         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1907     }
1908 }
1909
1910 void GenericCommunicator::SetKeyboardFocusOn()
1911 {
1912     uint surfaceId = 0;
1913
1914     m_ipcModule.getUint(&surfaceId);
1915
1916     t_ilm_bool status = m_executor->execute(new SurfaceSetKeyboardFocusCommand(surfaceId));
1917     if (status)
1918     {
1919         m_ipcModule.createMessage((char*)__FUNCTION__);
1920         m_ipcModule.sendMessage();
1921     }
1922     else
1923     {
1924         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1925     }
1926 }
1927
1928
1929 void GenericCommunicator::GetKeyboardFocusSurfaceId()
1930 {
1931     uint surfaceId;
1932     
1933     t_ilm_bool status = m_executor->execute(new SurfaceGetKeyboardFocusCommand(&surfaceId));
1934     if (status)
1935     {
1936         m_ipcModule.createMessage((char*)__FUNCTION__);
1937         m_ipcModule.appendUint(surfaceId);
1938         m_ipcModule.sendMessage();
1939     }
1940     else
1941     {
1942         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1943     }
1944     
1945     
1946 }
1947
1948
1949 void GenericCommunicator::UpdateInputEventAcceptanceOn()
1950 {
1951     uint surfaceId = 0;
1952         uint udevices = 0;
1953         InputDevice devices;
1954         t_ilm_bool accept;
1955
1956     m_ipcModule.getUint(&surfaceId);
1957     m_ipcModule.getUint(&udevices);
1958     m_ipcModule.getBool(&accept);
1959
1960     devices = (InputDevice) udevices;
1961     t_ilm_bool status = m_executor->execute(new SurfaceUpdateInputEventAcceptance(surfaceId, devices, accept));
1962     if (status)
1963     {
1964         m_ipcModule.createMessage((char*)__FUNCTION__);
1965         m_ipcModule.sendMessage();
1966     }
1967     else
1968     {
1969         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1970     }
1971 }
1972
1973 extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor)
1974 {
1975     return new GenericCommunicator(executor);
1976 }
1977
1978 extern "C" void destroyGenericCommunicator(GenericCommunicator* p)
1979 {
1980     delete p;
1981 }
1982