a31a8b4d482c903ba7bfcbb8c63744fede368eb1
[profile/ivi/layer-management.git] / LayerManagerClient / ilmClient / src / generic_ilm_client.c
1 /**************************************************************************
2  *
3  * Copyright 2012 BMW Car IT GmbH
4  * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  * Copyright (C) 2012 Bayerische Motorenwerke Aktiengesellschaft
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #include "ilm_client.h"
21 #include "ilm_types.h"
22 #include "IpcModuleLoader.h"
23 #include "ObjectType.h"
24 #include <pthread.h>
25 #include <sys/time.h>
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <signal.h>
30 #include <mqueue.h>
31 #include <fcntl.h>
32
33
34 //=============================================================================
35 // global settings
36 //=============================================================================
37 const int gReceiveTimeout  = -1;  // in ms, negative value for infinite
38 const int gResponseTimeout = 500; // in ms
39
40 // must be same as GraphicalObject::INVALID_ID, but this is defined in C++
41 // and can not be used here
42 #define INVALID_ID 0xFFFFFFFF
43
44 // queue names for incoming notifications and messages
45 #define NOTIFICATION_QUEUE_NAME "/ilmClient%dNotification"
46 #define INCOMING_QUEUE_NAME     "/ilmClient%dIncoming"
47
48 //=============================================================================
49 // global vars
50 //=============================================================================
51 extern char *__progname; // automatically gets assigned argv[0]
52
53 static struct IpcModule gIpcModule;
54
55 static pthread_t gReceiveThread;
56 static pthread_mutex_t gSendReceiveLock;
57 static pthread_t gNotificationThread;
58
59 static mqd_t incomingMqRead;
60 static mqd_t incomingMqWrite;
61
62 static mqd_t notificationMqRead;
63 static mqd_t notificationMqWrite;
64
65 static t_ilm_bool gInitialized = ILM_FALSE;
66
67 //=============================================================================
68 // notification management
69 //=============================================================================
70 #define MAX_CALLBACK_COUNT 64
71 struct
72 {
73     t_ilm_uint id;
74     layerNotificationFunc callback;
75 } static gLayerNotificationCallbacks[MAX_CALLBACK_COUNT];
76
77 struct
78 {
79     t_ilm_uint id;
80     surfaceNotificationFunc callback;
81 } static gSurfaceNotificationCallbacks[MAX_CALLBACK_COUNT];
82
83 void initNotificationCallbacks()
84 {
85     int i = 0;
86     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
87     {
88         gLayerNotificationCallbacks[i].id = INVALID_ID;
89         gLayerNotificationCallbacks[i].callback = NULL;
90         gSurfaceNotificationCallbacks[i].id = INVALID_ID;
91         gSurfaceNotificationCallbacks[i].callback = NULL;
92     }
93 }
94
95 layerNotificationFunc getLayerNotificationCallback(t_ilm_layer layer)
96 {
97     int i = 0;
98     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
99     {
100         if (gLayerNotificationCallbacks[i].id == layer)
101         {
102             return gLayerNotificationCallbacks[i].callback;
103         }
104     }
105     return NULL;
106 }
107
108 surfaceNotificationFunc getSurfaceNotificationCallback(t_ilm_surface surface)
109 {
110     int i = 0;
111     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
112     {
113         if (gSurfaceNotificationCallbacks[i].id == surface)
114         {
115             return gSurfaceNotificationCallbacks[i].callback;
116         }
117     }
118     return NULL;
119 }
120
121 t_ilm_bool findLayerCallback(t_ilm_layer layer)
122 {
123     int i = 0;
124
125     // try to overwrite existing entry for layer id
126     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
127     {
128         if (gLayerNotificationCallbacks[i].id == layer)
129         {
130             return ILM_TRUE;
131         }
132     }
133     return ILM_FALSE;
134 }
135
136 t_ilm_bool addLayerCallback(t_ilm_layer layer, layerNotificationFunc func)
137 {
138     int i = 0;
139
140     if (findLayerCallback(layer))
141     {
142         return ILM_FALSE;
143     }
144
145     // find free slot and store callback
146     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
147     {
148         if (gLayerNotificationCallbacks[i].id == INVALID_ID)
149         {
150             gLayerNotificationCallbacks[i].id = layer;
151             gLayerNotificationCallbacks[i].callback = func;
152             return ILM_TRUE;
153         }
154     }
155     printf("DbusIpcModule: addLayerCallback() failed. no free slots.");
156     return ILM_FALSE;
157 }
158
159 t_ilm_bool findSurfaceCallback(t_ilm_surface surface)
160 {
161     int i = 0;
162
163     // try to overwrite existing entry for layer id
164     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
165     {
166         if (gSurfaceNotificationCallbacks[i].id == surface)
167         {
168             return ILM_TRUE;
169         }
170     }
171     return ILM_FALSE;
172 }
173
174 t_ilm_bool addSurfaceCallback(t_ilm_surface surface, surfaceNotificationFunc func)
175 {
176     int i = 0;
177
178     if (findSurfaceCallback(surface))
179     {
180         return ILM_FALSE;
181     }
182
183     // find free slot and store callback
184     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
185     {
186         if (gSurfaceNotificationCallbacks[i].id == INVALID_ID)
187         {
188             gSurfaceNotificationCallbacks[i].id = surface;
189             gSurfaceNotificationCallbacks[i].callback = func;
190             return ILM_TRUE;
191         }
192     }
193     printf("DbusIpcModule: addSurfaceCallback() failed. no free slots.");
194     return ILM_FALSE;
195 }
196
197 void removeLayerCallback(t_ilm_layer layer)
198 {
199     int i = 0;
200     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
201     {
202         if (gLayerNotificationCallbacks[i].id == layer)
203         {
204             gLayerNotificationCallbacks[i].id = INVALID_ID;
205             gLayerNotificationCallbacks[i].callback = NULL;
206             return;
207         }
208     }
209 }
210
211 void removeSurfaceCallback(t_ilm_surface layer)
212 {
213     int i = 0;
214     for (i = 0; i < MAX_CALLBACK_COUNT; ++i)
215     {
216         if (gSurfaceNotificationCallbacks[i].id == layer)
217         {
218             gSurfaceNotificationCallbacks[i].id = INVALID_ID;
219             gSurfaceNotificationCallbacks[i].callback = NULL;
220             return;
221         }
222     }
223 }
224
225 //=============================================================================
226 // handling of internal notification thread for dispatching notifications
227 // Note: notification callbacks may be blocked by client, but receive thread
228 // must not be blocked
229 //=============================================================================
230 void* notificationThreadLoop(void* param)
231 {
232     t_ilm_message notification;
233
234     while (-1 != mq_receive(notificationMqRead, (char*)&notification, sizeof(notification), NULL))
235     {
236         t_ilm_const_string name = gIpcModule.getMessageName(notification);
237
238         // this depends on message name, but it is fast
239         if ('L' == name[15])
240         {
241             t_ilm_uint id;
242             t_ilm_uint mask;
243             struct ilmLayerProperties properties;
244
245             gIpcModule.getUint(notification, &id);
246             gIpcModule.getUint(notification, &mask);
247             gIpcModule.getDouble(notification, &properties.opacity);
248             gIpcModule.getUint(notification, &properties.sourceX);
249             gIpcModule.getUint(notification, &properties.sourceY);
250             gIpcModule.getUint(notification, &properties.sourceWidth);
251             gIpcModule.getUint(notification, &properties.sourceHeight);
252             gIpcModule.getUint(notification, &properties.origSourceWidth);
253             gIpcModule.getUint(notification, &properties.origSourceHeight);
254             gIpcModule.getUint(notification, &properties.destX);
255             gIpcModule.getUint(notification, &properties.destY);
256             gIpcModule.getUint(notification, &properties.destWidth);
257             gIpcModule.getUint(notification, &properties.destHeight);
258             gIpcModule.getUint(notification, &properties.orientation);
259             gIpcModule.getBool(notification, &properties.visibility);
260             gIpcModule.getUint(notification, &properties.type);
261             gIpcModule.getBool(notification, &properties.chromaKeyEnabled);
262             gIpcModule.getUint(notification, &properties.chromaKeyRed);
263             gIpcModule.getUint(notification, &properties.chromaKeyGreen);
264             gIpcModule.getUint(notification, &properties.chromaKeyBlue);
265             gIpcModule.getInt(notification, &properties.creatorPid);
266
267             layerNotificationFunc func = getLayerNotificationCallback(id);
268             if (func)
269             {
270                 (*func)(id, &properties, mask);
271             }
272             else
273             {
274                 fprintf(stderr, "notification for layer %d received, but no callback set\n", id);
275             }
276         }
277
278         if ('S' == name[15])
279         {
280             t_ilm_uint id;
281             t_ilm_uint mask;
282             struct ilmSurfaceProperties properties;
283
284             gIpcModule.getUint(notification, &id);
285             gIpcModule.getUint(notification, &mask);
286             gIpcModule.getDouble(notification, &properties.opacity);
287             gIpcModule.getUint(notification, &properties.sourceX);
288             gIpcModule.getUint(notification, &properties.sourceY);
289             gIpcModule.getUint(notification, &properties.sourceWidth);
290             gIpcModule.getUint(notification, &properties.sourceHeight);
291             gIpcModule.getUint(notification, &properties.origSourceWidth);
292             gIpcModule.getUint(notification, &properties.origSourceHeight);
293             gIpcModule.getUint(notification, &properties.destX);
294             gIpcModule.getUint(notification, &properties.destY);
295             gIpcModule.getUint(notification, &properties.destWidth);
296             gIpcModule.getUint(notification, &properties.destHeight);
297             gIpcModule.getUint(notification, &properties.orientation);
298             gIpcModule.getBool(notification, &properties.visibility);
299             gIpcModule.getUint(notification, &properties.frameCounter);
300             gIpcModule.getUint(notification, &properties.drawCounter);
301             gIpcModule.getUint(notification, &properties.updateCounter);
302             gIpcModule.getUint(notification, &properties.pixelformat);
303             gIpcModule.getUint(notification, &properties.nativeSurface);
304             gIpcModule.getUint(notification, &properties.inputDevicesAcceptance);
305             gIpcModule.getBool(notification, &properties.chromaKeyEnabled);
306             gIpcModule.getUint(notification, &properties.chromaKeyRed);
307             gIpcModule.getUint(notification, &properties.chromaKeyGreen);
308             gIpcModule.getUint(notification, &properties.chromaKeyBlue);
309             gIpcModule.getInt(notification, &properties.creatorPid);
310
311             surfaceNotificationFunc func = getSurfaceNotificationCallback(id);
312             if (func)
313             {
314                 (*func)(id, &properties, mask);
315             }
316             else
317             {
318                 fprintf(stderr, "notification for surface %d received, but no callback set\n", id);
319             }
320         }
321     }
322     gIpcModule.destroyMessage(notification);
323     return NULL;
324 }
325
326 //=============================================================================
327 // handling of internal receive thread for event handling
328 //=============================================================================
329 void* receiveThreadLoop(void* param)
330 {
331     t_ilm_bool running = ILM_TRUE;
332     t_ilm_bool waitForMessageRelease = ILM_FALSE;
333
334     while (running)
335     {
336         t_ilm_message message = gIpcModule.receive(gReceiveTimeout);
337         t_ilm_message_type messageType = gIpcModule.getMessageType(message);
338         switch (messageType)
339         {
340             case IpcMessageTypeNotification:
341                 if (-1 == mq_send(notificationMqWrite, (char*)&message, sizeof(message), 0))
342                 {
343                     if (EAGAIN == errno)
344                     {
345                         printf("Notification queue full, dropped notification %s\n", gIpcModule.getMessageName(message));
346                     }
347                 }
348                 break;
349
350             case IpcMessageTypeCommand:
351             case IpcMessageTypeError:
352                 if (-1 == mq_send(incomingMqWrite, (char*)&message, sizeof(message), 0))
353                 {
354                     if (EAGAIN == errno)
355                     {
356                         printf("Incoming queue full, dropped message %s\n", gIpcModule.getMessageName(message));
357                     }
358                 }
359                 break;
360
361             case IpcMessageTypeNone:
362                 break;
363
364             default:
365                 printf("ilmClient: discarded unexpected message (type: %d)\n", (int)messageType);
366                 gIpcModule.destroyMessage(message);
367                 break;
368         }
369     }
370
371     return NULL;
372 }
373
374 void calculateTimeout(struct timeval* currentTime, int giventimeout, struct timespec* timeout)
375 {
376     // nanoseconds is old value in nanoseconds + the given milliseconds as nanoseconds
377     t_ilm_ulong newNanoSeconds = currentTime->tv_usec * 1000 + giventimeout * (1000 * 1000);
378
379     // only use non full seconds, otherwise overflow!
380     timeout->tv_nsec = newNanoSeconds % (1000000000);
381
382     // new seconds are old seconds + full seconds from new nanoseconds part
383     timeout->tv_sec  = currentTime->tv_sec + (newNanoSeconds / 1000000000 );
384 }
385
386 t_ilm_bool sendAndWaitForResponse(t_ilm_message command, t_ilm_message* response, int timeoutInMs)
387 {
388     *response = 0;
389     t_ilm_message_type responseType = IpcMessageTypeNone;
390
391     // send / receive may only be performed by one thread at a time
392     pthread_mutex_lock(&gSendReceiveLock);
393
394     if (gIpcModule.sendToService(command))
395     {
396         if (-1 == mq_receive(incomingMqRead, (char*)response, sizeof(t_ilm_message), NULL))
397         {
398             fprintf(stderr,"waitForResponse: mq_receive failed, errno = %d\n", errno);
399         }
400         else
401         {
402             responseType = gIpcModule.getMessageType(*response);
403         }
404     }
405     pthread_mutex_unlock(&gSendReceiveLock);
406
407     return (*response && (IpcMessageTypeCommand == responseType));
408 }
409
410 //=============================================================================
411 // implementation
412 //=============================================================================
413 ilmErrorTypes ilm_init()
414 {
415     ilmErrorTypes result = ILM_FAILED;
416
417     if (gInitialized)
418     {
419         printf("ilm_init() was called, but ilmClientLib is already initialized. returning success, but initialization was skipped this time.\n");
420         return ILM_SUCCESS;
421     }
422
423     initNotificationCallbacks();
424
425     if (loadIpcModule(&gIpcModule))
426     {
427         int pid = getpid();
428
429         if (gIpcModule.initClientMode())
430         {
431             result = ILM_SUCCESS;
432
433             struct mq_attr mqAttr =
434             {
435                 .mq_maxmsg = 4,
436                 .mq_msgsize = sizeof(t_ilm_message),
437                 .mq_flags = 0, //O_NONBLOCK,
438                 .mq_curmsgs = 0
439             };
440
441             char mqName[30];
442             snprintf(mqName, sizeof(mqName), NOTIFICATION_QUEUE_NAME, getpid());
443
444             notificationMqWrite = mq_open(mqName, O_WRONLY | O_CREAT, 0600, &mqAttr);
445             notificationMqRead = mq_open(mqName, O_RDONLY);
446             mq_unlink(mqName); // is destroyed on closed filedescriptor
447
448             snprintf(mqName, sizeof(mqName), INCOMING_QUEUE_NAME, getpid());
449             incomingMqWrite = mq_open(mqName, O_WRONLY | O_CREAT, 0600, &mqAttr);
450             incomingMqRead = mq_open(mqName, O_RDONLY);
451             mq_unlink(mqName); // is destroyed on closed filedescriptor
452
453             if ((mqd_t)-1 == notificationMqRead || (mqd_t)-1 == notificationMqWrite)
454             {
455                 printf("mq_open failed, errno = %d\n", errno);
456                 return result;
457             }
458
459             pthread_mutex_init(&gSendReceiveLock, NULL);
460
461             pthread_attr_t notificationThreadAttributes;
462             pthread_attr_init(&notificationThreadAttributes);
463             pthread_attr_setdetachstate(&notificationThreadAttributes,
464                                         PTHREAD_CREATE_JOINABLE);
465
466             int ret = pthread_create(&gReceiveThread,
467                                      &notificationThreadAttributes,
468                                      receiveThreadLoop,
469                                      NULL);
470             if (0 != ret)
471             {
472                 result = ILM_FAILED;
473                 printf("Failed to start internal receive thread. returned %d = %s\n", ret, (ret == EAGAIN ? "EAGAIN" : "EINVAL"));
474                 return result;
475             }
476
477             ret = pthread_create(&gNotificationThread,
478                                  &notificationThreadAttributes,
479                                  notificationThreadLoop,
480                                  NULL);
481             if (0 != ret)
482             {
483                 result = ILM_FAILED;
484                 printf("Failed to start internal notification thread. returned %d = %s\n", ret, (ret == EAGAIN ? "EAGAIN" : "EINVAL"));
485                 return result;
486             }
487         }
488         else
489         {
490             result = ILM_FAILED;
491             printf("Failed to initialize Client Ipc Module");
492             return result;
493         }
494
495         t_ilm_message response = 0;
496         t_ilm_message command = gIpcModule.createMessage("ServiceConnect");
497         if (command
498                 && gIpcModule.appendUint(command, pid)
499                 && gIpcModule.appendString(command, __progname)
500                 && sendAndWaitForResponse(command, &response, gResponseTimeout))
501         {
502             result = ILM_SUCCESS;
503         }
504         else
505         {
506             result = ILM_FAILED;
507             printf("Failed to connect to LayerManagerService.");
508         }
509         gIpcModule.destroyMessage(response);
510         gIpcModule.destroyMessage(command);
511     }
512
513     gInitialized = (result == ILM_SUCCESS) ? ILM_TRUE : ILM_FALSE;
514
515     return result;
516 }
517
518 ilmErrorTypes ilm_destroy()
519 {
520     ilmErrorTypes result = ILM_FAILED;
521
522     t_ilm_message response = 0;
523     t_ilm_message command = gIpcModule.createMessage("ServiceDisconnect");
524     if (command
525         && gIpcModule.appendUint(command, getpid())
526         && sendAndWaitForResponse(command, &response, gResponseTimeout))
527     {
528         result = ILM_SUCCESS;
529     }
530     gIpcModule.destroyMessage(response);
531     gIpcModule.destroyMessage(command);
532
533     // cancel worker threads
534     void* threadReturnValue = NULL;
535
536     pthread_cancel(gReceiveThread);
537     pthread_cancel(gNotificationThread);
538
539     pthread_join(gReceiveThread, &threadReturnValue);
540     pthread_join(gNotificationThread, &threadReturnValue);
541
542     pthread_mutex_unlock(&gSendReceiveLock);
543
544     pthread_mutex_destroy(&gSendReceiveLock);
545
546     gIpcModule.destroy();
547
548     mq_close(notificationMqRead);
549     mq_close(notificationMqWrite);
550
551     mq_close(incomingMqRead);
552     mq_close(incomingMqWrite);
553
554     gInitialized = ILM_FALSE;
555
556     return ILM_SUCCESS;
557 }
558
559 ilmErrorTypes ilm_getPropertiesOfSurface(t_ilm_uint surfaceID, struct ilmSurfaceProperties* pSurfaceProperties)
560 {
561     ilmErrorTypes returnValue = ILM_FAILED;
562
563     t_ilm_message response = 0;
564     t_ilm_message command = gIpcModule.createMessage("GetPropertiesOfSurface");
565
566     if (pSurfaceProperties
567         && command
568         && gIpcModule.appendUint(command, surfaceID)
569         && sendAndWaitForResponse(command, &response, gResponseTimeout)
570         && gIpcModule.getDouble(response, &pSurfaceProperties->opacity)
571         && gIpcModule.getUint(response, &pSurfaceProperties->sourceX)
572         && gIpcModule.getUint(response, &pSurfaceProperties->sourceY)
573         && gIpcModule.getUint(response, &pSurfaceProperties->sourceWidth)
574         && gIpcModule.getUint(response, &pSurfaceProperties->sourceHeight)
575         && gIpcModule.getUint(response, &pSurfaceProperties->origSourceWidth)
576         && gIpcModule.getUint(response, &pSurfaceProperties->origSourceHeight)
577         && gIpcModule.getUint(response, &pSurfaceProperties->destX)
578         && gIpcModule.getUint(response, &pSurfaceProperties->destY)
579         && gIpcModule.getUint(response, &pSurfaceProperties->destWidth)
580         && gIpcModule.getUint(response, &pSurfaceProperties->destHeight)
581         && gIpcModule.getUint(response, &pSurfaceProperties->orientation)
582         && gIpcModule.getBool(response, &pSurfaceProperties->visibility)
583         && gIpcModule.getUint(response, &pSurfaceProperties->frameCounter)
584         && gIpcModule.getUint(response, &pSurfaceProperties->drawCounter)
585         && gIpcModule.getUint(response, &pSurfaceProperties->updateCounter)
586         && gIpcModule.getUint(response, &pSurfaceProperties->pixelformat)
587         && gIpcModule.getUint(response, &pSurfaceProperties->nativeSurface)
588         && gIpcModule.getUint(response, &pSurfaceProperties->inputDevicesAcceptance)
589         && gIpcModule.getBool(response, &pSurfaceProperties->chromaKeyEnabled)
590         && gIpcModule.getUint(response, &pSurfaceProperties->chromaKeyRed)
591         && gIpcModule.getUint(response, &pSurfaceProperties->chromaKeyGreen)
592         && gIpcModule.getUint(response, &pSurfaceProperties->chromaKeyBlue)
593         && gIpcModule.getInt(response, &pSurfaceProperties->creatorPid))
594     {
595         returnValue = ILM_SUCCESS;
596     }
597     gIpcModule.destroyMessage(response);
598     gIpcModule.destroyMessage(command);
599     return returnValue;
600 }
601
602 ilmErrorTypes ilm_getPropertiesOfLayer(t_ilm_uint layerID, struct ilmLayerProperties* pLayerProperties)
603 {
604     ilmErrorTypes returnValue = ILM_FAILED;
605
606     t_ilm_message response = 0;
607     t_ilm_message command = gIpcModule.createMessage("GetPropertiesOfLayer");
608     if (pLayerProperties
609         && command
610         && gIpcModule.appendUint(command, layerID)
611         && sendAndWaitForResponse(command, &response, gResponseTimeout)
612         && gIpcModule.getDouble(response, &pLayerProperties->opacity)
613         && gIpcModule.getUint(response, &pLayerProperties->sourceX)
614         && gIpcModule.getUint(response, &pLayerProperties->sourceY)
615         && gIpcModule.getUint(response, &pLayerProperties->sourceWidth)
616         && gIpcModule.getUint(response, &pLayerProperties->sourceHeight)
617         && gIpcModule.getUint(response, &pLayerProperties->origSourceWidth)
618         && gIpcModule.getUint(response, &pLayerProperties->origSourceHeight)
619         && gIpcModule.getUint(response, &pLayerProperties->destX)
620         && gIpcModule.getUint(response, &pLayerProperties->destY)
621         && gIpcModule.getUint(response, &pLayerProperties->destWidth)
622         && gIpcModule.getUint(response, &pLayerProperties->destHeight)
623         && gIpcModule.getUint(response, &pLayerProperties->orientation)
624         && gIpcModule.getBool(response, &pLayerProperties->visibility)
625         && gIpcModule.getUint(response, &pLayerProperties->type)
626         && gIpcModule.getBool(response, &pLayerProperties->chromaKeyEnabled)
627         && gIpcModule.getUint(response, &pLayerProperties->chromaKeyRed)
628         && gIpcModule.getUint(response, &pLayerProperties->chromaKeyGreen)
629         && gIpcModule.getUint(response, &pLayerProperties->chromaKeyBlue)
630         && gIpcModule.getInt(response, &pLayerProperties->creatorPid))
631     {
632         returnValue = ILM_SUCCESS;
633     }
634     gIpcModule.destroyMessage(response);
635     gIpcModule.destroyMessage(command);
636     return returnValue;
637 }
638
639 ilmErrorTypes ilm_getNumberOfHardwareLayers(t_ilm_uint screenID, t_ilm_uint* pNumberOfHardwareLayers)
640 {
641     ilmErrorTypes returnValue = ILM_FAILED;
642
643     t_ilm_message response = 0;
644     t_ilm_message command = gIpcModule.createMessage("GetNumberOfHardwareLayers");
645     if (pNumberOfHardwareLayers
646         && command
647         && gIpcModule.appendUint(command, screenID)
648         && sendAndWaitForResponse(command, &response, gResponseTimeout)
649         && gIpcModule.getUint(response, pNumberOfHardwareLayers))
650     {
651         returnValue = ILM_SUCCESS;
652     }
653     gIpcModule.destroyMessage(response);
654     gIpcModule.destroyMessage(command);
655     return returnValue;
656 }
657
658 ilmErrorTypes ilm_getScreenResolution(t_ilm_uint screenID, t_ilm_uint* pWidth, t_ilm_uint* pHeight)
659 {
660     ilmErrorTypes returnValue = ILM_FAILED;
661
662     t_ilm_message response = 0;
663     t_ilm_message command = gIpcModule.createMessage("GetScreenResolution");
664     if (pWidth && pHeight
665         && command
666         && gIpcModule.appendUint(command, screenID)
667         && sendAndWaitForResponse(command, &response, gResponseTimeout)
668         && gIpcModule.getUint(response, pWidth)
669         && gIpcModule.getUint(response, pHeight))
670     {
671         returnValue = ILM_SUCCESS;
672     }
673     gIpcModule.destroyMessage(response);
674     gIpcModule.destroyMessage(command);
675     return returnValue;
676 }
677
678 ilmErrorTypes ilm_getLayerIDs(t_ilm_int* pLength, t_ilm_layer** ppArray)
679 {
680     ilmErrorTypes returnValue = ILM_FAILED;
681
682     t_ilm_message response = 0;
683     t_ilm_message command = gIpcModule.createMessage("ListAllLayerIDS");
684     if (pLength && ppArray
685         && command
686         && sendAndWaitForResponse(command, &response, gResponseTimeout)
687         && gIpcModule.getUintArray(response, ppArray, pLength))
688     {
689         returnValue = ILM_SUCCESS;
690     }
691     gIpcModule.destroyMessage(response);
692     gIpcModule.destroyMessage(command);
693     return returnValue;
694 }
695
696 ilmErrorTypes ilm_getLayerIDsOnScreen(t_ilm_uint screenId, t_ilm_int* pLength, t_ilm_layer** ppArray)
697 {
698     ilmErrorTypes returnValue = ILM_FAILED;
699
700     t_ilm_message response = 0;
701     t_ilm_message command = gIpcModule.createMessage("ListAllLayerIDsOnScreen");
702     if (pLength && ppArray
703         && command
704         && gIpcModule.appendUint(command, screenId)
705         && sendAndWaitForResponse(command, &response, gResponseTimeout)
706         && gIpcModule.getUintArray(response, ppArray, pLength))
707     {
708         returnValue = ILM_SUCCESS;
709     }
710     gIpcModule.destroyMessage(response);
711     gIpcModule.destroyMessage(command);
712     return returnValue;
713 }
714
715 ilmErrorTypes ilm_getSurfaceIDs(t_ilm_int* pLength, t_ilm_surface** ppArray)
716 {
717     ilmErrorTypes returnValue = ILM_FAILED;
718
719     t_ilm_message response = 0;
720     t_ilm_message command = gIpcModule.createMessage("ListAllSurfaceIDS");
721     if (pLength && ppArray
722         && command
723         && sendAndWaitForResponse(command, &response, gResponseTimeout)
724         && gIpcModule.getUintArray(response, ppArray, pLength))
725     {
726         returnValue = ILM_SUCCESS;
727     }
728     gIpcModule.destroyMessage(response);
729     gIpcModule.destroyMessage(command);
730     return returnValue;
731 }
732
733 ilmErrorTypes ilm_getLayerGroupIDs(t_ilm_int* pLength, t_ilm_layergroup** ppArray)
734 {
735     ilmErrorTypes returnValue = ILM_FAILED;
736
737     t_ilm_message response = 0;
738     t_ilm_message command = gIpcModule.createMessage("ListAllLayerGroupIDS");
739     if (pLength && ppArray
740         && command
741         && sendAndWaitForResponse(command, &response, gResponseTimeout)
742         && gIpcModule.getUintArray(response, ppArray, pLength))
743     {
744         returnValue = ILM_SUCCESS;
745     }
746     gIpcModule.destroyMessage(response);
747     gIpcModule.destroyMessage(command);
748     return returnValue;
749 }
750
751 ilmErrorTypes ilm_getSurfaceGroupIDs(t_ilm_int* pLength, t_ilm_surfacegroup** ppArray)
752 {
753     ilmErrorTypes returnValue = ILM_FAILED;
754
755     t_ilm_message response = 0;
756     t_ilm_message command = gIpcModule.createMessage("ListAllSurfaceGroupIDS");
757     if (pLength && ppArray
758         && command
759         && sendAndWaitForResponse(command, &response, gResponseTimeout)
760         && gIpcModule.getUintArray(response, ppArray, pLength))
761     {
762         returnValue = ILM_SUCCESS;
763     }
764     gIpcModule.destroyMessage(response);
765     gIpcModule.destroyMessage(command);
766     return returnValue;
767 }
768
769 ilmErrorTypes ilm_getSurfaceIDsOnLayer(t_ilm_layer layer, t_ilm_int* pLength, t_ilm_surface** ppArray)
770 {
771     ilmErrorTypes returnValue = ILM_FAILED;
772
773     t_ilm_message response = 0;
774     t_ilm_message command = gIpcModule.createMessage("ListSurfaceofLayer");
775     if (pLength && ppArray
776         && command
777         && gIpcModule.appendUint(command, layer)
778         && sendAndWaitForResponse(command, &response, gResponseTimeout)
779         && gIpcModule.getUintArray(response, ppArray, pLength))
780     {
781         returnValue = ILM_SUCCESS;
782     }
783     gIpcModule.destroyMessage(response);
784     gIpcModule.destroyMessage(command);
785     return returnValue;
786 }
787
788 ilmErrorTypes ilm_layerCreate(t_ilm_layer* pLayerId)
789 {
790     ilmErrorTypes returnValue = ILM_FAILED;
791
792     if (pLayerId && (INVALID_ID != *pLayerId))
793     {
794         t_ilm_message response = 0;
795         t_ilm_message command = gIpcModule.createMessage("CreateLayerFromId");
796         if (command
797             && gIpcModule.appendUint(command, *pLayerId)
798             && sendAndWaitForResponse(command, &response, gResponseTimeout)
799             && gIpcModule.getUint(response, pLayerId))
800         {
801             returnValue = ILM_SUCCESS;
802         }
803         gIpcModule.destroyMessage(response);
804         gIpcModule.destroyMessage(command);
805     }
806     else
807     {
808         t_ilm_message response = 0;
809         t_ilm_message command = gIpcModule.createMessage("CreateLayer");
810         if (command
811             && sendAndWaitForResponse(command, &response, gResponseTimeout)
812             && gIpcModule.getUint(response, pLayerId))
813         {
814             returnValue = ILM_SUCCESS;
815         }
816         gIpcModule.destroyMessage(response);
817         gIpcModule.destroyMessage(command);
818     }
819     return returnValue;
820 }
821
822 ilmErrorTypes ilm_layerCreateWithDimension(t_ilm_layer* pLayerId, t_ilm_uint width, t_ilm_uint height)
823 {
824     ilmErrorTypes returnValue = ILM_FAILED;
825
826     if (pLayerId && (INVALID_ID != *pLayerId))
827     {
828         t_ilm_message response = 0;
829         t_ilm_message command = gIpcModule.createMessage("CreateLayerFromIdWithDimension");
830         if (command
831             && gIpcModule.appendUint(command, *pLayerId)
832             && gIpcModule.appendUint(command, width)
833             && gIpcModule.appendUint(command, height)
834             && sendAndWaitForResponse(command, &response, gResponseTimeout)
835             && gIpcModule.getUint(response, pLayerId))
836         {
837             returnValue = ILM_SUCCESS;
838         }
839         gIpcModule.destroyMessage(response);
840         gIpcModule.destroyMessage(command);
841     }
842     else
843     {
844         t_ilm_message response = 0;
845         t_ilm_message command = gIpcModule.createMessage("CreateLayerWithDimension");
846         if (command
847             && gIpcModule.appendUint(command, width)
848             && gIpcModule.appendUint(command, height)
849             && sendAndWaitForResponse(command, &response, gResponseTimeout)
850             && gIpcModule.getUint(response, pLayerId))
851         {
852             returnValue = ILM_SUCCESS;
853         }
854         gIpcModule.destroyMessage(response);
855         gIpcModule.destroyMessage(command);
856     }
857     return returnValue;
858 }
859
860 ilmErrorTypes ilm_layerRemove(t_ilm_layer layerId)
861 {
862     ilmErrorTypes returnValue = ILM_FAILED;
863
864     t_ilm_message response = 0;
865     t_ilm_message command = gIpcModule.createMessage("RemoveLayer");
866     if (command
867         && gIpcModule.appendUint(command, layerId)
868         && sendAndWaitForResponse(command, &response, gResponseTimeout))
869     {
870         returnValue = ILM_SUCCESS;
871     }
872     gIpcModule.destroyMessage(response);
873     gIpcModule.destroyMessage(command);
874     return returnValue;
875 }
876
877 ilmErrorTypes ilm_layerAddSurface(t_ilm_layer layerId, t_ilm_surface surfaceId)
878 {
879     ilmErrorTypes returnValue = ILM_FAILED;
880
881     t_ilm_message response = 0;
882     t_ilm_message command = gIpcModule.createMessage("AddSurfaceToLayer");
883     if (command
884         && gIpcModule.appendUint(command, surfaceId)
885         && gIpcModule.appendUint(command, layerId)
886         && sendAndWaitForResponse(command, &response, gResponseTimeout))
887     {
888         returnValue = ILM_SUCCESS;
889     }
890     gIpcModule.destroyMessage(response);
891     gIpcModule.destroyMessage(command);
892     return returnValue;
893 }
894
895 ilmErrorTypes ilm_layerRemoveSurface(t_ilm_layer layerId, t_ilm_surface surfaceId)
896 {
897     ilmErrorTypes returnValue = ILM_FAILED;
898
899     t_ilm_message response = 0;
900     t_ilm_message command = gIpcModule.createMessage("RemoveSurfaceFromLayer");
901     if (command
902         && gIpcModule.appendUint(command, surfaceId)
903         && gIpcModule.appendUint(command, layerId)
904         && sendAndWaitForResponse(command, &response, gResponseTimeout))
905     {
906         returnValue = ILM_SUCCESS;
907     }
908     gIpcModule.destroyMessage(response);
909     gIpcModule.destroyMessage(command);
910     return returnValue;
911 }
912
913 ilmErrorTypes ilm_layerGetType(t_ilm_layer layerId, ilmLayerType* pLayerType)
914 {
915     ilmErrorTypes returnValue = ILM_FAILED;
916
917     t_ilm_message response = 0;
918     t_ilm_message command = gIpcModule.createMessage("GetLayerType");
919     if (pLayerType
920         && command
921         && gIpcModule.appendUint(command, layerId)
922         && sendAndWaitForResponse(command, &response, gResponseTimeout)
923         && gIpcModule.getUint(response, pLayerType))
924     {
925         returnValue = ILM_SUCCESS;
926     }
927     gIpcModule.destroyMessage(response);
928     gIpcModule.destroyMessage(command);
929     return returnValue;
930 }
931
932 ilmErrorTypes ilm_layerSetVisibility(t_ilm_layer layerId, t_ilm_bool newVisibility)
933 {
934     ilmErrorTypes returnValue = ILM_FAILED;
935
936     t_ilm_message response = 0;
937     t_ilm_message command = gIpcModule.createMessage("SetLayerVisibility");
938     if (command
939         && gIpcModule.appendUint(command, layerId)
940         && gIpcModule.appendBool(command, newVisibility)
941         && sendAndWaitForResponse(command, &response, gResponseTimeout))
942     {
943         returnValue = ILM_SUCCESS;
944     }
945     gIpcModule.destroyMessage(response);
946     gIpcModule.destroyMessage(command);
947     return returnValue;
948 }
949
950 ilmErrorTypes ilm_layerGetVisibility(t_ilm_layer layerId, t_ilm_bool *pVisibility)
951 {
952     ilmErrorTypes returnValue = ILM_FAILED;
953
954     t_ilm_message response = 0;
955     t_ilm_message command = gIpcModule.createMessage("GetLayerVisibility");
956     if (pVisibility
957         && command
958         && gIpcModule.appendUint(command, layerId)
959         && sendAndWaitForResponse(command, &response, gResponseTimeout)
960         && gIpcModule.getBool(response, pVisibility))
961     {
962         returnValue = ILM_SUCCESS;
963     }
964     gIpcModule.destroyMessage(response);
965     gIpcModule.destroyMessage(command);
966     return returnValue;
967 }
968
969 ilmErrorTypes ilm_layerSetOpacity(t_ilm_layer layerId, t_ilm_float opacity)
970 {
971     ilmErrorTypes returnValue = ILM_FAILED;
972
973     t_ilm_message response = 0;
974     t_ilm_message command = gIpcModule.createMessage("SetLayerOpacity");
975     if (command
976         && gIpcModule.appendUint(command, layerId)
977         && gIpcModule.appendDouble(command, opacity)
978         && sendAndWaitForResponse(command, &response, gResponseTimeout))
979     {
980         returnValue = ILM_SUCCESS;
981     }
982     gIpcModule.destroyMessage(response);
983     gIpcModule.destroyMessage(command);
984     return returnValue;
985 }
986
987 ilmErrorTypes ilm_layerGetOpacity(t_ilm_layer layerId, t_ilm_float *pOpacity)
988 {
989     ilmErrorTypes returnValue = ILM_FAILED;
990
991     t_ilm_message response = 0;
992     t_ilm_message command = gIpcModule.createMessage("GetLayerOpacity");
993     if (pOpacity
994         && command
995         && gIpcModule.appendUint(command, layerId)
996         && sendAndWaitForResponse(command, &response, gResponseTimeout)
997         && gIpcModule.getDouble(response, pOpacity))
998     {
999         returnValue = ILM_SUCCESS;
1000     }
1001     gIpcModule.destroyMessage(response);
1002     gIpcModule.destroyMessage(command);
1003     return returnValue;
1004 }
1005
1006 ilmErrorTypes ilm_layerSetSourceRectangle(t_ilm_layer layerId, t_ilm_uint x, t_ilm_uint y, t_ilm_uint width, t_ilm_uint height)
1007 {
1008     ilmErrorTypes returnValue = ILM_FAILED;
1009
1010     t_ilm_message response = 0;
1011     t_ilm_message command = gIpcModule.createMessage("SetLayerSourceRegion");
1012     if (command
1013         && gIpcModule.appendUint(command, layerId)
1014         && gIpcModule.appendUint(command, x)
1015         && gIpcModule.appendUint(command, y)
1016         && gIpcModule.appendUint(command, width)
1017         && gIpcModule.appendUint(command, height)
1018         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1019     {
1020         returnValue = ILM_SUCCESS;
1021     }
1022     gIpcModule.destroyMessage(response);
1023     gIpcModule.destroyMessage(command);
1024     return returnValue;
1025 }
1026
1027 ilmErrorTypes ilm_layerSetDestinationRectangle(t_ilm_layer layerId, t_ilm_int x, t_ilm_int y, t_ilm_int width, t_ilm_int height)
1028 {
1029     ilmErrorTypes returnValue = ILM_FAILED;
1030
1031     t_ilm_message response = 0;
1032     t_ilm_message command = gIpcModule.createMessage("SetLayerDestinationRegion");
1033     if (command
1034         && gIpcModule.appendUint(command, layerId)
1035         && gIpcModule.appendUint(command, x)
1036         && gIpcModule.appendUint(command, y)
1037         && gIpcModule.appendUint(command, width)
1038         && gIpcModule.appendUint(command, height)
1039         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1040     {
1041         returnValue = ILM_SUCCESS;
1042     }
1043     gIpcModule.destroyMessage(response);
1044     gIpcModule.destroyMessage(command);
1045     return returnValue;
1046 }
1047
1048 ilmErrorTypes ilm_layerGetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1049 {
1050     ilmErrorTypes returnValue = ILM_FAILED;
1051
1052     t_ilm_message response = 0;
1053     t_ilm_message command = gIpcModule.createMessage("GetLayerDimension");
1054     if (pDimension
1055         && command
1056         && gIpcModule.appendUint(command, layerId)
1057         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1058         && gIpcModule.getUint(response, &pDimension[0])
1059         && gIpcModule.getUint(response, &pDimension[1]))
1060     {
1061         returnValue = ILM_SUCCESS;
1062     }
1063     gIpcModule.destroyMessage(response);
1064     gIpcModule.destroyMessage(command);
1065     return returnValue;
1066 }
1067
1068 ilmErrorTypes ilm_layerSetDimension(t_ilm_layer layerId, t_ilm_uint *pDimension)
1069 {
1070     ilmErrorTypes returnValue = ILM_FAILED;
1071
1072     t_ilm_message response = 0;
1073     t_ilm_message command = gIpcModule.createMessage("SetLayerDimension");
1074     if (pDimension
1075         && command
1076         && gIpcModule.appendUint(command, layerId)
1077         && gIpcModule.appendUint(command, pDimension[0])
1078         && gIpcModule.appendUint(command, pDimension[1])
1079         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1080     {
1081         returnValue = ILM_SUCCESS;
1082     }
1083     gIpcModule.destroyMessage(response);
1084     gIpcModule.destroyMessage(command);
1085     return returnValue;
1086 }
1087
1088 ilmErrorTypes ilm_layerGetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1089 {
1090     ilmErrorTypes returnValue = ILM_FAILED;
1091
1092     t_ilm_message response = 0;
1093     t_ilm_message command = gIpcModule.createMessage("GetLayerPosition");
1094     if (pPosition
1095         && command
1096         && gIpcModule.appendUint(command, layerId)
1097         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1098         && gIpcModule.getUint(response, &pPosition[0])
1099         && gIpcModule.getUint(response, &pPosition[1]))
1100     {
1101         returnValue = ILM_SUCCESS;
1102     }
1103     gIpcModule.destroyMessage(response);
1104     gIpcModule.destroyMessage(command);
1105     return returnValue;
1106 }
1107
1108 ilmErrorTypes ilm_layerSetPosition(t_ilm_layer layerId, t_ilm_uint *pPosition)
1109 {
1110     ilmErrorTypes returnValue = ILM_FAILED;
1111
1112     t_ilm_message response = 0;
1113     t_ilm_message command = gIpcModule.createMessage("SetLayerPosition");
1114     if (pPosition
1115         && command
1116         && gIpcModule.appendUint(command, layerId)
1117         && gIpcModule.appendUint(command, pPosition[0])
1118         && gIpcModule.appendUint(command, pPosition[1])
1119         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1120     {
1121         returnValue = ILM_SUCCESS;
1122     }
1123     gIpcModule.destroyMessage(response);
1124     gIpcModule.destroyMessage(command);
1125     return returnValue;
1126 }
1127
1128 ilmErrorTypes ilm_layerSetOrientation(t_ilm_layer layerId, ilmOrientation orientation)
1129 {
1130     ilmErrorTypes returnValue = ILM_FAILED;
1131
1132     t_ilm_message response = 0;
1133     t_ilm_message command = gIpcModule.createMessage("SetLayerOrientation");
1134     if (command
1135         && gIpcModule.appendUint(command, layerId)
1136         && gIpcModule.appendUint(command, orientation)
1137         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1138     {
1139         returnValue = ILM_SUCCESS;
1140     }
1141     gIpcModule.destroyMessage(response);
1142     gIpcModule.destroyMessage(command);
1143     return returnValue;
1144 }
1145
1146 ilmErrorTypes ilm_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrientation)
1147 {
1148     ilmErrorTypes returnValue = ILM_FAILED;
1149
1150     t_ilm_message response = 0;
1151     t_ilm_message command = gIpcModule.createMessage("GetLayerOrientation");
1152     if (pOrientation
1153         && command
1154         && gIpcModule.appendUint(command, layerId)
1155         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1156         && gIpcModule.getUint(response, pOrientation))
1157     {
1158         returnValue = ILM_SUCCESS;
1159     }
1160     gIpcModule.destroyMessage(response);
1161     gIpcModule.destroyMessage(command);
1162     return returnValue;
1163 }
1164
1165 ilmErrorTypes ilm_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
1166 {
1167     ilmErrorTypes returnValue = ILM_FAILED;
1168
1169     t_ilm_message response = 0;
1170     t_ilm_message command = gIpcModule.createMessage("SetLayerChromaKey");
1171     if (command
1172         && gIpcModule.appendUint(command, layerId))
1173     {
1174         t_ilm_bool comResult = ILM_TRUE;
1175
1176         // Checking pColor has a content, otherwise chromakey is disabled
1177         if (pColor)
1178         {
1179             const t_ilm_uint number = 3;
1180             comResult = gIpcModule.appendUintArray(command, (t_ilm_uint *)pColor, number);
1181         }
1182         if (comResult
1183             && sendAndWaitForResponse(command, &response, gResponseTimeout))
1184         {
1185             returnValue = ILM_SUCCESS;
1186         }
1187         gIpcModule.destroyMessage(response);
1188     }
1189     gIpcModule.destroyMessage(command);
1190     return returnValue;
1191 }
1192
1193 ilmErrorTypes ilm_layerSetRenderOrder(t_ilm_layer layerId, t_ilm_layer *pSurfaceId, t_ilm_int number)
1194 {
1195     ilmErrorTypes returnValue = ILM_FAILED;
1196
1197     t_ilm_message response = 0;
1198     t_ilm_message command = gIpcModule.createMessage("SetSurfaceRenderOrderWithinLayer");
1199     if (pSurfaceId
1200         && command
1201         && gIpcModule.appendUint(command, layerId)
1202         && gIpcModule.appendUintArray(command, pSurfaceId, number)
1203         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1204     {
1205         returnValue = ILM_SUCCESS;
1206     }
1207     gIpcModule.destroyMessage(response);
1208     gIpcModule.destroyMessage(command);
1209     return returnValue;
1210 }
1211
1212 ilmErrorTypes ilm_layerGetCapabilities(t_ilm_layer layerId, t_ilm_layercapabilities *pCapabilities)
1213 {
1214     ilmErrorTypes returnValue = ILM_FAILED;
1215
1216     t_ilm_message response = 0;
1217     t_ilm_message command = gIpcModule.createMessage("GetLayerCapabilities");
1218     if (pCapabilities
1219         && command
1220         && gIpcModule.appendUint(command, layerId)
1221         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1222         && gIpcModule.getUint(response, pCapabilities))
1223     {
1224         returnValue = ILM_SUCCESS;
1225     }
1226     gIpcModule.destroyMessage(response);
1227     gIpcModule.destroyMessage(command);
1228     return returnValue;
1229 }
1230
1231 ilmErrorTypes ilm_layerTypeGetCapabilities(ilmLayerType layerType, t_ilm_layercapabilities *pCapabilities)
1232 {
1233     ilmErrorTypes returnValue = ILM_FAILED;
1234
1235     t_ilm_message response = 0;
1236     t_ilm_message command = gIpcModule.createMessage("GetLayertypeCapabilities");
1237     if (pCapabilities
1238         && command
1239         && gIpcModule.appendUint(command, layerType)
1240         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1241         && gIpcModule.getUint(response, pCapabilities))
1242     {
1243         returnValue = ILM_SUCCESS;
1244     }
1245     gIpcModule.destroyMessage(response);
1246     gIpcModule.destroyMessage(command);
1247     return returnValue;
1248 }
1249
1250 ilmErrorTypes ilm_layergroupCreate(t_ilm_layergroup *pLayergroup)
1251 {
1252     ilmErrorTypes returnValue = ILM_FAILED;
1253
1254     if (pLayergroup && (INVALID_ID != *pLayergroup))
1255     {
1256         t_ilm_message response = 0;
1257         t_ilm_message command = gIpcModule.createMessage("CreateLayerGroupFromId");
1258         if (pLayergroup
1259             && command
1260             && gIpcModule.appendUint(command, *pLayergroup)
1261             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1262             && gIpcModule.getUint(response, pLayergroup))
1263         {
1264             returnValue = ILM_SUCCESS;
1265         }
1266         gIpcModule.destroyMessage(response);
1267         gIpcModule.destroyMessage(command);
1268     }
1269     else
1270     {
1271         t_ilm_message response = 0;
1272         t_ilm_message command = gIpcModule.createMessage("CreateLayerGroup");
1273         if (pLayergroup
1274             && command
1275             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1276             && gIpcModule.getUint(response, pLayergroup))
1277         {
1278             returnValue = ILM_SUCCESS;
1279         }
1280         gIpcModule.destroyMessage(response);
1281         gIpcModule.destroyMessage(command);
1282     }
1283     return returnValue;
1284 }
1285
1286 ilmErrorTypes ilm_layergroupRemove(t_ilm_layergroup group)
1287 {
1288     ilmErrorTypes returnValue = ILM_FAILED;
1289
1290     t_ilm_message response = 0;
1291     t_ilm_message command = gIpcModule.createMessage("RemoveLayerGroup");
1292     if (command
1293         && gIpcModule.appendUint(command, group)
1294         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1295     {
1296         returnValue = ILM_SUCCESS;
1297     }
1298     gIpcModule.destroyMessage(response);
1299     gIpcModule.destroyMessage(command);
1300     return returnValue;
1301 }
1302
1303 ilmErrorTypes ilm_layergroupAddLayer(t_ilm_layergroup group, t_ilm_layer layer)
1304 {
1305     ilmErrorTypes returnValue = ILM_FAILED;
1306
1307     t_ilm_message response = 0;
1308     t_ilm_message command = gIpcModule.createMessage("AddLayerToLayerGroup");
1309     if (command
1310         && gIpcModule.appendUint(command, layer)
1311         && gIpcModule.appendUint(command, group)
1312         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1313     {
1314         returnValue = ILM_SUCCESS;
1315     }
1316     gIpcModule.destroyMessage(response);
1317     gIpcModule.destroyMessage(command);
1318     return returnValue;
1319 }
1320
1321 ilmErrorTypes ilm_layergroupRemoveLayer(t_ilm_layergroup group, t_ilm_layer layer)
1322 {
1323     ilmErrorTypes returnValue = ILM_FAILED;
1324
1325     t_ilm_message response = 0;
1326     t_ilm_message command = gIpcModule.createMessage("RemoveLayerFromLayerGroup");
1327     if (command
1328         && gIpcModule.appendUint(command, layer)
1329         && gIpcModule.appendUint(command, group)
1330         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1331     {
1332         returnValue = ILM_SUCCESS;
1333     }
1334     gIpcModule.destroyMessage(response);
1335     gIpcModule.destroyMessage(command);
1336     return returnValue;
1337 }
1338
1339 ilmErrorTypes ilm_layergroupSetVisibility(t_ilm_layergroup group, t_ilm_bool newVisibility)
1340 {
1341     ilmErrorTypes returnValue = ILM_FAILED;
1342
1343     t_ilm_message response = 0;
1344     t_ilm_message command = gIpcModule.createMessage("SetLayergroupVisibility");
1345     if (command
1346         && gIpcModule.appendUint(command, group)
1347         && gIpcModule.appendBool(command, newVisibility)
1348         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1349     {
1350         returnValue = ILM_SUCCESS;
1351     }
1352     gIpcModule.destroyMessage(response);
1353     gIpcModule.destroyMessage(command);
1354     return returnValue;
1355 }
1356
1357 ilmErrorTypes ilm_layergroupSetOpacity(t_ilm_layergroup group, t_ilm_float opacity)
1358 {
1359     ilmErrorTypes returnValue = ILM_FAILED;
1360
1361     t_ilm_message response = 0;
1362     t_ilm_message command = gIpcModule.createMessage("SetLayergroupOpacity");
1363     if (command
1364         && gIpcModule.appendUint(command, group)
1365         && gIpcModule.appendDouble(command, opacity)
1366         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1367     {
1368         returnValue = ILM_SUCCESS;
1369     }
1370     gIpcModule.destroyMessage(response);
1371     gIpcModule.destroyMessage(command);
1372     return returnValue;
1373 }
1374
1375 ilmErrorTypes ilm_surfaceCreate(t_ilm_nativehandle nativehandle, t_ilm_int width, t_ilm_int height, ilmPixelFormat pixelFormat, t_ilm_surface* pSurfaceId)
1376 {
1377     ilmErrorTypes returnValue = ILM_FAILED;
1378
1379     if (pSurfaceId && (INVALID_ID != *pSurfaceId))
1380     {
1381         t_ilm_message response = 0;
1382         t_ilm_message command = gIpcModule.createMessage("CreateSurfaceFromId");
1383         if (command
1384             && gIpcModule.appendUint(command, nativehandle)
1385             && gIpcModule.appendUint(command, width)
1386             && gIpcModule.appendUint(command, height)
1387             && gIpcModule.appendUint(command, pixelFormat)
1388             && gIpcModule.appendUint(command, *pSurfaceId)
1389             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1390             && gIpcModule.getUint(response, pSurfaceId))
1391         {
1392             returnValue = ILM_SUCCESS;
1393         }
1394         gIpcModule.destroyMessage(response);
1395         gIpcModule.destroyMessage(command);
1396     }
1397     else
1398     {
1399         t_ilm_message response = 0;
1400         t_ilm_message command = gIpcModule.createMessage("CreateSurface");
1401         if (command
1402             && gIpcModule.appendUint(command, nativehandle)
1403             && gIpcModule.appendUint(command, width)
1404             && gIpcModule.appendUint(command, height)
1405             && gIpcModule.appendUint(command, pixelFormat)
1406             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1407             && gIpcModule.getUint(response, pSurfaceId))
1408         {
1409             returnValue = ILM_SUCCESS;
1410         }
1411         gIpcModule.destroyMessage(response);
1412         gIpcModule.destroyMessage(command);
1413     }
1414     return returnValue;
1415 }
1416
1417 ilmErrorTypes ilm_surfaceInitialize(t_ilm_surface *pSurfaceId)
1418 {
1419     ilmErrorTypes returnValue = ILM_FAILED;
1420
1421     if (pSurfaceId && (INVALID_ID != *pSurfaceId))
1422     {
1423         t_ilm_message response = 0;
1424         t_ilm_message command = gIpcModule.createMessage("InitializeSurfaceFromId");
1425         if (command
1426             && gIpcModule.appendUint(command, *pSurfaceId)
1427             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1428             && gIpcModule.getUint(response, pSurfaceId))
1429         {
1430             returnValue = ILM_SUCCESS;
1431         }
1432         gIpcModule.destroyMessage(response);
1433         gIpcModule.destroyMessage(command);
1434     }
1435     else
1436     {
1437         t_ilm_message response = 0;
1438         t_ilm_message command = gIpcModule.createMessage("InitializeSurface");
1439         if (command
1440             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1441             && gIpcModule.getUint(response, pSurfaceId))
1442         {
1443             returnValue = ILM_SUCCESS;
1444         }
1445         gIpcModule.destroyMessage(response);
1446         gIpcModule.destroyMessage(command);
1447     }
1448     return returnValue;
1449 }
1450
1451 ilmErrorTypes ilm_surfaceSetNativeContent(t_ilm_nativehandle nativehandle, t_ilm_int width, t_ilm_int height, ilmPixelFormat pixelFormat, t_ilm_surface surfaceId)
1452 {
1453     ilmErrorTypes returnValue = ILM_FAILED;
1454
1455     t_ilm_message response = 0;
1456     t_ilm_message command = gIpcModule.createMessage("SetSurfaceNativeContent");
1457     if (command
1458         && gIpcModule.appendUint(command, surfaceId)
1459         && gIpcModule.appendUint(command, nativehandle)
1460         && gIpcModule.appendUint(command, width)
1461         && gIpcModule.appendUint(command, height)
1462         && gIpcModule.appendUint(command, pixelFormat)
1463         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1464     {
1465         returnValue = ILM_SUCCESS;
1466     }
1467     gIpcModule.destroyMessage(response);
1468     gIpcModule.destroyMessage(command);
1469     return returnValue;
1470 }
1471
1472 ilmErrorTypes ilm_surfaceRemoveNativeContent(t_ilm_surface surfaceId)
1473 {
1474     ilmErrorTypes returnValue = ILM_FAILED;
1475
1476     t_ilm_message response = 0;
1477     t_ilm_message command = gIpcModule.createMessage("RemoveSurfaceNativeContent");
1478     if (command
1479         && gIpcModule.appendUint(command, surfaceId)
1480         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1481     {
1482         returnValue = ILM_SUCCESS;
1483     }
1484     gIpcModule.destroyMessage(response);
1485     gIpcModule.destroyMessage(command);
1486     return returnValue;
1487 }
1488
1489 ilmErrorTypes ilm_surfaceRemove(t_ilm_surface surfaceId)
1490 {
1491     ilmErrorTypes returnValue = ILM_FAILED;
1492
1493     t_ilm_message response = 0;
1494     t_ilm_message command = gIpcModule.createMessage("RemoveSurface");
1495     if (command
1496         && gIpcModule.appendUint(command, surfaceId)
1497         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1498     {
1499         returnValue = ILM_SUCCESS;
1500     }
1501     gIpcModule.destroyMessage(response);
1502     gIpcModule.destroyMessage(command);
1503     return returnValue;
1504 }
1505
1506 ilmErrorTypes ilm_surfaceSetVisibility(t_ilm_surface surfaceId, t_ilm_bool newVisibility)
1507 {
1508     ilmErrorTypes returnValue = ILM_FAILED;
1509
1510     t_ilm_message response = 0;
1511     t_ilm_message command = gIpcModule.createMessage("SetSurfaceVisibility");
1512     if (command
1513         && gIpcModule.appendUint(command, surfaceId)
1514         && gIpcModule.appendBool(command, newVisibility)
1515         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1516     {
1517         returnValue = ILM_SUCCESS;
1518     }
1519     gIpcModule.destroyMessage(response);
1520     gIpcModule.destroyMessage(command);
1521     return returnValue;
1522 }
1523
1524 ilmErrorTypes ilm_surfaceGetVisibility(t_ilm_surface surfaceId, t_ilm_bool *pVisibility)
1525 {
1526     ilmErrorTypes returnValue = ILM_FAILED;
1527
1528     t_ilm_message response = 0;
1529     t_ilm_message command = gIpcModule.createMessage("GetSurfaceVisibility");
1530     if (pVisibility
1531         && command
1532         && gIpcModule.appendUint(command, surfaceId)
1533         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1534         && gIpcModule.getBool(response, pVisibility))
1535     {
1536         returnValue = ILM_SUCCESS;
1537     }
1538     gIpcModule.destroyMessage(response);
1539     gIpcModule.destroyMessage(command);
1540     return returnValue;
1541 }
1542
1543 ilmErrorTypes ilm_surfaceSetOpacity(t_ilm_surface surfaceId, t_ilm_float opacity)
1544 {
1545     ilmErrorTypes returnValue = ILM_FAILED;
1546
1547     t_ilm_message response = 0;
1548     t_ilm_message command = gIpcModule.createMessage("SetSurfaceOpacity");
1549     if (command
1550         && gIpcModule.appendUint(command, surfaceId)
1551         && gIpcModule.appendDouble(command, opacity)
1552         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1553     {
1554         returnValue = ILM_SUCCESS;
1555     }
1556     gIpcModule.destroyMessage(response);
1557     gIpcModule.destroyMessage(command);
1558     return returnValue;
1559 }
1560
1561 ilmErrorTypes ilm_surfaceGetOpacity(t_ilm_surface surfaceId, t_ilm_float *pOpacity)
1562 {
1563     ilmErrorTypes returnValue = ILM_FAILED;
1564
1565     t_ilm_message response = 0;
1566     t_ilm_message command = gIpcModule.createMessage("GetSurfaceOpacity");
1567     if (pOpacity
1568         && command
1569         && gIpcModule.appendUint(command, surfaceId)
1570         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1571         && gIpcModule.getDouble(response, pOpacity))
1572     {
1573         returnValue = ILM_SUCCESS;
1574     }
1575     gIpcModule.destroyMessage(response);
1576     gIpcModule.destroyMessage(command);
1577     return returnValue;
1578 }
1579
1580 ilmErrorTypes ilm_surfaceSetSourceRectangle(t_ilm_surface surfaceId, t_ilm_int x, t_ilm_int y, t_ilm_int width, t_ilm_int height)
1581 {
1582     ilmErrorTypes returnValue = ILM_FAILED;
1583
1584     t_ilm_message response = 0;
1585     t_ilm_message command = gIpcModule.createMessage("SetSurfaceSourceRegion");
1586     if (command
1587         && gIpcModule.appendUint(command, surfaceId)
1588         && gIpcModule.appendUint(command, x)
1589         && gIpcModule.appendUint(command, y)
1590         && gIpcModule.appendUint(command, width)
1591         && gIpcModule.appendUint(command, height)
1592         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1593     {
1594         returnValue = ILM_SUCCESS;
1595     }
1596     gIpcModule.destroyMessage(response);
1597     gIpcModule.destroyMessage(command);
1598     return returnValue;
1599 }
1600
1601 ilmErrorTypes ilm_surfaceSetDestinationRectangle(t_ilm_surface surfaceId, t_ilm_int x, t_ilm_int y, t_ilm_int width, t_ilm_int height)
1602 {
1603     ilmErrorTypes returnValue = ILM_FAILED;
1604
1605     t_ilm_message response = 0;
1606     t_ilm_message command = gIpcModule.createMessage("SetSurfaceDestinationRegion");
1607     if (command
1608         && gIpcModule.appendUint(command, surfaceId)
1609         && gIpcModule.appendUint(command, x)
1610         && gIpcModule.appendUint(command, y)
1611         && gIpcModule.appendUint(command, width)
1612         && gIpcModule.appendUint(command, height)
1613         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1614     {
1615         returnValue = ILM_SUCCESS;
1616     }
1617     gIpcModule.destroyMessage(response);
1618     gIpcModule.destroyMessage(command);
1619     return returnValue;
1620 }
1621
1622 ilmErrorTypes ilm_surfaceGetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
1623 {
1624     ilmErrorTypes returnValue = ILM_FAILED;
1625
1626     t_ilm_message response = 0;
1627     t_ilm_message command = gIpcModule.createMessage("GetSurfaceDimension");
1628     if (pDimension
1629         && command
1630         && gIpcModule.appendUint(command, surfaceId)
1631         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1632         && gIpcModule.getUint(response, &pDimension[0])
1633         && gIpcModule.getUint(response, &pDimension[1]))
1634     {
1635         returnValue = ILM_SUCCESS;
1636     }
1637     gIpcModule.destroyMessage(response);
1638     gIpcModule.destroyMessage(command);
1639     return returnValue;
1640 }
1641
1642 ilmErrorTypes ilm_surfaceSetDimension(t_ilm_surface surfaceId, t_ilm_uint *pDimension)
1643 {
1644     ilmErrorTypes returnValue = ILM_FAILED;
1645
1646     t_ilm_message response = 0;
1647     t_ilm_message command = gIpcModule.createMessage("SetSurfaceDimension");
1648     if (pDimension
1649         && command
1650         && gIpcModule.appendUint(command, surfaceId)
1651         && gIpcModule.appendUint(command, pDimension[0])
1652         && gIpcModule.appendUint(command, pDimension[1])
1653         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1654     {
1655         returnValue = ILM_SUCCESS;
1656     }
1657     gIpcModule.destroyMessage(response);
1658     gIpcModule.destroyMessage(command);
1659     return returnValue;
1660 }
1661
1662 ilmErrorTypes ilm_surfaceGetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
1663 {
1664     ilmErrorTypes returnValue = ILM_FAILED;
1665
1666     t_ilm_message response = 0;
1667     t_ilm_message command = gIpcModule.createMessage("GetSurfacePosition");
1668     if (pPosition
1669         && command
1670         && gIpcModule.appendUint(command, surfaceId)
1671         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1672         && gIpcModule.getUint(response, &pPosition[0])
1673         && gIpcModule.getUint(response, &pPosition[1]))
1674     {
1675         returnValue = ILM_SUCCESS;
1676     }
1677     gIpcModule.destroyMessage(response);
1678     gIpcModule.destroyMessage(command);
1679     return returnValue;
1680 }
1681
1682 ilmErrorTypes ilm_surfaceSetPosition(t_ilm_surface surfaceId, t_ilm_uint *pPosition)
1683 {
1684     ilmErrorTypes returnValue = ILM_FAILED;
1685
1686     t_ilm_message response = 0;
1687     t_ilm_message command = gIpcModule.createMessage("SetSurfacePosition");
1688     if (pPosition
1689         && command
1690         && gIpcModule.appendUint(command, surfaceId)
1691         && gIpcModule.appendUint(command, pPosition[0])
1692         && gIpcModule.appendUint(command, pPosition[1])
1693         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1694     {
1695         returnValue = ILM_SUCCESS;
1696     }
1697     gIpcModule.destroyMessage(response);
1698     gIpcModule.destroyMessage(command);
1699     return returnValue;
1700 }
1701
1702 ilmErrorTypes ilm_surfaceSetOrientation(t_ilm_surface surfaceId, ilmOrientation orientation)
1703 {
1704     ilmErrorTypes returnValue = ILM_FAILED;
1705
1706     t_ilm_message response = 0;
1707     t_ilm_message command = gIpcModule.createMessage("SetSurfaceOrientation");
1708     if (command
1709         && gIpcModule.appendUint(command, surfaceId)
1710         && gIpcModule.appendUint(command, orientation)
1711         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1712     {
1713         returnValue = ILM_SUCCESS;
1714     }
1715     gIpcModule.destroyMessage(response);
1716     gIpcModule.destroyMessage(command);
1717     return returnValue;
1718 }
1719
1720 ilmErrorTypes ilm_surfaceGetOrientation(t_ilm_surface surfaceId, ilmOrientation *pOrientation)
1721 {
1722     ilmErrorTypes returnValue = ILM_FAILED;
1723
1724     t_ilm_message response = 0;
1725     t_ilm_message command = gIpcModule.createMessage("GetSurfaceOrientation");
1726     if (pOrientation
1727         && command
1728         && gIpcModule.appendUint(command, surfaceId)
1729         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1730         && gIpcModule.getUint(response, pOrientation))
1731     {
1732         returnValue = ILM_SUCCESS;
1733     }
1734     gIpcModule.destroyMessage(response);
1735     gIpcModule.destroyMessage(command);
1736     return returnValue;
1737 }
1738
1739 ilmErrorTypes ilm_surfaceGetPixelformat(t_ilm_layer surfaceId, ilmPixelFormat *pPixelformat)
1740 {
1741     ilmErrorTypes returnValue = ILM_FAILED;
1742
1743     t_ilm_message response = 0;
1744     t_ilm_message command = gIpcModule.createMessage("GetSurfacePixelformat");
1745     if (pPixelformat
1746         && command
1747         && gIpcModule.appendUint(command, surfaceId)
1748         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1749         && gIpcModule.getUint(response, pPixelformat))
1750     {
1751         returnValue = ILM_SUCCESS;
1752     }
1753     gIpcModule.destroyMessage(response);
1754     gIpcModule.destroyMessage(command);
1755     return returnValue;
1756 }
1757
1758 ilmErrorTypes ilm_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
1759 {
1760     ilmErrorTypes returnValue = ILM_FAILED;
1761
1762     t_ilm_message response = 0;
1763     t_ilm_message command = gIpcModule.createMessage("SetSurfaceChromaKey");
1764     if (command
1765         && gIpcModule.appendUint(command, surfaceId))
1766     {
1767         t_ilm_bool comResult = ILM_TRUE;
1768
1769         // Checking pColor has a content, otherwise chromakey is disabled
1770         if (pColor)
1771         {
1772             const t_ilm_uint number = 3;
1773             comResult = gIpcModule.appendUintArray(command, (t_ilm_uint *)pColor, number);
1774         }
1775         if (comResult
1776             && sendAndWaitForResponse(command, &response, gResponseTimeout))
1777         {
1778             returnValue = ILM_SUCCESS;
1779         }
1780     }
1781     gIpcModule.destroyMessage(response);
1782     gIpcModule.destroyMessage(command);
1783     return returnValue;
1784 }
1785
1786 ilmErrorTypes ilm_surfacegroupCreate(t_ilm_surfacegroup *pSurfacegroup)
1787 {
1788     ilmErrorTypes returnValue = ILM_FAILED;
1789
1790     if (pSurfacegroup && (INVALID_ID != *pSurfacegroup))
1791     {
1792         t_ilm_message response = 0;
1793         t_ilm_message command = gIpcModule.createMessage("CreateSurfaceGroupFromId");
1794         if (command
1795             && gIpcModule.appendUint(command, *pSurfacegroup)
1796             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1797             && gIpcModule.getUint(response, pSurfacegroup))
1798         {
1799             returnValue = ILM_SUCCESS;
1800         }
1801         gIpcModule.destroyMessage(response);
1802         gIpcModule.destroyMessage(command);
1803     }
1804     else
1805     {
1806         t_ilm_message response = 0;
1807         t_ilm_message command = gIpcModule.createMessage("CreateSurfaceGroup");
1808         if (pSurfacegroup
1809             && command
1810             && sendAndWaitForResponse(command, &response, gResponseTimeout)
1811             && gIpcModule.getUint(response, pSurfacegroup))
1812         {
1813             returnValue = ILM_SUCCESS;
1814         }
1815         gIpcModule.destroyMessage(response);
1816         gIpcModule.destroyMessage(command);
1817     }
1818     return returnValue;
1819 }
1820
1821 ilmErrorTypes ilm_surfacegroupRemove(t_ilm_surfacegroup group)
1822 {
1823     ilmErrorTypes returnValue = ILM_FAILED;
1824
1825     t_ilm_message response = 0;
1826     t_ilm_message command = gIpcModule.createMessage("RemoveSurfaceGroup");
1827     if (command
1828         && gIpcModule.appendUint(command, group)
1829         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1830     {
1831         returnValue = ILM_SUCCESS;
1832     }
1833     gIpcModule.destroyMessage(response);
1834     gIpcModule.destroyMessage(command);
1835     return returnValue;
1836 }
1837
1838 ilmErrorTypes ilm_surfacegroupAddSurface(t_ilm_surfacegroup group, t_ilm_surface surface)
1839 {
1840     ilmErrorTypes returnValue = ILM_FAILED;
1841
1842     t_ilm_message response = 0;
1843     t_ilm_message command = gIpcModule.createMessage("AddSurfaceToSurfaceGroup");
1844     if (command
1845         && gIpcModule.appendUint(command, surface)
1846         && gIpcModule.appendUint(command, group)
1847         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1848     {
1849         returnValue = ILM_SUCCESS;
1850     }
1851     gIpcModule.destroyMessage(response);
1852     gIpcModule.destroyMessage(command);
1853     return returnValue;
1854 }
1855
1856 ilmErrorTypes ilm_surfacegroupRemoveSurface(t_ilm_surfacegroup group, t_ilm_surface surface)
1857 {
1858     ilmErrorTypes returnValue = ILM_FAILED;
1859
1860     t_ilm_message response = 0;
1861     t_ilm_message command = gIpcModule.createMessage("RemoveSurfaceFromSurfaceGroup");
1862     if (command
1863         && gIpcModule.appendUint(command, surface)
1864         && gIpcModule.appendUint(command, group)
1865         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1866     {
1867         returnValue = ILM_SUCCESS;
1868     }
1869     gIpcModule.destroyMessage(response);
1870     gIpcModule.destroyMessage(command);
1871     return returnValue;
1872 }
1873
1874 ilmErrorTypes ilm_surfacegroupSetVisibility(t_ilm_surfacegroup group, t_ilm_bool newVisibility)
1875 {
1876     ilmErrorTypes returnValue = ILM_FAILED;
1877
1878     t_ilm_message response = 0;
1879     t_ilm_message command = gIpcModule.createMessage("SetSurfacegroupVisibility");
1880     if (command
1881         && gIpcModule.appendUint(command, group)
1882         && gIpcModule.appendBool(command, newVisibility)
1883         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1884     {
1885         returnValue = ILM_SUCCESS;
1886     }
1887     gIpcModule.destroyMessage(response);
1888     gIpcModule.destroyMessage(command);
1889     return returnValue;
1890 }
1891
1892 ilmErrorTypes ilm_surfacegroupSetOpacity(t_ilm_surfacegroup group, t_ilm_float opacity)
1893 {
1894     ilmErrorTypes returnValue = ILM_FAILED;
1895
1896     t_ilm_message response = 0;
1897     t_ilm_message command = gIpcModule.createMessage("SetSurfacegroupOpacity");
1898     if (command
1899         && gIpcModule.appendUint(command, group)
1900         && gIpcModule.appendDouble(command, opacity)
1901         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1902     {
1903         returnValue = ILM_SUCCESS;
1904     }
1905     gIpcModule.destroyMessage(response);
1906     gIpcModule.destroyMessage(command);
1907     return returnValue;
1908 }
1909
1910 ilmErrorTypes ilm_displaySetRenderOrder(t_ilm_display display, t_ilm_layer *pLayerId, const t_ilm_uint number)
1911 {
1912     ilmErrorTypes returnValue = ILM_FAILED;
1913
1914     t_ilm_message response = 0;
1915     t_ilm_message command = gIpcModule.createMessage("SetRenderOrderOfLayers");
1916     if (pLayerId
1917         && command
1918         && gIpcModule.appendUintArray(command, pLayerId, number)
1919         && gIpcModule.appendUint(command, display)
1920         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1921     {
1922         returnValue = ILM_SUCCESS;
1923     }
1924     gIpcModule.destroyMessage(response);
1925     gIpcModule.destroyMessage(command);
1926     return returnValue;
1927 }
1928
1929 ilmErrorTypes ilm_getScreenIDs(t_ilm_uint* pNumberOfIDs, t_ilm_uint** ppIDs)
1930 {
1931     ilmErrorTypes returnValue = ILM_FAILED;
1932
1933     t_ilm_message response = 0;
1934     t_ilm_message command = gIpcModule.createMessage("GetScreenIDs");
1935     if (pNumberOfIDs && ppIDs
1936         && command
1937         && sendAndWaitForResponse(command, &response, gResponseTimeout)
1938         && gIpcModule.getUintArray(response, ppIDs, (t_ilm_int *)pNumberOfIDs))
1939     {
1940         returnValue = ILM_SUCCESS;
1941     }
1942     gIpcModule.destroyMessage(response);
1943     gIpcModule.destroyMessage(command);
1944     return returnValue;
1945 }
1946
1947 ilmErrorTypes ilm_takeScreenshot(t_ilm_uint screen, t_ilm_const_string filename)
1948 {
1949     ilmErrorTypes returnValue = ILM_FAILED;
1950
1951     t_ilm_message response = 0;
1952     t_ilm_message command = gIpcModule.createMessage("ScreenShot");
1953     if (command
1954         && gIpcModule.appendUint(command, screen)
1955         && gIpcModule.appendString(command, filename)
1956         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1957     {
1958         returnValue = ILM_SUCCESS;
1959     }
1960     gIpcModule.destroyMessage(response);
1961     gIpcModule.destroyMessage(command);
1962     return returnValue;
1963 }
1964
1965 ilmErrorTypes ilm_takeLayerScreenshot(t_ilm_const_string filename, t_ilm_layer layerid)
1966 {
1967     ilmErrorTypes returnValue = ILM_FAILED;
1968
1969     t_ilm_message response = 0;
1970     t_ilm_message command = gIpcModule.createMessage("ScreenShotOfLayer");
1971     if (command
1972         && gIpcModule.appendString(command, filename)
1973         && gIpcModule.appendUint(command, layerid)
1974         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1975     {
1976         returnValue = ILM_SUCCESS;
1977     }
1978     gIpcModule.destroyMessage(response);
1979     gIpcModule.destroyMessage(command);
1980     return returnValue;
1981 }
1982
1983 ilmErrorTypes ilm_takeSurfaceScreenshot(t_ilm_const_string filename, t_ilm_surface surfaceid)
1984 {
1985     ilmErrorTypes returnValue = ILM_FAILED;
1986
1987     t_ilm_message response = 0;
1988     t_ilm_message command = gIpcModule.createMessage("ScreenShotOfSurface");
1989     if (command
1990         && gIpcModule.appendString(command, filename)
1991         && gIpcModule.appendUint(command, surfaceid)
1992         && sendAndWaitForResponse(command, &response, gResponseTimeout))
1993     {
1994         returnValue = ILM_SUCCESS;
1995     }
1996     gIpcModule.destroyMessage(response);
1997     gIpcModule.destroyMessage(command);
1998     return returnValue;
1999 }
2000
2001 ilmErrorTypes ilm_SetKeyboardFocusOn(t_ilm_surface surfaceId)
2002 {
2003     ilmErrorTypes returnValue = ILM_FAILED;
2004
2005     t_ilm_message response = 0;
2006     t_ilm_message command = gIpcModule.createMessage("SetKeyboardFocusOn");
2007     if (command
2008         && gIpcModule.appendUint(command, surfaceId)
2009         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2010     {
2011         returnValue = ILM_SUCCESS;
2012     }
2013     gIpcModule.destroyMessage(response);
2014     gIpcModule.destroyMessage(command);
2015     return returnValue;
2016 }
2017
2018 ilmErrorTypes ilm_GetKeyboardFocusSurfaceId(t_ilm_surface* pSurfaceId)
2019 {
2020     ilmErrorTypes returnValue = ILM_FAILED;
2021
2022     t_ilm_message response = 0;
2023     t_ilm_message command = gIpcModule.createMessage("GetKeyboardFocusSurfaceId");
2024     if (command
2025         && sendAndWaitForResponse(command, &response, gResponseTimeout)
2026         && gIpcModule.getUint(response, pSurfaceId))
2027     {
2028         returnValue = ILM_SUCCESS;
2029     }
2030     gIpcModule.destroyMessage(response);
2031     gIpcModule.destroyMessage(command);
2032     return returnValue;
2033 }
2034
2035 ilmErrorTypes ilm_UpdateInputEventAcceptanceOn(t_ilm_surface surfaceId, ilmInputDevice devices, t_ilm_bool acceptance)
2036 {
2037     ilmErrorTypes returnValue = ILM_FAILED;
2038
2039     t_ilm_message response = 0;
2040     t_ilm_message command = gIpcModule.createMessage("UpdateInputEventAcceptanceOn");
2041     if (command
2042         && gIpcModule.appendUint(command, surfaceId)
2043         && gIpcModule.appendUint(command, devices)
2044         && gIpcModule.appendBool(command, acceptance)
2045         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2046     {
2047         returnValue = ILM_SUCCESS;
2048     }
2049     gIpcModule.destroyMessage(response);
2050     gIpcModule.destroyMessage(command);
2051     return returnValue;
2052 }
2053
2054 ilmErrorTypes ilm_SetOptimizationMode(ilmOptimization id, ilmOptimizationMode mode)
2055 {
2056     ilmErrorTypes returnValue = ILM_FAILED;
2057
2058     t_ilm_message response = 0;
2059     t_ilm_message command = gIpcModule.createMessage("SetOptimizationMode");
2060     if (command
2061         && gIpcModule.appendUint(command,id)
2062         && gIpcModule.appendUint(command,mode)
2063         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2064     {
2065         returnValue = ILM_SUCCESS;
2066     }
2067     gIpcModule.destroyMessage(response);
2068     gIpcModule.destroyMessage(command);
2069     return returnValue;
2070 }
2071
2072 ilmErrorTypes ilm_GetOptimizationMode(ilmOptimization id, ilmOptimizationMode* pMode)
2073 {
2074     ilmErrorTypes returnValue = ILM_FAILED;
2075     t_ilm_message response = 0;
2076     t_ilm_message command = gIpcModule.createMessage("GetOptimizationMode");
2077     if (command
2078         && gIpcModule.appendUint(command,id)
2079         && sendAndWaitForResponse(command, &response, gResponseTimeout)
2080         && gIpcModule.getUint(response, pMode))
2081     {
2082         returnValue = ILM_SUCCESS;
2083     }
2084     gIpcModule.destroyMessage(response);
2085     gIpcModule.destroyMessage(command);
2086     return returnValue;
2087 }
2088
2089 ilmErrorTypes ilm_commitChanges()
2090 {
2091     ilmErrorTypes returnValue = ILM_FAILED;
2092
2093     t_ilm_message response = 0;
2094     t_ilm_message command = gIpcModule.createMessage("CommitChanges");
2095
2096     if (command
2097         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2098     {
2099         returnValue = ILM_SUCCESS;
2100     }
2101     gIpcModule.destroyMessage(response);
2102     gIpcModule.destroyMessage(command);
2103     return returnValue;
2104 }
2105
2106 ilmErrorTypes ilm_layerAddNotification(t_ilm_layer layer, layerNotificationFunc callback)
2107 {
2108     ilmErrorTypes returnValue = ILM_FAILED;
2109
2110     if (findLayerCallback(layer))
2111     {
2112         return ILM_ERROR_INVALID_ARGUMENTS;
2113     }
2114
2115     t_ilm_message response = 0;
2116     t_ilm_message command = gIpcModule.createMessage("LayerAddNotification");
2117     if (command
2118         && gIpcModule.appendUint(command, layer)
2119         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2120     {
2121         addLayerCallback(layer, callback);
2122         returnValue = ILM_SUCCESS;
2123     }
2124     gIpcModule.destroyMessage(response);
2125     gIpcModule.destroyMessage(command);
2126     return returnValue;
2127 }
2128
2129 ilmErrorTypes ilm_layerRemoveNotification(t_ilm_layer layer)
2130 {
2131     ilmErrorTypes returnValue = ILM_FAILED;
2132
2133     if (!findLayerCallback(layer))
2134     {
2135         return ILM_ERROR_INVALID_ARGUMENTS;
2136     }
2137
2138     t_ilm_message response = 0;
2139     t_ilm_message command = gIpcModule.createMessage("LayerRemoveNotification");
2140     if (command
2141         && gIpcModule.appendUint(command, layer)
2142         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2143     {
2144         removeLayerCallback(layer);
2145         returnValue = ILM_SUCCESS;
2146     }
2147     gIpcModule.destroyMessage(response);
2148     gIpcModule.destroyMessage(command);
2149     return returnValue;
2150 }
2151
2152 ilmErrorTypes ilm_surfaceAddNotification(t_ilm_surface surface, surfaceNotificationFunc callback)
2153 {
2154     ilmErrorTypes returnValue = ILM_FAILED;
2155
2156     if (findSurfaceCallback(surface))
2157     {
2158         return ILM_ERROR_INVALID_ARGUMENTS;
2159     }
2160
2161     t_ilm_message response = 0;
2162     t_ilm_message command = gIpcModule.createMessage("SurfaceAddNotification");
2163     if (command
2164         && gIpcModule.appendUint(command, surface)
2165         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2166     {
2167         addSurfaceCallback(surface, callback);
2168         returnValue = ILM_SUCCESS;
2169     }
2170     gIpcModule.destroyMessage(response);
2171     gIpcModule.destroyMessage(command);
2172     return returnValue;
2173 }
2174
2175 ilmErrorTypes ilm_surfaceRemoveNotification(t_ilm_surface surface)
2176 {
2177     ilmErrorTypes returnValue = ILM_FAILED;
2178
2179     if (!findSurfaceCallback(surface))
2180     {
2181         return ILM_ERROR_INVALID_ARGUMENTS;
2182     }
2183
2184     t_ilm_message response = 0;
2185     t_ilm_message command = gIpcModule.createMessage("SurfaceRemoveNotification");
2186     if (command
2187         && gIpcModule.appendUint(command, surface)
2188         && sendAndWaitForResponse(command, &response, gResponseTimeout))
2189     {
2190         removeSurfaceCallback(surface);
2191         returnValue = ILM_SUCCESS;
2192     }
2193     gIpcModule.destroyMessage(response);
2194     gIpcModule.destroyMessage(command);
2195     return returnValue;
2196 }