GenericCommunicator: added new LayerManager Communicator based on ipc modules
[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.sendMessage();
570     }
571     else
572     {
573         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
574     }
575 }
576
577 void GenericCommunicator::GetPropertiesOfLayer()
578 {
579     uint id = 0;
580     m_ipcModule.getUint(&id);
581
582     Layer* layer = m_executor->getScene()->getLayer(id);
583     if (layer != NULL)
584     {
585         Rectangle dest = layer->getDestinationRegion();
586         Rectangle src = layer->getSourceRegion();
587         OrientationType orientation = layer->getOrientation();
588
589         m_ipcModule.createMessage((char*)__FUNCTION__);
590         m_ipcModule.appendDouble(layer->getOpacity());
591         m_ipcModule.appendUint(src.x);
592         m_ipcModule.appendUint(src.y);
593         m_ipcModule.appendUint(src.width);
594         m_ipcModule.appendUint(src.height);
595         m_ipcModule.appendUint(layer->OriginalSourceWidth);
596         m_ipcModule.appendUint(layer->OriginalSourceHeight);
597         m_ipcModule.appendUint(dest.x);
598         m_ipcModule.appendUint(dest.y);
599         m_ipcModule.appendUint(dest.width);
600         m_ipcModule.appendUint(dest.height);
601         m_ipcModule.appendUint(orientation);
602         m_ipcModule.appendBool(layer->getVisibility());
603         m_ipcModule.sendMessage();
604     }
605     else
606     {
607         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
608     }
609 }
610
611 void GenericCommunicator::CreateSurface()
612 {
613     uint handle = 0;
614     m_ipcModule.getUint(&handle);
615     uint width = 0;
616     m_ipcModule.getUint(&width);
617     uint height = 0;
618     m_ipcModule.getUint(&height);
619     uint pixelformat = 0;
620     m_ipcModule.getUint(&pixelformat);
621     PixelFormat pf = (PixelFormat) pixelformat;
622
623     //LOG_DEBUG("GenericCommunicator::CreateSurface","pixelformat: " << pixelformat);
624     uint id = GraphicalObject::INVALID_ID;
625     /* First of all create the surface */
626     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
627     /* after that apply the native content */
628     status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));    
629     if (status)
630     {
631         m_ipcModule.createMessage((char*)__FUNCTION__);
632         m_ipcModule.appendUint(id);
633         m_ipcModule.sendMessage();
634     }
635     else
636     {
637         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
638     }
639 }
640
641 void GenericCommunicator::CreateSurfaceFromId()
642 {
643     uint handle = 0;
644     m_ipcModule.getUint(&handle);
645     uint width = 0;
646     m_ipcModule.getUint(&width);
647     uint height = 0;
648     m_ipcModule.getUint(&height);
649     uint pixelformat = 0;
650     m_ipcModule.getUint(&pixelformat);
651     PixelFormat pf = (PixelFormat) pixelformat;
652
653     //LOG_DEBUG("GenericCommunicator::CreateSurface","pixelformat: " << pixelformat);
654     uint id = 0;
655     m_ipcModule.getUint(&id);
656
657     // First of all create the surface
658     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
659     // after that apply the native content
660     status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));    
661
662     if (status)
663     {
664         m_ipcModule.createMessage((char*)__FUNCTION__);
665         m_ipcModule.appendUint(id);
666         m_ipcModule.sendMessage();
667     }
668     else
669     {
670         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
671     }
672 }
673
674 void GenericCommunicator::InitializeSurface()
675 {
676     uint id = GraphicalObject::INVALID_ID;
677
678     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
679     if (status)
680     {
681         m_ipcModule.createMessage((char*)__FUNCTION__);
682         m_ipcModule.appendUint(id);
683         m_ipcModule.sendMessage();
684     }
685     else
686     {
687         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
688     }
689 }
690
691 void GenericCommunicator::InitializeSurfaceFromId()
692 {
693     uint id = 0;
694     m_ipcModule.getUint(&id);
695     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
696     if (status)
697     {
698         m_ipcModule.createMessage((char*)__FUNCTION__);
699         m_ipcModule.appendUint(id);
700         m_ipcModule.sendMessage();
701     }
702     else
703     {
704         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
705     }
706 }
707
708 void GenericCommunicator::SetSurfaceNativeContent()
709 {
710     uint id = 0;
711     m_ipcModule.getUint(&id);
712     uint handle = 0;
713     m_ipcModule.getUint(&handle);
714     uint width = 0;
715     m_ipcModule.getUint(&width);
716     uint height = 0;
717     m_ipcModule.getUint(&height);
718     uint pixelformat = 0;
719     m_ipcModule.getUint(&pixelformat);
720     PixelFormat pf = (PixelFormat) pixelformat;
721
722     t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));
723     if (status)
724     {
725         m_ipcModule.createMessage((char*)__FUNCTION__);
726         m_ipcModule.sendMessage();
727     }
728     else
729     {
730         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
731     }
732 }
733
734 void GenericCommunicator::RemoveSurface()
735 {
736     uint param = 0;
737     m_ipcModule.getUint(&param);
738     t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(param));
739     if (status)
740     {
741         m_ipcModule.createMessage((char*)__FUNCTION__);
742         m_ipcModule.sendMessage();
743     }
744     else
745     {
746         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
747     }
748 }
749
750 void GenericCommunicator::CreateLayer()
751 {
752     uint id = GraphicalObject::INVALID_ID;
753     // use resolution of default screen as default width and height of layers
754     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
755     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
756     if (status)
757     {
758         m_ipcModule.createMessage((char*)__FUNCTION__);
759         m_ipcModule.appendUint(id);
760         m_ipcModule.sendMessage();
761     }
762     else
763     {
764         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
765     }
766 }
767
768 void GenericCommunicator::CreateLayerFromId()
769 {
770     uint id = GraphicalObject::INVALID_ID;
771
772     m_ipcModule.getUint(&id);
773     // use resolution of default screen as default width and height of layers
774     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
775     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
776     if (status)
777     {
778         m_ipcModule.createMessage((char*)__FUNCTION__);
779         m_ipcModule.appendUint(id);
780         m_ipcModule.sendMessage();
781     }
782     else
783     {
784         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
785     }
786 }
787
788
789 void GenericCommunicator::CreateLayerWithDimension()
790 {
791     uint width = 0;
792     m_ipcModule.getUint(&width);
793     uint height = 0;
794     m_ipcModule.getUint(&height);
795
796     uint id = GraphicalObject::INVALID_ID;
797     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(width, height, &id));
798     if (status)
799     {
800         m_ipcModule.createMessage((char*)__FUNCTION__);
801         m_ipcModule.appendUint(id);
802         m_ipcModule.sendMessage();
803     }
804     else
805     {
806         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
807     }
808 }
809
810 void GenericCommunicator::CreateLayerFromIdWithDimension()
811 {
812     uint id = GraphicalObject::INVALID_ID;
813
814     m_ipcModule.getUint(&id);
815     uint width = 0;
816     m_ipcModule.getUint(&width);
817     uint height = 0;
818     m_ipcModule.getUint(&height);
819     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(width, height, &id));
820     if (status)
821     {
822         m_ipcModule.createMessage((char*)__FUNCTION__);
823         m_ipcModule.appendUint(id);
824         m_ipcModule.sendMessage();
825     }
826     else
827     {
828         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
829     }
830 }
831
832 void GenericCommunicator::RemoveLayer()
833 {
834     uint param = 0;
835     m_ipcModule.getUint(&param);
836     t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(param));
837     if (status)
838     {
839         m_ipcModule.createMessage((char*)__FUNCTION__);
840         m_ipcModule.sendMessage();
841     }
842     else
843     {
844         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
845     }
846 }
847
848 void GenericCommunicator::AddSurfaceToSurfaceGroup()
849 {
850     uint surfaceid = 0;
851     m_ipcModule.getUint(&surfaceid);
852     uint surfacegroupid = 0;
853     m_ipcModule.getUint(&surfacegroupid);
854
855     t_ilm_bool status = m_executor->execute(new SurfacegroupAddSurfaceCommand(surfacegroupid, surfaceid));
856     if (status)
857     {
858         m_ipcModule.createMessage((char*)__FUNCTION__);
859         m_ipcModule.sendMessage();
860     }
861     else
862     {
863         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
864     }
865 }
866
867 void GenericCommunicator::RemoveSurfaceFromSurfaceGroup()
868 {
869     uint surfaceid = 0;
870     m_ipcModule.getUint(&surfaceid);
871     uint surfacegroupid = 0;
872     m_ipcModule.getUint(&surfacegroupid);
873
874     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveSurfaceCommand(surfacegroupid, surfaceid));
875     if (status)
876     {
877         m_ipcModule.createMessage((char*)__FUNCTION__);
878         m_ipcModule.sendMessage();
879     }
880     else
881     {
882         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
883     }
884 }
885
886 void GenericCommunicator::AddLayerToLayerGroup()
887 {
888     uint layerid = 0;
889     m_ipcModule.getUint(&layerid);
890     uint layergroupid = 0;
891     m_ipcModule.getUint(&layergroupid);
892
893     t_ilm_bool status = m_executor->execute(new LayergroupAddLayerCommand(layergroupid, layerid));
894     if (status)
895     {
896         m_ipcModule.createMessage((char*)__FUNCTION__);
897         m_ipcModule.sendMessage();
898     }
899     else
900     {
901         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
902     }
903 }
904
905 void GenericCommunicator::RemoveLayerFromLayerGroup()
906 {
907     uint layerid = 0;
908     m_ipcModule.getUint(&layerid);
909     uint layergroupid = 0;
910     m_ipcModule.getUint(&layergroupid);
911
912     t_ilm_bool status = m_executor->execute(new LayergroupRemoveLayerCommand(layergroupid, layerid));
913     if (status)
914     {
915         m_ipcModule.createMessage((char*)__FUNCTION__);
916         m_ipcModule.sendMessage();
917     }
918     else
919     {
920         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
921     }
922 }
923
924 void GenericCommunicator::AddSurfaceToLayer()
925 {
926     uint surfaceid = 0;
927     m_ipcModule.getUint(&surfaceid);
928     uint layer = 0;
929     m_ipcModule.getUint(&layer);
930
931     t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(layer, surfaceid));
932     if (status)
933     {
934         m_ipcModule.createMessage((char*)__FUNCTION__);
935         m_ipcModule.sendMessage();
936     }
937     else
938     {
939         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
940     }
941 }
942
943 void GenericCommunicator::RemoveSurfaceFromLayer()
944 {
945     uint surfaceid = 0;
946     m_ipcModule.getUint(&surfaceid);
947     uint layerid = 0;
948     m_ipcModule.getUint(&layerid);
949
950     t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(layerid, surfaceid));
951     if (status)
952     {
953         m_ipcModule.createMessage((char*)__FUNCTION__);
954         m_ipcModule.sendMessage();
955     }
956     else
957     {
958         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
959     }
960 }
961
962 void GenericCommunicator::CreateSurfaceGroup()
963 {
964     uint newID = GraphicalObject::INVALID_ID;
965
966     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
967     if (status)
968     {
969         m_ipcModule.createMessage((char*)__FUNCTION__);
970         m_ipcModule.appendUint(newID);
971         m_ipcModule.sendMessage();
972     }
973     else
974     {
975         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
976     }
977 }
978
979 void GenericCommunicator::CreateSurfaceGroupFromId()
980 {
981     uint newID = GraphicalObject::INVALID_ID;
982
983     m_ipcModule.getUint(&newID);
984
985     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
986     if (status)
987     {
988         m_ipcModule.createMessage((char*)__FUNCTION__);
989         m_ipcModule.appendUint(newID);
990         m_ipcModule.sendMessage();
991     }
992     else
993     {
994         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
995     }
996 }
997
998 void GenericCommunicator::RemoveSurfaceGroup()
999 {
1000     uint param = 0;
1001     m_ipcModule.getUint(&param);
1002
1003     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveCommand(param));
1004     if (status)
1005     {
1006         m_ipcModule.createMessage((char*)__FUNCTION__);
1007         m_ipcModule.sendMessage();
1008     }
1009     else
1010     {
1011         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1012     }
1013 }
1014
1015 void GenericCommunicator::CreateLayerGroup()
1016 {
1017     uint newID = GraphicalObject::INVALID_ID;
1018
1019     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
1020     if (status)
1021     {
1022         m_ipcModule.createMessage((char*)__FUNCTION__);
1023         m_ipcModule.appendUint(newID);
1024         m_ipcModule.sendMessage();
1025     }
1026     else
1027     {
1028         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1029     }
1030 }
1031
1032 void GenericCommunicator::CreateLayerGroupFromId()
1033 {
1034     uint newID = GraphicalObject::INVALID_ID;
1035
1036     m_ipcModule.getUint(&newID);
1037
1038     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
1039     if (status)
1040     {
1041         m_ipcModule.createMessage((char*)__FUNCTION__);
1042         m_ipcModule.appendUint(newID);
1043         m_ipcModule.sendMessage();
1044     }
1045     else
1046     {
1047         m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE);
1048     }
1049 }
1050
1051 void GenericCommunicator::RemoveLayerGroup()
1052 {
1053     uint param = 0;
1054     m_ipcModule.getUint(&param);
1055
1056     t_ilm_bool status = m_executor->execute(new LayergroupRemoveCommand(param));
1057     if (status)
1058     {
1059         m_ipcModule.createMessage((char*)__FUNCTION__);
1060         m_ipcModule.sendMessage();
1061     }
1062     else
1063     {
1064         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1065     }
1066 }
1067
1068 void GenericCommunicator::SetSurfaceSourceRegion()
1069 {
1070     uint id = 0;
1071     m_ipcModule.getUint(&id);
1072     uint x = 0;
1073     m_ipcModule.getUint(&x);
1074     uint y = 0;
1075     m_ipcModule.getUint(&y);
1076     uint width = 0;
1077     m_ipcModule.getUint(&width);
1078     uint height = 0;
1079     m_ipcModule.getUint(&height);
1080
1081     t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(id, x, y, width, height));
1082     if (status)
1083     {
1084         m_ipcModule.createMessage((char*)__FUNCTION__);
1085         m_ipcModule.sendMessage();
1086     }
1087     else
1088     {
1089         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1090     }
1091 }
1092
1093 void GenericCommunicator::SetLayerSourceRegion()
1094 {
1095     uint id = 0;
1096     m_ipcModule.getUint(&id);
1097     uint x = 0;
1098     m_ipcModule.getUint(&x);
1099     uint y = 0;
1100     m_ipcModule.getUint(&y);
1101     uint width = 0;
1102     m_ipcModule.getUint(&width);
1103     uint height = 0;
1104     m_ipcModule.getUint(&height);
1105
1106     //LOG_DEBUG("DBUSC","new SetSourceRectangleCommand with arguments: " <<id <<" " << x <<" "<< y <<" "<< width <<" "<< height );
1107     t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(id, x, y, width, height));
1108     if (status)
1109     {
1110         m_ipcModule.createMessage((char*)__FUNCTION__);
1111         m_ipcModule.sendMessage();
1112     }
1113     else
1114     {
1115         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1116     }
1117 }
1118
1119 void GenericCommunicator::SetSurfaceDestinationRegion()
1120 {
1121     uint id = 0;
1122     m_ipcModule.getUint(&id);
1123     uint x = 0;
1124     m_ipcModule.getUint(&x);
1125     uint y = 0;
1126     m_ipcModule.getUint(&y);
1127     uint width = 0;
1128     m_ipcModule.getUint(&width);
1129     uint height = 0;
1130     m_ipcModule.getUint(&height);
1131
1132     t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(id, x, y, width, height));
1133     if (status)
1134     {
1135         m_ipcModule.createMessage((char*)__FUNCTION__);
1136         m_ipcModule.sendMessage();
1137     }
1138     else
1139     {
1140         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1141     }
1142 }
1143
1144 void GenericCommunicator::SetSurfacePosition()
1145 {
1146     uint id = 0;
1147     m_ipcModule.getUint(&id);
1148     uint x = 0;
1149     m_ipcModule.getUint(&x);
1150     uint y = 0;
1151     m_ipcModule.getUint(&y);
1152
1153     t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(id, x, y));
1154     if (status)
1155     {
1156         m_ipcModule.createMessage((char*)__FUNCTION__);
1157         m_ipcModule.sendMessage();
1158     }
1159     else
1160     {
1161         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1162     }
1163 }
1164
1165 void GenericCommunicator::GetSurfacePosition()
1166 {
1167     uint id = 0;
1168     m_ipcModule.getUint(&id);
1169     uint x = 0;
1170     uint y = 0;
1171
1172     t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(id, &x, &y));
1173     if (status)
1174     {
1175         m_ipcModule.createMessage((char*)__FUNCTION__);
1176         m_ipcModule.appendUint(x);
1177         m_ipcModule.appendUint(y);
1178         m_ipcModule.sendMessage();
1179     }
1180     else
1181     {
1182         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1183     }
1184 }
1185
1186 void GenericCommunicator::SetSurfaceDimension()
1187 {
1188     uint id = 0;
1189     m_ipcModule.getUint(&id);
1190     uint width = 0;
1191     m_ipcModule.getUint(&width);
1192     uint height = 0;
1193     m_ipcModule.getUint(&height);
1194
1195     t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(id, width, height));
1196     if (status)
1197     {
1198         m_ipcModule.createMessage((char*)__FUNCTION__);
1199         m_ipcModule.sendMessage();
1200     }
1201     else
1202     {
1203         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1204     }
1205 }
1206
1207 void GenericCommunicator::SetLayerDestinationRegion()
1208 {
1209     uint id = 0;
1210     m_ipcModule.getUint(&id);
1211     uint x = 0;
1212     m_ipcModule.getUint(&x);
1213     uint y = 0;
1214     m_ipcModule.getUint(&y);
1215     uint width = 0;
1216     m_ipcModule.getUint(&width);
1217     uint height = 0;
1218     m_ipcModule.getUint(&height);
1219
1220     t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(id, x, y, width, height));
1221     if (status)
1222     {
1223         m_ipcModule.createMessage((char*)__FUNCTION__);
1224         m_ipcModule.sendMessage();
1225     }
1226     else
1227     {
1228         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1229     }
1230 }
1231
1232 void GenericCommunicator::SetLayerPosition()
1233 {
1234     uint id = 0;
1235     m_ipcModule.getUint(&id);
1236     uint x = 0;
1237     m_ipcModule.getUint(&x);
1238     uint y = 0;
1239     m_ipcModule.getUint(&y);
1240
1241     t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(id, x, y));
1242     if (status)
1243     {
1244         m_ipcModule.createMessage((char*)__FUNCTION__);
1245         m_ipcModule.sendMessage();
1246     }
1247     else
1248     {
1249         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1250     }
1251 }
1252
1253 void GenericCommunicator::GetLayerPosition()
1254 {
1255     uint id = 0;
1256     m_ipcModule.getUint(&id);
1257     uint x = 0;
1258     uint y = 0;
1259
1260     t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(id, &x, &y));
1261     if (status)
1262     {
1263         m_ipcModule.createMessage((char*)__FUNCTION__);
1264         m_ipcModule.appendUint(x);
1265         m_ipcModule.appendUint(y);
1266         m_ipcModule.sendMessage();
1267     }
1268     else
1269     {
1270         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1271     }
1272 }
1273
1274 void GenericCommunicator::SetLayerDimension()
1275 {
1276     uint id = 0;
1277     m_ipcModule.getUint(&id);
1278     uint width = 0;
1279     m_ipcModule.getUint(&width);
1280     uint height = 0;
1281     m_ipcModule.getUint(&height);
1282
1283     t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(id, width, height));
1284     if (status)
1285     {
1286         m_ipcModule.createMessage((char*)__FUNCTION__);
1287         m_ipcModule.sendMessage();
1288     }
1289     else
1290     {
1291         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1292     }
1293 }
1294
1295 void GenericCommunicator::GetLayerDimension()
1296 {
1297     uint id = 0;
1298     m_ipcModule.getUint(&id);
1299     uint width = 0;
1300     uint height = 0;
1301
1302     t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(id, &width, &height));
1303     if (status)
1304     {
1305         m_ipcModule.createMessage((char*)__FUNCTION__);
1306         m_ipcModule.appendUint(width);
1307         m_ipcModule.appendUint(height);
1308         m_ipcModule.sendMessage();
1309     }
1310     else
1311     {
1312         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1313     }
1314 }
1315
1316 void GenericCommunicator::GetSurfaceDimension()
1317 {
1318     uint id = 0;
1319     m_ipcModule.getUint(&id);
1320     uint width = 0;
1321     uint height = 0;
1322
1323     t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(id, &width, &height));
1324     if (status)
1325     {
1326         m_ipcModule.createMessage((char*)__FUNCTION__);
1327         m_ipcModule.appendUint(width);
1328         m_ipcModule.appendUint(height);
1329         m_ipcModule.sendMessage();
1330     }
1331     else
1332     {
1333         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1334     }
1335 }
1336
1337 void GenericCommunicator::SetSurfaceOpacity()
1338 {
1339     uint id = 0;
1340     m_ipcModule.getUint(&id);
1341     double param = 0.0;
1342     m_ipcModule.getDouble(&param);
1343
1344     t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(id, param));
1345     if (status)
1346     {
1347         m_ipcModule.createMessage((char*)__FUNCTION__);
1348         m_ipcModule.sendMessage();
1349     }
1350     else
1351     {
1352         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1353     }
1354 }
1355
1356 void GenericCommunicator::SetLayerOpacity()
1357 {
1358     uint id = 0;
1359     m_ipcModule.getUint(&id);
1360     double param = 0.0;
1361     m_ipcModule.getDouble(&param);
1362
1363     t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(id, param));
1364     if (status)
1365     {
1366         m_ipcModule.createMessage((char*)__FUNCTION__);
1367         m_ipcModule.sendMessage();
1368     }
1369     else
1370     {
1371         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1372     }
1373 }
1374
1375 void GenericCommunicator::SetSurfacegroupOpacity()
1376 {
1377     uint id = 0;
1378     m_ipcModule.getUint(&id);
1379     double param = 0.0;
1380     m_ipcModule.getDouble(&param);
1381
1382     t_ilm_bool status = m_executor->execute(new SurfacegroupSetOpacityCommand(id, param));
1383     if (status)
1384     {
1385         m_ipcModule.createMessage((char*)__FUNCTION__);
1386         m_ipcModule.sendMessage();
1387     }
1388     else
1389     {
1390         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1391     }
1392 }
1393
1394 void GenericCommunicator::SetLayergroupOpacity()
1395 {
1396     uint id = 0;
1397     m_ipcModule.getUint(&id);
1398     double param = 0.0;
1399     m_ipcModule.getDouble(&param);
1400
1401     t_ilm_bool status = m_executor->execute(new LayergroupSetOpacityCommand(id, param));
1402     if (status)
1403     {
1404         m_ipcModule.createMessage((char*)__FUNCTION__);
1405         m_ipcModule.sendMessage();
1406     }
1407     else
1408     {
1409         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1410     }
1411 }
1412
1413 void GenericCommunicator::GetSurfaceOpacity()
1414 {
1415     uint id = 0;
1416     m_ipcModule.getUint(&id);
1417     double param = 0.0;
1418
1419     t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(id, &param));
1420     if (status)
1421     {
1422         m_ipcModule.createMessage((char*)__FUNCTION__);
1423         m_ipcModule.appendDouble(param);
1424         m_ipcModule.sendMessage();
1425     }
1426     else
1427     {
1428         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1429     }
1430 }
1431
1432 void GenericCommunicator::GetLayerOpacity()
1433 {
1434     uint id = 0;
1435     m_ipcModule.getUint(&id);
1436     double param = 0.0;
1437
1438     t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(id, &param));
1439     if (status)
1440     {
1441         m_ipcModule.createMessage((char*)__FUNCTION__);
1442         m_ipcModule.appendDouble(param);
1443         m_ipcModule.sendMessage();
1444     }
1445     else
1446     {
1447         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1448     }
1449 }
1450
1451 void GenericCommunicator::SetSurfaceOrientation()
1452 {
1453     uint id = 0;
1454     m_ipcModule.getUint(&id);
1455     uint param = 0;
1456     m_ipcModule.getUint(&param);
1457     OrientationType o = (OrientationType) param;
1458
1459     t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(id, o));
1460     if (status)
1461     {
1462         m_ipcModule.createMessage((char*)__FUNCTION__);
1463         m_ipcModule.sendMessage();
1464     }
1465     else
1466     {
1467         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1468     }
1469 }
1470
1471 void GenericCommunicator::GetSurfaceOrientation()
1472 {
1473     uint id = 0;
1474     m_ipcModule.getUint(&id);
1475     OrientationType o;
1476
1477     t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(id, &o));
1478     if (status)
1479     {
1480         m_ipcModule.createMessage((char*)__FUNCTION__);
1481         m_ipcModule.appendUint(o);
1482         m_ipcModule.sendMessage();
1483     }
1484     else
1485     {
1486         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1487     }
1488 }
1489
1490 void GenericCommunicator::SetLayerOrientation()
1491 {
1492     uint id = 0;
1493     m_ipcModule.getUint(&id);
1494     uint param = 0;
1495     m_ipcModule.getUint(&param);
1496     OrientationType o = (OrientationType) param;
1497
1498     t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(id, o));
1499     if (status)
1500     {
1501         m_ipcModule.createMessage((char*)__FUNCTION__);
1502         m_ipcModule.sendMessage();
1503     }
1504     else
1505     {
1506         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1507     }
1508 }
1509
1510 void GenericCommunicator::GetLayerOrientation()
1511 {
1512     uint id = 0;
1513     m_ipcModule.getUint(&id);
1514     OrientationType o;
1515
1516     t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(id, &o));
1517     if (status)
1518     {
1519         m_ipcModule.createMessage((char*)__FUNCTION__);
1520         m_ipcModule.appendUint(o);
1521         m_ipcModule.sendMessage();
1522     }
1523     else
1524     {
1525         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1526     }
1527 }
1528
1529 void GenericCommunicator::GetSurfacePixelformat()
1530 {
1531     uint id = 0;
1532     m_ipcModule.getUint(&id);
1533     PixelFormat param;
1534
1535     t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(id, &param));
1536     if (status)
1537     {
1538         m_ipcModule.createMessage((char*)__FUNCTION__);
1539         m_ipcModule.appendUint(param);
1540         m_ipcModule.sendMessage();
1541     }
1542     else
1543     {
1544         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1545     }
1546 }
1547
1548 void GenericCommunicator::SetSurfaceVisibility()
1549 {
1550     uint surfaceid = 0;
1551     m_ipcModule.getUint(&surfaceid);
1552     t_ilm_bool newVis = ILM_FALSE;
1553     m_ipcModule.getBool(&newVis);
1554
1555     t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(surfaceid, newVis));
1556     if (status)
1557     {
1558         m_ipcModule.createMessage((char*)__FUNCTION__);
1559         m_ipcModule.sendMessage();
1560     }
1561     else
1562     {
1563         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1564     }
1565 }
1566
1567 void GenericCommunicator::SetLayerVisibility()
1568 {
1569     uint layerid = 0;
1570     m_ipcModule.getUint(&layerid);
1571     t_ilm_bool myparam = ILM_FALSE;
1572     m_ipcModule.getBool(&myparam);
1573
1574     t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(layerid, myparam));
1575     if (status)
1576     {
1577         m_ipcModule.createMessage((char*)__FUNCTION__);
1578         m_ipcModule.sendMessage();
1579     }
1580     else
1581     {
1582         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1583     }
1584 }
1585
1586 void GenericCommunicator::GetSurfaceVisibility()
1587 {
1588     uint id = 0;
1589     m_ipcModule.getUint(&id);
1590     bool param;
1591
1592     t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(id, &param));
1593     if (status)
1594     {
1595         m_ipcModule.createMessage((char*)__FUNCTION__);
1596         //LOG_DEBUG("GenericCommunicator", "returning surfacevisibility: " << param);
1597         m_ipcModule.appendBool(param);
1598         m_ipcModule.sendMessage();
1599     }
1600     else
1601     {
1602         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1603     }
1604 }
1605
1606 void GenericCommunicator::GetLayerVisibility()
1607 {
1608     uint id = 0;
1609     m_ipcModule.getUint(&id);
1610     bool param;
1611
1612     t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(id, &param));
1613     if (status)
1614     {
1615         m_ipcModule.createMessage((char*)__FUNCTION__);
1616         m_ipcModule.appendBool(param);
1617         //LOG_DEBUG("GenericCommunicator", "returning layervisibility: " << param);
1618         m_ipcModule.sendMessage();
1619     }
1620     else
1621     {
1622         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1623     }
1624 }
1625
1626 void GenericCommunicator::SetSurfacegroupVisibility()
1627 {
1628     uint groupid = 0;
1629     m_ipcModule.getUint(&groupid);
1630     t_ilm_bool myparam = ILM_FALSE;
1631     m_ipcModule.getBool(&myparam);
1632
1633     t_ilm_bool status = m_executor->execute(new SurfacegroupSetVisibilityCommand(groupid, myparam));
1634     if (status)
1635     {
1636         m_ipcModule.createMessage((char*)__FUNCTION__);
1637         m_ipcModule.sendMessage();
1638     }
1639     else
1640     {
1641         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1642     }
1643 }
1644
1645 void GenericCommunicator::SetLayergroupVisibility()
1646 {
1647     uint groupid = 0;
1648     m_ipcModule.getUint(&groupid);
1649     t_ilm_bool myparam = ILM_FALSE;
1650     m_ipcModule.getBool(&myparam);
1651
1652     t_ilm_bool status = m_executor->execute(new LayergroupSetVisibilityCommand(groupid, myparam));
1653     if (status)
1654     {
1655         m_ipcModule.createMessage((char*)__FUNCTION__);
1656         m_ipcModule.sendMessage();
1657     }
1658     else
1659     {
1660         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1661     }
1662 }
1663
1664
1665 void GenericCommunicator::SetRenderOrderOfLayers()
1666 {
1667     uint* array = NULL;
1668     int length = 0;
1669
1670     m_ipcModule.getUintArray(&array, &length);
1671
1672     //LOG_DEBUG("GenericCommunicator","Renderorder: Got " << length << " ids.");
1673
1674     t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(array, length));
1675     if (status)
1676     {
1677         m_ipcModule.createMessage((char*)__FUNCTION__);
1678         m_ipcModule.sendMessage();
1679     }
1680     else
1681     {
1682         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1683     }
1684 }
1685
1686 void GenericCommunicator::SetSurfaceRenderOrderWithinLayer()
1687 {
1688     uint* array = NULL;
1689     int length = 0;
1690
1691     uint layerid = 0;
1692     m_ipcModule.getUint(&layerid);
1693
1694     m_ipcModule.getUintArray(&array, &length);
1695
1696     t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(layerid, array, length));
1697     if (status)
1698     {
1699         m_ipcModule.createMessage((char*)__FUNCTION__);
1700         m_ipcModule.sendMessage();
1701     }
1702     else
1703     {
1704         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1705     }
1706 }
1707
1708 void GenericCommunicator::GetLayerType()
1709 {
1710     uint id = 0;
1711     m_ipcModule.getUint(&id);
1712     Layer* l = m_executor->getScene()->getLayer(id);
1713     if (l != NULL)
1714     {
1715         m_ipcModule.createMessage((char*)__FUNCTION__);
1716         m_ipcModule.appendUint(l->getLayerType());
1717         m_ipcModule.sendMessage();
1718     }
1719     else
1720     {
1721         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1722     }
1723 }
1724
1725 void GenericCommunicator::GetLayertypeCapabilities()
1726 {
1727     uint id = 0;
1728     m_ipcModule.getUint(&id);
1729     LayerType type = (LayerType) id;
1730     uint capabilities = m_executor->getLayerTypeCapabilities(type);
1731     //LOG_DEBUG("GenericCommunicator", "GetLayertypeCapabilities: returning capabilities:" << capabilities);
1732     m_ipcModule.createMessage((char*)__FUNCTION__);
1733     m_ipcModule.appendUint(capabilities);
1734     m_ipcModule.sendMessage();
1735 }
1736
1737 void GenericCommunicator::GetLayerCapabilities()
1738 {
1739     uint id = 0;
1740     m_ipcModule.getUint(&id);
1741     Layer* l = m_executor->getScene()->getLayer(id);
1742     if (l != NULL)
1743     {
1744         m_ipcModule.createMessage((char*)__FUNCTION__);
1745         m_ipcModule.appendUint(l->getCapabilities());
1746         m_ipcModule.sendMessage();
1747     }
1748     else
1749     {
1750         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1751     }
1752 }
1753
1754 void GenericCommunicator::FadeIn()
1755 {
1756     m_ipcModule.createMessage((char*)__FUNCTION__);
1757     m_ipcModule.sendMessage();
1758 }
1759
1760 void GenericCommunicator::SynchronizedFade()
1761 {
1762     m_ipcModule.createMessage((char*)__FUNCTION__);
1763     m_ipcModule.sendMessage();
1764 }
1765
1766 void GenericCommunicator::FadeOut()
1767 {
1768     m_ipcModule.createMessage((char*)__FUNCTION__);
1769     m_ipcModule.sendMessage();
1770 }
1771
1772 void GenericCommunicator::Exit()
1773 {
1774     t_ilm_bool status = m_executor->execute(new ExitCommand());
1775     if (status)
1776     {
1777         m_ipcModule.createMessage((char*)__FUNCTION__);
1778         m_ipcModule.sendMessage();
1779     }
1780     else
1781     {
1782         m_ipcModule.sendError(INVALID_ARGUMENT);
1783     }
1784 }
1785
1786 void GenericCommunicator::CommitChanges()
1787 {
1788     t_ilm_bool status = m_executor->execute(new CommitCommand());
1789     if (status)
1790     {
1791         m_ipcModule.createMessage((char*)__FUNCTION__);
1792         m_ipcModule.sendMessage();
1793     }
1794     else
1795     {
1796         m_ipcModule.sendError(INVALID_ARGUMENT);
1797     }
1798 }
1799
1800 void GenericCommunicator::CreateShader()
1801 {
1802     char* vertname = NULL;
1803     m_ipcModule.getString(vertname);
1804     char* fragname = NULL;
1805     m_ipcModule.getString(fragname);
1806     uint id = 0;
1807
1808     t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(vertname, fragname, &id));
1809     if (status)
1810     {
1811         m_ipcModule.createMessage((char*)__FUNCTION__);
1812         m_ipcModule.appendUint(id);
1813         m_ipcModule.sendMessage();
1814     }
1815     else
1816     {
1817         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1818     }
1819 }
1820
1821 void GenericCommunicator::DestroyShader()
1822 {
1823     uint shaderid = 0;
1824     m_ipcModule.getUint(&shaderid);
1825
1826     t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(shaderid));
1827     if (status)
1828     {
1829         m_ipcModule.createMessage((char*)__FUNCTION__);
1830         m_ipcModule.sendMessage();
1831     }
1832     else
1833     {
1834         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1835     }
1836 }
1837
1838 void GenericCommunicator::SetShader()
1839 {
1840     uint surfaceId = 0;
1841     uint shaderid = 0;
1842     m_ipcModule.getUint(&surfaceId);
1843     m_ipcModule.getUint(&shaderid);
1844
1845     t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(surfaceId, shaderid));
1846     if (status)
1847     {
1848         m_ipcModule.createMessage((char*)__FUNCTION__);
1849         m_ipcModule.sendMessage();
1850     }
1851     else
1852     {
1853         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1854     }
1855 }
1856
1857 void GenericCommunicator::SetUniforms()
1858 {
1859     uint id = 0; m_ipcModule.getUint(&id);
1860
1861     std::vector<string> uniforms;
1862
1863     // TODO
1864     //m_ipcModule.getStringArray(&uniforms);
1865
1866     t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(id, uniforms));
1867     if (status)
1868     {
1869         m_ipcModule.createMessage((char*)__FUNCTION__);
1870         m_ipcModule.sendMessage();
1871     }
1872     else
1873     {
1874         m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
1875     }
1876 }
1877
1878 extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor)
1879 {
1880     return new GenericCommunicator(executor);
1881 }
1882
1883 extern "C" void destroyGenericCommunicator(GenericCommunicator* p)
1884 {
1885     delete p;
1886 }
1887