2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NSSharedMemory
19 /// \brief This file contains implementation of class CNSSharedMemWriter.
20 /// This class provides API to open, close and perform write operation on shared memory.
22 ////////////////////////////////////////////////////////////////////////////////////////////////////
25 * @file ns_sharedmem_writer.h
26 * @brief \~english This file contains implementation of class CNSSharedMemWriter.
27 * This class provides API to open, close and perform write operation on shared memory.
30 /** @addtogroup BaseSystem
33 /** @addtogroup native_service
37 /** @addtogroup framework_unified
38 * @ingroup native_service
41 /** @addtogroup native
42 * @ingroup framework_unified
45 #ifndef __NATIVESERVICES_NATIVESERVICES_INC_NATIVE_NS_SHAREDMEM_WRITER_H__ // NOLINT (build/header_guard)
46 #define __NATIVESERVICES_NATIVESERVICES_INC_NATIVE_NS_SHAREDMEM_WRITER_H__
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 ////////////////////////////////////////////////////////////////////////////////////////////////////
51 #include <native_service/frameworkunified_types.h>
57 * @class CNSSharedMemWriter
58 * \~english @brief write shared memory
59 * \~english @par Brief Introduction
60 * This class is used for write shared memory.
63 class CNSSharedMemWriter {
65 ////////////////////////////////////////////////////////////////////////////////////////////////
66 /// \ingroup CNSSharedMemWriter
67 /// \~english @par Brief
68 /// Constructor for CNSSharedMemWriter
69 /// \~english @param[in] f_cSharedMemName
70 /// const std::string& - name of the shared memory
71 /// \~english @param[in] f_uiSize
72 /// UI_32 - size of shared memory
73 /// \~english @retval None
74 /// \~english @par Preconditons
76 /// \~english @par Change of internal status
78 /// \~english @par Conditions of processing failure
80 /// \~english @par Detail
81 /// Create object of CNSSharedMemWriter class.
82 /// This class don't used to open shared memory object or allocate memory.
83 /// \~english @par Classification
85 /// \~english @par Type
87 /// \~english @see ~CNSSharedMemWriter
88 ////////////////////////////////////////////////////////////////////////////////////////////////
89 CNSSharedMemWriter(const std::string &f_cSharedMemName, const UI_32 f_uiSize);
91 ////////////////////////////////////////////////////////////////////////////////////////////////
92 /// \ingroup CNSSharedMemWriter
93 /// \~english @par Brief
94 /// Destructor of CNSSharedMemWriter class.
95 /// \~english @param None
96 /// \~english @retval none
97 /// \~english @par Preconditons
99 /// \~english @par Change of internal status
100 /// - Change the state of shared memory to closed state
101 /// \~english @par Conditions of processing failure
103 /// \~english @par Detail
104 /// Closes the shared memory, if it is open.
106 /// Please note the following points when using this API for application.
107 /// - Since the destructor does not delete the shared memory area, \n
108 /// the application must execute shm_unlink to delete the shared memory area.
109 /// \~english @par Classification
111 /// \~english @par Type
113 /// \~english @see CNSSharedMemWriter(const std::string&, const BOOL), CNSSharedMemWriter(), Close
114 ////////////////////////////////////////////////////////////////////////////////////////////////
115 ~CNSSharedMemWriter();
117 ////////////////////////////////////////////////////////////////////////////////////////////////
118 /// \ingroup CNSSharedMemWriter
119 /// \~english @par Brief
120 /// This function opens and maps the shared memory object.
121 /// \~english @param None
122 /// \~english @retval eFrameworkunifiedStatusOK if shared memory opened successfully
123 /// \~english @retval eFrameworkunifiedStatusNullPointer pointer of the CNSSharedMem object is NULL
124 /// \~english @retval eFrameworkunifiedStatusFail unable to open shared memory
125 /// \~english @par Preconditons
127 /// \~english @par Change of internal status
128 /// - Open shared memory object
129 /// \~english @par Conditions of processing failure
130 /// - pointer of the CNSSharedMem object is NULL.[eFrameworkunifiedStatusNullPointer]
131 /// - unable to open shared memory.[eFrameworkunifiedStatusFail]
132 /// \~english @par Detail
133 /// This function opens and maps the shared memory object.\n
134 /// It creates the shared memory if it does not exists.
135 /// \~english @par Classification
137 /// \~english @par Type
140 /// - eFrameworkunifiedStatus:Result
141 /// - eFrameworkunifiedStatusOK:Success
142 /// - Except eFrameworkunifiedStatusOK:Failure
143 /// \~english @see Close
144 ////////////////////////////////////////////////////////////////////////////////////////////////
145 EFrameworkunifiedStatus Open();
147 ////////////////////////////////////////////////////////////////////////////////////////////////
148 /// \ingroup CNSSharedMemWriter
149 /// \~english @par Brief
150 /// This function is used to check whether the shared memory buffer is opened or not.
151 /// \~english @retval TRUE - Open
152 /// \~english @retval FALSE - Not open
153 /// \~english @par Preconditons
155 /// \~english @par Change of internal status
157 /// \~english @par Conditions of processing failure
159 /// \~english @par Detail
160 /// - Check whether the shared memory buffer is opened or not, and return the result.
161 /// \~english @par Classification
163 /// \~english @par Type
165 /// \~english @see none
166 ////////////////////////////////////////////////////////////////////////////////////////////////
169 ////////////////////////////////////////////////////////////////////////////////////////////////
170 /// \ingroup CNSSharedMemWriter
171 /// \~english @par Brief
172 /// This function unmaps the shared memory object.
173 /// \~english @retval eFrameworkunifiedStatusOK if shared memory closed successfully
174 /// \~english @retval eFrameworkunifiedStatusNullPointer pointer of the CNSSharedMem object is NULL
175 /// \~english @retval eFrameworkunifiedStatusFail if shared memory is not open
176 /// \~english @par Preconditons
178 /// \~english @par Change of internal status
179 /// - Close the shared memory object
180 /// \~english @par Conditions of processing failure
181 /// - Pointer of the CNSSharedMem object is NULL.[eFrameworkunifiedStatusNullPointer]
182 /// - If shared memory is not open.[eFrameworkunifiedStatusFail]
183 /// \~english @par Detail
184 /// - This function unmaps the shared memory object.\n
185 /// If pointer of the CNSSharedMem object is NULL, will return eFrameworkunifiedStatusNullPointer.
186 /// \~english @par Classification
188 /// \~english @par Type
191 /// - eFrameworkunifiedStatus:Result
192 /// - eFrameworkunifiedStatusOK:Success
193 /// - Except eFrameworkunifiedStatusOK:Failure
194 /// \~english @see Open
195 ////////////////////////////////////////////////////////////////////////////////////////////////
196 EFrameworkunifiedStatus Close();
198 ////////////////////////////////////////////////////////////////////////////////////////////////
199 /// \ingroup CNSSharedMemWriter
200 /// \~english @par Brief
201 /// This function writes the data into the shared memory.
202 /// \~english @param[in] buffer
203 /// PSTR - pointer to the buffer containing the data to be written
204 /// \~english @param[in] f_uilength
205 /// const UI_32 - length of the data buffer to be written
206 /// \~english @retval The number of bytes written
207 /// \~english @retval NS_SHM_ERROR if an error occurred
208 /// \~english @par Preconditons
209 /// - Open the shared memory object
210 /// \~english @par Change of internal status
211 /// - shared memory is changed.
212 /// \~english @par Conditions of processing failure
213 /// - m_pShmWriter is NULL.
214 /// - buffer is NULL.
215 /// - f_uilength is 0.
216 /// \~english @par Detail
217 /// - This function writes the buffer's data whose length is f_uilength to shared memory.\n
218 /// If successed,return write size,else return NS_SHM_ERROR.
219 /// \~english @par Classification
221 /// \~english @par Type
224 /// - l_iWriteSize:Result
225 /// - NS_SHM_ERROR:Failure
226 /// - Except NS_SHM_ERROR:Success
227 /// \~english @see None
228 ////////////////////////////////////////////////////////////////////////////////////////////////
229 SI_32 Write(PCSTR buffer, const UI_32 f_uilength);
231 ////////////////////////////////////////////////////////////////////////////////////////////////
232 /// \ingroup CNSSharedMemWriter
233 /// \~english @par Brief
234 /// This function clears the shared memory buffer.
235 /// \~english @retval eFrameworkunifiedStatusOK if shared memory cleared successfully
236 /// \~english @retval eFrameworkunifiedStatusNullPointer pointer of the CNSSharedMem object is NULL
237 /// \~english @retval eFrameworkunifiedStatusFail if shared memory is not open
238 /// \~english @par Preconditons
240 /// \~english @par Change of internal status
241 /// - shared memory is changed.
242 /// \~english @par Conditions of processing failure
243 /// - Pointer of the CNSSharedMem object is NULL.[eFrameworkunifiedStatusNullPointer]
244 /// - If shared memory is not open.[eFrameworkunifiedStatusFail]
245 /// \~english @par Detail
246 /// - This function clears the shared memory buffer.\n
247 /// If pointer of the CNSSharedMem object is NULL, will return eFrameworkunifiedStatusNullPointer.
248 /// \~english @par Classification
250 /// \~english @par Type
253 /// - eFrameworkunifiedStatus:Result
254 /// - eFrameworkunifiedStatusOK:Success
255 /// - Except eFrameworkunifiedStatusOK:Failure
256 /// \~english @see None
257 ////////////////////////////////////////////////////////////////////////////////////////////////
258 EFrameworkunifiedStatus ClearBuf();
261 // no members in protected
264 ////////////////////////////////////////////////////////////////////////////////////////////////
265 /// CNSSharedMemWriter
266 /// Constructor of CNSSharedMemWriter class
272 ////////////////////////////////////////////////////////////////////////////////////////////////
273 CNSSharedMemWriter();
275 CNSSharedMem *m_pShmWriter; // pointer to the CNSSharedMem object
278 #endif /*__NATIVESERVICES_NATIVESERVICES_INC_NATIVE_NS_SHAREDMEM_WRITER_H__*/ // NOLINT (build/header_guard)