Re-organized sub-directory by category
[staging/basesystem.git] / service / native / notification_persistent_service / server / include / ns_npp_binary_accesser.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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.
21 ///
22 ///
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24
25 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_
26 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_
27
28 #include <native_service/frameworkunified_types.h>
29 #include <string>
30 #include <vector>
31 #include "ns_npp_persistent_accesser.h"
32
33 class CPersistentAccesser;
34 class CPersistentData;
35 class CNotificationsToPersist;
36 class CPersistDataHeader;
37
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 /// vector of all available persistent notification and its data.
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
41 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
42
43 typedef Persistent_Notification_List_Type::iterator Persistent_Notification_List_Iterator;
44
45 /**
46  *  This class stores data in a file in binary format.
47  *
48  */
49 class CBinaryAccesser: public CPersistentAccesser {
50  public:
51   typedef enum FileOpentype {
52     EREAD = 0,
53     EWRITE
54   } FILE_OPEN_TYPE;
55
56   ////////////////////////////////////////////////////////////////////////////////////////////////
57   /// CBinaryAccesser
58   /// Constructor of CBinaryAccesser class
59   ///
60   /// \param
61   ///
62   /// \return
63   ///
64   ////////////////////////////////////////////////////////////////////////////////////////////////
65   CBinaryAccesser();
66
67   ////////////////////////////////////////////////////////////////////////////////////////////////
68   /// ~CBinaryAccesser
69   /// Destructor of CBinaryAccesser class
70   ///
71   /// \param
72   ///
73   /// \return
74   ///
75   ////////////////////////////////////////////////////////////////////////////////////////////////
76   ~CBinaryAccesser();
77
78   ////////////////////////////////////////////////////////////////////////////////////////////////
79   /// PersistData
80   /// Persist data in persistent memory in a file in binary format.
81   ///
82   /// \param [IN] f_cmemfilepath
83   ///      std::string - Memory file path for saving notification.
84   ///
85   /// \param [IN] f_vdata
86   ///      Persistent_Notification_List_Type* - Data which has to be persisted.
87   ///
88   /// \param [IN] f_epersistenttype
89   ///      EFrameworkunifiedNotificationType - Type of Notification.
90   ///
91   /// \param [IN] f_epersistcategory
92   ///      EFrameworkunifiedPersistCategory - persist category
93   ///
94   /// \return EFrameworkunifiedStatus
95   //      EFrameworkunifiedStatus - success or failure status
96   ///
97   ////////////////////////////////////////////////////////////////////////////////////////////////
98   EFrameworkunifiedStatus PersistData(std::string f_cmemfilepath,
99                          Persistent_Notification_List_Type *f_vdata,
100                          EFrameworkunifiedNotificationType f_epersistenttype,
101                          EFrameworkunifiedPersistCategory f_epersistcategory = eFrameworkunifiedUserData);
102
103   ////////////////////////////////////////////////////////////////////////////////////////////////
104   /// RetrieveData
105   /// Retrieve data from from a file from persistent memory and store in a vector.
106   ///
107   /// \param [IN] f_cmemfilepath
108   ///      std::string - Memory file path from where to retrieve notification data.
109   ///
110   /// \param [OUT] f_vdata
111   ///      Persistent_Notification_List_Type*& - Retrieved notification data is filled in this vector.
112   ///
113   /// \param [IN] f_epersistcategory
114   ///      EFrameworkunifiedPersistCategory - persist category
115   ///
116   /// \return EFrameworkunifiedStatus
117   //      EFrameworkunifiedStatus - success or failure status
118   ///
119   ////////////////////////////////////////////////////////////////////////////////////////////////
120   EFrameworkunifiedStatus RetrieveData(std::string f_cmemfilepath,
121                           Persistent_Notification_List_Type *&f_vdata, // NOLINT (runtime/references)
122                           EFrameworkunifiedPersistCategory f_epersistcategory = eFrameworkunifiedUserData);
123
124  private:
125   UI_32 m_uiCurStrOffset;
126   UI_32 m_uiCurStrSize;
127
128   ////////////////////////////////////////////////////////////////////////////////////////////////
129   /// OpenFileForReading
130   /// Open file in read mode.
131   ///
132   /// \param [OUT] f_Fd
133   ///      int * - File descriptor to read from a file
134   ///
135   /// \param [IN] f_cfilepath
136   ///      std::string - File Path from the file is to be read
137   ///
138   /// \return EFrameworkunifiedStatus
139   //      EFrameworkunifiedStatus - success or failure status
140   ///
141   ////////////////////////////////////////////////////////////////////////////////////////////////
142   EFrameworkunifiedStatus OpenFileForReading(int *f_infd,
143                                 std::string f_cfilepath);
144
145   ////////////////////////////////////////////////////////////////////////////////////////////////
146   /// OpenFileForWriting
147   /// Open file in write mode.
148   ///
149   /// \param [OUT] f_Fd
150   ///      int * - File descriptor to write to a file
151   ///
152   /// \param [IN] f_cfilepath
153   ///      std::string - File Path for  the file that is to be written
154   ///
155   /// \return EFrameworkunifiedStatus
156   //      EFrameworkunifiedStatus - success or failure status
157   ///
158   ////////////////////////////////////////////////////////////////////////////////////////////////
159   EFrameworkunifiedStatus OpenFileForWriting(int *f_outfd,
160                                 std::string f_cfilepath);
161
162   ////////////////////////////////////////////////////////////////////////////////////////////////
163   /// WriteHeaderAndData
164   /// Write header and data in a file.
165   ///
166   /// \param [IN] f_pnotificationstopersist
167   ///      CNotificationsToPersist - Object of class CNotificationsToPersist
168   ///
169   /// \param [IN] f_pdata
170   ///      PVOID - notification data
171   ///
172   /// \param [IN] f_Fd
173   ///      int - File descriptor to write the file.
174   ///
175   /// \return EFrameworkunifiedStatus
176   //      EFrameworkunifiedStatus - success or failure status
177   ///
178   ////////////////////////////////////////////////////////////////////////////////////////////////
179   EFrameworkunifiedStatus WriteHeaderAndData(CNotificationsToPersist *f_pnotificationstopersist,
180                                 PVOID f_pdata,
181                                 int f_outfd);
182
183   ////////////////////////////////////////////////////////////////////////////////////////////////
184   /// ReadHeaderAndData
185   /// Read header from the file.
186   ///
187   /// \param [IN] f_objcpersistdataheader
188   ///      CPersistDataHeader& - Object of class CPersistDataHeader
189   ///
190   /// \param [OUT] f_pdata
191   ///      CHAR*& -
192   ///
193   /// \param [IN] f_Fd
194   ///      int - File descriptor to read the file.
195   ///
196   /// \return EFrameworkunifiedStatus
197   //      EFrameworkunifiedStatus - success or failure status
198   ///
199   ////////////////////////////////////////////////////////////////////////////////////////////////
200   EFrameworkunifiedStatus ReadHeaderAndData(CPersistDataHeader &f_objcpersistdataheader, // NOLINT (runtime/references)
201                                CHAR *&f_pdata, int f_infd); // NOLINT (runtime/references)
202
203   ////////////////////////////////////////////////////////////////////////////////////////////////
204   /// FillNotificationList
205   /// This function retrieves the notification data from file and fill it in map.
206   ///
207   /// \param [IN] f_Fd
208   ///      int - File descriptor to retrieve notification data.
209   ///
210   /// \param [OUT] f_vdata
211   ///      Persistent_Notification_List_Type*& - Retrieved notification data is filled in this vector.
212   ///
213   /// \param [IN] f_epersistcategory
214   ///      EFrameworkunifiedPersistCategory - persist category
215   ///
216   /// \return EFrameworkunifiedStatus
217   //      EFrameworkunifiedStatus - success or failure status
218   ///
219   ////////////////////////////////////////////////////////////////////////////////////////////////
220   EFrameworkunifiedStatus FillNotificationList(int f_infd,
221                                   Persistent_Notification_List_Type *&f_vdata, // NOLINT (runtime/references)
222                                   EFrameworkunifiedPersistCategory f_epersistcategory);
223
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);
228 };
229
230 #endif  // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_BINARY_ACCESSER_H_