LayerManagement: fixed warnings detected by style guide check scripts
[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     // First of all create the surface
724     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
725
726     // after that apply the native content
727     status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
728
729     if (status)
730     {
731         response = m_ipcModule.createResponse(message);
732         m_ipcModule.appendUint(response, id);
733     }
734     else
735     {
736         response = m_ipcModule.createErrorResponse(message);
737         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
738     }
739
740     m_ipcModule.sendToClients(response, &clientHandle, 1);
741     m_ipcModule.destroyMessage(response);
742 }
743
744 void GenericCommunicator::CreateSurfaceFromId(t_ilm_message message)
745 {
746     t_ilm_message response;
747     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
748     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
749     uint handle = 0;
750     uint width = 0;
751     uint height = 0;
752     uint pixelformat = 0;
753     PixelFormat pf = PIXELFORMAT_UNKNOWN;
754     uint id = 0;
755
756     m_ipcModule.getUint(message, &handle);
757     m_ipcModule.getUint(message, &width);
758     m_ipcModule.getUint(message, &height);
759     m_ipcModule.getUint(message, &pixelformat);
760     m_ipcModule.getUint(message, &id);
761
762     pf = (PixelFormat) pixelformat;
763
764     // First of all create the surface
765     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
766
767     // after that apply the native content
768     status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
769
770     if (status)
771     {
772         response = m_ipcModule.createResponse(message);
773         m_ipcModule.appendUint(response, id);
774     }
775     else
776     {
777         response = m_ipcModule.createErrorResponse(message);
778         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
779     }
780
781     m_ipcModule.sendToClients(response, &clientHandle, 1);
782     m_ipcModule.destroyMessage(response);
783 }
784
785 void GenericCommunicator::InitializeSurface(t_ilm_message message)
786 {
787     t_ilm_message response;
788     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
789     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
790     uint id = GraphicalObject::INVALID_ID;
791
792     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
793     if (status)
794     {
795         response = m_ipcModule.createResponse(message);
796         m_ipcModule.appendUint(response, id);
797     }
798     else
799     {
800         response = m_ipcModule.createErrorResponse(message);
801         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
802     }
803
804     m_ipcModule.sendToClients(response, &clientHandle, 1);
805     m_ipcModule.destroyMessage(response);
806 }
807
808 void GenericCommunicator::InitializeSurfaceFromId(t_ilm_message message)
809 {
810     t_ilm_message response;
811     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
812     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
813     uint id = 0;
814     m_ipcModule.getUint(message, &id);
815     t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
816     if (status)
817     {
818         response = m_ipcModule.createResponse(message);
819         m_ipcModule.appendUint(response, id);
820     }
821     else
822     {
823         response = m_ipcModule.createErrorResponse(message);
824         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
825     }
826
827     m_ipcModule.sendToClients(response, &clientHandle, 1);
828     m_ipcModule.destroyMessage(response);
829 }
830
831 void GenericCommunicator::SetSurfaceNativeContent(t_ilm_message message)
832 {
833     t_ilm_message response;
834     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
835     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
836     uint id = 0;
837     uint handle = 0;
838     uint width = 0;
839     uint height = 0;
840     uint pixelformat = 0;
841     PixelFormat pf = PIXELFORMAT_UNKNOWN;
842
843     m_ipcModule.getUint(message, &id);
844     m_ipcModule.getUint(message, &handle);
845     m_ipcModule.getUint(message, &width);
846     m_ipcModule.getUint(message, &height);
847     m_ipcModule.getUint(message, &pixelformat);
848
849     pf = (PixelFormat) pixelformat;
850
851     t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
852     if (status)
853     {
854         response = m_ipcModule.createResponse(message);
855     }
856     else
857     {
858         response = m_ipcModule.createErrorResponse(message);
859         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
860     }
861
862     m_ipcModule.sendToClients(response, &clientHandle, 1);
863     m_ipcModule.destroyMessage(response);
864 }
865
866 void GenericCommunicator::RemoveSurfaceNativeContent(t_ilm_message message)
867 {
868     t_ilm_message response;
869     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
870     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
871     uint id = 0;
872     m_ipcModule.getUint(message, &id);
873
874     t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(clientPid, id));
875     if (status)
876     {
877         response = m_ipcModule.createResponse(message);
878     }
879     else
880     {
881         response = m_ipcModule.createErrorResponse(message);
882         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
883     }
884
885     m_ipcModule.sendToClients(response, &clientHandle, 1);
886     m_ipcModule.destroyMessage(response);
887 }
888
889 void GenericCommunicator::RemoveSurface(t_ilm_message message)
890 {
891     t_ilm_message response;
892     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
893     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
894     uint param = 0;
895     m_ipcModule.getUint(message, &param);
896     t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(clientPid, param));
897     if (status)
898     {
899         response = m_ipcModule.createResponse(message);
900     }
901     else
902     {
903         response = m_ipcModule.createErrorResponse(message);
904         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
905     }
906
907     m_ipcModule.sendToClients(response, &clientHandle, 1);
908     m_ipcModule.destroyMessage(response);
909 }
910
911 void GenericCommunicator::CreateLayer(t_ilm_message message)
912 {
913     t_ilm_message response;
914     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
915     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
916     uint id = GraphicalObject::INVALID_ID;
917     // use resolution of default screen as default width and height of layers
918     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
919     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
920     if (status)
921     {
922         response = m_ipcModule.createResponse(message);
923         m_ipcModule.appendUint(response, id);
924     }
925     else
926     {
927         response = m_ipcModule.createErrorResponse(message);
928         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
929     }
930
931     m_ipcModule.sendToClients(response, &clientHandle, 1);
932     m_ipcModule.destroyMessage(response);
933 }
934
935 void GenericCommunicator::CreateLayerFromId(t_ilm_message message)
936 {
937     t_ilm_message response;
938     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
939     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
940     uint id = GraphicalObject::INVALID_ID;
941
942     m_ipcModule.getUint(message, &id);
943     // use resolution of default screen as default width and height of layers
944     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
945     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
946     if (status)
947     {
948         response = m_ipcModule.createResponse(message);
949         m_ipcModule.appendUint(response, id);
950     }
951     else
952     {
953         response = m_ipcModule.createErrorResponse(message);
954         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
955     }
956
957     m_ipcModule.sendToClients(response, &clientHandle, 1);
958     m_ipcModule.destroyMessage(response);
959 }
960
961
962 void GenericCommunicator::CreateLayerWithDimension(t_ilm_message message)
963 {
964     t_ilm_message response;
965     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
966     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
967     uint width = 0;
968     m_ipcModule.getUint(message, &width);
969     uint height = 0;
970     m_ipcModule.getUint(message, &height);
971
972     uint id = GraphicalObject::INVALID_ID;
973     t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
974     if (status)
975     {
976         response = m_ipcModule.createResponse(message);
977         m_ipcModule.appendUint(response, id);
978     }
979     else
980     {
981         response = m_ipcModule.createErrorResponse(message);
982         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
983     }
984
985     m_ipcModule.sendToClients(response, &clientHandle, 1);
986     m_ipcModule.destroyMessage(response);
987 }
988
989 void GenericCommunicator::CreateLayerFromIdWithDimension(t_ilm_message message)
990 {
991     t_ilm_message response;
992     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
993     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
994     uint id = GraphicalObject::INVALID_ID;
995     uint width = 0;
996     uint height = 0;
997     t_ilm_bool status = ILM_FALSE;
998
999     m_ipcModule.getUint(message, &id);
1000     m_ipcModule.getUint(message, &width);
1001     m_ipcModule.getUint(message, &height);
1002
1003     status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
1004     if (status)
1005     {
1006         response = m_ipcModule.createResponse(message);
1007         m_ipcModule.appendUint(response, id);
1008     }
1009     else
1010     {
1011         response = m_ipcModule.createErrorResponse(message);
1012         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
1013     }
1014
1015     m_ipcModule.sendToClients(response, &clientHandle, 1);
1016     m_ipcModule.destroyMessage(response);
1017 }
1018
1019 void GenericCommunicator::RemoveLayer(t_ilm_message message)
1020 {
1021     t_ilm_message response;
1022     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1023     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1024     uint param = 0;
1025     m_ipcModule.getUint(message, &param);
1026     t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(clientPid, param));
1027     if (status)
1028     {
1029         response = m_ipcModule.createResponse(message);
1030     }
1031     else
1032     {
1033         response = m_ipcModule.createErrorResponse(message);
1034         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1035     }
1036
1037     m_ipcModule.sendToClients(response, &clientHandle, 1);
1038     m_ipcModule.destroyMessage(response);
1039 }
1040
1041 void GenericCommunicator::AddSurfaceToLayer(t_ilm_message message)
1042 {
1043     t_ilm_message response;
1044     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1045     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1046     uint surfaceid = 0;
1047     uint layer = 0;
1048
1049     m_ipcModule.getUint(message, &surfaceid);
1050     m_ipcModule.getUint(message, &layer);
1051
1052     t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(clientPid, layer, surfaceid));
1053     if (status)
1054     {
1055         response = m_ipcModule.createResponse(message);
1056     }
1057     else
1058     {
1059         response = m_ipcModule.createErrorResponse(message);
1060         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
1061     }
1062
1063     m_ipcModule.sendToClients(response, &clientHandle, 1);
1064     m_ipcModule.destroyMessage(response);
1065 }
1066
1067 void GenericCommunicator::RemoveSurfaceFromLayer(t_ilm_message message)
1068 {
1069     t_ilm_message response;
1070     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1071     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1072     uint surfaceid = 0;
1073     uint layerid = 0;
1074     m_ipcModule.getUint(message, &surfaceid);
1075     m_ipcModule.getUint(message, &layerid);
1076
1077     t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(clientPid, layerid, surfaceid));
1078     if (status)
1079     {
1080         response = m_ipcModule.createResponse(message);
1081     }
1082     else
1083     {
1084         response = m_ipcModule.createErrorResponse(message);
1085         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1086     }
1087
1088     m_ipcModule.sendToClients(response, &clientHandle, 1);
1089     m_ipcModule.destroyMessage(response);
1090 }
1091
1092 void GenericCommunicator::SetSurfaceSourceRegion(t_ilm_message message)
1093 {
1094     t_ilm_message response;
1095     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1096     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1097     uint id = 0;
1098     uint x = 0;
1099     uint y = 0;
1100     uint width = 0;
1101     uint height = 0;
1102
1103     m_ipcModule.getUint(message, &id);
1104     m_ipcModule.getUint(message, &x);
1105     m_ipcModule.getUint(message, &y);
1106     m_ipcModule.getUint(message, &width);
1107     m_ipcModule.getUint(message, &height);
1108
1109     t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(clientPid, id, x, y, width, height));
1110     if (status)
1111     {
1112         response = m_ipcModule.createResponse(message);
1113     }
1114     else
1115     {
1116         response = m_ipcModule.createErrorResponse(message);
1117         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1118     }
1119
1120     m_ipcModule.sendToClients(response, &clientHandle, 1);
1121     m_ipcModule.destroyMessage(response);
1122 }
1123
1124 void GenericCommunicator::SetLayerSourceRegion(t_ilm_message message)
1125 {
1126     t_ilm_message response;
1127     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1128     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1129     uint id = 0;
1130     uint x = 0;
1131     uint y = 0;
1132     uint width = 0;
1133     uint height = 0;
1134
1135     m_ipcModule.getUint(message, &id);
1136     m_ipcModule.getUint(message, &x);
1137     m_ipcModule.getUint(message, &y);
1138     m_ipcModule.getUint(message, &width);
1139     m_ipcModule.getUint(message, &height);
1140
1141     t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(clientPid, id, x, y, width, height));
1142     if (status)
1143     {
1144         response = m_ipcModule.createResponse(message);
1145     }
1146     else
1147     {
1148         response = m_ipcModule.createErrorResponse(message);
1149         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1150     }
1151
1152     m_ipcModule.sendToClients(response, &clientHandle, 1);
1153     m_ipcModule.destroyMessage(response);
1154 }
1155
1156 void GenericCommunicator::SetSurfaceDestinationRegion(t_ilm_message message)
1157 {
1158     t_ilm_message response;
1159     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1160     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1161     uint id = 0;
1162     uint x = 0;
1163     uint y = 0;
1164     uint width = 0;
1165     uint height = 0;
1166
1167     m_ipcModule.getUint(message, &id);
1168     m_ipcModule.getUint(message, &x);
1169     m_ipcModule.getUint(message, &y);
1170     m_ipcModule.getUint(message, &width);
1171     m_ipcModule.getUint(message, &height);
1172
1173     t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
1174     if (status)
1175     {
1176         response = m_ipcModule.createResponse(message);
1177     }
1178     else
1179     {
1180         response = m_ipcModule.createErrorResponse(message);
1181         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1182     }
1183
1184     m_ipcModule.sendToClients(response, &clientHandle, 1);
1185     m_ipcModule.destroyMessage(response);
1186 }
1187
1188 void GenericCommunicator::SetSurfacePosition(t_ilm_message message)
1189 {
1190     t_ilm_message response;
1191     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1192     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1193     uint id = 0;
1194     uint x = 0;
1195     uint y = 0;
1196
1197     m_ipcModule.getUint(message, &id);
1198     m_ipcModule.getUint(message, &x);
1199     m_ipcModule.getUint(message, &y);
1200
1201     t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(clientPid, id, x, y));
1202     if (status)
1203     {
1204         response = m_ipcModule.createResponse(message);
1205     }
1206     else
1207     {
1208         response = m_ipcModule.createErrorResponse(message);
1209         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1210     }
1211
1212     m_ipcModule.sendToClients(response, &clientHandle, 1);
1213     m_ipcModule.destroyMessage(response);
1214 }
1215
1216 void GenericCommunicator::GetSurfacePosition(t_ilm_message message)
1217 {
1218     t_ilm_message response;
1219     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1220     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1221     uint id = 0;
1222     uint x = 0;
1223     uint y = 0;
1224
1225     m_ipcModule.getUint(message, &id);
1226
1227     t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(clientPid, id, &x, &y));
1228     if (status)
1229     {
1230         response = m_ipcModule.createResponse(message);
1231         m_ipcModule.appendUint(response, x);
1232         m_ipcModule.appendUint(response, y);
1233     }
1234     else
1235     {
1236         response = m_ipcModule.createErrorResponse(message);
1237         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1238     }
1239
1240     m_ipcModule.sendToClients(response, &clientHandle, 1);
1241     m_ipcModule.destroyMessage(response);
1242 }
1243
1244 void GenericCommunicator::SetSurfaceDimension(t_ilm_message message)
1245 {
1246     t_ilm_message response;
1247     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1248     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1249     uint id = 0;
1250     uint width = 0;
1251     uint height = 0;
1252
1253     m_ipcModule.getUint(message, &id);
1254     m_ipcModule.getUint(message, &width);
1255     m_ipcModule.getUint(message, &height);
1256
1257     t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(clientPid, id, width, height));
1258     if (status)
1259     {
1260         response = m_ipcModule.createResponse(message);
1261     }
1262     else
1263     {
1264         response = m_ipcModule.createErrorResponse(message);
1265         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1266     }
1267
1268     m_ipcModule.sendToClients(response, &clientHandle, 1);
1269     m_ipcModule.destroyMessage(response);
1270 }
1271
1272 void GenericCommunicator::SetLayerDestinationRegion(t_ilm_message message)
1273 {
1274     t_ilm_message response;
1275     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1276     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1277     uint id = 0;
1278     uint x = 0;
1279     uint y = 0;
1280     uint width = 0;
1281     uint height = 0;
1282
1283     m_ipcModule.getUint(message, &id);
1284     m_ipcModule.getUint(message, &x);
1285     m_ipcModule.getUint(message, &y);
1286     m_ipcModule.getUint(message, &width);
1287     m_ipcModule.getUint(message, &height);
1288
1289     t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
1290     if (status)
1291     {
1292         response = m_ipcModule.createResponse(message);
1293     }
1294     else
1295     {
1296         response = m_ipcModule.createErrorResponse(message);
1297         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1298     }
1299
1300     m_ipcModule.sendToClients(response, &clientHandle, 1);
1301     m_ipcModule.destroyMessage(response);
1302 }
1303
1304 void GenericCommunicator::SetLayerPosition(t_ilm_message message)
1305 {
1306     t_ilm_message response;
1307     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1308     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1309     uint id = 0;
1310     uint x = 0;
1311     uint y = 0;
1312
1313     m_ipcModule.getUint(message, &id);
1314     m_ipcModule.getUint(message, &x);
1315     m_ipcModule.getUint(message, &y);
1316
1317     t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(clientPid, id, x, y));
1318     if (status)
1319     {
1320         response = m_ipcModule.createResponse(message);
1321     }
1322     else
1323     {
1324         response = m_ipcModule.createErrorResponse(message);
1325         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1326     }
1327
1328     m_ipcModule.sendToClients(response, &clientHandle, 1);
1329     m_ipcModule.destroyMessage(response);
1330 }
1331
1332 void GenericCommunicator::GetLayerPosition(t_ilm_message message)
1333 {
1334     t_ilm_message response;
1335     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1336     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1337     uint id = 0;
1338     uint x = 0;
1339     uint y = 0;
1340
1341     m_ipcModule.getUint(message, &id);
1342
1343     t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(clientPid, id, &x, &y));
1344     if (status)
1345     {
1346         response = m_ipcModule.createResponse(message);
1347         m_ipcModule.appendUint(response, x);
1348         m_ipcModule.appendUint(response, y);
1349     }
1350     else
1351     {
1352         response = m_ipcModule.createErrorResponse(message);
1353         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1354     }
1355
1356     m_ipcModule.sendToClients(response, &clientHandle, 1);
1357     m_ipcModule.destroyMessage(response);
1358 }
1359
1360 void GenericCommunicator::SetLayerDimension(t_ilm_message message)
1361 {
1362     t_ilm_message response;
1363     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1364     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1365     uint id = 0;
1366     uint width = 0;
1367     uint height = 0;
1368
1369     m_ipcModule.getUint(message, &id);
1370     m_ipcModule.getUint(message, &width);
1371     m_ipcModule.getUint(message, &height);
1372
1373     t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(clientPid, id, width, height));
1374     if (status)
1375     {
1376         response = m_ipcModule.createResponse(message);
1377     }
1378     else
1379     {
1380         response = m_ipcModule.createErrorResponse(message);
1381         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1382     }
1383
1384     m_ipcModule.sendToClients(response, &clientHandle, 1);
1385     m_ipcModule.destroyMessage(response);
1386 }
1387
1388 void GenericCommunicator::GetLayerDimension(t_ilm_message message)
1389 {
1390     t_ilm_message response;
1391     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1392     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1393     uint id = 0;
1394     uint width = 0;
1395     uint height = 0;
1396
1397     m_ipcModule.getUint(message, &id);
1398
1399     t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(clientPid, id, &width, &height));
1400     if (status)
1401     {
1402         response = m_ipcModule.createResponse(message);
1403         m_ipcModule.appendUint(response, width);
1404         m_ipcModule.appendUint(response, height);
1405     }
1406     else
1407     {
1408         response = m_ipcModule.createErrorResponse(message);
1409         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1410     }
1411
1412     m_ipcModule.sendToClients(response, &clientHandle, 1);
1413     m_ipcModule.destroyMessage(response);
1414 }
1415
1416 void GenericCommunicator::GetSurfaceDimension(t_ilm_message message)
1417 {
1418     t_ilm_message response;
1419     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1420     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1421     uint id = 0;
1422     uint width = 0;
1423     uint height = 0;
1424
1425     m_ipcModule.getUint(message, &id);
1426
1427     t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(clientPid, id, &width, &height));
1428     if (status)
1429     {
1430         response = m_ipcModule.createResponse(message);
1431         m_ipcModule.appendUint(response, width);
1432         m_ipcModule.appendUint(response, height);
1433     }
1434     else
1435     {
1436         response = m_ipcModule.createErrorResponse(message);
1437         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1438     }
1439
1440     m_ipcModule.sendToClients(response, &clientHandle, 1);
1441     m_ipcModule.destroyMessage(response);
1442 }
1443
1444 void GenericCommunicator::SetSurfaceOpacity(t_ilm_message message)
1445 {
1446     t_ilm_message response;
1447     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1448     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1449     uint id = 0;
1450     double param = 0.0;
1451
1452     m_ipcModule.getUint(message, &id);
1453     m_ipcModule.getDouble(message, &param);
1454
1455     t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(clientPid, id, param));
1456     if (status)
1457     {
1458         response = m_ipcModule.createResponse(message);
1459     }
1460     else
1461     {
1462         response = m_ipcModule.createErrorResponse(message);
1463         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1464     }
1465
1466     m_ipcModule.sendToClients(response, &clientHandle, 1);
1467     m_ipcModule.destroyMessage(response);
1468 }
1469
1470 void GenericCommunicator::SetLayerOpacity(t_ilm_message message)
1471 {
1472     t_ilm_message response;
1473     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1474     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1475     uint id = 0;
1476     double param = 0.0;
1477
1478     m_ipcModule.getUint(message, &id);
1479     m_ipcModule.getDouble(message, &param);
1480
1481     t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(clientPid, id, param));
1482     if (status)
1483     {
1484         response = m_ipcModule.createResponse(message);
1485     }
1486     else
1487     {
1488         response = m_ipcModule.createErrorResponse(message);
1489         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1490     }
1491
1492     m_ipcModule.sendToClients(response, &clientHandle, 1);
1493     m_ipcModule.destroyMessage(response);
1494 }
1495
1496 void GenericCommunicator::GetSurfaceOpacity(t_ilm_message message)
1497 {
1498     t_ilm_message response;
1499     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1500     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1501     uint id = 0;
1502     double param = 0.0;
1503
1504     m_ipcModule.getUint(message, &id);
1505
1506     t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(clientPid, id, &param));
1507     if (status)
1508     {
1509         response = m_ipcModule.createResponse(message);
1510         m_ipcModule.appendDouble(response, param);
1511     }
1512     else
1513     {
1514         response = m_ipcModule.createErrorResponse(message);
1515         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1516     }
1517
1518     m_ipcModule.sendToClients(response, &clientHandle, 1);
1519     m_ipcModule.destroyMessage(response);
1520 }
1521
1522 void GenericCommunicator::GetLayerOpacity(t_ilm_message message)
1523 {
1524     t_ilm_message response;
1525     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1526     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1527     uint id = 0;
1528     double param = 0.0;
1529
1530     m_ipcModule.getUint(message, &id);
1531
1532     t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(clientPid, id, &param));
1533     if (status)
1534     {
1535         response = m_ipcModule.createResponse(message);
1536         m_ipcModule.appendDouble(response, param);
1537     }
1538     else
1539     {
1540         response = m_ipcModule.createErrorResponse(message);
1541         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1542     }
1543
1544     m_ipcModule.sendToClients(response, &clientHandle, 1);
1545     m_ipcModule.destroyMessage(response);
1546 }
1547
1548 void GenericCommunicator::SetSurfaceOrientation(t_ilm_message message)
1549 {
1550     t_ilm_message response;
1551     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1552     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1553     uint id = 0;
1554     uint param = 0;
1555     OrientationType o = Zero;
1556
1557     m_ipcModule.getUint(message, &id);
1558     m_ipcModule.getUint(message, &param);
1559
1560     o = (OrientationType) param;
1561
1562     t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(clientPid, id, o));
1563     if (status)
1564     {
1565         response = m_ipcModule.createResponse(message);
1566     }
1567     else
1568     {
1569         response = m_ipcModule.createErrorResponse(message);
1570         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1571     }
1572
1573     m_ipcModule.sendToClients(response, &clientHandle, 1);
1574     m_ipcModule.destroyMessage(response);
1575 }
1576
1577 void GenericCommunicator::GetSurfaceOrientation(t_ilm_message message)
1578 {
1579     t_ilm_message response;
1580     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1581     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1582     uint id = 0;
1583     OrientationType o;
1584
1585     m_ipcModule.getUint(message, &id);
1586
1587     t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(clientPid, id, &o));
1588     if (status)
1589     {
1590         response = m_ipcModule.createResponse(message);
1591         m_ipcModule.appendUint(response, o);
1592     }
1593     else
1594     {
1595         response = m_ipcModule.createErrorResponse(message);
1596         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1597     }
1598
1599     m_ipcModule.sendToClients(response, &clientHandle, 1);
1600     m_ipcModule.destroyMessage(response);
1601 }
1602
1603 void GenericCommunicator::SetLayerOrientation(t_ilm_message message)
1604 {
1605     t_ilm_message response;
1606     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1607     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1608     uint id = 0;
1609     uint param = 0;
1610     OrientationType o = Zero;
1611
1612     m_ipcModule.getUint(message, &id);
1613     m_ipcModule.getUint(message, &param);
1614
1615     o = (OrientationType) param;
1616
1617     t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(clientPid, id, o));
1618     if (status)
1619     {
1620         response = m_ipcModule.createResponse(message);
1621     }
1622     else
1623     {
1624         response = m_ipcModule.createErrorResponse(message);
1625         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1626     }
1627
1628     m_ipcModule.sendToClients(response, &clientHandle, 1);
1629     m_ipcModule.destroyMessage(response);
1630 }
1631
1632 void GenericCommunicator::GetLayerOrientation(t_ilm_message message)
1633 {
1634     t_ilm_message response;
1635     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1636     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1637     uint id = 0;
1638     OrientationType o;
1639
1640     m_ipcModule.getUint(message, &id);
1641
1642     t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(clientPid, id, &o));
1643     if (status)
1644     {
1645         response = m_ipcModule.createResponse(message);
1646         m_ipcModule.appendUint(response, o);
1647     }
1648     else
1649     {
1650         response = m_ipcModule.createErrorResponse(message);
1651         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1652     }
1653
1654     m_ipcModule.sendToClients(response, &clientHandle, 1);
1655     m_ipcModule.destroyMessage(response);
1656 }
1657
1658 void GenericCommunicator::GetSurfacePixelformat(t_ilm_message message)
1659 {
1660     t_ilm_message response;
1661     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1662     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1663     uint id = 0;
1664     PixelFormat pixelFormat;
1665
1666     m_ipcModule.getUint(message, &id);
1667
1668     t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(clientPid, id, &pixelFormat));
1669     if (status)
1670     {
1671         response = m_ipcModule.createResponse(message);
1672         m_ipcModule.appendUint(response, pixelFormat);
1673     }
1674     else
1675     {
1676         response = m_ipcModule.createErrorResponse(message);
1677         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1678     }
1679
1680     m_ipcModule.sendToClients(response, &clientHandle, 1);
1681     m_ipcModule.destroyMessage(response);
1682 }
1683
1684 void GenericCommunicator::SetSurfaceVisibility(t_ilm_message message)
1685 {
1686     t_ilm_message response;
1687     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1688     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1689     uint surfaceid = 0;
1690     t_ilm_bool newVis = ILM_FALSE;
1691
1692     m_ipcModule.getUint(message, &surfaceid);
1693     m_ipcModule.getBool(message, &newVis);
1694
1695     t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(clientPid, surfaceid, newVis));
1696     if (status)
1697     {
1698         response = m_ipcModule.createResponse(message);
1699     }
1700     else
1701     {
1702         response = m_ipcModule.createErrorResponse(message);
1703         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1704     }
1705
1706     m_ipcModule.sendToClients(response, &clientHandle, 1);
1707     m_ipcModule.destroyMessage(response);
1708 }
1709
1710 void GenericCommunicator::SetLayerVisibility(t_ilm_message message)
1711 {
1712     t_ilm_message response;
1713     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1714     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1715     uint layerid = 0;
1716     t_ilm_bool myparam = ILM_FALSE;
1717
1718     m_ipcModule.getUint(message, &layerid);
1719     m_ipcModule.getBool(message, &myparam);
1720
1721     t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(clientPid, layerid, myparam));
1722     if (status)
1723     {
1724         response = m_ipcModule.createResponse(message);
1725     }
1726     else
1727     {
1728         response = m_ipcModule.createErrorResponse(message);
1729         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1730     }
1731
1732     m_ipcModule.sendToClients(response, &clientHandle, 1);
1733     m_ipcModule.destroyMessage(response);
1734 }
1735
1736 void GenericCommunicator::GetSurfaceVisibility(t_ilm_message message)
1737 {
1738     t_ilm_message response;
1739     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1740     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1741     uint id = 0;
1742     bool visibility;
1743
1744     m_ipcModule.getUint(message, &id);
1745
1746     t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(clientPid, id, &visibility));
1747     if (status)
1748     {
1749         response = m_ipcModule.createResponse(message);
1750         m_ipcModule.appendBool(response, visibility);
1751     }
1752     else
1753     {
1754         response = m_ipcModule.createErrorResponse(message);
1755         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1756     }
1757
1758     m_ipcModule.sendToClients(response, &clientHandle, 1);
1759     m_ipcModule.destroyMessage(response);
1760 }
1761
1762 void GenericCommunicator::GetLayerVisibility(t_ilm_message message)
1763 {
1764     t_ilm_message response;
1765     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1766     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1767     uint id = 0;
1768     bool visibility;
1769
1770     m_ipcModule.getUint(message, &id);
1771
1772     t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(clientPid, id, &visibility));
1773     if (status)
1774     {
1775         response = m_ipcModule.createResponse(message);
1776         m_ipcModule.appendBool(response, visibility);
1777     }
1778     else
1779     {
1780         response = m_ipcModule.createErrorResponse(message);
1781         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1782     }
1783
1784     m_ipcModule.sendToClients(response, &clientHandle, 1);
1785     m_ipcModule.destroyMessage(response);
1786 }
1787
1788 void GenericCommunicator::SetRenderOrderOfLayers(t_ilm_message message)
1789 {
1790     t_ilm_message response;
1791     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1792     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1793     uint* array = NULL;
1794     int length = 0;
1795     uint screenID = 0;
1796
1797     m_ipcModule.getUintArray(message, &array, &length);
1798     m_ipcModule.getUint(message, &screenID);
1799
1800     t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(clientPid, screenID, array, length));
1801     if (status)
1802     {
1803         response = m_ipcModule.createResponse(message);
1804     }
1805     else
1806     {
1807         response = m_ipcModule.createErrorResponse(message);
1808         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1809     }
1810
1811     m_ipcModule.sendToClients(response, &clientHandle, 1);
1812     m_ipcModule.destroyMessage(response);
1813 }
1814
1815 void GenericCommunicator::SetSurfaceRenderOrderWithinLayer(t_ilm_message message)
1816 {
1817     t_ilm_message response;
1818     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1819     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1820     uint* array = NULL;
1821     int length = 0;
1822     uint layerid = 0;
1823
1824     m_ipcModule.getUint(message, &layerid);
1825     m_ipcModule.getUintArray(message, &array, &length);
1826
1827     t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(clientPid, layerid, array, length));
1828     if (status)
1829     {
1830         response = m_ipcModule.createResponse(message);
1831     }
1832     else
1833     {
1834         response = m_ipcModule.createErrorResponse(message);
1835         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1836     }
1837
1838     m_ipcModule.sendToClients(response, &clientHandle, 1);
1839     m_ipcModule.destroyMessage(response);
1840 }
1841
1842 void GenericCommunicator::GetLayerType(t_ilm_message message)
1843 {
1844     t_ilm_message response;
1845     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1846     uint id = 0;
1847     m_ipcModule.getUint(message, &id);
1848
1849     Layer* layer = m_executor->getScene()->getLayer(id);
1850     if (layer)
1851     {
1852         response = m_ipcModule.createResponse(message);
1853         m_ipcModule.appendUint(response, layer->getLayerType());
1854     }
1855     else
1856     {
1857         response = m_ipcModule.createErrorResponse(message);
1858         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1859     }
1860
1861     m_ipcModule.sendToClients(response, &clientHandle, 1);
1862     m_ipcModule.destroyMessage(response);
1863 }
1864
1865 void GenericCommunicator::GetLayertypeCapabilities(t_ilm_message message)
1866 {
1867     t_ilm_message response;
1868     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1869     uint id = 0;
1870     LayerType type = Unknown;
1871
1872     m_ipcModule.getUint(message, &id);
1873
1874     type = (LayerType) id;
1875
1876     uint capabilities = m_executor->getLayerTypeCapabilities(type);
1877     response = m_ipcModule.createResponse(message);
1878     m_ipcModule.appendUint(response, capabilities);
1879     m_ipcModule.sendToClients(response, &clientHandle, 1);
1880     m_ipcModule.destroyMessage(response);
1881 }
1882
1883 void GenericCommunicator::GetLayerCapabilities(t_ilm_message message)
1884 {
1885     t_ilm_message response;
1886     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1887     uint id = 0;
1888     m_ipcModule.getUint(message, &id);
1889
1890     Layer* layer = m_executor->getScene()->getLayer(id);
1891     if (layer)
1892     {
1893         response = m_ipcModule.createResponse(message);
1894         m_ipcModule.appendUint(response, layer->getCapabilities());
1895     }
1896     else
1897     {
1898         response = m_ipcModule.createErrorResponse(message);
1899         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1900     }
1901
1902     m_ipcModule.sendToClients(response, &clientHandle, 1);
1903     m_ipcModule.destroyMessage(response);
1904 }
1905
1906 void GenericCommunicator::FadeIn(t_ilm_message message)
1907 {
1908     t_ilm_message response;
1909     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1910     response = m_ipcModule.createErrorResponse(message);
1911     m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
1912     m_ipcModule.sendToClients(response, &clientHandle, 1);
1913     m_ipcModule.destroyMessage(response);
1914 }
1915
1916 void GenericCommunicator::SynchronizedFade(t_ilm_message message)
1917 {
1918     t_ilm_message response;
1919     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1920     response = m_ipcModule.createErrorResponse(message);
1921     m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
1922     m_ipcModule.sendToClients(response, &clientHandle, 1);
1923     m_ipcModule.destroyMessage(response);
1924 }
1925
1926 void GenericCommunicator::FadeOut(t_ilm_message message)
1927 {
1928     t_ilm_message response;
1929     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1930     response = m_ipcModule.createErrorResponse(message);
1931     m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
1932     m_ipcModule.sendToClients(response, &clientHandle, 1);
1933     m_ipcModule.destroyMessage(response);
1934 }
1935
1936 void GenericCommunicator::Exit(t_ilm_message message)
1937 {
1938     t_ilm_message response;
1939     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1940     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1941     t_ilm_bool status = m_executor->execute(new ExitCommand(clientPid));
1942     if (status)
1943     {
1944         response = m_ipcModule.createResponse(message);
1945     }
1946     else
1947     {
1948         response = m_ipcModule.createErrorResponse(message);
1949         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
1950     }
1951
1952     m_ipcModule.sendToClients(response, &clientHandle, 1);
1953     m_ipcModule.destroyMessage(response);
1954 }
1955
1956 void GenericCommunicator::CommitChanges(t_ilm_message message)
1957 {
1958     t_ilm_message response;
1959     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1960     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1961     t_ilm_bool status = m_executor->execute(new CommitCommand(clientPid));
1962     if (status)
1963     {
1964         response = m_ipcModule.createResponse(message);
1965     }
1966     else
1967     {
1968         response = m_ipcModule.createErrorResponse(message);
1969         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
1970     }
1971
1972     m_ipcModule.sendToClients(response, &clientHandle, 1);
1973     m_ipcModule.destroyMessage(response);
1974 }
1975
1976 void GenericCommunicator::CreateShader(t_ilm_message message)
1977 {
1978     t_ilm_message response;
1979     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
1980     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
1981     char vertname[1024];
1982     char fragname[1024];
1983     uint id = 0;
1984
1985     m_ipcModule.getString(message, vertname);
1986     m_ipcModule.getString(message, fragname);
1987
1988     t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(clientPid, vertname, fragname, &id));
1989     if (status)
1990     {
1991         response = m_ipcModule.createResponse(message);
1992         m_ipcModule.appendUint(response, id);
1993     }
1994     else
1995     {
1996         response = m_ipcModule.createErrorResponse(message);
1997         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
1998     }
1999
2000     m_ipcModule.sendToClients(response, &clientHandle, 1);
2001     m_ipcModule.destroyMessage(response);
2002 }
2003
2004 void GenericCommunicator::DestroyShader(t_ilm_message message)
2005 {
2006     t_ilm_message response;
2007     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2008     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2009     uint shaderid = 0;
2010
2011     m_ipcModule.getUint(message, &shaderid);
2012
2013     t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(clientPid, shaderid));
2014     if (status)
2015     {
2016         response = m_ipcModule.createResponse(message);
2017     }
2018     else
2019     {
2020         response = m_ipcModule.createErrorResponse(message);
2021         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2022     }
2023
2024     m_ipcModule.sendToClients(response, &clientHandle, 1);
2025     m_ipcModule.destroyMessage(response);
2026 }
2027
2028 void GenericCommunicator::SetShader(t_ilm_message message)
2029 {
2030     t_ilm_message response;
2031     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2032     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2033     uint surfaceId = 0;
2034     uint shaderid = 0;
2035
2036     m_ipcModule.getUint(message, &surfaceId);
2037     m_ipcModule.getUint(message, &shaderid);
2038
2039     t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(clientPid, surfaceId, shaderid));
2040     if (status)
2041     {
2042         response = m_ipcModule.createResponse(message);
2043     }
2044     else
2045     {
2046         response = m_ipcModule.createErrorResponse(message);
2047         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2048     }
2049
2050     m_ipcModule.sendToClients(response, &clientHandle, 1);
2051     m_ipcModule.destroyMessage(response);
2052 }
2053
2054 void GenericCommunicator::SetUniforms(t_ilm_message message)
2055 {
2056     t_ilm_message response;
2057     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2058     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2059     uint id = 0;
2060     std::vector<string> uniforms;
2061
2062     m_ipcModule.getUint(message, &id);
2063
2064     // TODO
2065     //m_ipcModule.getStringArray(&uniforms);
2066
2067     t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(clientPid, id, uniforms));
2068     if (status)
2069     {
2070         response = m_ipcModule.createResponse(message);
2071     }
2072     else
2073     {
2074         response = m_ipcModule.createErrorResponse(message);
2075         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2076     }
2077
2078     m_ipcModule.sendToClients(response, &clientHandle, 1);
2079     m_ipcModule.destroyMessage(response);
2080 }
2081
2082 void GenericCommunicator::SetKeyboardFocusOn(t_ilm_message message)
2083 {
2084     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2085     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2086     t_ilm_message response;
2087     uint surfaceId = 0;
2088
2089     m_ipcModule.getUint(message, &surfaceId);
2090
2091     t_ilm_bool status = m_executor->execute(new SurfaceSetKeyboardFocusCommand(clientPid, surfaceId));
2092     if (status)
2093     {
2094         response = m_ipcModule.createResponse(message);
2095     }
2096     else
2097     {
2098         response = m_ipcModule.createErrorResponse(message);
2099         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2100     }
2101
2102     m_ipcModule.sendToClients(response, &clientHandle, 1);
2103     m_ipcModule.destroyMessage(response);
2104 }
2105
2106
2107 void GenericCommunicator::GetKeyboardFocusSurfaceId(t_ilm_message message)
2108 {
2109     t_ilm_message response;
2110     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2111     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2112     uint surfaceId;
2113
2114     t_ilm_bool status = m_executor->execute(new SurfaceGetKeyboardFocusCommand(clientPid, &surfaceId));
2115     if (status)
2116     {
2117         response = m_ipcModule.createResponse(message);
2118         m_ipcModule.appendUint(response, surfaceId);
2119     }
2120     else
2121     {
2122         response = m_ipcModule.createErrorResponse(message);
2123         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2124     }
2125
2126     m_ipcModule.sendToClients(response, &clientHandle, 1);
2127     m_ipcModule.destroyMessage(response);
2128 }
2129
2130
2131 void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
2132 {
2133     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2134     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2135     t_ilm_message response;
2136     uint surfaceId = 0;
2137     uint udevices = 0;
2138     InputDevice devices;
2139     t_ilm_bool accept;
2140
2141     m_ipcModule.getUint(message, &surfaceId);
2142     m_ipcModule.getUint(message, &udevices);
2143     m_ipcModule.getBool(message, &accept);
2144
2145     devices = (InputDevice) udevices;
2146
2147     t_ilm_bool status = m_executor->execute(new SurfaceUpdateInputEventAcceptance(clientPid, surfaceId, devices, accept));
2148     if (status)
2149     {
2150         response = m_ipcModule.createResponse(message);
2151     }
2152     else
2153     {
2154         response = m_ipcModule.createErrorResponse(message);
2155         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2156     }
2157
2158     m_ipcModule.sendToClients(response, &clientHandle, 1);
2159     m_ipcModule.destroyMessage(response);
2160 }
2161
2162 void GenericCommunicator::SetSurfaceChromaKey(t_ilm_message message)
2163 {
2164     t_ilm_message response;
2165     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2166     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2167     uint* array = NULL;
2168     int length = 0;
2169     uint surfaceid = 0;
2170
2171     m_ipcModule.getUint(message, &surfaceid);
2172     m_ipcModule.getUintArray(message, &array, &length);
2173
2174     t_ilm_bool status = m_executor->execute(new SurfaceSetChromaKeyCommand(clientPid, surfaceid, array, length));
2175     if (status)
2176     {
2177         response = m_ipcModule.createResponse(message);
2178     }
2179     else
2180     {
2181         response = m_ipcModule.createErrorResponse(message);
2182         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2183     }
2184
2185     m_ipcModule.sendToClients(response, &clientHandle, 1);
2186     m_ipcModule.destroyMessage(response);
2187 }
2188
2189 void GenericCommunicator::SetLayerChromaKey(t_ilm_message message)
2190 {
2191     t_ilm_message response;
2192     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2193     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2194     uint* array = NULL;
2195     int length = 0;
2196     uint layerid = 0;
2197
2198     m_ipcModule.getUint(message, &layerid);
2199     m_ipcModule.getUintArray(message, &array, &length);
2200
2201     t_ilm_bool status = m_executor->execute(new LayerSetChromaKeyCommand(clientPid, layerid, array, length));
2202     if (status)
2203     {
2204         response = m_ipcModule.createResponse(message);
2205     }
2206     else
2207     {
2208         response = m_ipcModule.createErrorResponse(message);
2209         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2210     }
2211
2212     m_ipcModule.sendToClients(response, &clientHandle, 1);
2213     m_ipcModule.destroyMessage(response);
2214 }
2215
2216 void GenericCommunicator::LayerAddNotification(t_ilm_message message)
2217 {
2218     t_ilm_message response;
2219     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2220     uint layerid = 0;
2221
2222     m_ipcModule.getUint(message, &layerid);
2223
2224     Layer* layer = m_executor->getScene()->getLayer(layerid);
2225     if (layer)
2226     {
2227         layer->addNotification(clientHandle);
2228         response = m_ipcModule.createResponse(message);
2229     }
2230     else
2231     {
2232         response = m_ipcModule.createErrorResponse(message);
2233         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
2234     }
2235
2236     m_ipcModule.sendToClients(response, &clientHandle, 1);
2237     m_ipcModule.destroyMessage(response);
2238 }
2239
2240 void GenericCommunicator::SurfaceAddNotification(t_ilm_message message)
2241 {
2242     t_ilm_message response;
2243     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2244     uint surfaceid = 0;
2245
2246     m_ipcModule.getUint(message, &surfaceid);
2247
2248     Surface* surface = m_executor->getScene()->getSurface(surfaceid);
2249     if (surface)
2250     {
2251         surface->addNotification(clientHandle);
2252         response = m_ipcModule.createResponse(message);
2253     }
2254     else
2255     {
2256         response = m_ipcModule.createErrorResponse(message);
2257         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
2258     }
2259
2260     m_ipcModule.sendToClients(response, &clientHandle, 1);
2261     m_ipcModule.destroyMessage(response);
2262 }
2263
2264 void GenericCommunicator::LayerRemoveNotification(t_ilm_message message)
2265 {
2266     t_ilm_message response;
2267     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2268     uint layerid = 0;
2269
2270     m_ipcModule.getUint(message, &layerid);
2271
2272     Layer* layer = m_executor->getScene()->getLayer(layerid);
2273     if (layer)
2274     {
2275         layer->removeNotification(clientHandle);
2276         response = m_ipcModule.createResponse(message);
2277     }
2278     else
2279     {
2280         response = m_ipcModule.createErrorResponse(message);
2281         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
2282     }
2283
2284     m_ipcModule.sendToClients(response, &clientHandle, 1);
2285     m_ipcModule.destroyMessage(response);
2286 }
2287
2288 void GenericCommunicator::SurfaceRemoveNotification(t_ilm_message message)
2289 {
2290     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2291     t_ilm_message response;
2292     uint surfaceid = 0;
2293
2294     m_ipcModule.getUint(message, &surfaceid);
2295
2296     Surface* surface = m_executor->getScene()->getSurface(surfaceid);
2297     if (surface)
2298     {
2299         surface->removeNotification(clientHandle);
2300         response = m_ipcModule.createResponse(message);
2301     }
2302     else
2303     {
2304         response = m_ipcModule.createErrorResponse(message);
2305         m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
2306     }
2307
2308     m_ipcModule.sendToClients(response, &clientHandle, 1);
2309     m_ipcModule.destroyMessage(response);
2310 }
2311
2312 void GenericCommunicator::processNotificationQueue()
2313 {
2314     NotificationQueue& notificationQueue = m_executor->getClientNotificationQueue();
2315     NotificationQueue::iterator iter = notificationQueue.begin();
2316     NotificationQueue::iterator end = notificationQueue.end();
2317
2318     for (; iter != end; ++iter)
2319     {
2320         GraphicalObject* object = iter->first;
2321         t_ilm_notification_mask mask = iter->second;
2322         sendNotification(object, mask);
2323     }
2324     notificationQueue.clear();
2325 }
2326
2327 void GenericCommunicator::sendNotification(GraphicalObject* object, t_ilm_notification_mask mask)
2328 {
2329     switch (object->type)
2330     {
2331     case TypeLayer:
2332         {
2333             Layer* layer = static_cast<Layer*>(object);
2334             if (layer)
2335             {
2336                 ApplicationReferenceList& arl = layer->getNotificationClients();
2337
2338                 if (arl.size())
2339                 {
2340                     t_ilm_message notification;
2341                     Rectangle dest = layer->getDestinationRegion();
2342                     Rectangle src = layer->getSourceRegion();
2343                     OrientationType orientation = layer->getOrientation();
2344
2345                     unsigned char chromaKeyRed = 0;
2346                     unsigned char chromaKeyGreen = 0;
2347                     unsigned char chromaKeyBlue = 0;
2348                     layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
2349
2350                     std::stringstream notificationName;
2351                     notificationName << "NotificationForLayer" << layer->getID();
2352
2353                     notification = m_ipcModule.createNotification(notificationName.str().c_str());
2354                     m_ipcModule.appendUint(notification, layer->getID());
2355                     m_ipcModule.appendUint(notification, mask);
2356
2357                     m_ipcModule.appendDouble(notification, layer->getOpacity());
2358                     m_ipcModule.appendUint(notification, src.x);
2359                     m_ipcModule.appendUint(notification, src.y);
2360                     m_ipcModule.appendUint(notification, src.width);
2361                     m_ipcModule.appendUint(notification, src.height);
2362                     m_ipcModule.appendUint(notification, layer->OriginalSourceWidth);
2363                     m_ipcModule.appendUint(notification, layer->OriginalSourceHeight);
2364                     m_ipcModule.appendUint(notification, dest.x);
2365                     m_ipcModule.appendUint(notification, dest.y);
2366                     m_ipcModule.appendUint(notification, dest.width);
2367                     m_ipcModule.appendUint(notification, dest.height);
2368                     m_ipcModule.appendUint(notification, orientation);
2369                     m_ipcModule.appendBool(notification, layer->getVisibility());
2370                     m_ipcModule.appendUint(notification, layer->getLayerType());
2371                     m_ipcModule.appendBool(notification, layer->getChromaKeyEnabled());
2372                     m_ipcModule.appendUint(notification, chromaKeyRed);
2373                     m_ipcModule.appendUint(notification, chromaKeyGreen);
2374                     m_ipcModule.appendUint(notification, chromaKeyBlue);
2375                     m_ipcModule.appendInt(notification, layer->getCreatorPid());
2376
2377                     int clientCount = arl.size();
2378                     t_ilm_client_handle clientArray[256];
2379
2380                     ApplicationReferenceList::iterator iter = arl.begin();
2381                     ApplicationReferenceList::iterator end = arl.end();
2382
2383                     for (int clientNumber = 0;
2384                             iter != end, clientNumber < 256;
2385                             ++iter, ++clientNumber)
2386                     {
2387                         t_ilm_client_handle client = *iter;
2388                         clientArray[clientNumber] = client;
2389                     }
2390
2391                     LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): layer " << layer->getID() << " was updated.");
2392
2393                     if (!m_ipcModule.sendToClients(notification, clientArray, clientCount))
2394                     {
2395                         LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
2396                     }
2397
2398                     m_ipcModule.destroyMessage(notification);
2399                 }
2400             }
2401         }
2402         break;
2403     case TypeSurface:
2404         {
2405             Surface* surface = static_cast<Surface*>(object);
2406             if (surface)
2407             {
2408                 ApplicationReferenceList& arl = surface->getNotificationClients();
2409
2410                 if (arl.size())
2411                 {
2412                     t_ilm_message notification;
2413                     std::stringstream notificationName;
2414                     notificationName << "NotificationForSurface" << surface->getID();
2415
2416                     unsigned char chromaKeyRed = 0;
2417                     unsigned char chromaKeyGreen = 0;
2418                     unsigned char chromaKeyBlue = 0;
2419                     surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
2420
2421                     notification = m_ipcModule.createNotification(notificationName.str().c_str());
2422                     m_ipcModule.appendUint(notification, surface->getID());
2423                     m_ipcModule.appendUint(notification, mask);
2424
2425                     m_ipcModule.appendDouble(notification, surface->getOpacity());
2426                     m_ipcModule.appendUint(notification, surface->getSourceRegion().x);
2427                     m_ipcModule.appendUint(notification, surface->getSourceRegion().y);
2428                     m_ipcModule.appendUint(notification, surface->getSourceRegion().width);
2429                     m_ipcModule.appendUint(notification, surface->getSourceRegion().height);
2430                     m_ipcModule.appendUint(notification, surface->OriginalSourceWidth);
2431                     m_ipcModule.appendUint(notification, surface->OriginalSourceHeight);
2432                     m_ipcModule.appendUint(notification, surface->getDestinationRegion().x);
2433                     m_ipcModule.appendUint(notification, surface->getDestinationRegion().y);
2434                     m_ipcModule.appendUint(notification, surface->getDestinationRegion().width);
2435                     m_ipcModule.appendUint(notification, surface->getDestinationRegion().height);
2436                     m_ipcModule.appendUint(notification, surface->getOrientation());
2437                     m_ipcModule.appendBool(notification, surface->getVisibility());
2438                     m_ipcModule.appendUint(notification, surface->frameCounter);
2439                     m_ipcModule.appendUint(notification, surface->drawCounter);
2440                     m_ipcModule.appendUint(notification, surface->updateCounter);
2441                     m_ipcModule.appendUint(notification, surface->getPixelFormat());
2442                     m_ipcModule.appendUint(notification, surface->getNativeContent());
2443                     m_ipcModule.appendUint(notification, surface->getInputEventAcceptanceOnDevices());
2444                     m_ipcModule.appendBool(notification, surface->getChromaKeyEnabled());
2445                     m_ipcModule.appendUint(notification, chromaKeyRed);
2446                     m_ipcModule.appendUint(notification, chromaKeyGreen);
2447                     m_ipcModule.appendUint(notification, chromaKeyBlue);
2448                     m_ipcModule.appendInt(notification, surface->getCreatorPid());
2449
2450                     int clientCount = arl.size();
2451                     t_ilm_client_handle clients[256];
2452
2453                     ApplicationReferenceList::iterator iter = arl.begin();
2454                     ApplicationReferenceList::iterator end = arl.end();
2455
2456                     for (int clientNumber = 0;
2457                             iter != end, clientNumber < 256;
2458                             ++iter, ++clientNumber)
2459                     {
2460                         clients[clientNumber] = *iter;
2461                     }
2462
2463                     LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): surface " << surface->getID() << " was updated.");
2464
2465                     if (!m_ipcModule.sendToClients(notification, clients, clientCount))
2466                     {
2467                         LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
2468                     }
2469
2470                     m_ipcModule.destroyMessage(notification);
2471                 }
2472             }
2473         }
2474         break;
2475     default:
2476         LOG_INFO("GenericCommunicator", "Unknown notification found in queue.");
2477         break;
2478     }
2479 }
2480
2481 HealthCondition GenericCommunicator::pluginGetHealth()
2482 {
2483     HealthCondition health = PluginBase::pluginGetHealth();
2484     if (0 != pthread_kill(mThreadId, 0))
2485     {
2486         health = HealthDead;
2487     }
2488     return health;
2489 }
2490
2491 void GenericCommunicator::SetOptimizationMode(t_ilm_message message)
2492 {
2493     t_ilm_message response;
2494     OptimizationType optimizationId;
2495     OptimizationModeType optimizationMode;
2496     unsigned int optMode;
2497     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2498     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2499
2500     m_ipcModule.getUint(message, &optMode);
2501     optimizationId = (OptimizationType)optMode;
2502     m_ipcModule.getUint(message, &optMode);
2503     optimizationMode = (OptimizationModeType)optMode;
2504
2505     t_ilm_bool status = m_executor->execute(new SetOptimizationModeCommand(clientPid, optimizationId, optimizationMode));
2506     if (status)
2507     {
2508         response = m_ipcModule.createResponse(message);
2509     }
2510     else
2511     {
2512         response = m_ipcModule.createErrorResponse(message);
2513         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2514     }
2515     m_ipcModule.sendToClients(response, &clientHandle, 1);
2516     m_ipcModule.destroyMessage(response);
2517 }
2518
2519 void GenericCommunicator::GetOptimizationMode(t_ilm_message message)
2520 {
2521     t_ilm_message response;
2522     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2523     t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
2524     OptimizationType optimizationId;
2525     OptimizationModeType optimizationMode;
2526     unsigned int o;
2527
2528     m_ipcModule.getUint(message, &o);
2529     optimizationId = (OptimizationType)o;
2530
2531     t_ilm_bool status = m_executor->execute(new GetOptimizationModeCommand(clientPid, optimizationId, &optimizationMode));
2532     if (status)
2533     {
2534         response = m_ipcModule.createResponse(message);
2535         m_ipcModule.appendUint(response, (unsigned int)optimizationMode);
2536     }
2537     else
2538     {
2539         response = m_ipcModule.createErrorResponse(message);
2540         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2541     }
2542     m_ipcModule.sendToClients(response, &clientHandle, 1);
2543     m_ipcModule.destroyMessage(response);
2544 }
2545
2546 void GenericCommunicator::GetPropertiesOfScreen(t_ilm_message message)
2547 {
2548     t_ilm_message response;
2549     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
2550     uint id = 0;
2551     m_ipcModule.getUint(message, &id);
2552
2553     LmScreen* screen = m_executor->getScene()->getScreen(id);
2554     if (screen != NULL)
2555     {
2556         LayerList renderOrder = screen->getCurrentRenderOrder();
2557         std::vector<t_ilm_layer> layerIdVector;
2558
2559         LayerListConstIterator iter = renderOrder.begin();
2560         LayerListConstIterator end = renderOrder.end();
2561         for (; iter != end; ++iter)
2562         {
2563             layerIdVector.push_back((*iter)->getID());
2564         }
2565
2566         uint numberOfHardwareLayers = m_executor->getNumberOfHardwareLayers(id);
2567         uint* resolution = m_executor->getScreenResolution(id);
2568
2569         response = m_ipcModule.createResponse(message);
2570         m_ipcModule.appendUintArray(response, layerIdVector.data(), layerIdVector.size());
2571         m_ipcModule.appendUint(response, numberOfHardwareLayers);
2572         m_ipcModule.appendUint(response, resolution[0]);
2573         m_ipcModule.appendUint(response, resolution[1]);
2574     }
2575     else
2576     {
2577         response = m_ipcModule.createErrorResponse(message);
2578         m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
2579     }
2580
2581     m_ipcModule.sendToClients(response, &clientHandle, 1);
2582     m_ipcModule.destroyMessage(response);
2583 }
2584
2585 DECLARE_LAYERMANAGEMENT_PLUGIN(GenericCommunicator)
2586