Fix path to various non-standard directories
[staging/basesystem.git] / service / native / notification_persistent_service / server / include / ns_npp_persistence.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 CPersistence class.
20 ///           This is a abstract class for file and folder persistency.
21 ///
22 ///
23 ///
24 ////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_
27 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_
28
29 #include <native_service/frameworkunified_types.h>
30 #include <native_service/ns_np_service.h>
31 #include <string>
32 #include <map>
33 #include <list>
34
35 #include "ns_npp_notificationpersistentservicelog.h"
36 #include "ns_npp_copy_worker.h"
37
38 class CRegistryEntry;
39
40 typedef std::string TSourceName;
41 typedef std::string TTag;
42 typedef std::map< TTag, CRegistryEntry > TTagRegistryList;
43 typedef TTagRegistryList::iterator TTagRegistryListItr;
44
45 typedef std::map<TSourceName, TTagRegistryList> TSourceRegistryList;
46 typedef TSourceRegistryList::iterator TSourceRegistryListItr;
47
48 typedef std::list<NSP_CopyInfoCmd> TPendingJobs;
49 typedef TPendingJobs::iterator TPendingJobsItr;
50
51 /**
52  *  This is a abstract class for file and folder persistence.
53  */
54 class CPersistence {
55  public:
56   ////////////////////////////////////////////////////////////////////////////////////////////////
57   /// CPersistence
58   /// Constructor of CPersistence class
59   ///
60   /// \param
61   ///
62   /// \return
63   ///
64   ////////////////////////////////////////////////////////////////////////////////////////////////
65   CPersistence();
66
67   ////////////////////////////////////////////////////////////////////////////////////////////////
68   /// ~CPersistence
69   /// Destructor of CPersistence class
70   ///
71   /// \param
72   ///
73   /// \return
74   ///
75   ////////////////////////////////////////////////////////////////////////////////////////////////
76   virtual ~CPersistence();
77
78   ////////////////////////////////////////////////////////////////////////////////////////////////
79   /// Register
80   ///  Register file/folder tag for persistence.
81   ///
82   /// \param [IN] f_cappname
83   ///      string - Name of the application requesting for persistence
84   ///
85   /// \param [IN] f_ctag
86   ///      string - File/Folder corresponding to this tag will be retrieved.
87   ///
88   /// \param [IN] bisuserpersistence
89   ///      BOOL - TRUE if user persistence else FALSE
90   ///
91   /// \return EFrameworkunifiedStatus
92   //      EFrameworkunifiedStatus - success or failure status
93   ///
94   ////////////////////////////////////////////////////////////////////////////////////////////////
95   virtual EFrameworkunifiedStatus Register(std::string f_crequestorappname, std::string f_ctag, BOOL bisuserpersistence);
96
97   ////////////////////////////////////////////////////////////////////////////////////////////////
98   /// Release
99   /// Entry for the file/Folder is stored in map for persistence.
100   /// If f_bPersist is TRUE file/folder will be persisted immediately else will be persist on shutdown
101   ///
102   /// \param [IN] f_cappname
103   ///      string - Name of the application requesting for persistence
104   ///
105   /// \param [IN] f_ctag
106   ///      string - File/Folder will be persist against this tag.
107   ///
108   /// \param [IN] f_cmempath
109   ///      string - File/Folder path that is to be persisted.
110   ///
111   /// \param [IN] enotificationpersistentservicereleasetype
112   ///      EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease = 0  :not on release
113   ///                        eFrameworkunifiedPersistOnShutdown :persist on shutdown
114   ///                        eFrameworkunifiedPersistInstantly  :persist instantly
115   ///
116   /// \param [IN] f_cusername
117   ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
118   ///            else an empty string
119   /// \return EFrameworkunifiedStatus
120   //      EFrameworkunifiedStatus - success or failure status
121   ///
122   ////////////////////////////////////////////////////////////////////////////////////////////////
123   virtual EFrameworkunifiedStatus Release(std::string f_cappname,
124                              std::string f_ctag,
125                              std::string f_cmempath,
126                              EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
127                              std::string f_cusername) = 0;
128
129
130   ////////////////////////////////////////////////////////////////////////////////////////////////
131   /// Load
132   ///  Load file/folder from persistent memory to the specified location.
133   ///
134   /// \param [IN] f_cappname
135   ///      string - Name of the application requesting for persistence
136   ///
137   /// \param [IN] f_ctag
138   ///      string - File/Folder corresponding to this tag will be retrieved.
139   ///
140   /// \param [IN] f_cretrievepath
141   ///      string - Path to retrieve.
142   ///
143   /// \param [IN] f_cusername
144   ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
145   ///            else an empty string
146   ///
147   /// \return EFrameworkunifiedStatus
148   //      EFrameworkunifiedStatus - success or failure status
149   ///
150   ////////////////////////////////////////////////////////////////////////////////////////////////
151   virtual EFrameworkunifiedStatus Load(std::string f_cappname,
152                           std::string f_ctag,
153                           std::string f_cretrievepath,
154                           std::string f_cusername) = 0;
155
156   ////////////////////////////////////////////////////////////////////////////////////////////////
157   /// Persist
158   /// Persist file/folder immediately
159   ///
160   /// \param [IN] f_objregistryentry
161   ///      CRegistryEntry& - Registry entry job object to persist.
162   ///
163   /// \return EFrameworkunifiedStatus
164   //      EFrameworkunifiedStatus - success or failure status
165   ///
166   ////////////////////////////////////////////////////////////////////////////////////////////////
167   EFrameworkunifiedStatus Persist(CRegistryEntry &f_objregistryentry); // NOLINT (runtime/references)
168
169   ////////////////////////////////////////////////////////////////////////////////////////////
170   /// AckReceivedFromWorker
171   ///
172   ///
173   /// \param [in] pSource
174   ///         PCSTR - Name of the source.
175   /// \param [in] f_ctag
176   ///          PCSTR - file/folder tag.
177   /// \param [in] f_bcopystatus
178   ///         BOOL - Status of file/folder copy by copy worker.
179   /// \param [in] f_eloadtype
180   ///         ENPS_Loadtype - Type of load release or load.
181   ///
182   /// \return status
183   ///         EFrameworkunifiedStatus - success or error
184   ////////////////////////////////////////////////////////////////////////////////////////////
185   virtual EFrameworkunifiedStatus AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, BOOL f_bcopystatus,
186                                            ENPS_Loadtype f_eloadtype);
187
188   ////////////////////////////////////////////////////////////////////////////////////////////
189   /// PersistAllReleaseRequests
190   /// Persist all files/folders which are not persisted yet.
191   ///
192   /// \param [in] f_uinotificationpersistentservicepersistcategoryflag
193   ///     UI_32 - Hex value from enum EFrameworkunifiedPersistCategory, representing data to persist
194   ///     0 - persist orignal data and
195   ///     1 - persist default data
196   ///
197   /// \return status
198   ///         EFrameworkunifiedStatus - success or error
199   ////////////////////////////////////////////////////////////////////////////////////////////
200   virtual EFrameworkunifiedStatus PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag);
201
202   ////////////////////////////////////////////////////////////////////////////////////////////
203   /// HaveAllReleaseRequestsPersisted
204   /// Checks if all release requests are processed or not
205   ///
206   /// \param [out] f_ctagnotreleased
207   ///     std::string - list of tags not released by application
208   ///
209   /// \return BOOL
210   ///         TRUE if all release requests are processed else false
211   ////////////////////////////////////////////////////////////////////////////////////////////
212   BOOL HaveAllReleaseRequestsPersisted(std::string &f_ctagnotreleased); // NOLINT (runtime/references)
213
214   ////////////////////////////////////////////////////////////////////////////////////////////
215   /// ResetPersistFlag
216   /// Resets persist flag.
217   ///
218   /// \param none
219   ///
220   /// \return none
221   ////////////////////////////////////////////////////////////////////////////////////////////
222   VOID ResetPersistFlag();
223
224   ////////////////////////////////////////////////////////////////////////////////////////////
225   /// PersistAllUserRequests
226   /// Persist all files/folders which are not persisted yet.
227   ///
228   ///
229   /// \return status
230   ///         EFrameworkunifiedStatus - success or error
231   ////////////////////////////////////////////////////////////////////////////////////////////
232   virtual EFrameworkunifiedStatus PersistAllUserRequests();
233
234   // virtual VOID ListAllInMap() = 0;
235
236   ////////////////////////////////////////////////////////////////////////////////////////////
237   /// SetReadThreadHandle
238   /// Set read thread handle.
239   ///
240   /// \param [in] f_hreadthread
241   ///        HANDLE - Handle of the read thread.
242   ///
243   /// \return
244   ///
245   ////////////////////////////////////////////////////////////////////////////////////////////
246   VOID SetReadThreadHandle(HANDLE f_hreadthread);
247
248   ////////////////////////////////////////////////////////////////////////////////////////////
249   /// SetWriteThreadHandle
250   /// Set write thread handle.
251   ///
252   /// \param [in] f_hwritethread
253   ///        HANDLE - Handle of the write thread.
254   ///
255   /// \return
256   ///
257   ////////////////////////////////////////////////////////////////////////////////////////////
258   VOID SetWriteThreadHandle(HANDLE f_hwritethread);
259
260   ////////////////////////////////////////////////////////////////////////////////////////////
261   /// GetStoragePath
262   /// Get the permanent storage path. Get it from NS_NPPService's config file.
263   ///
264   /// \return std::string
265   ///         std::string - Permanant storage path
266   ////////////////////////////////////////////////////////////////////////////////////////////
267   static std::string GetStoragePath();
268
269   ////////////////////////////////////////////////////////////////////////////////////////////////
270   /// SetPersistentCategory
271   /// Sets the persist type of file/folder
272   ///
273   /// \param [IN] f_crequestorname
274   ///      string - Application Name
275   ///
276   /// \param [IN] f_ctag
277   ///      string - File/Folder will be persist against this tag.
278   ///
279   /// \param [IN] f_epersistcategory
280   ///      EFrameworkunifiedPersistCategory - persistent category
281   ///
282   /// \return EFrameworkunifiedStatus
283   //      EFrameworkunifiedStatus - success or failure status
284   ///
285   ////////////////////////////////////////////////////////////////////////////////////////////////
286   EFrameworkunifiedStatus SetPersistentCategory(const std::string &f_crequestorname,
287                                    const std::string &f_ctag,
288                                    EFrameworkunifiedPersistCategory f_epersistcategory);
289
290   ////////////////////////////////////////////////////////////////////////////////////////////
291   /// IsUserPersistence
292   /// Check if the file/folder being persisted is user specific
293   ///
294   /// \param [in] - f_ctag
295   ///         std::string - File/Folder Tag
296   ///
297   /// \return status
298   ///         BOOL - TRUE for user specific persistence
299   ///          FALSE  for global persistence
300   ///////////////////////////////////////////////////////////////////////////////////////////
301   virtual BOOL IsUserPersistence(std::string f_ctag);
302
303 #ifdef NPP_PROFILEINFO_ENABLE
304
305   ////////////////////////////////////////////////////////////////////////////////////////////////
306   /// GetPersistenceProfilingData
307   /// This function is used to get the persistence info
308   ///
309   /// \param [out] f_cpersistenceprofileinfo
310   ///         std::string - Persistence info concated in a string
311   ///
312   /// \return EFrameworkunifiedStatus
313   ///     EFrameworkunifiedStatus - success or failure
314   ///
315   ////////////////////////////////////////////////////////////////////////////////////////////////
316   EFrameworkunifiedStatus GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo); // NOLINT (runtime/references)
317
318 #endif
319
320  protected:
321   EFrameworkunifiedStatus ProcessReleaseRequest(std::string f_crequesterappname,
322                                    std::string f_ctag,
323                                    ENotificationpersistentservicePersistType f_epersisttype,
324                                    std::string f_cmempath,
325                                    EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
326                                    std::string f_cusername);
327
328   EFrameworkunifiedStatus ProcessLoadRequest(std::string f_crequesterappname,
329                                 std::string f_ctag,
330                                 ENotificationpersistentservicePersistType f_epersisttype,
331                                 std::string f_cretrievepath,
332                                 std::string f_cusername);
333
334   VOID AddRequestData(NSP_CopyInfoCmd &f_tcpinfo, // NOLINT (runtime/references)
335                       std::string f_sourcepath,
336                       std::string f_destpath,
337                       std::string f_crequesterappname,
338                       std::string f_ctag,
339                       ENPS_Loadtype f_eloadtype,
340                       ENotificationpersistentservicePersistType f_epersisttype);
341
342   EFrameworkunifiedStatus SendRequestMessage(NSP_CopyInfoCmd &f_tcpinfo); // NOLINT (runtime/references)
343
344   std::string m_cStoragePath;  ///< Persistent memory storage path
345
346   NOTIFICATIONPERSISTENTSERVICE_COMPRESSION_TYPE m_eCompressionType;  ///< Compression type for file/folder persistency
347
348   HANDLE m_hNSWriteToPersistentMem;  ///< Child thread handle, copies file to persistent memory.
349
350   HANDLE m_hNSReadFromPersistentMem;  ///< Child thread handle, copies file from persistent memory.
351
352   // TODO(my_username): Remove this member var. Once the API to get application handle is available, use that.
353   HANDLE m_hAppHandle;
354
355   TSourceRegistryList m_mPersistRegistry;
356
357   TPendingJobs m_lPendingJobs;  ///< stores the list of pending jobs sequentially
358
359   BOOL m_bPersist;  ///< persist or not. It will be set to TRUE either on shutdown or userchange
360
361   UI_32 m_uiNotificationpersistentservicePersistCategoryFlag;  ///< Stores the persist category flag value on shutdown request.
362   ///< It is needed to decide which data to persist, if
363   ///< release request is received by NSNPP after shutdown request
364 };
365 #endif  // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_