summaryrefslogtreecommitdiffstats
path: root/nsframework/notification_persistent_service/server/include/ns_npp_persistence.h
blob: d84f9fbef16b6d467ea22bf918ad7f833ab01c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_NPPService
/// \brief    The file contains declaration of CPersistence class.
///           This is a abstract class for file and folder persistency.
///
///
///
////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_
#define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_

#include <native_service/frameworkunified_types.h>
#include <native_service/ns_np_service.h>
#include <string>
#include <map>
#include <list>

#include "ns_npp_notificationpersistentservicelog.h"
#include "ns_npp_copy_worker.h"

class CRegistryEntry;

typedef std::string TSourceName;
typedef std::string TTag;
typedef std::map< TTag, CRegistryEntry > TTagRegistryList;
typedef TTagRegistryList::iterator TTagRegistryListItr;

typedef std::map<TSourceName, TTagRegistryList> TSourceRegistryList;
typedef TSourceRegistryList::iterator TSourceRegistryListItr;

typedef std::list<NSP_CopyInfoCmd> TPendingJobs;
typedef TPendingJobs::iterator TPendingJobsItr;

/**
 *  This is a abstract class for file and folder persistence.
 */
class CPersistence {
 public:
  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// CPersistence
  /// Constructor of CPersistence class
  ///
  /// \param
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CPersistence();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// ~CPersistence
  /// Destructor of CPersistence class
  ///
  /// \param
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  virtual ~CPersistence();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// Register
  ///  Register file/folder tag for persistence.
  ///
  /// \param [IN] f_cappname
  ///      string - Name of the application requesting for persistence
  ///
  /// \param [IN] f_ctag
  ///      string - File/Folder corresponding to this tag will be retrieved.
  ///
  /// \param [IN] bisuserpersistence
  ///      BOOL - TRUE if user persistence else FALSE
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus Register(std::string f_crequestorappname, std::string f_ctag, BOOL bisuserpersistence);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// Release
  /// Entry for the file/Folder is stored in map for persistence.
  /// If f_bPersist is TRUE file/folder will be persisted immediately else will be persist on shutdown
  ///
  /// \param [IN] f_cappname
  ///      string - Name of the application requesting for persistence
  ///
  /// \param [IN] f_ctag
  ///      string - File/Folder will be persist against this tag.
  ///
  /// \param [IN] f_cmempath
  ///      string - File/Folder path that is to be persisted.
  ///
  /// \param [IN] enotificationpersistentservicereleasetype
  ///      EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease = 0  :not on release
  ///                        eFrameworkunifiedPersistOnShutdown :persist on shutdown
  ///                        eFrameworkunifiedPersistInstantly  :persist instantly
  ///
  /// \param [IN] f_cusername
  ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
  ///            else an empty string
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus Release(std::string f_cappname,
                             std::string f_ctag,
                             std::string f_cmempath,
                             EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
                             std::string f_cusername) = 0;


  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// Load
  ///  Load file/folder from persistent memory to the specified location.
  ///
  /// \param [IN] f_cappname
  ///      string - Name of the application requesting for persistence
  ///
  /// \param [IN] f_ctag
  ///      string - File/Folder corresponding to this tag will be retrieved.
  ///
  /// \param [IN] f_cretrievepath
  ///      string - Path to retrieve.
  ///
  /// \param [IN] f_cusername
  ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
  ///            else an empty string
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus Load(std::string f_cappname,
                          std::string f_ctag,
                          std::string f_cretrievepath,
                          std::string f_cusername) = 0;

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// Persist
  /// Persist file/folder immediately
  ///
  /// \param [IN] f_objregistryentry
  ///      CRegistryEntry& - Registry entry job object to persist.
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus Persist(CRegistryEntry &f_objregistryentry); // NOLINT (runtime/references)

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// AckReceivedFromWorker
  ///
  ///
  /// \param [in] pSource
  ///         PCSTR - Name of the source.
  /// \param [in] f_ctag
  ///          PCSTR - file/folder tag.
  /// \param [in] f_bcopystatus
  ///         BOOL - Status of file/folder copy by copy worker.
  /// \param [in] f_eloadtype
  ///         ENPS_Loadtype - Type of load release or load.
  ///
  /// \return status
  ///         EFrameworkunifiedStatus - success or error
  ////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, BOOL f_bcopystatus,
                                           ENPS_Loadtype f_eloadtype);

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// PersistAllReleaseRequests
  /// Persist all files/folders which are not persisted yet.
  ///
  /// \param [in] f_uinotificationpersistentservicepersistcategoryflag
  ///     UI_32 - Hex value from enum EFrameworkunifiedPersistCategory, representing data to persist
  ///     0 - persist orignal data and
  ///     1 - persist default data
  ///
  /// \return status
  ///         EFrameworkunifiedStatus - success or error
  ////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag);

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// HaveAllReleaseRequestsPersisted
  /// Checks if all release requests are processed or not
  ///
  /// \param [out] f_ctagnotreleased
  ///     std::string - list of tags not released by application
  ///
  /// \return BOOL
  ///         TRUE if all release requests are processed else false
  ////////////////////////////////////////////////////////////////////////////////////////////
  BOOL HaveAllReleaseRequestsPersisted(std::string &f_ctagnotreleased); // NOLINT (runtime/references)

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// ResetPersistFlag
  /// Resets persist flag.
  ///
  /// \param none
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  VOID ResetPersistFlag();

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// PersistAllUserRequests
  /// Persist all files/folders which are not persisted yet.
  ///
  ///
  /// \return status
  ///         EFrameworkunifiedStatus - success or error
  ////////////////////////////////////////////////////////////////////////////////////////////
  virtual EFrameworkunifiedStatus PersistAllUserRequests();

  // virtual VOID ListAllInMap() = 0;

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// SetReadThreadHandle
  /// Set read thread handle.
  ///
  /// \param [in] f_hreadthread
  ///        HANDLE - Handle of the read thread.
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////
  VOID SetReadThreadHandle(HANDLE f_hreadthread);

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// SetWriteThreadHandle
  /// Set write thread handle.
  ///
  /// \param [in] f_hwritethread
  ///        HANDLE - Handle of the write thread.
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////
  VOID SetWriteThreadHandle(HANDLE f_hwritethread);

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// GetStoragePath
  /// Get the permanent storage path. Get it from NS_NPPService's config file.
  ///
  /// \return std::string
  ///         std::string - Permanant storage path
  ////////////////////////////////////////////////////////////////////////////////////////////
  static std::string GetStoragePath();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// SetPersistentCategory
  /// Sets the persist type of file/folder
  ///
  /// \param [IN] f_crequestorname
  ///      string - Application Name
  ///
  /// \param [IN] f_ctag
  ///      string - File/Folder will be persist against this tag.
  ///
  /// \param [IN] f_epersistcategory
  ///      EFrameworkunifiedPersistCategory - persistent category
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus SetPersistentCategory(const std::string &f_crequestorname,
                                   const std::string &f_ctag,
                                   EFrameworkunifiedPersistCategory f_epersistcategory);

  ////////////////////////////////////////////////////////////////////////////////////////////
  /// IsUserPersistence
  /// Check if the file/folder being persisted is user specific
  ///
  /// \param [in] - f_ctag
  ///         std::string - File/Folder Tag
  ///
  /// \return status
  ///         BOOL - TRUE for user specific persistence
  ///          FALSE  for global persistence
  ///////////////////////////////////////////////////////////////////////////////////////////
  virtual BOOL IsUserPersistence(std::string f_ctag);

