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