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_NPPService
19 /// \brief The file contains declaration of CBinaryAccesser class.
20 /// This class stores data in a file in binary format.
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
25 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_
26 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_
28 #include <native_service/frameworkunified_types.h>
31 #include "ns_npp_persistent_accesser.h"
33 class CPersistentAccesser;
34 class CPersistentData;
35 class CNotificationsToPersist;
36 class CPersistDataHeader;
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 /// vector of all available persistent notification and its data.
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
41 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
43 typedef Persistent_Notification_List_Type::iterator Persistent_Notification_List_Iterator;
46 * This class stores data in a file in binary format.
49 class CBinaryAccesser: public CPersistentAccesser {
51 typedef enum FileOpentype {
56 ////////////////////////////////////////////////////////////////////////////////////////////////
58 /// Constructor of CBinaryAccesser class
64 ////////////////////////////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////////////////////////////
69 /// Destructor of CBinaryAccesser class
75 ////////////////////////////////////////////////////////////////////////////////////////////////
78 ////////////////////////////////////////////////////////////////////////////////////////////////
80 /// Persist data in persistent memory in a file in binary format.
82 /// \param [IN] f_cmemfilepath
83 /// std::string - Memory file path for saving notification.
85 /// \param [IN] f_vdata
86 /// Persistent_Notification_List_Type* - Data which has to be persisted.
88 /// \param [IN] f_epersistenttype
89 /// EFrameworkunifiedNotificationType - Type of Notification.
91 /// \param [IN] f_epersistcategory
92 /// EFrameworkunifiedPersistCategory - persist category
94 /// \return EFrameworkunifiedStatus
95 // EFrameworkunifiedStatus - success or failure status
97 ////////////////////////////////////////////////////////////////////////////////////////////////
98 EFrameworkunifiedStatus PersistData(std::string f_cmemfilepath,
99 Persistent_Notification_List_Type *f_vdata,
100 EFrameworkunifiedNotificationType f_epersistenttype,
101 EFrameworkunifiedPersistCategory f_epersistcategory = eFrameworkunifiedUserData);
103 ////////////////////////////////////////////////////////////////////////////////////////////////
105 /// Retrieve data from from a file from persistent memory and store in a vector.
107 /// \param [IN] f_cmemfilepath
108 /// std::string - Memory file path from where to retrieve notification data.
110 /// \param [OUT] f_vdata
111 /// Persistent_Notification_List_Type*& - Retrieved notification data is filled in this vector.
113 /// \param [IN] f_epersistcategory
114 /// EFrameworkunifiedPersistCategory - persist category
116 /// \return EFrameworkunifiedStatus
117 // EFrameworkunifiedStatus - success or failure status
119 ////////////////////////////////////////////////////////////////////////////////////////////////
120 EFrameworkunifiedStatus RetrieveData(std::string f_cmemfilepath,
121 Persistent_Notification_List_Type *&f_vdata, // NOLINT (runtime/references)
122 EFrameworkunifiedPersistCategory f_epersistcategory = eFrameworkunifiedUserData);
125 UI_32 m_uiCurStrOffset;
126 UI_32 m_uiCurStrSize;
128 ////////////////////////////////////////////////////////////////////////////////////////////////
129 /// OpenFileForReading
130 /// Open file in read mode.
132 /// \param [OUT] f_Fd
133 /// int * - File descriptor to read from a file
135 /// \param [IN] f_cfilepath
136 /// std::string - File Path from the file is to be read
138 /// \return EFrameworkunifiedStatus
139 // EFrameworkunifiedStatus - success or failure status
141 ////////////////////////////////////////////////////////////////////////////////////////////////
142 EFrameworkunifiedStatus OpenFileForReading(int *f_infd,
143 std::string f_cfilepath);
145 ////////////////////////////////////////////////////////////////////////////////////////////////
146 /// OpenFileForWriting
147 /// Open file in write mode.
149 /// \param [OUT] f_Fd
150 /// int * - File descriptor to write to a file
152 /// \param [IN] f_cfilepath
153 /// std::string - File Path for the file that is to be written
155 /// \return EFrameworkunifiedStatus
156 // EFrameworkunifiedStatus - success or failure status
158 ////////////////////////////////////////////////////////////////////////////////////////////////
159 EFrameworkunifiedStatus OpenFileForWriting(int *f_outfd,
160 std::string f_cfilepath);
162 ////////////////////////////////////////////////////////////////////////////////////////////////
163 /// WriteHeaderAndData
164 /// Write header and data in a file.
166 /// \param [IN] f_pnotificationstopersist
167 /// CNotificationsToPersist - Object of class CNotificationsToPersist
169 /// \param [IN] f_pdata
170 /// PVOID - notification data
173 /// int - File descriptor to write the file.
175 /// \return EFrameworkunifiedStatus
176 // EFrameworkunifiedStatus - success or failure status
178 ////////////////////////////////////////////////////////////////////////////////////////////////
179 EFrameworkunifiedStatus WriteHeaderAndData(CNotificationsToPersist *f_pnotificationstopersist,
183 ////////////////////////////////////////////////////////////////////////////////////////////////
184 /// ReadHeaderAndData
185 /// Read header from the file.
187 /// \param [IN] f_objcpersistdataheader
188 /// CPersistDataHeader& - Object of class CPersistDataHeader
190 /// \param [OUT] f_pdata
194 /// int - File descriptor to read the file.
196 /// \return EFrameworkunifiedStatus
197 // EFrameworkunifiedStatus - success or failure status
199 ////////////////////////////////////////////////////////////////////////////////////////////////
200 EFrameworkunifiedStatus ReadHeaderAndData(CPersistDataHeader &f_objcpersistdataheader, // NOLINT (runtime/references)
201 CHAR *&f_pdata, int f_infd); // NOLINT (runtime/references)
203 ////////////////////////////////////////////////////////////////////////////////////////////////
204 /// FillNotificationList
205 /// This function retrieves the notification data from file and fill it in map.
208 /// int - File descriptor to retrieve notification data.
210 /// \param [OUT] f_vdata
211 /// Persistent_Notification_List_Type*& - Retrieved notification data is filled in this vector.
213 /// \param [IN] f_epersistcategory
214 /// EFrameworkunifiedPersistCategory - persist category
216 /// \return EFrameworkunifiedStatus
217 // EFrameworkunifiedStatus - success or failure status
219 ////////////////////////////////////////////////////////////////////////////////////////////////
220 EFrameworkunifiedStatus FillNotificationList(int f_infd,
221 Persistent_Notification_List_Type *&f_vdata, // NOLINT (runtime/references)
222 EFrameworkunifiedPersistCategory f_epersistcategory);
224 EFrameworkunifiedStatus WriteFileHeaderAndDuplicate(int f_outfd, std::string f_cfilepath);
225 EFrameworkunifiedStatus CheckFileHeader(int f_infd);
226 EFrameworkunifiedStatus OpenBakFileForReading(int *f_infd, std::string f_cfilepath);
227 UI_32 CalcCRC(PVOID f_pdata, UI_32 f_size);
230 #endif // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_