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