#ifdef NPP_PROFILEINFO_ENABLE

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// GetPersistenceProfilingData
  /// This function is used to get the persistence info
  ///
  /// \param [out] f_cpersistenceprofileinfo
  ///         std::string - Persistence info concated in a string
  ///
  /// \return EFrameworkunifiedStatus
  ///     EFrameworkunifiedStatus - success or failure
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo); // NOLINT (runtime/references)

#endif

 protected:
  EFrameworkunifiedStatus ProcessReleaseRequest(std::string f_crequesterappname,
                                   std::string f_ctag,
                                   ENotificationpersistentservicePersistType f_epersisttype,
                                   std::string f_cmempath,
                                   EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
                                   std::string f_cusername);

  EFrameworkunifiedStatus ProcessLoadRequest(std::string f_crequesterappname,
                                std::string f_ctag,
                                ENotificationpersistentservicePersistType f_epersisttype,
                                std::string f_cretrievepath,
                                std::string f_cusername);

  VOID AddRequestData(NSP_CopyInfoCmd &f_tcpinfo, // NOLINT (runtime/references)
                      std::string f_sourcepath,
                      std::string f_destpath,
                      std::string f_crequesterappname,
                      std::string f_ctag,
                      ENPS_Loadtype f_eloadtype,
                      ENotificationpersistentservicePersistType f_epersisttype);

  EFrameworkunifiedStatus SendRequestMessage(NSP_CopyInfoCmd &f_tcpinfo); // NOLINT (runtime/references)

  std::string m_cStoragePath;  ///< Persistent memory storage path

  NOTIFICATIONPERSISTENTSERVICE_COMPRESSION_TYPE m_eCompressionType;  ///< Compression type for file/folder persistency

  HANDLE m_hNSWriteToPersistentMem;  ///< Child thread handle, copies file to persistent memory.

  HANDLE m_hNSReadFromPersistentMem;  ///< Child thread handle, copies file from persistent memory.

  // TODO(my_username): Remove this member var. Once the API to get application handle is available, use that.
  HANDLE m_hAppHandle;

  TSourceRegistryList m_mPersistRegistry;

  TPendingJobs m_lPendingJobs;  ///< stores the list of pending jobs sequentially

  BOOL m_bPersist;  ///< persist or not. It will be set to TRUE either on shutdown or userchange

  UI_32 m_uiNotificationpersistentservicePersistCategoryFlag;  ///< Stores the persist category flag value on shutdown request.
  ///< It is needed to decide which data to persist, if
  ///< release request is received by NSNPP after shutdown request
};
#endif  // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_H_