DLT_CSTRING implementation non verbose mode.
[profile/ivi/dlt-daemon.git] / include / dlt / dlt_shm.h
1 /**
2  * @licence app begin@
3  * Copyright (C) 2012  BMW AG
4  *
5  * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
6  *
7  * Contributions are licensed to the GENIVI Alliance under one or more
8  * Contribution License Agreements.
9  *
10  * \copyright
11  * This Source Code Form is subject to the terms of the
12  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
13  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
14  *
15  *
16  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
17  *
18  * \file dlt_shm.h
19  * For further information see http://www.genivi.org/.
20  * @licence end@
21  */
22
23
24 /*******************************************************************************
25 **                                                                            **
26 **  SRC-MODULE: dlt_shm.h                                                     **
27 **                                                                            **
28 **  TARGET    : linux                                                         **
29 **                                                                            **
30 **  PROJECT   : DLT                                                           **
31 **                                                                            **
32 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
33 **                                                                            **
34 **  PURPOSE   :                                                               **
35 **                                                                            **
36 **  REMARKS   :                                                               **
37 **                                                                            **
38 **  PLATFORM DEPENDANT [yes/no]: yes                                          **
39 **                                                                            **
40 **  TO BE CHANGED BY USER [yes/no]: no                                        **
41 **                                                                            **
42 *******************************************************************************/
43
44 /*******************************************************************************
45 **                      Author Identity                                       **
46 ********************************************************************************
47 **                                                                            **
48 ** Initials     Name                       Company                            **
49 ** --------     -------------------------  ---------------------------------- **
50 **  aw          Alexander Wenzel           BMW                                **
51 *******************************************************************************/
52
53 #ifndef DLT_SHM_H
54 #define DLT_SHM_H
55
56 #include "dlt_common.h"
57
58 /* shared memory key */
59 /* must be the same for server and cleint */
60 #define DLT_SHM_KEY     11771
61
62 /* default size of shared memory */
63 /* size is extended during creation to fit segment size */
64 /* client retreives real size from shm buffer */
65 #define DLT_SHM_SIZE    100000
66
67 /* Id of the used semaphore */
68 /* used for synchronisation of write and read access of multiple clients and server */
69 /* must be the same for server and client */
70 #define DLT_SHM_SEM             22771
71
72 #define DLT_SHM_HEAD    "SHM"
73
74 typedef struct
75 {
76         int shmid;      /* Id of shared memory */
77         int semid;      /* Id of semaphore */
78         DltBuffer buffer;
79 } DltShm;
80
81 typedef struct
82 {
83         char head[4];
84         unsigned char status;
85         int size;       
86 } DltShmBlockHead;
87
88 #define DLT_SHM_SEM_GET(id) dlt_shm_pv(id,-1)
89 #define DLT_SHM_SEM_FREE(id) dlt_shm_pv(id,1)
90
91 /**
92  * Initialise the shared memory on the client side.
93  * This function must be called before using further shm functions.
94  * @param buf pointer to shm structure
95  * @param key the identifier of the shm, must be the same for server and client
96  * @return negative value if there was an error
97  */
98 extern int dlt_shm_init_client(DltShm *buf,int key);
99
100 /**
101  * Initialise the shared memory on the server side.
102  * This function must be called before using further shm functions.
103  * @param buf pointer to shm structure
104  * @param key the identifier of the shm, must be the same for server and client
105  * @param size the requested size of the shm
106  * @return negative value if there was an error
107  */
108 extern int dlt_shm_init_server(DltShm *buf,int key,int size);
109
110 /**
111  * Push data from client onto the shm.
112  * @param buf pointer to shm structure
113  * @param data1 pointer to first data block to be written, null if not used
114  * @param size1 size in bytes of first data block to be written, 0 if not used
115  * @param data2 pointer to second data block to be written, null if not used
116  * @param size2 size in bytes of second data block to be written, 0 if not used
117  * @param data3 pointer to third data block to be written, null if not used
118  * @param size3 size in bytes of third data block to be written, 0 if not used
119  * @return negative value if there was an error
120  */
121 extern int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const unsigned char *data2,unsigned int size2,const unsigned char *data3,unsigned int size3);
122
123 /**
124  * Pull data from shm.
125  * This function should be called from client.
126  * Data is deleted from shm after this call.
127  * @param buf pointer to shm structure
128  * @param data pointer to buffer where data is to be written
129  * @param size maximum size to be written into buffer
130  * @return negative value if there was an error
131  */
132 extern int dlt_shm_pull(DltShm *buf,unsigned char *data, int size);
133
134 /**
135  * Copy message from shm.
136  * This function should be called from server.
137  * Data is not deleted from shm after this call.
138  * @param buf pointer to shm structure
139  * @param data pointer to buffer where data is to be written
140  * @param size maximum size to be written into buffer
141  * @return negative value if there was an error
142  */
143 extern int dlt_shm_copy(DltShm *buf,unsigned char *data, int size);
144
145 /**
146  * Delete message from shm.
147  * This function should be called from server.
148  * This function should be called after each succesful copy.
149  * @param buf pointer to shm structure
150  * @return negative value if there was an error
151  */
152 extern int dlt_shm_remove(DltShm *buf);
153
154 /**
155  * Print information about shm.
156  * @param buf pointer to shm structure
157  */
158 extern void dlt_shm_info(DltShm *buf);
159
160 /**
161  * Print status about shm.
162  * @param buf pointer to shm structure
163  */
164 extern void dlt_shm_status(DltShm *buf);
165
166 /**
167  * Deinitialise the shared memory on the client side.
168  * @param buf pointer to shm structure
169  * @return negative value if there was an error
170  */
171 extern int dlt_shm_free_client(DltShm *buf);
172
173 /**
174  * Returns the total size of the shm.
175  * @param buf pointer to shm structure
176  * @return size of the shared memory.
177  */
178 extern int dlt_shm_get_total_size(DltShm *buf);
179
180 /**
181  * Returns the used size in the shm.
182  * @param buf pointer to shm structure
183  * @return size of the shared memory.
184  */
185 extern int dlt_shm_get_used_size(DltShm *buf);
186
187 /**
188  * Returns the number of messages in the shm.
189  * @param buf pointer to shm structure
190  * @return size of the shared memory.
191  */
192 extern int dlt_shm_get_message_count(DltShm *buf);
193
194 /**
195  * Reset pointers and counters when shm corrupted.
196  * @param buf pointer to shm structure
197  * @return size of the shared memory.
198  */
199 extern int dlt_shm_reset(DltShm *buf);
200
201 /**
202  * Recover to find next valid message.
203  * @param buf pointer to shm structure
204  * @return size of the shared memory.
205  */
206 extern int dlt_shm_recover(DltShm *buf);
207
208 /**
209  * Deinitialise the shared memory on the server side.
210  * @param buf pointer to shm structure
211  * @return negative value if there was an error
212  */
213 extern int dlt_shm_free_server(DltShm *buf);
214
215 #endif /* DLT_SHM_H */