3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
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/.
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
19 * For further information see http://www.genivi.org/.
24 /*******************************************************************************
26 ** SRC-MODULE: dlt_shm.h **
32 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
38 ** PLATFORM DEPENDANT [yes/no]: yes **
40 ** TO BE CHANGED BY USER [yes/no]: no **
42 *******************************************************************************/
44 /*******************************************************************************
46 ********************************************************************************
48 ** Initials Name Company **
49 ** -------- ------------------------- ---------------------------------- **
50 ** aw Alexander Wenzel BMW **
51 *******************************************************************************/
56 #include "dlt_common.h"
58 /* shared memory key */
59 /* must be the same for server and cleint */
60 #define DLT_SHM_KEY 11771
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
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
72 #define DLT_SHM_HEAD "SHM"
76 int shmid; /* Id of shared memory */
77 int semid; /* Id of semaphore */
88 #define DLT_SHM_SEM_GET(id) dlt_shm_pv(id,-1)
89 #define DLT_SHM_SEM_FREE(id) dlt_shm_pv(id,1)
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
98 extern int dlt_shm_init_client(DltShm *buf,int key);
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
108 extern int dlt_shm_init_server(DltShm *buf,int key,int size);
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
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);
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
132 extern int dlt_shm_pull(DltShm *buf,unsigned char *data, int size);
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
143 extern int dlt_shm_copy(DltShm *buf,unsigned char *data, int size);
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
152 extern int dlt_shm_remove(DltShm *buf);
155 * Print information about shm.
156 * @param buf pointer to shm structure
158 extern void dlt_shm_info(DltShm *buf);
161 * Print status about shm.
162 * @param buf pointer to shm structure
164 extern void dlt_shm_status(DltShm *buf);
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
171 extern int dlt_shm_free_client(DltShm *buf);
174 * Returns the total size of the shm.
175 * @param buf pointer to shm structure
176 * @return size of the shared memory.
178 extern int dlt_shm_get_total_size(DltShm *buf);
181 * Returns the used size in the shm.
182 * @param buf pointer to shm structure
183 * @return size of the shared memory.
185 extern int dlt_shm_get_used_size(DltShm *buf);
188 * Returns the number of messages in the shm.
189 * @param buf pointer to shm structure
190 * @return size of the shared memory.
192 extern int dlt_shm_get_message_count(DltShm *buf);
195 * Reset pointers and counters when shm corrupted.
196 * @param buf pointer to shm structure
197 * @return size of the shared memory.
199 extern int dlt_shm_reset(DltShm *buf);
202 * Recover to find next valid message.
203 * @param buf pointer to shm structure
204 * @return size of the shared memory.
206 extern int dlt_shm_recover(DltShm *buf);
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
213 extern int dlt_shm_free_server(DltShm *buf);
215 #endif /* DLT_SHM_H */