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