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