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