ilmClient: Fixing Serialization of Optimization Commands.
[profile/ivi/layer-management.git] / LayerManagerPlugins / Communicators / GenericCommunicator / src / GenericCommunicator.cpp
1 /***************************************************************************
2  * Copyright 2012 BMW Car IT GmbH
3  * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia 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
20 #include "GenericCommunicator.h"
21 #include "ilm_types.h"
22 #include "Log.h"
23
24 #include "ICommandExecutor.h"
25 #include "CommitCommand.h"
26 #include "LayerCreateCommand.h"
27 #include "LayergroupCreateCommand.h"
28 #include "SurfaceCreateCommand.h"
29 #include "SurfacegroupCreateCommand.h"
30 #include "SurfaceGetDimensionCommand.h"
31 #include "LayerGetDimensionCommand.h"
32 #include "SurfaceGetOpacityCommand.h"
33 #include "LayerGetOpacityCommand.h"
34 #include "SurfaceGetPixelformatCommand.h"
35 #include "LayerGetVisibilityCommand.h"
36 #include "SurfaceGetVisibilityCommand.h"
37 #include "LayerAddSurfaceCommand.h"
38 #include "LayerRemoveSurfaceCommand.h"
39 #include "LayerRemoveCommand.h"
40 #include "SurfaceRemoveCommand.h"
41 #include "LayergroupRemoveCommand.h"
42 #include "SurfacegroupRemoveCommand.h"
43 #include "SurfaceGetOrientationCommand.h"
44 #include "LayerGetOrientationCommand.h"
45 #include "LayergroupAddLayerCommand.h"
46 #include "LayergroupRemoveLayerCommand.h"
47 #include "LayerSetDestinationRectangleCommand.h"
48 #include "SurfaceSetDestinationRectangleCommand.h"
49 #include "LayerSetOpacityCommand.h"
50 #include "LayergroupSetOpacityCommand.h"
51 #include "SurfaceSetOpacityCommand.h"
52 #include "SurfacegroupSetOpacityCommand.h"
53 #include "LayerSetSourceRectangleCommand.h"
54 #include "SurfaceSetSourceRectangleCommand.h"
55 #include "LayerSetOrientationCommand.h"
56 #include "SurfaceSetOrientationCommand.h"
57 #include "SurfacegroupAddSurfaceCommand.h"
58 #include "SurfacegroupRemoveSurfaceCommand.h"
59 #include "LayerSetVisibilityCommand.h"
60 #include "SurfaceSetVisibilityCommand.h"
61 #include "LayergroupSetVisibilityCommand.h"
62 #include "SurfacegroupSetVisibilityCommand.h"
63 #include "DebugCommand.h"
64 #include "ExitCommand.h"
65 #include "ScreenSetRenderOrderCommand.h"
66 #include "LayerSetRenderOrderCommand.h"
67 #include "LayerSetDimensionCommand.h"
68 #include "SurfaceSetDimensionCommand.h"
69 #include "LayerSetPositionCommand.h"
70 #include "SurfaceSetPositionCommand.h"
71 #include "LayerGetPositionCommand.h"
72 #include "SurfaceGetPositionCommand.h"
73 #include "ShaderCreateCommand.h"
74 #include "ShaderDestroyCommand.h"
75 #include "SurfaceSetShaderCommand.h"
76 #include "ShaderSetUniformsCommand.h"
77 #include "ScreenDumpCommand.h"
78 #include "LayerDumpCommand.h"
79 #include "SurfaceDumpCommand.h"
80 #include "SurfaceSetNativeContentCommand.h"
81 #include "SurfaceRemoveNativeContentCommand.h"
82 #include "SurfaceSetKeyboardFocusCommand.h"
83 #include "SurfaceGetKeyboardFocusCommand.h"
84 #include "SurfaceUpdateInputEventAcceptance.h"
85 #include "SurfaceSetChromaKeyCommand.h"
86 #include "LayerSetChromaKeyCommand.h"
87 #include "SetOptimizationModeCommand.h"
88 #include "GetOptimizationModeCommand.h"
89 #include <stdbool.h>
90 #include <unistd.h>
91 #include <stdio.h>
92 #include <string.h>
93 #include <stdlib.h>
94 #include <string>
95 #include <pthread.h>
96 #include <signal.h>
97
98 #define DEFAULT_SCREEN 0
99
100 const char* RESOURCE_ALREADY_INUSE = "Ressource already in use";
101 const char* INVALID_ARGUMENT = "Invalid argument";
102 const char* RESOURCE_NOT_FOUND = "Ressource not found";
103 const char* NOT_IMPLEMENTED = "Feature not implemented";
104
105
106 GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
107 : ICommunicator(executor)
108 , m_running(ILM_FALSE)
109 {
110     MethodTable manager_methods[] =
111     {
112         { "ServiceConnect",                   &GenericCommunicator::ServiceConnect },
113         { "ServiceDisconnect",                &GenericCommunicator::ServiceDisconnect },
114         { "Debug",                            &GenericCommunicator::Debug },
115         { "ScreenShot",                       &GenericCommunicator::ScreenShot },
116         { "ScreenShotOfLayer",                &GenericCommunicator::ScreenShotOfLayer },
117         { "ScreenShotOfSurface",              &GenericCommunicator::ScreenShotOfSurface },
118         { "GetScreenResolution",              &GenericCommunicator::GetScreenResolution },
119         { "GetNumberOfHardwareLayers",        &GenericCommunicator::GetNumberOfHardwareLayers },
120         { "GetScreenIDs",                     &GenericCommunicator::GetScreenIDs },
121         { "ListAllLayerIDS",                  &GenericCommunicator::ListAllLayerIDS },
122         { "ListAllLayerIDsOnScreen",          &GenericCommunicator::ListAllLayerIDsOnScreen },
123         { "ListAllSurfaceIDS",                &GenericCommunicator::ListAllSurfaceIDS },
124         { "ListAllLayerGroupIDS",             &GenericCommunicator::ListAllLayerGroupIDS },
125         { "ListAllSurfaceGroupIDS",           &GenericCommunicator::ListAllSurfaceGroupIDS },
126         { "ListSurfacesOfSurfacegroup",       &GenericCommunicator::ListSurfacesOfSurfacegroup },
127         { "ListLayersOfLayergroup",           &GenericCommunicator::ListLayersOfLayergroup },
128         { "ListSurfaceofLayer",               &GenericCommunicator::ListSurfaceofLayer },
129         { "GetPropertiesOfSurface",           &GenericCommunicator::GetPropertiesOfSurface },
130         { "GetPropertiesOfLayer",             &GenericCommunicator::GetPropertiesOfLayer },
131         { "CreateSurface",                    &GenericCommunicator::CreateSurface },
132         { "CreateSurfaceFromId",              &GenericCommunicator::CreateSurfaceFromId },
133         { "InitializeSurface",                &GenericCommunicator::InitializeSurface },
134         { "InitializeSurfaceFromId",          &GenericCommunicator::InitializeSurfaceFromId },
135         { "SetSurfaceNativeContent",          &GenericCommunicator::SetSurfaceNativeContent },
136         { "RemoveSurfaceNativeContent",       &GenericCommunicator::RemoveSurfaceNativeContent },
137         { "RemoveSurface",                    &GenericCommunicator::RemoveSurface },
138         { "CreateLayer",                      &GenericCommunicator::CreateLayer },
139         { "CreateLayerFromId",                &GenericCommunicator::CreateLayerFromId },
140         { "CreateLayerWithDimension",         &GenericCommunicator::CreateLayerWithDimension },
141         { "CreateLayerFromIdWithDimension",   &GenericCommunicator::CreateLayerFromIdWithDimension },
142         { "RemoveLayer",                      &GenericCommunicator::RemoveLayer },
143         { "AddSurfaceToSurfaceGroup",         &GenericCommunicator::AddSurfaceToSurfaceGroup },
144         { "RemoveSurfaceFromSurfaceGroup",    &GenericCommunicator::RemoveSurfaceFromSurfaceGroup },
145         { "AddLayerToLayerGroup",             &GenericCommunicator::AddLayerToLayerGroup },
146         { "RemoveLayerFromLayerGroup",        &GenericCommunicator::RemoveLayerFromLayerGroup },
147         { "AddSurfaceToLayer",                &GenericCommunicator::AddSurfaceToLayer },
148         { "RemoveSurfaceFromLayer",           &GenericCommunicator::RemoveSurfaceFromLayer },
149         { "CreateSurfaceGroup",               &GenericCommunicator::CreateSurfaceGroup },
150         { "CreateSurfaceGroupFromId",         &GenericCommunicator::CreateSurfaceGroupFromId },
151         { "RemoveSurfaceGroup",               &GenericCommunicator::RemoveSurfaceGroup },
152         { "CreateLayerGroup",                 &GenericCommunicator::CreateLayerGroup },
153         { "CreateLayerGroupFromId",           &GenericCommunicator::CreateLayerGroupFromId },
154         { "RemoveLayerGroup",                 &GenericCommunicator::RemoveLayerGroup },
155         { "SetSurfaceSourceRegion",           &GenericCommunicator::SetSurfaceSourceRegion },
156         { "SetLayerSourceRegion",             &GenericCommunicator::SetLayerSourceRegion },
157         { "SetSurfaceDestinationRegion",      &GenericCommunicator::SetSurfaceDestinationRegion },
158         { "SetSurfacePosition",               &GenericCommunicator::SetSurfacePosition },
159         { "GetSurfacePosition",               &GenericCommunicator::GetSurfacePosition },
160         { "SetSurfaceDimension",              &GenericCommunicator::SetSurfaceDimension },
161         { "SetLayerDestinationRegion",        &GenericCommunicator::SetLayerDestinationRegion },
162         { "SetLayerPosition",                 &GenericCommunicator::SetLayerPosition },
163         { "GetLayerPosition",                 &GenericCommunicator::GetLayerPosition },
164         { "SetLayerDimension",                &GenericCommunicator::SetLayerDimension },
165         { "GetLayerDimension",                &GenericCommunicator::GetLayerDimension },
166         { "GetSurfaceDimension",              &GenericCommunicator::GetSurfaceDimension },
167         { "SetSurfaceOpacity",                &GenericCommunicator::SetSurfaceOpacity },
168         { "SetLayerOpacity",                  &GenericCommunicator::SetLayerOpacity },
169         { "SetSurfacegroupOpacity",           &GenericCommunicator::SetSurfacegroupOpacity },
170         { "SetLayergroupOpacity",             &GenericCommunicator::SetLayergroupOpacity },
171         { "GetSurfaceOpacity",                &GenericCommunicator::GetSurfaceOpacity },
172         { "GetLayerOpacity",                  &GenericCommunicator::GetLayerOpacity },
173         { "SetSurfaceOrientation",            &GenericCommunicator::SetSurfaceOrientation },
174         { "GetSurfaceOrientation",            &GenericCommunicator::GetSurfaceOrientation },
175         { "SetLayerOrientation",              &GenericCommunicator::SetLayerOrientation },
176         { "GetLayerOrientation",              &GenericCommunicator::GetLayerOrientation },
177         { "GetSurfacePixelformat",            &GenericCommunicator::GetSurfacePixelformat },
178         { "SetSurfaceVisibility",             &GenericCommunicator::SetSurfaceVisibility },
179         { "SetLayerVisibility",               &GenericCommunicator::SetLayerVisibility },
180         { "GetSurfaceVisibility",             &GenericCommunicator::GetSurfaceVisibility },
181         { "GetLayerVisibility",               &GenericCommunicator::GetLayerVisibility },
182         { "SetSurfacegroupVisibility",        &GenericCommunicator::SetSurfacegroupVisibility },
183         { "SetLayergroupVisibility",          &GenericCommunicator::SetLayergroupVisibility },
184         { "SetRenderOrderOfLayers",           &GenericCommunicator::SetRenderOrderOfLayers },
185         { "SetSurfaceRenderOrderWithinLayer", &GenericCommunicator::SetSurfaceRenderOrderWithinLayer },
186         { "GetLayerType",                     &GenericCommunicator::GetLayerType },
187         { "GetLayertypeCapabilities",         &GenericCommunicator::GetLayertypeCapabilities },
188         { "GetLayerCapabilities",             &GenericCommunicator::GetLayerCapabilities },
189         { "Exit",                             &GenericCommunicator::Exit },
190         { "CommitChanges",                    &GenericCommunicator::CommitChanges },
191         { "CreateShader",                     &GenericCommunicator::CreateShader },
192         { "DestroyShader",                    &GenericCommunicator::DestroyShader },
193         { "SetShader",                        &GenericCommunicator::SetShader },
194         { "SetUniforms",                      &GenericCommunicator::SetUniforms },
195         { "SetKeyboardFocusOn",               &GenericCommunicator::SetKeyboardFocusOn },
196         { "GetKeyboardFocusSurfaceId",        &GenericCommunicator::GetKeyboardFocusSurfaceId },
197         { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn },
198         { "SetSurfaceChromaKey",              &GenericCommunicator::SetSurfaceChromaKey },
199         { "SetLayerChromaKey",                &GenericCommunicator::SetLayerChromaKey },
200         { "LayerAddNotification",             &GenericCommunicator::LayerAddNotification },
201         { "SurfaceAddNotification",           &GenericCommunicator::SurfaceAddNotification },
202         { "LayerRemoveNotification",          &GenericCommunicator::LayerRemoveNotification },
203         { "SurfaceRemoveNotification",        &GenericCommunicator::SurfaceRemoveNotification },
204         { "SetOptimizationMode",              &GenericCommunicator::SetOptimizationMode },
205         { "GetOptimizationMode",              &GenericCommunicator::GetOptimizationMode }
206     };
207
208     int entryCount = sizeof(manager_methods) / sizeof(MethodTable);
209
210     for (int index = 0; index < entryCount; ++index)
211     {
212         MethodTable* method = &manager_methods[index];
213         if (method->function)
214         {
215             m_callBackTable[method->name] = *method;
216             LOG_DEBUG("GenericCommunicator", "registered callback for " << method->name);
217         }
218     }
219
220     memset(&m_ipcModule, 0, sizeof(m_ipcModule));
221
222     mThreadId = pthread_self();
223 }
224
225 bool GenericCommunicator::start()
226 {
227     LOG_DEBUG("GenericCommunicator", "Starting up IpcModules.");
228
229     if (!loadIpcModule(&m_ipcModule))
230     {
231         LOG_ERROR("GenericCommunicator", "Loading IpcModule failed.");
232         return ILM_FALSE;
233     }
234     LOG_DEBUG("GenericCommunicator", "Loading IpcModule success.");
235
236     if (!m_ipcModule.initServiceMode())
237     {
238         LOG_ERROR("GenericCommunicator", "Initializing IpcModule failed.");
239         return ILM_FALSE;
240     }
241     LOG_DEBUG("GenericCommunicator", "Initializing IpcModule success.");
242
243     m_running = ILM_TRUE;
244     setHealth(HealthRunning);
245
246     return ILM_TRUE;
247 }
248
249 void GenericCommunicator::stop()
250 {
251     LOG_INFO("GenericCommunicator","stopping");
252
253     if (m_running)
254     {
255         m_ipcModule.destroy();
256     }
257     setHealth(HealthStopped);
258 }
259
260 void GenericCommunicator::process(int timeout_ms)
261 {
262     t_ilm_message message = m_ipcModule.receive(timeout_ms);
263     if (!message)
264     {
265         return;
266     }
267
268     t_ilm_message_type messageType = m_ipcModule.getMessageType(message);
269     t_ilm_const_string name = m_ipcModule.getMessageName(message);
270     t_ilm_client_handle senderHandle = m_ipcModule.getSenderHandle(message);
271
272     switch(messageType)
273     {
274     case IpcMessageTypeCommand:
275         if (m_callBackTable.end() != m_callBackTable.find(name))
276         {
277             LOG_DEBUG("GenericCommunicator", "received: " << name << " from "
278                        << m_executor->getSenderName(senderHandle)
279                        << "(" << m_executor->getSenderPid(senderHandle) << ")");
280             CallBackMethod method = m_callBackTable[name].function;
281             (this->*method)(message);
282         }
283         else
284         {
285             LOG_WARNING("GenericCommunicator", "Received unknown command " << name
286                   << " from " << m_executor->getSenderName(senderHandle)
287                   << "(pid " << m_executor->getSenderPid(senderHandle) << ")");
288         }
289         processNotificationQueue();
290         break;
291
292     case IpcMessageTypeConnect:
293         LOG_DEBUG("GenericCommunicator", "client " << m_executor->getSenderName(senderHandle)
294                   << "(pid " << m_executor->getSenderPid(senderHandle) << ") connected");
295         break;
296
297     case IpcMessageTypeDisconnect:
298         LOG_DEBUG("GenericCommunicator", "client " << m_executor->getSenderName(senderHandle)
299                   << "(pid " << m_executor->getSenderPid(senderHandle) << ") disconnected");
300         {
301             const LayerMap& layers = m_executor->getScene()->getAllLayers();
302             LayerMapConstIterator layerIter =  layers.begin();
303             LayerMapConstIterator layerIterEnd = layers.end();
304             for (; layerIter != layerIterEnd; ++layerIter)
305             {
306                 Layer* layer = layerIter->second;
307                 layer->removeNotification(senderHandle);
308             }
309
310             const SurfaceMap& surfaces = m_executor->getScene()->getAllSurfaces();
311             SurfaceMapConstIterator surfaceIter =  surfaces.begin();
312             SurfaceMapConstIterator surfaceIterEnd = surfaces.end();
313             for (; surfaceIter != surfaceIterEnd; ++surfaceIter)
314             {
315                 Surface* surface = surfaceIter->second;
316                 surface->removeNotification(senderHandle);
317             }
318         }
319         break;
320
321     case IpcMessageTypeError:
322         LOG_DEBUG("GenericCommunicator", "Received error message " << name << " from "
323                   << m_executor->getSenderName(senderHandle)
324                   << "(pid " << m_executor->getSenderPid(senderHandle) << ")");
325         break;
326
327     case IpcMessageTypeShutdown:
328     case IpcMessageTypeNone:
329         break;
330
331     default:
332         LOG_DEBUG("GenericCommunicator", "Received unknown data from "
333                   << m_executor->getSenderName(senderHandle)
334                   << "(pid " << m_executor->getSenderPid(senderHandle) << "), Message type: " << messageType);
335         break;
336     }
337     m_ipcModule.destroyMessage(message);
338 }
339
340 void GenericCommunicator::setdebug(bool onoff)
341 {
342     (void)onoff; // TODO: remove, only prevents warning
343 }
344
345 void GenericCommunicator::ServiceConnect(t_ilm_message message)
346 {
347     LOG_DEBUG("GenericCommunicator", "ServiceConnect called");
348
349     t_ilm_message response;
350     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
351
352     unsigned int processId = 0;
353     char processName[1024];
354     m_ipcModule.getUint(message, &processId);
355     m_ipcModule.getString(message, processName);
356
357     m_executor->addApplicationReference(clientHandle, new IApplicationReference(processName, processId));
358
359     response = m_ipcModule.createResponse(message);
360     m_ipcModule.sendToClients(response, &clientHandle, 1);
361     m_ipcModule.destroyMessage(response);
362 }
363
364 void GenericCommunicator::ServiceDisconnect(t_ilm_message message)
365 {
366     LOG_DEBUG("GenericCommunicator", "ServiceDisconnect called");
367
368     t_ilm_message response;
369     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
370
371     m_executor->removeApplicationReference(clientHandle);
372
373     response = m_ipcModule.createResponse(message);
374     m_ipcModule.sendToClients(response, &clientHandle, 1);
375     m_ipcModule.destroyMessage(response);
376 }
377
378 void GenericCommunicator::Debug(t_ilm_message message)
379 {
380     t_ilm_message response;
381     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
382     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
383     t_ilm_bool param = ILM_FALSE;
384     m_ipcModule.getBool(message, &param);
385
386     t_ilm_bool status = m_executor->execute(new DebugCommand(clientPid, param));
387     if (status)
388     {
389         response = m_ipcModule.createResponse(message);
390     }
391     else
392     {
393         response = m_ipcModule.createErrorResponse(message);
394         m_ipcModule.appendString(response, INVALID_ARGUMENT);
395     }
396
397     m_ipcModule.sendToClients(response, &clientHandle, 1);
398     m_ipcModule.destroyMessage(response);
399 }
400
401 void GenericCommunicator::GetScreenResolution(t_ilm_message message)
402 {
403     t_ilm_message response;
404     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
405     uint screenid = 0;
406     m_ipcModule.getUint(message, &screenid);
407     uint* resolution = m_executor->getScreenResolution(screenid);
408
409     response = m_ipcModule.createResponse(message);
410     m_ipcModule.appendUint(response, resolution[0]);
411     m_ipcModule.appendUint(response, resolution[1]);
412     m_ipcModule.sendToClients(response, &clientHandle, 1);
413     m_ipcModule.destroyMessage(response);
414 }
415
416 void GenericCommunicator::GetNumberOfHardwareLayers(t_ilm_message message)
417 {
418     t_ilm_message response;
419     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
420     uint screenid = 0;
421     m_ipcModule.getUint(message, &screenid);
422     uint numberOfHardwareLayers = m_executor->getNumberOfHardwareLayers(screenid);
423     response = m_ipcModule.createResponse(message);
424     m_ipcModule.appendUint(response, numberOfHardwareLayers);
425     m_ipcModule.sendToClients(response, &clientHandle, 1);
426     m_ipcModule.destroyMessage(response);
427 }
428
429 void GenericCommunicator::GetScreenIDs(t_ilm_message message)
430 {
431     t_ilm_message response;
432     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
433     uint length = 0;
434     uint* IDs = m_executor->getScreenIDs(&length);
435     response = m_ipcModule.createResponse(message);
436     m_ipcModule.appendUintArray(response, IDs, length);
437     m_ipcModule.sendToClients(response, &clientHandle, 1);
438     m_ipcModule.destroyMessage(response);
439 }
440
441 void GenericCommunicator::ScreenShot(t_ilm_message message)
442 {
443     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
444     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
445     t_ilm_message response;
446     uint screenid = 0;
447     char filename[1024];
448
449     m_ipcModule.getUint(message, &screenid);
450     m_ipcModule.getString(message, filename);
451
452     t_ilm_bool status = m_executor->execute(new ScreenDumpCommand(clientPid, filename, screenid));
453     if (status)
454     {
455         response = m_ipcModule.createResponse(message);
456     }
457     else
458     {
459         response = m_ipcModule.createErrorResponse(message);
460         m_ipcModule.appendString(response, INVALID_ARGUMENT);
461     }
462
463     m_ipcModule.sendToClients(response, &clientHandle, 1);
464     m_ipcModule.destroyMessage(response);
465 }
466
467 void GenericCommunicator::ScreenShotOfLayer(t_ilm_message message)
468 {
469     t_ilm_message response;
470     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
471     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
472     char filename[1024];
473     m_ipcModule.getString(message, filename);
474     uint layerid = 0;
475     m_ipcModule.getUint(message, &layerid);
476
477     t_ilm_bool status = m_executor->execute(new LayerDumpCommand(clientPid, filename, layerid));
478     if (status)
479     {
480         response = m_ipcModule.createResponse(message);
481     }
482     else
483     {
484         response = m_ipcModule.createErrorResponse(message);
485         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
486     }
487
488     m_ipcModule.sendToClients(response, &clientHandle, 1);
489     m_ipcModule.destroyMessage(response);
490 }
491
492 void GenericCommunicator::ScreenShotOfSurface(t_ilm_message message)
493 {
494     t_ilm_message response;
495     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
496     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
497     char filename[1024];
498     m_ipcModule.getString(message, filename);
499     uint id = 0;
500     m_ipcModule.getUint(message, &id);
501     t_ilm_bool status = m_executor->execute(new SurfaceDumpCommand(clientPid, filename, id));
502     if (status)
503     {
504         response = m_ipcModule.createResponse(message);
505     }
506     else
507     {
508         response = m_ipcModule.createErrorResponse(message);
509         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
510     }
511
512     m_ipcModule.sendToClients(response, &clientHandle, 1);
513     m_ipcModule.destroyMessage(response);
514 }
515
516 void GenericCommunicator::ListAllLayerIDS(t_ilm_message message)
517 {
518     t_ilm_message response;
519     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
520     uint* array = NULL;
521     uint length = 0;
522     m_executor->getScene()->lockScene();
523     m_executor->getScene()->getLayerIDs(&length, &array);
524     m_executor->getScene()->unlockScene();
525     response = m_ipcModule.createResponse(message);
526     m_ipcModule.appendUintArray(response, array, length);
527     m_ipcModule.sendToClients(response, &clientHandle, 1);
528     m_ipcModule.destroyMessage(response);
529 }
530
531 void GenericCommunicator::ListAllLayerIDsOnScreen(t_ilm_message message)
532 {
533     t_ilm_message response;
534     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
535     uint screenID = 0;
536     m_ipcModule.getUint(message, &screenID);
537
538     uint* array = NULL;
539     uint length = 0;
540     m_executor->getScene()->lockScene();
541     t_ilm_bool status = m_executor->getScene()->getLayerIDsOfScreen(screenID, &length, &array);
542     m_executor->getScene()->unlockScene();
543     if (status)
544     {
545         response = m_ipcModule.createResponse(message);
546         m_ipcModule.appendUintArray(response, array, length);
547     }
548     else
549     {
550         response = m_ipcModule.createErrorResponse(message);
551         m_ipcModule.appendString(response, INVALID_ARGUMENT);
552     }
553
554     m_ipcModule.sendToClients(response, &clientHandle, 1);
555     m_ipcModule.destroyMessage(response);
556 }
557
558 void GenericCommunicator::ListAllSurfaceIDS(t_ilm_message message)
559 {
560     t_ilm_message response;
561     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
562     uint* array = NULL;
563     uint length = 0;
564     m_executor->getScene()->lockScene();
565     m_executor->getScene()->getSurfaceIDs(&length, &array);
566     m_executor->getScene()->unlockScene();
567     response = m_ipcModule.createResponse(message);
568     m_ipcModule.appendUintArray(response, array, length);
569     m_ipcModule.sendToClients(response, &clientHandle, 1);
570     m_ipcModule.destroyMessage(response);
571 }
572
573 void GenericCommunicator::ListAllLayerGroupIDS(t_ilm_message message)
574 {
575     t_ilm_message response;
576     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
577     uint* array = NULL;
578     uint length = 0;
579     m_executor->getScene()->lockScene();
580     m_executor->getScene()->getLayerGroupIDs(&length, &array);
581     m_executor->getScene()->unlockScene();
582     response = m_ipcModule.createResponse(message);
583     m_ipcModule.appendUintArray(response, array, length);
584     m_ipcModule.sendToClients(response, &clientHandle, 1);
585     m_ipcModule.destroyMessage(response);
586 }
587
588 void GenericCommunicator::ListAllSurfaceGroupIDS(t_ilm_message message)
589 {
590     t_ilm_message response;
591     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
592     uint* array = NULL;
593     uint length = 0;
594     m_executor->getScene()->lockScene();
595     m_executor->getScene()->getSurfaceGroupIDs(&length, &array);
596     m_executor->getScene()->unlockScene();
597     response = m_ipcModule.createResponse(message);
598     m_ipcModule.appendUintArray(response, array, length);
599     m_ipcModule.sendToClients(response, &clientHandle, 1);
600     m_ipcModule.destroyMessage(response);
601 }
602
603 void GenericCommunicator::ListSurfacesOfSurfacegroup(t_ilm_message message)
604 {
605     t_ilm_message response;
606     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
607     uint id = 0;
608     m_ipcModule.getUint(message, &id);
609     m_executor->getScene()->lockScene();
610     SurfaceGroup* sg = m_executor->getScene()->getSurfaceGroup(id);
611     if (NULL != sg)
612     {
613         std::list<Surface*> surfaces = sg->getList();
614         uint length = surfaces.size();
615         uint* array = new uint[length];
616         uint arrayPos = 0;
617
618         for (std::list<Surface*>::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
619         {
620             Surface* s = *it;
621             array[arrayPos] = s->getID();
622             ++arrayPos;
623         }
624         m_executor->getScene()->unlockScene();
625
626         response = m_ipcModule.createResponse(message);
627         m_ipcModule.appendUintArray(response, array, length);
628     }
629     else
630     {
631         m_executor->getScene()->unlockScene();
632         response = m_ipcModule.createErrorResponse(message);
633         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
634     }
635
636     m_ipcModule.sendToClients(response, &clientHandle, 1);
637     m_ipcModule.destroyMessage(response);
638 }
639
640 void GenericCommunicator::ListLayersOfLayergroup(t_ilm_message message)
641 {
642     t_ilm_message response;
643     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
644     uint id = 0;
645     m_ipcModule.getUint(message, &id);
646     m_executor->getScene()->lockScene();
647     LayerGroup* sg = m_executor->getScene()->getLayerGroup(id);
648     if (NULL != sg)
649     {
650         std::list<Layer*> layers = sg->getList();
651
652         uint length = layers.size();
653         uint* array = new uint[length];
654         uint arrayPos = 0;
655
656         for (std::list<Layer*>::const_iterator it = layers.begin(); it != layers.end(); ++it)
657         {
658             Layer* l = *it;
659             array[arrayPos] = l->getID();
660             ++arrayPos;
661         }
662         m_executor->getScene()->unlockScene();
663
664         response = m_ipcModule.createResponse(message);
665         m_ipcModule.appendUintArray(response, array, length);
666     }
667     else
668     {
669         m_executor->getScene()->unlockScene();
670         response = m_ipcModule.createErrorResponse(message);
671         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
672     }
673
674     m_ipcModule.sendToClients(response, &clientHandle, 1);
675     m_ipcModule.destroyMessage(response);
676 }
677
678 void GenericCommunicator::ListSurfaceofLayer(t_ilm_message message)
679 {
680     t_ilm_message response;
681     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
682     uint id = 0;
683     m_ipcModule.getUint(message, &id);
684     m_executor->getScene()->lockScene();
685     Layer* layer = m_executor->getScene()->getLayer(id);
686     if (layer != NULL)
687     {
688         std::list<Surface*> surfaces = layer->getAllSurfaces();
689
690         uint length = surfaces.size();
691         uint* array = new uint[length];
692         uint arrayPos = 0;
693
694         for (std::list<Surface*>::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
695         {
696             Surface* s = *it;
697             array[arrayPos] = s->getID();
698             ++arrayPos;
699         }
700         m_executor->getScene()->unlockScene();
701
702         response = m_ipcModule.createResponse(message);
703         m_ipcModule.appendUintArray(response, array, length);
704     }
705     else
706     {
707         m_executor->getScene()->unlockScene();
708         response = m_ipcModule.createErrorResponse(message);
709         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
710     }
711
712     m_ipcModule.sendToClients(response, &clientHandle, 1);
713     m_ipcModule.destroyMessage(response);
714 }
715
716 void GenericCommunicator::GetPropertiesOfSurface(t_ilm_message message)
717 {
718     t_ilm_message response;
719     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
720     uint id = 0;
721     m_ipcModule.getUint(message, &id);
722
723     Surface* surface = m_executor->getScene()->getSurface(id);
724     if (surface != NULL)
725     {
726         Rectangle dest = surface->getDestinationRegion();
727         Rectangle src = surface->getSourceRegion();
728         OrientationType orientation = surface->getOrientation();
729         unsigned char chromaKeyRed = 0;
730         unsigned char chromaKeyGreen = 0;
731         unsigned char chromaKeyBlue = 0;
732         surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
733
734         response = m_ipcModule.createResponse(message);
735         m_ipcModule.appendDouble(response, surface->getOpacity());
736         m_ipcModule.appendUint(response, src.x);
737         m_ipcModule.appendUint(response, src.y);
738         m_ipcModule.appendUint(response, src.width);
739         m_ipcModule.appendUint(response, src.height);
740         m_ipcModule.appendUint(response, surface->OriginalSourceWidth);
741         m_ipcModule.appendUint(response, surface->OriginalSourceHeight);
742         m_ipcModule.appendUint(response, dest.x);
743         m_ipcModule.appendUint(response, dest.y);
744         m_ipcModule.appendUint(response, dest.width);
745         m_ipcModule.appendUint(response, dest.height);
746         m_ipcModule.appendUint(response, orientation);
747         m_ipcModule.appendBool(response, surface->getVisibility());
748         m_ipcModule.appendUint(response, surface->frameCounter);
749         m_ipcModule.appendUint(response, surface->drawCounter);
750         m_ipcModule.appendUint(response, surface->updateCounter);
751         m_ipcModule.appendUint(response, surface->getPixelFormat());
752         m_ipcModule.appendUint(response, surface->getNativeContent());
753         m_ipcModule.appendUint(response, surface->getInputEventAcceptanceOnDevices());
754         m_ipcModule.appendBool(response, surface->getChromaKeyEnabled());
755         m_ipcModule.appendUint(response, chromaKeyRed);
756         m_ipcModule.appendUint(response, chromaKeyGreen);
757         m_ipcModule.appendUint(response, chromaKeyBlue);
758         m_ipcModule.appendInt(response, surface->getCreatorPid());
759     }
760     else
761     {
762         response = m_ipcModule.createErrorResponse(message);
763         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
764     }
765
766     m_ipcModule.sendToClients(response, &clientHandle, 1);
767     m_ipcModule.destroyMessage(response);
768 }
769
770 void GenericCommunicator::GetPropertiesOfLayer(t_ilm_message message)
771 {
772     t_ilm_message response;
773     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
774     uint id = 0;
775     m_ipcModule.getUint(message, &id);
776
777     Layer* layer = m_executor->getScene()->getLayer(id);
778     if (layer != NULL)
779     {
780         Rectangle dest = layer->getDestinationRegion();
781         Rectangle src = layer->getSourceRegion();
782         OrientationType orientation = layer->getOrientation();
783         unsigned char chromaKeyRed = 0;
784         unsigned char chromaKeyGreen = 0;
785         unsigned char chromaKeyBlue = 0;
786         layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
787
788         response = m_ipcModule.createResponse(message);
789         m_ipcModule.appendDouble(response, layer->getOpacity());
790         m_ipcModule.appendUint(response, src.x);
791         m_ipcModule.appendUint(response, src.y);
792         m_ipcModule.appendUint(response, src.width);
793         m_ipcModule.appendUint(response, src.height);
794         m_ipcModule.appendUint(response, layer->OriginalSourceWidth);
795         m_ipcModule.appendUint(response, layer->OriginalSourceHeight);
796         m_ipcModule.appendUint(response, dest.x);
797         m_ipcModule.appendUint(response, dest.y);
798         m_ipcModule.appendUint(response, dest.width);
799         m_ipcModule.appendUint(response, dest.height);
800         m_ipcModule.appendUint(response, orientation);
801         m_ipcModule.appendBool(response, layer->getVisibility());
802         m_ipcModule.appendUint(response, layer->getLayerType());
803         m_ipcModule.appendBool(response, layer->getChromaKeyEnabled());
804         m_ipcModule.appendUint(response, chromaKeyRed);
805         m_ipcModule.appendUint(response, chromaKeyGreen);
806         m_ipcModule.appendUint(response, chromaKeyBlue);
807         m_ipcModule.appendInt(response, layer->getCreatorPid());
808     }
809     else
810     {
811         response = m_ipcModule.createErrorResponse(message);
812         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
813     }
814
815     m_ipcModule.sendToClients(response, &clientHandle, 1);
816     m_ipcModule.destroyMessage(response);
817 }
818
819 void GenericCommunicator::CreateSurface(t_ilm_message message)
820 {
821     t_ilm_message response;
822     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
823     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
824     uint handle = 0;
825     uint width = 0;
826     uint height = 0;
827     uint pixelformat = 0;
828     PixelFormat pf = PIXELFORMAT_UNKNOWN;
829     uint id = GraphicalObject::INVALID_ID;
830
831     m_ipcModule.getUint(message, &handle);
832     m_ipcModule.getUint(message, &width);
833     m_ipcModule.getUint(message, &height);
834     m_ipcModule.getUint(message, &pixelformat);
835
836     pf = (PixelFormat) pixelformat;
837
838
839     // First of all create the surface
840     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
841
842     // after that apply the native content
843     status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
844
845     if (status)
846     {
847         response = m_ipcModule.createResponse(message);
848         m_ipcModule.appendUint(response, id);
849     }
850     else
851     {
852         response = m_ipcModule.createErrorResponse(message);
853         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
854     }
855
856     m_ipcModule.sendToClients(response, &clientHandle, 1);
857     m_ipcModule.destroyMessage(response);
858 }
859
860 void GenericCommunicator::CreateSurfaceFromId(t_ilm_message message)
861 {
862     t_ilm_message response;
863     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
864     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
865     uint handle = 0;
866     uint width = 0;
867     uint height = 0;
868     uint pixelformat = 0;
869     PixelFormat pf = PIXELFORMAT_UNKNOWN;
870     uint id = 0;
871
872     m_ipcModule.getUint(message, &handle);
873     m_ipcModule.getUint(message, &width);
874     m_ipcModule.getUint(message, &height);
875     m_ipcModule.getUint(message, &pixelformat);
876     m_ipcModule.getUint(message, &id);
877
878     pf = (PixelFormat) pixelformat;
879
880     // First of all create the surface
881     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
882
883     // after that apply the native content
884     status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
885
886     if (status)
887     {
888         response = m_ipcModule.createResponse(message);
889         m_ipcModule.appendUint(response, id);
890     }
891     else
892     {
893         response = m_ipcModule.createErrorResponse(message);
894         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
895     }
896
897     m_ipcModule.sendToClients(response, &clientHandle, 1);
898     m_ipcModule.destroyMessage(response);
899 }
900
901 void GenericCommunicator::InitializeSurface(t_ilm_message message)
902 {
903     t_ilm_message response;
904     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
905     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
906     uint id = GraphicalObject::INVALID_ID;
907
908     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
909     if (status)
910     {
911         response = m_ipcModule.createResponse(message);
912         m_ipcModule.appendUint(response, id);
913     }
914     else
915     {
916         response = m_ipcModule.createErrorResponse(message);
917         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
918     }
919
920     m_ipcModule.sendToClients(response, &clientHandle, 1);
921     m_ipcModule.destroyMessage(response);
922 }
923
924 void GenericCommunicator::InitializeSurfaceFromId(t_ilm_message message)
925 {
926     t_ilm_message response;
927     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
928     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
929     uint id = 0;
930     m_ipcModule.getUint(message, &id);
931     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
932     if (status)
933     {
934         response = m_ipcModule.createResponse(message);
935         m_ipcModule.appendUint(response, id);
936     }
937     else
938     {
939         response = m_ipcModule.createErrorResponse(message);
940         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
941     }
942
943     m_ipcModule.sendToClients(response, &clientHandle, 1);
944     m_ipcModule.destroyMessage(response);
945 }
946
947 void GenericCommunicator::SetSurfaceNativeContent(t_ilm_message message)
948 {
949     t_ilm_message response;
950     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
951     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
952     uint id = 0;
953     uint handle = 0;
954     uint width = 0;
955     uint height = 0;
956     uint pixelformat = 0;
957     PixelFormat pf = PIXELFORMAT_UNKNOWN;
958
959     m_ipcModule.getUint(message, &id);
960     m_ipcModule.getUint(message, &handle);
961     m_ipcModule.getUint(message, &width);
962     m_ipcModule.getUint(message, &height);
963     m_ipcModule.getUint(message, &pixelformat);
964
965     pf = (PixelFormat) pixelformat;
966
967     t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
968     if (status)
969     {
970         response = m_ipcModule.createResponse(message);
971     }
972     else
973     {
974         response = m_ipcModule.createErrorResponse(message);
975         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
976     }
977
978     m_ipcModule.sendToClients(response, &clientHandle, 1);
979     m_ipcModule.destroyMessage(response);
980 }
981
982 void GenericCommunicator::RemoveSurfaceNativeContent(t_ilm_message message)
983 {
984     t_ilm_message response;
985     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
986     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
987     uint id = 0;
988     m_ipcModule.getUint(message, &id);
989
990     t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(clientPid, id));
991     if (status)
992     {
993         response = m_ipcModule.createResponse(message);
994     }
995     else
996     {
997         response = m_ipcModule.createErrorResponse(message);
998         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
999     }
1000
1001     m_ipcModule.sendToClients(response, &clientHandle, 1);
1002     m_ipcModule.destroyMessage(response);
1003 }
1004
1005 void GenericCommunicator::RemoveSurface(t_ilm_message message)
1006 {
1007     t_ilm_message response;
1008     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1009     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1010     uint param = 0;
1011     m_ipcModule.getUint(message, &param);
1012     t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(clientPid, param));
1013     if (status)
1014     {
1015         response = m_ipcModule.createResponse(message);
1016     }
1017     else
1018     {
1019         response = m_ipcModule.createErrorResponse(message);
1020         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1021     }
1022
1023     m_ipcModule.sendToClients(response, &clientHandle, 1);
1024     m_ipcModule.destroyMessage(response);
1025 }
1026
1027 void GenericCommunicator::CreateLayer(t_ilm_message message)
1028 {
1029     t_ilm_message response;
1030     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1031     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1032     uint id = GraphicalObject::INVALID_ID;
1033     // use resolution of default screen as default width and height of layers
1034     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
1035     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
1036     if (status)
1037     {
1038         response = m_ipcModule.createResponse(message);
1039         m_ipcModule.appendUint(response, id);
1040     }
1041     else
1042     {
1043         response = m_ipcModule.createErrorResponse(message);
1044         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1045     }
1046
1047     m_ipcModule.sendToClients(response, &clientHandle, 1);
1048     m_ipcModule.destroyMessage(response);
1049 }
1050
1051 void GenericCommunicator::CreateLayerFromId(t_ilm_message message)
1052 {
1053     t_ilm_message response;
1054     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1055     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1056     uint id = GraphicalObject::INVALID_ID;
1057
1058     m_ipcModule.getUint(message, &id);
1059     // use resolution of default screen as default width and height of layers
1060     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
1061     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
1062     if (status)
1063     {
1064         response = m_ipcModule.createResponse(message);
1065         m_ipcModule.appendUint(response, id);
1066     }
1067     else
1068     {
1069         response = m_ipcModule.createErrorResponse(message);
1070         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1071     }
1072
1073     m_ipcModule.sendToClients(response, &clientHandle, 1);
1074     m_ipcModule.destroyMessage(response);
1075 }
1076
1077
1078 void GenericCommunicator::CreateLayerWithDimension(t_ilm_message message)
1079 {
1080     t_ilm_message response;
1081     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1082     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1083     uint width = 0;
1084     m_ipcModule.getUint(message, &width);
1085     uint height = 0;
1086     m_ipcModule.getUint(message, &height);
1087
1088     uint id = GraphicalObject::INVALID_ID;
1089     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
1090     if (status)
1091     {
1092         response = m_ipcModule.createResponse(message);
1093         m_ipcModule.appendUint(response, id);
1094     }
1095     else
1096     {
1097         response = m_ipcModule.createErrorResponse(message);
1098         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1099     }
1100
1101     m_ipcModule.sendToClients(response, &clientHandle, 1);
1102     m_ipcModule.destroyMessage(response);
1103 }
1104
1105 void GenericCommunicator::CreateLayerFromIdWithDimension(t_ilm_message message)
1106 {
1107     t_ilm_message response;
1108     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1109     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1110     uint id = GraphicalObject::INVALID_ID;
1111     uint width = 0;
1112     uint height = 0;
1113     t_ilm_bool status = ILM_FALSE;
1114
1115     m_ipcModule.getUint(message, &id);
1116     m_ipcModule.getUint(message, &width);
1117     m_ipcModule.getUint(message, &height);
1118
1119     status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
1120     if (status)
1121     {
1122         response = m_ipcModule.createResponse(message);
1123         m_ipcModule.appendUint(response, id);
1124     }
1125     else
1126     {
1127         response = m_ipcModule.createErrorResponse(message);
1128         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1129     }
1130
1131     m_ipcModule.sendToClients(response, &clientHandle, 1);
1132     m_ipcModule.destroyMessage(response);
1133 }
1134
1135 void GenericCommunicator::RemoveLayer(t_ilm_message message)
1136 {
1137     t_ilm_message response;
1138     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1139     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1140     uint param = 0;
1141     m_ipcModule.getUint(message, &param);
1142     t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(clientPid, param));
1143     if (status)
1144     {
1145         response = m_ipcModule.createResponse(message);
1146     }
1147     else
1148     {
1149         response = m_ipcModule.createErrorResponse(message);
1150         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1151     }
1152
1153     m_ipcModule.sendToClients(response, &clientHandle, 1);
1154     m_ipcModule.destroyMessage(response);
1155 }
1156
1157 void GenericCommunicator::AddSurfaceToSurfaceGroup(t_ilm_message message)
1158 {
1159     t_ilm_message response;
1160     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1161     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1162     uint surfaceid = 0;
1163     uint surfacegroupid = 0;
1164
1165     m_ipcModule.getUint(message, &surfaceid);
1166     m_ipcModule.getUint(message, &surfacegroupid);
1167
1168     t_ilm_bool status = m_executor->execute(new SurfacegroupAddSurfaceCommand(clientPid, surfacegroupid, surfaceid));
1169     if (status)
1170     {
1171         response = m_ipcModule.createResponse(message);
1172     }
1173     else
1174     {
1175         response = m_ipcModule.createErrorResponse(message);
1176         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1177     }
1178
1179     m_ipcModule.sendToClients(response, &clientHandle, 1);
1180     m_ipcModule.destroyMessage(response);
1181 }
1182
1183 void GenericCommunicator::RemoveSurfaceFromSurfaceGroup(t_ilm_message message)
1184 {
1185     t_ilm_message response;
1186     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1187     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1188     uint surfaceid = 0;
1189     uint surfacegroupid = 0;
1190
1191     m_ipcModule.getUint(message, &surfaceid);
1192     m_ipcModule.getUint(message, &surfacegroupid);
1193
1194     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveSurfaceCommand(clientPid, surfacegroupid, surfaceid));
1195     if (status)
1196     {
1197         response = m_ipcModule.createResponse(message);
1198     }
1199     else
1200     {
1201         response = m_ipcModule.createErrorResponse(message);
1202         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1203     }
1204
1205     m_ipcModule.sendToClients(response, &clientHandle, 1);
1206     m_ipcModule.destroyMessage(response);
1207 }
1208
1209 void GenericCommunicator::AddLayerToLayerGroup(t_ilm_message message)
1210 {
1211     t_ilm_message response;
1212     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1213     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1214     uint layerid = 0;
1215     uint layergroupid = 0;
1216
1217     m_ipcModule.getUint(message, &layerid);
1218     m_ipcModule.getUint(message, &layergroupid);
1219
1220     t_ilm_bool status = m_executor->execute(new LayergroupAddLayerCommand(clientPid, layergroupid, layerid));
1221     if (status)
1222     {
1223         response = m_ipcModule.createResponse(message);
1224     }
1225     else
1226     {
1227         response = m_ipcModule.createErrorResponse(message);
1228         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1229     }
1230
1231     m_ipcModule.sendToClients(response, &clientHandle, 1);
1232     m_ipcModule.destroyMessage(response);
1233 }
1234
1235 void GenericCommunicator::RemoveLayerFromLayerGroup(t_ilm_message message)
1236 {
1237     t_ilm_message response;
1238     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1239     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1240     uint layerid = 0;
1241     uint layergroupid = 0;
1242
1243     m_ipcModule.getUint(message, &layerid);
1244     m_ipcModule.getUint(message, &layergroupid);
1245
1246     t_ilm_bool status = m_executor->execute(new LayergroupRemoveLayerCommand(clientPid, layergroupid, layerid));
1247     if (status)
1248     {
1249         response = m_ipcModule.createResponse(message);
1250     }
1251     else
1252     {
1253         response = m_ipcModule.createErrorResponse(message);
1254         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1255     }
1256
1257     m_ipcModule.sendToClients(response, &clientHandle, 1);
1258     m_ipcModule.destroyMessage(response);
1259 }
1260
1261 void GenericCommunicator::AddSurfaceToLayer(t_ilm_message message)
1262 {
1263     t_ilm_message response;
1264     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1265     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1266     uint surfaceid = 0;
1267     uint layer = 0;
1268
1269     m_ipcModule.getUint(message, &surfaceid);
1270     m_ipcModule.getUint(message, &layer);
1271
1272     t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(clientPid, layer, surfaceid));
1273     if (status)
1274     {
1275         response = m_ipcModule.createResponse(message);
1276     }
1277     else
1278     {
1279         response = m_ipcModule.createErrorResponse(message);
1280         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1281     }
1282
1283     m_ipcModule.sendToClients(response, &clientHandle, 1);
1284     m_ipcModule.destroyMessage(response);
1285 }
1286
1287 void GenericCommunicator::RemoveSurfaceFromLayer(t_ilm_message message)
1288 {
1289     t_ilm_message response;
1290     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1291     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1292     uint surfaceid = 0;
1293     uint layerid = 0;
1294     m_ipcModule.getUint(message, &surfaceid);
1295     m_ipcModule.getUint(message, &layerid);
1296
1297     t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(clientPid, layerid, surfaceid));
1298     if (status)
1299     {
1300         response = m_ipcModule.createResponse(message);
1301     }
1302     else
1303     {
1304         response = m_ipcModule.createErrorResponse(message);
1305         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1306     }
1307
1308     m_ipcModule.sendToClients(response, &clientHandle, 1);
1309     m_ipcModule.destroyMessage(response);
1310 }
1311
1312 void GenericCommunicator::CreateSurfaceGroup(t_ilm_message message)
1313 {
1314     t_ilm_message response;
1315     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1316     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1317     uint newID = GraphicalObject::INVALID_ID;
1318
1319     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(clientPid, &newID));
1320     if (status)
1321     {
1322         response = m_ipcModule.createResponse(message);
1323         m_ipcModule.appendUint(response, newID);
1324     }
1325     else
1326     {
1327         response = m_ipcModule.createErrorResponse(message);
1328         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1329     }
1330
1331     m_ipcModule.sendToClients(response, &clientHandle, 1);
1332     m_ipcModule.destroyMessage(response);
1333 }
1334
1335 void GenericCommunicator::CreateSurfaceGroupFromId(t_ilm_message message)
1336 {
1337     t_ilm_message response;
1338     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1339     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1340     uint newID = GraphicalObject::INVALID_ID;
1341
1342     m_ipcModule.getUint(message, &newID);
1343
1344     t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(clientPid, &newID));
1345     if (status)
1346     {
1347         response = m_ipcModule.createResponse(message);
1348         m_ipcModule.appendUint(response, newID);
1349     }
1350     else
1351     {
1352         response = m_ipcModule.createErrorResponse(message);
1353         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1354     }
1355
1356     m_ipcModule.sendToClients(response, &clientHandle, 1);
1357     m_ipcModule.destroyMessage(response);
1358 }
1359
1360 void GenericCommunicator::RemoveSurfaceGroup(t_ilm_message message)
1361 {
1362     t_ilm_message response;
1363     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1364     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1365     uint param = 0;
1366     m_ipcModule.getUint(message, &param);
1367
1368     t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveCommand(clientPid, param));
1369     if (status)
1370     {
1371         response = m_ipcModule.createResponse(message);
1372     }
1373     else
1374     {
1375         response = m_ipcModule.createErrorResponse(message);
1376         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1377     }
1378
1379     m_ipcModule.sendToClients(response, &clientHandle, 1);
1380     m_ipcModule.destroyMessage(response);
1381 }
1382
1383 void GenericCommunicator::CreateLayerGroup(t_ilm_message message)
1384 {
1385     t_ilm_message response;
1386     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1387     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1388     uint newID = GraphicalObject::INVALID_ID;
1389
1390     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(clientPid, &newID));
1391     if (status)
1392     {
1393         response = m_ipcModule.createResponse(message);
1394         m_ipcModule.appendUint(response, newID);
1395     }
1396     else
1397     {
1398         response = m_ipcModule.createErrorResponse(message);
1399         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1400     }
1401
1402     m_ipcModule.sendToClients(response, &clientHandle, 1);
1403     m_ipcModule.destroyMessage(response);
1404 }
1405
1406 void GenericCommunicator::CreateLayerGroupFromId(t_ilm_message message)
1407 {
1408     t_ilm_message response;
1409     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1410     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1411     uint newID = GraphicalObject::INVALID_ID;
1412
1413     m_ipcModule.getUint(message, &newID);
1414
1415     t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(clientPid, &newID));
1416     if (status)
1417     {
1418         response = m_ipcModule.createResponse(message);
1419         m_ipcModule.appendUint(response, newID);
1420     }
1421     else
1422     {
1423         response = m_ipcModule.createErrorResponse(message);
1424         m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
1425     }
1426
1427     m_ipcModule.sendToClients(response, &clientHandle, 1);
1428     m_ipcModule.destroyMessage(response);
1429 }
1430
1431 void GenericCommunicator::RemoveLayerGroup(t_ilm_message message)
1432 {
1433     t_ilm_message response;
1434     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1435     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1436     uint param = 0;
1437     m_ipcModule.getUint(message, &param);
1438
1439     t_ilm_bool status = m_executor->execute(new LayergroupRemoveCommand(clientPid, param));
1440     if (status)
1441     {
1442         response = m_ipcModule.createResponse(message);
1443     }
1444     else
1445     {
1446         response = m_ipcModule.createErrorResponse(message);
1447         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1448     }
1449
1450     m_ipcModule.sendToClients(response, &clientHandle, 1);
1451     m_ipcModule.destroyMessage(response);
1452 }
1453
1454 void GenericCommunicator::SetSurfaceSourceRegion(t_ilm_message message)
1455 {
1456     t_ilm_message response;
1457     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1458     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1459     uint id = 0;
1460     uint x = 0;
1461     uint y = 0;
1462     uint width = 0;
1463     uint height = 0;
1464
1465     m_ipcModule.getUint(message, &id);
1466     m_ipcModule.getUint(message, &x);
1467     m_ipcModule.getUint(message, &y);
1468     m_ipcModule.getUint(message, &width);
1469     m_ipcModule.getUint(message, &height);
1470
1471     t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(clientPid, id, x, y, width, height));
1472     if (status)
1473     {
1474         response = m_ipcModule.createResponse(message);
1475     }
1476     else
1477     {
1478         response = m_ipcModule.createErrorResponse(message);
1479         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1480     }
1481
1482     m_ipcModule.sendToClients(response, &clientHandle, 1);
1483     m_ipcModule.destroyMessage(response);
1484 }
1485
1486 void GenericCommunicator::SetLayerSourceRegion(t_ilm_message message)
1487 {
1488     t_ilm_message response;
1489     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1490     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1491     uint id = 0;
1492     uint x = 0;
1493     uint y = 0;
1494     uint width = 0;
1495     uint height = 0;
1496
1497     m_ipcModule.getUint(message, &id);
1498     m_ipcModule.getUint(message, &x);
1499     m_ipcModule.getUint(message, &y);
1500     m_ipcModule.getUint(message, &width);
1501     m_ipcModule.getUint(message, &height);
1502
1503     t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(clientPid, id, x, y, width, height));
1504     if (status)
1505     {
1506         response = m_ipcModule.createResponse(message);
1507     }
1508     else
1509     {
1510         response = m_ipcModule.createErrorResponse(message);
1511         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1512     }
1513
1514     m_ipcModule.sendToClients(response, &clientHandle, 1);
1515     m_ipcModule.destroyMessage(response);
1516 }
1517
1518 void GenericCommunicator::SetSurfaceDestinationRegion(t_ilm_message message)
1519 {
1520     t_ilm_message response;
1521     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1522     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1523     uint id = 0;
1524     uint x = 0;
1525     uint y = 0;
1526     uint width = 0;
1527     uint height = 0;
1528
1529     m_ipcModule.getUint(message, &id);
1530     m_ipcModule.getUint(message, &x);
1531     m_ipcModule.getUint(message, &y);
1532     m_ipcModule.getUint(message, &width);
1533     m_ipcModule.getUint(message, &height);
1534
1535     t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
1536     if (status)
1537     {
1538         response = m_ipcModule.createResponse(message);
1539     }
1540     else
1541     {
1542         response = m_ipcModule.createErrorResponse(message);
1543         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1544     }
1545
1546     m_ipcModule.sendToClients(response, &clientHandle, 1);
1547     m_ipcModule.destroyMessage(response);
1548 }
1549
1550 void GenericCommunicator::SetSurfacePosition(t_ilm_message message)
1551 {
1552     t_ilm_message response;
1553     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1554     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1555     uint id = 0;
1556     uint x = 0;
1557     uint y = 0;
1558
1559     m_ipcModule.getUint(message, &id);
1560     m_ipcModule.getUint(message, &x);
1561     m_ipcModule.getUint(message, &y);
1562
1563     t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(clientPid, id, x, y));
1564     if (status)
1565     {
1566         response = m_ipcModule.createResponse(message);
1567     }
1568     else
1569     {
1570         response = m_ipcModule.createErrorResponse(message);
1571         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1572     }
1573
1574     m_ipcModule.sendToClients(response, &clientHandle, 1);
1575     m_ipcModule.destroyMessage(response);
1576 }
1577
1578 void GenericCommunicator::GetSurfacePosition(t_ilm_message message)
1579 {
1580     t_ilm_message response;
1581     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1582     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1583     uint id = 0;
1584     uint x = 0;
1585     uint y = 0;
1586
1587     m_ipcModule.getUint(message, &id);
1588
1589     t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(clientPid, id, &x, &y));
1590     if (status)
1591     {
1592         response = m_ipcModule.createResponse(message);
1593         m_ipcModule.appendUint(response, x);
1594         m_ipcModule.appendUint(response, y);
1595     }
1596     else
1597     {
1598         response = m_ipcModule.createErrorResponse(message);
1599         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1600     }
1601
1602     m_ipcModule.sendToClients(response, &clientHandle, 1);
1603     m_ipcModule.destroyMessage(response);
1604 }
1605
1606 void GenericCommunicator::SetSurfaceDimension(t_ilm_message message)
1607 {
1608     t_ilm_message response;
1609     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1610     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1611     uint id = 0;
1612     uint width = 0;
1613     uint height = 0;
1614
1615     m_ipcModule.getUint(message, &id);
1616     m_ipcModule.getUint(message, &width);
1617     m_ipcModule.getUint(message, &height);
1618
1619     t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(clientPid, id, width, height));
1620     if (status)
1621     {
1622         response = m_ipcModule.createResponse(message);
1623     }
1624     else
1625     {
1626         response = m_ipcModule.createErrorResponse(message);
1627         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1628     }
1629
1630     m_ipcModule.sendToClients(response, &clientHandle, 1);
1631     m_ipcModule.destroyMessage(response);
1632 }
1633
1634 void GenericCommunicator::SetLayerDestinationRegion(t_ilm_message message)
1635 {
1636     t_ilm_message response;
1637     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1638     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1639     uint id = 0;
1640     uint x = 0;
1641     uint y = 0;
1642     uint width = 0;
1643     uint height = 0;
1644
1645     m_ipcModule.getUint(message, &id);
1646     m_ipcModule.getUint(message, &x);
1647     m_ipcModule.getUint(message, &y);
1648     m_ipcModule.getUint(message, &width);
1649     m_ipcModule.getUint(message, &height);
1650
1651     t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
1652     if (status)
1653     {
1654         response = m_ipcModule.createResponse(message);
1655     }
1656     else
1657     {
1658         response = m_ipcModule.createErrorResponse(message);
1659         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1660     }
1661
1662     m_ipcModule.sendToClients(response, &clientHandle, 1);
1663     m_ipcModule.destroyMessage(response);
1664 }
1665
1666 void GenericCommunicator::SetLayerPosition(t_ilm_message message)
1667 {
1668     t_ilm_message response;
1669     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1670     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1671     uint id = 0;
1672     uint x = 0;
1673     uint y = 0;
1674
1675     m_ipcModule.getUint(message, &id);
1676     m_ipcModule.getUint(message, &x);
1677     m_ipcModule.getUint(message, &y);
1678
1679     t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(clientPid, id, x, y));
1680     if (status)
1681     {
1682         response = m_ipcModule.createResponse(message);
1683     }
1684     else
1685     {
1686         response = m_ipcModule.createErrorResponse(message);
1687         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1688     }
1689
1690     m_ipcModule.sendToClients(response, &clientHandle, 1);
1691     m_ipcModule.destroyMessage(response);
1692 }
1693
1694 void GenericCommunicator::GetLayerPosition(t_ilm_message message)
1695 {
1696     t_ilm_message response;
1697     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1698     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1699     uint id = 0;
1700     uint x = 0;
1701     uint y = 0;
1702
1703     m_ipcModule.getUint(message, &id);
1704
1705     t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(clientPid, id, &x, &y));
1706     if (status)
1707     {
1708         response = m_ipcModule.createResponse(message);
1709         m_ipcModule.appendUint(response, x);
1710         m_ipcModule.appendUint(response, y);
1711     }
1712     else
1713     {
1714         response = m_ipcModule.createErrorResponse(message);
1715         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1716     }
1717
1718     m_ipcModule.sendToClients(response, &clientHandle, 1);
1719     m_ipcModule.destroyMessage(response);
1720 }
1721
1722 void GenericCommunicator::SetLayerDimension(t_ilm_message message)
1723 {
1724     t_ilm_message response;
1725     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1726     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1727     uint id = 0;
1728     uint width = 0;
1729     uint height = 0;
1730
1731     m_ipcModule.getUint(message, &id);
1732     m_ipcModule.getUint(message, &width);
1733     m_ipcModule.getUint(message, &height);
1734
1735     t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(clientPid, id, width, height));
1736     if (status)
1737     {
1738         response = m_ipcModule.createResponse(message);
1739     }
1740     else
1741     {
1742         response = m_ipcModule.createErrorResponse(message);
1743         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1744     }
1745
1746     m_ipcModule.sendToClients(response, &clientHandle, 1);
1747     m_ipcModule.destroyMessage(response);
1748 }
1749
1750 void GenericCommunicator::GetLayerDimension(t_ilm_message message)
1751 {
1752     t_ilm_message response;
1753     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1754     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1755     uint id = 0;
1756     uint width = 0;
1757     uint height = 0;
1758
1759     m_ipcModule.getUint(message, &id);
1760
1761     t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(clientPid, id, &width, &height));
1762     if (status)
1763     {
1764         response = m_ipcModule.createResponse(message);
1765         m_ipcModule.appendUint(response, width);
1766         m_ipcModule.appendUint(response, height);
1767     }
1768     else
1769     {
1770         response = m_ipcModule.createErrorResponse(message);
1771         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1772     }
1773
1774     m_ipcModule.sendToClients(response, &clientHandle, 1);
1775     m_ipcModule.destroyMessage(response);
1776 }
1777
1778 void GenericCommunicator::GetSurfaceDimension(t_ilm_message message)
1779 {
1780     t_ilm_message response;
1781     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1782     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1783     uint id = 0;
1784     uint width = 0;
1785     uint height = 0;
1786
1787     m_ipcModule.getUint(message, &id);
1788
1789     t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(clientPid, id, &width, &height));
1790     if (status)
1791     {
1792         response = m_ipcModule.createResponse(message);
1793         m_ipcModule.appendUint(response, width);
1794         m_ipcModule.appendUint(response, height);
1795     }
1796     else
1797     {
1798         response = m_ipcModule.createErrorResponse(message);
1799         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1800     }
1801
1802     m_ipcModule.sendToClients(response, &clientHandle, 1);
1803     m_ipcModule.destroyMessage(response);
1804 }
1805
1806 void GenericCommunicator::SetSurfaceOpacity(t_ilm_message message)
1807 {
1808     t_ilm_message response;
1809     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1810     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1811     uint id = 0;
1812     double param = 0.0;
1813
1814     m_ipcModule.getUint(message, &id);
1815     m_ipcModule.getDouble(message, &param);
1816
1817     t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(clientPid, id, param));
1818     if (status)
1819     {
1820         response = m_ipcModule.createResponse(message);
1821     }
1822     else
1823     {
1824         response = m_ipcModule.createErrorResponse(message);
1825         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1826     }
1827
1828     m_ipcModule.sendToClients(response, &clientHandle, 1);
1829     m_ipcModule.destroyMessage(response);
1830 }
1831
1832 void GenericCommunicator::SetLayerOpacity(t_ilm_message message)
1833 {
1834     t_ilm_message response;
1835     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1836     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1837     uint id = 0;
1838     double param = 0.0;
1839
1840     m_ipcModule.getUint(message, &id);
1841     m_ipcModule.getDouble(message, &param);
1842
1843     t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(clientPid, id, param));
1844     if (status)
1845     {
1846         response = m_ipcModule.createResponse(message);
1847     }
1848     else
1849     {
1850         response = m_ipcModule.createErrorResponse(message);
1851         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1852     }
1853
1854     m_ipcModule.sendToClients(response, &clientHandle, 1);
1855     m_ipcModule.destroyMessage(response);
1856 }
1857
1858 void GenericCommunicator::SetSurfacegroupOpacity(t_ilm_message message)
1859 {
1860     t_ilm_message response;
1861     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1862     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1863     uint id = 0;
1864     double param = 0.0;
1865
1866     m_ipcModule.getUint(message, &id);
1867     m_ipcModule.getDouble(message, &param);
1868
1869     t_ilm_bool status = m_executor->execute(new SurfacegroupSetOpacityCommand(clientPid, id, param));
1870     if (status)
1871     {
1872         response = m_ipcModule.createResponse(message);
1873     }
1874     else
1875     {
1876         response = m_ipcModule.createErrorResponse(message);
1877         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1878     }
1879
1880     m_ipcModule.sendToClients(response, &clientHandle, 1);
1881     m_ipcModule.destroyMessage(response);
1882 }
1883
1884 void GenericCommunicator::SetLayergroupOpacity(t_ilm_message message)
1885 {
1886     t_ilm_message response;
1887     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1888     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1889     uint id = 0;
1890     double param = 0.0;
1891
1892     m_ipcModule.getUint(message, &id);
1893     m_ipcModule.getDouble(message, &param);
1894
1895     t_ilm_bool status = m_executor->execute(new LayergroupSetOpacityCommand(clientPid, id, param));
1896     if (status)
1897     {
1898         response = m_ipcModule.createResponse(message);
1899     }
1900     else
1901     {
1902         response = m_ipcModule.createErrorResponse(message);
1903         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1904     }
1905
1906     m_ipcModule.sendToClients(response, &clientHandle, 1);
1907     m_ipcModule.destroyMessage(response);
1908 }
1909
1910 void GenericCommunicator::GetSurfaceOpacity(t_ilm_message message)
1911 {
1912     t_ilm_message response;
1913     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1914     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1915     uint id = 0;
1916     double param = 0.0;
1917
1918     m_ipcModule.getUint(message, &id);
1919
1920     t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(clientPid, id, &param));
1921     if (status)
1922     {
1923         response = m_ipcModule.createResponse(message);
1924         m_ipcModule.appendDouble(response, param);
1925     }
1926     else
1927     {
1928         response = m_ipcModule.createErrorResponse(message);
1929         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1930     }
1931
1932     m_ipcModule.sendToClients(response, &clientHandle, 1);
1933     m_ipcModule.destroyMessage(response);
1934 }
1935
1936 void GenericCommunicator::GetLayerOpacity(t_ilm_message message)
1937 {
1938     t_ilm_message response;
1939     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1940     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1941     uint id = 0;
1942     double param = 0.0;
1943
1944     m_ipcModule.getUint(message, &id);
1945
1946     t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(clientPid, id, &param));
1947     if (status)
1948     {
1949         response = m_ipcModule.createResponse(message);
1950         m_ipcModule.appendDouble(response, param);
1951     }
1952     else
1953     {
1954         response = m_ipcModule.createErrorResponse(message);
1955         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1956     }
1957
1958     m_ipcModule.sendToClients(response, &clientHandle, 1);
1959     m_ipcModule.destroyMessage(response);
1960 }
1961
1962 void GenericCommunicator::SetSurfaceOrientation(t_ilm_message message)
1963 {
1964     t_ilm_message response;
1965     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1966     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1967     uint id = 0;
1968     uint param = 0;
1969     OrientationType o = Zero;
1970
1971     m_ipcModule.getUint(message, &id);
1972     m_ipcModule.getUint(message, &param);
1973
1974     o = (OrientationType) param;
1975
1976     t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(clientPid, id, o));
1977     if (status)
1978     {
1979         response = m_ipcModule.createResponse(message);
1980     }
1981     else
1982     {
1983         response = m_ipcModule.createErrorResponse(message);
1984         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
1985     }
1986
1987     m_ipcModule.sendToClients(response, &clientHandle, 1);
1988     m_ipcModule.destroyMessage(response);
1989 }
1990
1991 void GenericCommunicator::GetSurfaceOrientation(t_ilm_message message)
1992 {
1993     t_ilm_message response;
1994     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1995     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1996     uint id = 0;
1997     OrientationType o;
1998
1999     m_ipcModule.getUint(message, &id);
2000
2001     t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(clientPid, id, &o));
2002     if (status)
2003     {
2004         response = m_ipcModule.createResponse(message);
2005         m_ipcModule.appendUint(response, o);
2006     }
2007     else
2008     {
2009         response = m_ipcModule.createErrorResponse(message);
2010         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2011     }
2012
2013     m_ipcModule.sendToClients(response, &clientHandle, 1);
2014     m_ipcModule.destroyMessage(response);
2015 }
2016
2017 void GenericCommunicator::SetLayerOrientation(t_ilm_message message)
2018 {
2019     t_ilm_message response;
2020     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2021     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2022     uint id = 0;
2023     uint param = 0;
2024     OrientationType o = Zero;
2025
2026     m_ipcModule.getUint(message, &id);
2027     m_ipcModule.getUint(message, &param);
2028
2029     o = (OrientationType) param;
2030
2031     t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(clientPid, id, o));
2032     if (status)
2033     {
2034         response = m_ipcModule.createResponse(message);
2035     }
2036     else
2037     {
2038         response = m_ipcModule.createErrorResponse(message);
2039         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2040     }
2041
2042     m_ipcModule.sendToClients(response, &clientHandle, 1);
2043     m_ipcModule.destroyMessage(response);
2044 }
2045
2046 void GenericCommunicator::GetLayerOrientation(t_ilm_message message)
2047 {
2048     t_ilm_message response;
2049     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2050     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2051     uint id = 0;
2052     OrientationType o;
2053
2054     m_ipcModule.getUint(message, &id);
2055
2056     t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(clientPid, id, &o));
2057     if (status)
2058     {
2059         response = m_ipcModule.createResponse(message);
2060         m_ipcModule.appendUint(response, o);
2061     }
2062     else
2063     {
2064         response = m_ipcModule.createErrorResponse(message);
2065         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2066     }
2067
2068     m_ipcModule.sendToClients(response, &clientHandle, 1);
2069     m_ipcModule.destroyMessage(response);
2070 }
2071
2072 void GenericCommunicator::GetSurfacePixelformat(t_ilm_message message)
2073 {
2074     t_ilm_message response;
2075     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2076     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2077     uint id = 0;
2078     PixelFormat pixelFormat;
2079
2080     m_ipcModule.getUint(message, &id);
2081
2082     t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(clientPid, id, &pixelFormat));
2083     if (status)
2084     {
2085         response = m_ipcModule.createResponse(message);
2086         m_ipcModule.appendUint(response, pixelFormat);
2087     }
2088     else
2089     {
2090         response = m_ipcModule.createErrorResponse(message);
2091         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2092     }
2093
2094     m_ipcModule.sendToClients(response, &clientHandle, 1);
2095     m_ipcModule.destroyMessage(response);
2096 }
2097
2098 void GenericCommunicator::SetSurfaceVisibility(t_ilm_message message)
2099 {
2100     t_ilm_message response;
2101     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2102     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2103     uint surfaceid = 0;
2104     t_ilm_bool newVis = ILM_FALSE;
2105
2106     m_ipcModule.getUint(message, &surfaceid);
2107     m_ipcModule.getBool(message, &newVis);
2108
2109     t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(clientPid, surfaceid, newVis));
2110     if (status)
2111     {
2112         response = m_ipcModule.createResponse(message);
2113     }
2114     else
2115     {
2116         response = m_ipcModule.createErrorResponse(message);
2117         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2118     }
2119
2120     m_ipcModule.sendToClients(response, &clientHandle, 1);
2121     m_ipcModule.destroyMessage(response);
2122 }
2123
2124 void GenericCommunicator::SetLayerVisibility(t_ilm_message message)
2125 {
2126     t_ilm_message response;
2127     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2128     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2129     uint layerid = 0;
2130     t_ilm_bool myparam = ILM_FALSE;
2131
2132     m_ipcModule.getUint(message, &layerid);
2133     m_ipcModule.getBool(message, &myparam);
2134
2135     t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(clientPid, layerid, myparam));
2136     if (status)
2137     {
2138         response = m_ipcModule.createResponse(message);
2139     }
2140     else
2141     {
2142         response = m_ipcModule.createErrorResponse(message);
2143         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2144     }
2145
2146     m_ipcModule.sendToClients(response, &clientHandle, 1);
2147     m_ipcModule.destroyMessage(response);
2148 }
2149
2150 void GenericCommunicator::GetSurfaceVisibility(t_ilm_message message)
2151 {
2152     t_ilm_message response;
2153     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2154     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2155     uint id = 0;
2156     bool visibility;
2157
2158     m_ipcModule.getUint(message, &id);
2159
2160     t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(clientPid, id, &visibility));
2161     if (status)
2162     {
2163         response = m_ipcModule.createResponse(message);
2164         m_ipcModule.appendBool(response, visibility);
2165     }
2166     else
2167     {
2168         response = m_ipcModule.createErrorResponse(message);
2169         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2170     }
2171
2172     m_ipcModule.sendToClients(response, &clientHandle, 1);
2173     m_ipcModule.destroyMessage(response);
2174 }
2175
2176 void GenericCommunicator::GetLayerVisibility(t_ilm_message message)
2177 {
2178     t_ilm_message response;
2179     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2180     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2181     uint id = 0;
2182     bool visibility;
2183
2184     m_ipcModule.getUint(message, &id);
2185
2186     t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(clientPid, id, &visibility));
2187     if (status)
2188     {
2189         response = m_ipcModule.createResponse(message);
2190         m_ipcModule.appendBool(response, visibility);
2191     }
2192     else
2193     {
2194         response = m_ipcModule.createErrorResponse(message);
2195         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2196     }
2197
2198     m_ipcModule.sendToClients(response, &clientHandle, 1);
2199     m_ipcModule.destroyMessage(response);
2200 }
2201
2202 void GenericCommunicator::SetSurfacegroupVisibility(t_ilm_message message)
2203 {
2204     t_ilm_message response;
2205     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2206     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2207     uint groupid = 0;
2208     t_ilm_bool myparam = ILM_FALSE;
2209
2210     m_ipcModule.getUint(message, &groupid);
2211     m_ipcModule.getBool(message, &myparam);
2212
2213     t_ilm_bool status = m_executor->execute(new SurfacegroupSetVisibilityCommand(clientPid, groupid, myparam));
2214     if (status)
2215     {
2216         response = m_ipcModule.createResponse(message);
2217     }
2218     else
2219     {
2220         response = m_ipcModule.createErrorResponse(message);
2221         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2222     }
2223
2224     m_ipcModule.sendToClients(response, &clientHandle, 1);
2225     m_ipcModule.destroyMessage(response);
2226 }
2227
2228 void GenericCommunicator::SetLayergroupVisibility(t_ilm_message message)
2229 {
2230     t_ilm_message response;
2231     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2232     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2233     uint groupid = 0;
2234     t_ilm_bool myparam = ILM_FALSE;
2235
2236     m_ipcModule.getUint(message, &groupid);
2237     m_ipcModule.getBool(message, &myparam);
2238
2239     t_ilm_bool status = m_executor->execute(new LayergroupSetVisibilityCommand(clientPid, groupid, myparam));
2240     if (status)
2241     {
2242         response = m_ipcModule.createResponse(message);
2243     }
2244     else
2245     {
2246         response = m_ipcModule.createErrorResponse(message);
2247         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2248     }
2249
2250     m_ipcModule.sendToClients(response, &clientHandle, 1);
2251     m_ipcModule.destroyMessage(response);
2252 }
2253
2254
2255 void GenericCommunicator::SetRenderOrderOfLayers(t_ilm_message message)
2256 {
2257     t_ilm_message response;
2258     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2259     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2260     uint* array = NULL;
2261     int length = 0;
2262
2263     m_ipcModule.getUintArray(message, &array, &length);
2264
2265     t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(clientPid, array, length));
2266     if (status)
2267     {
2268         response = m_ipcModule.createResponse(message);
2269     }
2270     else
2271     {
2272         response = m_ipcModule.createErrorResponse(message);
2273         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2274     }
2275
2276     m_ipcModule.sendToClients(response, &clientHandle, 1);
2277     m_ipcModule.destroyMessage(response);
2278 }
2279
2280 void GenericCommunicator::SetSurfaceRenderOrderWithinLayer(t_ilm_message message)
2281 {
2282     t_ilm_message response;
2283     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2284     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2285     uint* array = NULL;
2286     int length = 0;
2287     uint layerid = 0;
2288
2289     m_ipcModule.getUint(message, &layerid);
2290     m_ipcModule.getUintArray(message, &array, &length);
2291
2292     t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(clientPid, layerid, array, length));
2293     if (status)
2294     {
2295         response = m_ipcModule.createResponse(message);
2296     }
2297     else
2298     {
2299         response = m_ipcModule.createErrorResponse(message);
2300         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2301     }
2302
2303     m_ipcModule.sendToClients(response, &clientHandle, 1);
2304     m_ipcModule.destroyMessage(response);
2305 }
2306
2307 void GenericCommunicator::GetLayerType(t_ilm_message message)
2308 {
2309     t_ilm_message response;
2310     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2311     uint id = 0;
2312     m_ipcModule.getUint(message, &id);
2313
2314     Layer* layer = m_executor->getScene()->getLayer(id);
2315     if (layer)
2316     {
2317         response = m_ipcModule.createResponse(message);
2318         m_ipcModule.appendUint(response, layer->getLayerType());
2319     }
2320     else
2321     {
2322         response = m_ipcModule.createErrorResponse(message);
2323         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2324     }
2325
2326     m_ipcModule.sendToClients(response, &clientHandle, 1);
2327     m_ipcModule.destroyMessage(response);
2328 }
2329
2330 void GenericCommunicator::GetLayertypeCapabilities(t_ilm_message message)
2331 {
2332     t_ilm_message response;
2333     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2334     uint id = 0;
2335     LayerType type = Unknown;
2336
2337     m_ipcModule.getUint(message, &id);
2338
2339     type = (LayerType) id;
2340
2341     uint capabilities = m_executor->getLayerTypeCapabilities(type);
2342     response = m_ipcModule.createResponse(message);
2343     m_ipcModule.appendUint(response, capabilities);
2344     m_ipcModule.sendToClients(response, &clientHandle, 1);
2345     m_ipcModule.destroyMessage(response);
2346 }
2347
2348 void GenericCommunicator::GetLayerCapabilities(t_ilm_message message)
2349 {
2350     t_ilm_message response;
2351     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2352     uint id = 0;
2353     m_ipcModule.getUint(message, &id);
2354
2355     Layer* layer = m_executor->getScene()->getLayer(id);
2356     if (layer)
2357     {
2358         response = m_ipcModule.createResponse(message);
2359         m_ipcModule.appendUint(response, layer->getCapabilities());
2360     }
2361     else
2362     {
2363         response = m_ipcModule.createErrorResponse(message);
2364         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2365     }
2366
2367     m_ipcModule.sendToClients(response, &clientHandle, 1);
2368     m_ipcModule.destroyMessage(response);
2369 }
2370
2371 void GenericCommunicator::FadeIn(t_ilm_message message)
2372 {
2373     t_ilm_message response;
2374     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2375     response = m_ipcModule.createErrorResponse(message);
2376     m_ipcModule.appendString(response, NOT_IMPLEMENTED);
2377     m_ipcModule.sendToClients(response, &clientHandle, 1);
2378     m_ipcModule.destroyMessage(response);
2379 }
2380
2381 void GenericCommunicator::SynchronizedFade(t_ilm_message message)
2382 {
2383     t_ilm_message response;
2384     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2385     response = m_ipcModule.createErrorResponse(message);
2386     m_ipcModule.appendString(response, NOT_IMPLEMENTED);
2387     m_ipcModule.sendToClients(response, &clientHandle, 1);
2388     m_ipcModule.destroyMessage(response);
2389 }
2390
2391 void GenericCommunicator::FadeOut(t_ilm_message message)
2392 {
2393     t_ilm_message response;
2394     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2395     response = m_ipcModule.createErrorResponse(message);
2396     m_ipcModule.appendString(response, NOT_IMPLEMENTED);
2397     m_ipcModule.sendToClients(response, &clientHandle, 1);
2398     m_ipcModule.destroyMessage(response);
2399 }
2400
2401 void GenericCommunicator::Exit(t_ilm_message message)
2402 {
2403     t_ilm_message response;
2404     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2405     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2406     t_ilm_bool status = m_executor->execute(new ExitCommand(clientPid));
2407     if (status)
2408     {
2409         response = m_ipcModule.createResponse(message);
2410     }
2411     else
2412     {
2413         response = m_ipcModule.createErrorResponse(message);
2414         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2415     }
2416
2417     m_ipcModule.sendToClients(response, &clientHandle, 1);
2418     m_ipcModule.destroyMessage(response);
2419 }
2420
2421 void GenericCommunicator::CommitChanges(t_ilm_message message)
2422 {
2423     t_ilm_message response;
2424     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2425     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2426     t_ilm_bool status = m_executor->execute(new CommitCommand(clientPid));
2427     if (status)
2428     {
2429         response = m_ipcModule.createResponse(message);
2430     }
2431     else
2432     {
2433         response = m_ipcModule.createErrorResponse(message);
2434         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2435     }
2436
2437     m_ipcModule.sendToClients(response, &clientHandle, 1);
2438     m_ipcModule.destroyMessage(response);
2439 }
2440
2441 void GenericCommunicator::CreateShader(t_ilm_message message)
2442 {
2443     t_ilm_message response;
2444     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2445     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2446     char vertname[1024];
2447     char fragname[1024];
2448     uint id = 0;
2449
2450     m_ipcModule.getString(message, vertname);
2451     m_ipcModule.getString(message, fragname);
2452
2453     t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(clientPid, vertname, fragname, &id));
2454     if (status)
2455     {
2456         response = m_ipcModule.createResponse(message);
2457         m_ipcModule.appendUint(response, id);
2458     }
2459     else
2460     {
2461         response = m_ipcModule.createErrorResponse(message);
2462         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2463     }
2464
2465     m_ipcModule.sendToClients(response, &clientHandle, 1);
2466     m_ipcModule.destroyMessage(response);
2467 }
2468
2469 void GenericCommunicator::DestroyShader(t_ilm_message message)
2470 {
2471     t_ilm_message response;
2472     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2473     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2474     uint shaderid = 0;
2475
2476     m_ipcModule.getUint(message, &shaderid);
2477
2478     t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(clientPid, shaderid));
2479     if (status)
2480     {
2481         response = m_ipcModule.createResponse(message);
2482     }
2483     else
2484     {
2485         response = m_ipcModule.createErrorResponse(message);
2486         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2487     }
2488
2489     m_ipcModule.sendToClients(response, &clientHandle, 1);
2490     m_ipcModule.destroyMessage(response);
2491 }
2492
2493 void GenericCommunicator::SetShader(t_ilm_message message)
2494 {
2495     t_ilm_message response;
2496     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2497     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2498     uint surfaceId = 0;
2499     uint shaderid = 0;
2500
2501     m_ipcModule.getUint(message, &surfaceId);
2502     m_ipcModule.getUint(message, &shaderid);
2503
2504     t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(clientPid, surfaceId, shaderid));
2505     if (status)
2506     {
2507         response = m_ipcModule.createResponse(message);
2508     }
2509     else
2510     {
2511         response = m_ipcModule.createErrorResponse(message);
2512         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2513     }
2514
2515     m_ipcModule.sendToClients(response, &clientHandle, 1);
2516     m_ipcModule.destroyMessage(response);
2517 }
2518
2519 void GenericCommunicator::SetUniforms(t_ilm_message message)
2520 {
2521     t_ilm_message response;
2522     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2523     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2524     uint id = 0;
2525     std::vector<string> uniforms;
2526
2527     m_ipcModule.getUint(message, &id);
2528
2529     // TODO
2530     //m_ipcModule.getStringArray(&uniforms);
2531
2532     t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(clientPid, id, uniforms));
2533     if (status)
2534     {
2535         response = m_ipcModule.createResponse(message);
2536     }
2537     else
2538     {
2539         response = m_ipcModule.createErrorResponse(message);
2540         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2541     }
2542
2543     m_ipcModule.sendToClients(response, &clientHandle, 1);
2544     m_ipcModule.destroyMessage(response);
2545 }
2546
2547 void GenericCommunicator::SetKeyboardFocusOn(t_ilm_message message)
2548 {
2549     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2550     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2551     t_ilm_message response;
2552     uint surfaceId = 0;
2553
2554     m_ipcModule.getUint(message, &surfaceId);
2555
2556     t_ilm_bool status = m_executor->execute(new SurfaceSetKeyboardFocusCommand(clientPid, surfaceId));
2557     if (status)
2558     {
2559         response = m_ipcModule.createResponse(message);
2560     }
2561     else
2562     {
2563         response = m_ipcModule.createErrorResponse(message);
2564         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2565     }
2566
2567     m_ipcModule.sendToClients(response, &clientHandle, 1);
2568     m_ipcModule.destroyMessage(response);
2569 }
2570
2571
2572 void GenericCommunicator::GetKeyboardFocusSurfaceId(t_ilm_message message)
2573 {
2574     t_ilm_message response;
2575     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2576     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2577     uint surfaceId;
2578
2579     t_ilm_bool status = m_executor->execute(new SurfaceGetKeyboardFocusCommand(clientPid, &surfaceId));
2580     if (status)
2581     {
2582         response = m_ipcModule.createResponse(message);
2583         m_ipcModule.appendUint(response, surfaceId);
2584     }
2585     else
2586     {
2587         response = m_ipcModule.createErrorResponse(message);
2588         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2589     }
2590
2591     m_ipcModule.sendToClients(response, &clientHandle, 1);
2592     m_ipcModule.destroyMessage(response);
2593 }
2594
2595
2596 void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
2597 {
2598     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2599     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2600     t_ilm_message response;
2601     uint surfaceId = 0;
2602     uint udevices = 0;
2603     InputDevice devices;
2604     t_ilm_bool accept;
2605
2606     m_ipcModule.getUint(message, &surfaceId);
2607     m_ipcModule.getUint(message, &udevices);
2608     m_ipcModule.getBool(message, &accept);
2609
2610     devices = (InputDevice) udevices;
2611
2612     t_ilm_bool status = m_executor->execute(new SurfaceUpdateInputEventAcceptance(clientPid, surfaceId, devices, accept));
2613     if (status)
2614     {
2615         response = m_ipcModule.createResponse(message);
2616     }
2617     else
2618     {
2619         response = m_ipcModule.createErrorResponse(message);
2620         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2621     }
2622
2623     m_ipcModule.sendToClients(response, &clientHandle, 1);
2624     m_ipcModule.destroyMessage(response);
2625 }
2626
2627 void GenericCommunicator::SetSurfaceChromaKey(t_ilm_message message)
2628 {
2629     t_ilm_message response;
2630     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2631     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2632     uint* array = NULL;
2633     int length = 0;
2634     uint surfaceid = 0;
2635
2636     m_ipcModule.getUint(message, &surfaceid);
2637     m_ipcModule.getUintArray(message, &array, &length);
2638
2639     t_ilm_bool status = m_executor->execute(new SurfaceSetChromaKeyCommand(clientPid, surfaceid, array, length));
2640     if (status)
2641     {
2642         response = m_ipcModule.createResponse(message);
2643     }
2644     else
2645     {
2646         response = m_ipcModule.createErrorResponse(message);
2647         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2648     }
2649
2650     m_ipcModule.sendToClients(response, &clientHandle, 1);
2651     m_ipcModule.destroyMessage(response);
2652 }
2653
2654 void GenericCommunicator::SetLayerChromaKey(t_ilm_message message)
2655 {
2656     t_ilm_message response;
2657     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2658     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2659     uint* array = NULL;
2660     int length = 0;
2661     uint layerid = 0;
2662
2663     m_ipcModule.getUint(message, &layerid);
2664     m_ipcModule.getUintArray(message, &array, &length);
2665
2666     t_ilm_bool status = m_executor->execute(new LayerSetChromaKeyCommand(clientPid, layerid, array, length));
2667     if (status)
2668     {
2669         response = m_ipcModule.createResponse(message);
2670     }
2671     else
2672     {
2673         response = m_ipcModule.createErrorResponse(message);
2674         m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
2675     }
2676
2677     m_ipcModule.sendToClients(response, &clientHandle, 1);
2678     m_ipcModule.destroyMessage(response);
2679 }
2680
2681 void GenericCommunicator::LayerAddNotification(t_ilm_message message)
2682 {
2683     t_ilm_message response;
2684     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2685     uint layerid = 0;
2686
2687     m_ipcModule.getUint(message, &layerid);
2688
2689     Layer* layer = m_executor->getScene()->getLayer(layerid);
2690     if (layer)
2691     {
2692         layer->addNotification(clientHandle);
2693         response = m_ipcModule.createResponse(message);
2694     }
2695     else
2696     {
2697         response = m_ipcModule.createErrorResponse(message);
2698         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2699     }
2700
2701     m_ipcModule.sendToClients(response, &clientHandle, 1);
2702     m_ipcModule.destroyMessage(response);
2703 }
2704
2705 void GenericCommunicator::SurfaceAddNotification(t_ilm_message message)
2706 {
2707     t_ilm_message response;
2708     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2709     uint surfaceid = 0;
2710
2711     m_ipcModule.getUint(message, &surfaceid);
2712
2713     Surface* surface = m_executor->getScene()->getSurface(surfaceid);
2714     if (surface)
2715     {
2716         surface->addNotification(clientHandle);
2717         response = m_ipcModule.createResponse(message);
2718     }
2719     else
2720     {
2721         response = m_ipcModule.createErrorResponse(message);
2722         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2723     }
2724
2725     m_ipcModule.sendToClients(response, &clientHandle, 1);
2726     m_ipcModule.destroyMessage(response);
2727 }
2728
2729 void GenericCommunicator::LayerRemoveNotification(t_ilm_message message)
2730 {
2731     t_ilm_message response;
2732     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2733     uint layerid = 0;
2734
2735     m_ipcModule.getUint(message, &layerid);
2736
2737     Layer* layer = m_executor->getScene()->getLayer(layerid);
2738     if (layer)
2739     {
2740         layer->removeNotification(clientHandle);
2741         response = m_ipcModule.createResponse(message);
2742     }
2743     else
2744     {
2745         response = m_ipcModule.createErrorResponse(message);
2746         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2747     }
2748
2749     m_ipcModule.sendToClients(response, &clientHandle, 1);
2750     m_ipcModule.destroyMessage(response);
2751 }
2752
2753 void GenericCommunicator::SurfaceRemoveNotification(t_ilm_message message)
2754 {
2755     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2756     t_ilm_message response;
2757     uint surfaceid = 0;
2758
2759     m_ipcModule.getUint(message, &surfaceid);
2760
2761     Surface* surface = m_executor->getScene()->getSurface(surfaceid);
2762     if (surface)
2763     {
2764         surface->removeNotification(clientHandle);
2765         response = m_ipcModule.createResponse(message);
2766     }
2767     else
2768     {
2769         response = m_ipcModule.createErrorResponse(message);
2770         m_ipcModule.appendString(response, INVALID_ARGUMENT);
2771     }
2772
2773     m_ipcModule.sendToClients(response, &clientHandle, 1);
2774     m_ipcModule.destroyMessage(response);
2775 }
2776
2777 void GenericCommunicator::processNotificationQueue()
2778 {
2779     NotificationQueue& notificationQueue = m_executor->getClientNotificationQueue();
2780     NotificationQueue::iterator iter = notificationQueue.begin();
2781     NotificationQueue::iterator end = notificationQueue.end();
2782
2783     for (; iter != end; ++iter)
2784     {
2785         GraphicalObject* object = iter->first;
2786         t_ilm_notification_mask mask = iter->second;
2787         sendNotification(object, mask);
2788     }
2789     notificationQueue.clear();
2790 }
2791
2792 void GenericCommunicator::sendNotification(GraphicalObject* object, t_ilm_notification_mask mask)
2793 {
2794     switch (object->type)
2795     {
2796     case TypeLayer:
2797     {
2798         Layer* layer = static_cast<Layer*>(object);
2799         if (layer)
2800         {
2801             ApplicationReferenceList& arl = layer->getNotificationClients();
2802
2803             if (arl.size())
2804             {
2805                 t_ilm_message notification;
2806                 Rectangle dest = layer->getDestinationRegion();
2807                 Rectangle src = layer->getSourceRegion();
2808                 OrientationType orientation = layer->getOrientation();
2809
2810                 unsigned char chromaKeyRed = 0;
2811                 unsigned char chromaKeyGreen = 0;
2812                 unsigned char chromaKeyBlue = 0;
2813                 layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
2814
2815                 std::stringstream notificationName;
2816                 notificationName << "NotificationForLayer" << layer->getID();
2817
2818                 notification = m_ipcModule.createNotification(notificationName.str().c_str());
2819                 m_ipcModule.appendUint(notification, layer->getID());
2820                 m_ipcModule.appendUint(notification, mask);
2821
2822                 m_ipcModule.appendDouble(notification, layer->getOpacity());
2823                 m_ipcModule.appendUint(notification, src.x);
2824                 m_ipcModule.appendUint(notification, src.y);
2825                 m_ipcModule.appendUint(notification, src.width);
2826                 m_ipcModule.appendUint(notification, src.height);
2827                 m_ipcModule.appendUint(notification, layer->OriginalSourceWidth);
2828                 m_ipcModule.appendUint(notification, layer->OriginalSourceHeight);
2829                 m_ipcModule.appendUint(notification, dest.x);
2830                 m_ipcModule.appendUint(notification, dest.y);
2831                 m_ipcModule.appendUint(notification, dest.width);
2832                 m_ipcModule.appendUint(notification, dest.height);
2833                 m_ipcModule.appendUint(notification, orientation);
2834                 m_ipcModule.appendBool(notification, layer->getVisibility());
2835                 m_ipcModule.appendUint(notification, layer->getLayerType());
2836                 m_ipcModule.appendBool(notification, layer->getChromaKeyEnabled());
2837                 m_ipcModule.appendUint(notification, chromaKeyRed);
2838                 m_ipcModule.appendUint(notification, chromaKeyGreen);
2839                 m_ipcModule.appendUint(notification, chromaKeyBlue);
2840                 m_ipcModule.appendInt(notification, layer->getCreatorPid());
2841
2842                 int clientCount = arl.size();
2843                 t_ilm_client_handle clientArray[256];
2844
2845                 ApplicationReferenceList::iterator iter = arl.begin();
2846                 ApplicationReferenceList::iterator end = arl.end();
2847
2848                 for (int clientNumber = 0;
2849                      iter != end, clientNumber < 256;
2850                      ++iter, ++clientNumber)
2851                 {
2852                     t_ilm_client_handle client = *iter;
2853                     clientArray[clientNumber] = client;
2854                 }
2855
2856                 LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): layer " << layer->getID() << " was updated.");
2857
2858                 if (!m_ipcModule.sendToClients(notification, clientArray, clientCount))
2859                 {
2860                     LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
2861                 }
2862
2863                 m_ipcModule.destroyMessage(notification);
2864             }
2865         }
2866     }
2867     break;
2868     case TypeSurface:
2869     {
2870         Surface* surface = static_cast<Surface*>(object);
2871         if (surface)
2872         {
2873             ApplicationReferenceList& arl = surface->getNotificationClients();
2874
2875             if (arl.size())
2876             {
2877                 t_ilm_message notification;
2878                 std::stringstream notificationName;
2879                 notificationName << "NotificationForSurface" << surface->getID();
2880
2881                 unsigned char chromaKeyRed = 0;
2882                 unsigned char chromaKeyGreen = 0;
2883                 unsigned char chromaKeyBlue = 0;
2884                 surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
2885
2886                 notification = m_ipcModule.createNotification(notificationName.str().c_str());
2887                 m_ipcModule.appendUint(notification, surface->getID());
2888                 m_ipcModule.appendUint(notification, mask);
2889
2890                 m_ipcModule.appendDouble(notification, surface->getOpacity());
2891                 m_ipcModule.appendUint(notification, surface->getSourceRegion().x);
2892                 m_ipcModule.appendUint(notification, surface->getSourceRegion().y);
2893                 m_ipcModule.appendUint(notification, surface->getSourceRegion().width);
2894                 m_ipcModule.appendUint(notification, surface->getSourceRegion().height);
2895                 m_ipcModule.appendUint(notification, surface->OriginalSourceWidth);
2896                 m_ipcModule.appendUint(notification, surface->OriginalSourceHeight);
2897                 m_ipcModule.appendUint(notification, surface->getDestinationRegion().x);
2898                 m_ipcModule.appendUint(notification, surface->getDestinationRegion().y);
2899                 m_ipcModule.appendUint(notification, surface->getDestinationRegion().width);
2900                 m_ipcModule.appendUint(notification, surface->getDestinationRegion().height);
2901                 m_ipcModule.appendUint(notification, surface->getOrientation());
2902                 m_ipcModule.appendBool(notification, surface->getVisibility());
2903                 m_ipcModule.appendUint(notification, surface->frameCounter);
2904                 m_ipcModule.appendUint(notification, surface->drawCounter);
2905                 m_ipcModule.appendUint(notification, surface->updateCounter);
2906                 m_ipcModule.appendUint(notification, surface->getPixelFormat());
2907                 m_ipcModule.appendUint(notification, surface->getNativeContent());
2908                 m_ipcModule.appendUint(notification, surface->getInputEventAcceptanceOnDevices());
2909                 m_ipcModule.appendBool(notification, surface->getChromaKeyEnabled());
2910                 m_ipcModule.appendUint(notification, chromaKeyRed);
2911                 m_ipcModule.appendUint(notification, chromaKeyGreen);
2912                 m_ipcModule.appendUint(notification, chromaKeyBlue);
2913                 m_ipcModule.appendInt(notification, surface->getCreatorPid());
2914
2915                 int clientCount = arl.size();
2916                 t_ilm_client_handle clients[256];
2917
2918                 ApplicationReferenceList::iterator iter = arl.begin();
2919                 ApplicationReferenceList::iterator end = arl.end();
2920
2921                 for (int clientNumber = 0;
2922                      iter != end, clientNumber < 256;
2923                      ++iter, ++clientNumber)
2924                 {
2925                     clients[clientNumber] = *iter;
2926                 }
2927
2928                 LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): surface " << surface->getID() << " was updated.");
2929
2930                 if (!m_ipcModule.sendToClients(notification, clients, clientCount))
2931                 {
2932                     LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
2933                 }
2934
2935                 m_ipcModule.destroyMessage(notification);
2936             }
2937         }
2938     }
2939     break;
2940     default:
2941         LOG_INFO("GenericCommunicator", "Unknown notification found in queue.");
2942         break;
2943     }
2944 }
2945
2946 HealthCondition GenericCommunicator::getHealth()
2947 {
2948     HealthCondition health = PluginBase::getHealth();
2949     if (0 != pthread_kill(mThreadId, 0))
2950     {
2951         health = HealthDead;
2952     }
2953     return health;
2954 }
2955
2956 void GenericCommunicator::SetOptimizationMode(t_ilm_message message)
2957 {
2958     t_ilm_message response;
2959     OptimizationType optimizationId;
2960     OptimizationModeType optimizationMode;
2961     unsigned int o;    
2962     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2963     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2964
2965     m_ipcModule.getUint(message,&o);
2966     optimizationId = (OptimizationType) o;
2967     m_ipcModule.getUint(message,&o);
2968     optimizationMode = (OptimizationModeType) o;
2969
2970     t_ilm_bool status = m_executor->execute(new SetOptimizationModeCommand(clientPid, optimizationId, optimizationMode));
2971     if (status)
2972     {
2973         response = m_ipcModule.createResponse(message);       
2974     }
2975     else
2976     {
2977         response = m_ipcModule.createErrorResponse(message);
2978         m_ipcModule.appendString(response,RESOURCE_NOT_FOUND);
2979     }
2980     m_ipcModule.sendToClients(response,&clientHandle,1);
2981     m_ipcModule.destroyMessage(response);
2982 }
2983
2984 void GenericCommunicator::GetOptimizationMode(t_ilm_message message)
2985 {
2986     t_ilm_message response;
2987     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2988     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2989     OptimizationType optimizationId;
2990     OptimizationModeType optimizationMode;
2991     unsigned int o;
2992
2993     m_ipcModule.getUint(message,&o);
2994     optimizationId = (OptimizationType)o;
2995
2996     t_ilm_bool status = m_executor->execute(new GetOptimizationModeCommand(clientPid, optimizationId, &optimizationMode));
2997     if (status)
2998     {
2999         
3000         response = m_ipcModule.createResponse(message);
3001         m_ipcModule.appendUint(response,(unsigned int)optimizationMode);
3002     }
3003     else
3004     {
3005         response = m_ipcModule.createErrorResponse(message);
3006         m_ipcModule.appendString(response,RESOURCE_NOT_FOUND);
3007     }
3008     m_ipcModule.sendToClients(response,&clientHandle,1);
3009     m_ipcModule.destroyMessage(response);
3010
3011 }
3012
3013 extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor)
3014 {
3015     return new GenericCommunicator(executor);
3016 }
3017
3018 extern "C" void destroyGenericCommunicator(GenericCommunicator* p)
3019 {
3020     delete p;
3021 }
3022