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