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