ilmClient: split into ilmCommon, ilmClient, ilmControl
[profile/ivi/layer-management.git] / LayerManagerClient / ilmCommon / include / ilm_tools.h
1 /***************************************************************************
2 *
3 * Copyright 2013 BMW Car IT GmbH
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *        http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19 #ifndef _ILM_TOOLS_H_
20 #define _ILM_TOOLS_H_
21
22 #include "ilm_configuration.h"
23 #include "ilm_types.h"
24 #include <pthread.h>
25 #include <semaphore.h>
26
27 /*
28  *=============================================================================
29  * Implementation of thread-safe circular queue for local use
30  *=============================================================================
31  */
32 typedef struct
33 {
34     pthread_mutex_t queueMutex;
35     sem_t readBlockSemaphore;
36
37     t_ilm_uint size;
38     t_ilm_uint maxSize;
39     t_ilm_uint readPos;
40     t_ilm_uint writePos;
41
42     t_ilm_message* messages;
43 } t_ilm_msg_queue;
44
45 extern t_ilm_msg_queue notificationQueue;
46 extern t_ilm_msg_queue incomingQueue;
47 extern pthread_mutex_t gSendReceiveLock;
48
49 void init_msg_queue(t_ilm_msg_queue* pQueue, t_ilm_uint maxSize);
50 t_ilm_bool msg_enqueue(t_ilm_msg_queue* pQueue, t_ilm_message message);
51 t_ilm_message msg_dequeue(t_ilm_msg_queue* pQueue);
52 void destroy_msg_queue(t_ilm_msg_queue* pQueue);
53
54 /*
55  *=============================================================================
56  * notification callback management
57  *=============================================================================
58  */
59 struct LayerCallback
60 {
61     t_ilm_uint id;
62     layerNotificationFunc callback;
63 };
64
65 struct SurfaceCallback
66 {
67     t_ilm_uint id;
68     surfaceNotificationFunc callback;
69 };
70
71 void initNotificationCallbacks();
72 layerNotificationFunc getLayerNotificationCallback(t_ilm_layer layer);
73 surfaceNotificationFunc getSurfaceNotificationCallback(t_ilm_surface surface);
74 t_ilm_bool findLayerCallback(t_ilm_layer layer);
75 t_ilm_bool addLayerCallback(t_ilm_layer layer, layerNotificationFunc func);
76 t_ilm_bool findSurfaceCallback(t_ilm_surface surface);
77 t_ilm_bool addSurfaceCallback(t_ilm_surface surface, surfaceNotificationFunc func);
78 void removeLayerCallback(t_ilm_layer layer);
79 void removeSurfaceCallback(t_ilm_surface layer);
80
81 /*
82  *=============================================================================
83  * internal thread management
84  *=============================================================================
85  */
86 void* notificationThreadLoop(void* param);
87 void* receiveThreadLoop(void* param);
88
89 /*
90  *=============================================================================
91  * receive with timeout
92  *=============================================================================
93  */
94 void calculateTimeout(struct timeval* currentTime, int giventimeout, struct timespec* timeout);
95 t_ilm_bool sendAndWaitForResponse(t_ilm_message command, t_ilm_message* response, int timeoutInMs, ilmErrorTypes* error);
96
97 #endif /* _ILM_TOOLS_H_ */