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 CPersistence class.
20 /// This is a abstract class for file and folder persistency.
24 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_
27 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_
29 #include <native_service/frameworkunified_types.h>
30 #include <native_service/ns_np_service.h>
35 #include "ns_npp_notificationpersistentservicelog.h"
36 #include "ns_npp_copy_worker.h"
40 typedef std::string TSourceName;
41 typedef std::string TTag;
42 typedef std::map< TTag, CRegistryEntry > TTagRegistryList;
43 typedef TTagRegistryList::iterator TTagRegistryListItr;
45 typedef std::map<TSourceName, TTagRegistryList> TSourceRegistryList;
46 typedef TSourceRegistryList::iterator TSourceRegistryListItr;
48 typedef std::list<NSP_CopyInfoCmd> TPendingJobs;
49 typedef TPendingJobs::iterator TPendingJobsItr;
52 * This is a abstract class for file and folder persistence.
56 ////////////////////////////////////////////////////////////////////////////////////////////////
58 /// Constructor of CPersistence class
64 ////////////////////////////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////////////////////////////
69 /// Destructor of CPersistence class
75 ////////////////////////////////////////////////////////////////////////////////////////////////
76 virtual ~CPersistence();
78 ////////////////////////////////////////////////////////////////////////////////////////////////
80 /// Register file/folder tag for persistence.
82 /// \param [IN] f_cappname
83 /// string - Name of the application requesting for persistence
85 /// \param [IN] f_ctag
86 /// string - File/Folder corresponding to this tag will be retrieved.
88 /// \param [IN] bisuserpersistence
89 /// BOOL - TRUE if user persistence else FALSE
91 /// \return EFrameworkunifiedStatus
92 // EFrameworkunifiedStatus - success or failure status
94 ////////////////////////////////////////////////////////////////////////////////////////////////
95 virtual EFrameworkunifiedStatus Register(std::string f_crequestorappname, std::string f_ctag, BOOL bisuserpersistence);
97 ////////////////////////////////////////////////////////////////////////////////////////////////
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
102 /// \param [IN] f_cappname
103 /// string - Name of the application requesting for persistence
105 /// \param [IN] f_ctag
106 /// string - File/Folder will be persist against this tag.
108 /// \param [IN] f_cmempath
109 /// string - File/Folder path that is to be persisted.
111 /// \param [IN] enotificationpersistentservicereleasetype
112 /// EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease = 0 :not on release
113 /// eFrameworkunifiedPersistOnShutdown :persist on shutdown
114 /// eFrameworkunifiedPersistInstantly :persist instantly
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
122 ////////////////////////////////////////////////////////////////////////////////////////////////
123 virtual EFrameworkunifiedStatus Release(std::string f_cappname,
125 std::string f_cmempath,
126 EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
127 std::string f_cusername) = 0;
130 ////////////////////////////////////////////////////////////////////////////////////////////////
132 /// Load file/folder from persistent memory to the specified location.
134 /// \param [IN] f_cappname
135 /// string - Name of the application requesting for persistence
137 /// \param [IN] f_ctag
138 /// string - File/Folder corresponding to this tag will be retrieved.
140 /// \param [IN] f_cretrievepath
141 /// string - Path to retrieve.
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
147 /// \return EFrameworkunifiedStatus
148 // EFrameworkunifiedStatus - success or failure status
150 ////////////////////////////////////////////////////////////////////////////////////////////////
151 virtual EFrameworkunifiedStatus Load(std::string f_cappname,
153 std::string f_cretrievepath,
154 std::string f_cusername) = 0;
156 ////////////////////////////////////////////////////////////////////////////////////////////////
158 /// Persist file/folder immediately
160 /// \param [IN] f_objregistryentry
161 /// CRegistryEntry& - Registry entry job object to persist.
163 /// \return EFrameworkunifiedStatus
164 // EFrameworkunifiedStatus - success or failure status
166 ////////////////////////////////////////////////////////////////////////////////////////////////
167 EFrameworkunifiedStatus Persist(CRegistryEntry &f_objregistryentry); // NOLINT (runtime/references)
169 ////////////////////////////////////////////////////////////////////////////////////////////
170 /// AckReceivedFromWorker
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.
183 /// EFrameworkunifiedStatus - success or error
184 ////////////////////////////////////////////////////////////////////////////////////////////
185 virtual EFrameworkunifiedStatus AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, BOOL f_bcopystatus,
186 ENPS_Loadtype f_eloadtype);
188 ////////////////////////////////////////////////////////////////////////////////////////////
189 /// PersistAllReleaseRequests
190 /// Persist all files/folders which are not persisted yet.
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
198 /// EFrameworkunifiedStatus - success or error
199 ////////////////////////////////////////////////////////////////////////////////////////////
200 virtual EFrameworkunifiedStatus PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag);
202 ////////////////////////////////////////////////////////////////////////////////////////////
203 /// HaveAllReleaseRequestsPersisted
204 /// Checks if all release requests are processed or not
206 /// \param [out] f_ctagnotreleased
207 /// std::string - list of tags not released by application
210 /// TRUE if all release requests are processed else false
211 ////////////////////////////////////////////////////////////////////////////////////////////
212 BOOL HaveAllReleaseRequestsPersisted(std::string &f_ctagnotreleased); // NOLINT (runtime/references)
214 ////////////////////////////////////////////////////////////////////////////////////////////
216 /// Resets persist flag.
221 ////////////////////////////////////////////////////////////////////////////////////////////
222 VOID ResetPersistFlag();
224 ////////////////////////////////////////////////////////////////////////////////////////////
225 /// PersistAllUserRequests
226 /// Persist all files/folders which are not persisted yet.
230 /// EFrameworkunifiedStatus - success or error
231 ////////////////////////////////////////////////////////////////////////////////////////////
232 virtual EFrameworkunifiedStatus PersistAllUserRequests();
234 // virtual VOID ListAllInMap() = 0;
236 ////////////////////////////////////////////////////////////////////////////////////////////
237 /// SetReadThreadHandle
238 /// Set read thread handle.
240 /// \param [in] f_hreadthread
241 /// HANDLE - Handle of the read thread.
245 ////////////////////////////////////////////////////////////////////////////////////////////
246 VOID SetReadThreadHandle(HANDLE f_hreadthread);
248 ////////////////////////////////////////////////////////////////////////////////////////////
249 /// SetWriteThreadHandle
250 /// Set write thread handle.
252 /// \param [in] f_hwritethread
253 /// HANDLE - Handle of the write thread.
257 ////////////////////////////////////////////////////////////////////////////////////////////
258 VOID SetWriteThreadHandle(HANDLE f_hwritethread);
260 ////////////////////////////////////////////////////////////////////////////////////////////
262 /// Get the permanent storage path. Get it from NS_NPPService's config file.
264 /// \return std::string
265 /// std::string - Permanant storage path
266 ////////////////////////////////////////////////////////////////////////////////////////////
267 static std::string GetStoragePath();
269 ////////////////////////////////////////////////////////////////////////////////////////////////
270 /// SetPersistentCategory
271 /// Sets the persist type of file/folder
273 /// \param [IN] f_crequestorname
274 /// string - Application Name
276 /// \param [IN] f_ctag
277 /// string - File/Folder will be persist against this tag.
279 /// \param [IN] f_epersistcategory
280 /// EFrameworkunifiedPersistCategory - persistent category
282 /// \return EFrameworkunifiedStatus
283 // EFrameworkunifiedStatus - success or failure status
285 ////////////////////////////////////////////////////////////////////////////////////////////////
286 EFrameworkunifiedStatus SetPersistentCategory(const std::string &f_crequestorname,
287 const std::string &f_ctag,
288 EFrameworkunifiedPersistCategory f_epersistcategory);
290 ////////////////////////////////////////////////////////////////////////////////////////////
291 /// IsUserPersistence
292 /// Check if the file/folder being persisted is user specific
294 /// \param [in] - f_ctag
295 /// std::string - File/Folder Tag
298 /// BOOL - TRUE for user specific persistence
299 /// FALSE for global persistence
300 ///////////////////////////////////////////////////////////////////////////////////////////
301 virtual BOOL IsUserPersistence(std::string f_ctag);
303 #ifdef NPP_PROFILEINFO_ENABLE
305 ////////////////////////////////////////////////////////////////////////////////////////////////
306 /// GetPersistenceProfilingData
307 /// This function is used to get the persistence info
309 /// \param [out] f_cpersistenceprofileinfo
310 /// std::string - Persistence info concated in a string
312 /// \return EFrameworkunifiedStatus
313 /// EFrameworkunifiedStatus - success or failure
315 ////////////////////////////////////////////////////////////////////////////////////////////////
316 EFrameworkunifiedStatus GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo); // NOLINT (runtime/references)
321 EFrameworkunifiedStatus ProcessReleaseRequest(std::string f_crequesterappname,
323 ENotificationpersistentservicePersistType f_epersisttype,
324 std::string f_cmempath,
325 EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
326 std::string f_cusername);
328 EFrameworkunifiedStatus ProcessLoadRequest(std::string f_crequesterappname,
330 ENotificationpersistentservicePersistType f_epersisttype,
331 std::string f_cretrievepath,
332 std::string f_cusername);
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,
339 ENPS_Loadtype f_eloadtype,
340 ENotificationpersistentservicePersistType f_epersisttype);
342 EFrameworkunifiedStatus SendRequestMessage(NSP_CopyInfoCmd &f_tcpinfo); // NOLINT (runtime/references)
344 std::string m_cStoragePath; ///< Persistent memory storage path
346 NOTIFICATIONPERSISTENTSERVICE_COMPRESSION_TYPE m_eCompressionType; ///< Compression type for file/folder persistency
348 HANDLE m_hNSWriteToPersistentMem; ///< Child thread handle, copies file to persistent memory.
350 HANDLE m_hNSReadFromPersistentMem; ///< Child thread handle, copies file from persistent memory.
352 // TODO(my_username): Remove this member var. Once the API to get application handle is available, use that.
355 TSourceRegistryList m_mPersistRegistry;
357 TPendingJobs m_lPendingJobs; ///< stores the list of pending jobs sequentially
359 BOOL m_bPersist; ///< persist or not. It will be set to TRUE either on shutdown or userchange
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
365 #endif // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_