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