summaryrefslogtreecommitdiffstats
path: root/nsframework/notification_persistent_service/server/include/ns_npp_notification_manager.h
blob: e730d02a911f341203d165c42513fe46c71a1651 (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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
 * @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.
 */

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \defgroup <<Group Tag>> <<Group Name>>
/// \ingroup  tag_NS_NPPService
/// .
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_NS_NPPService
/// \brief    This file contains declaration of singleton class CNotificationManager which is used
///       to manage notification information.
///
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_NOTIFICATION_MANAGER_H_
#define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_NOTIFICATION_MANAGER_H_

////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Files
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <native_service/frameworkunified_types.h>
#include <native_service/ns_np_service.h>

#include <map>
#include <vector>
#include <string>
#include <iostream>

/// forward declaration of class
class CNotification;
class CPersistentData;
class CNotificationsToPersist;
class CStateNotification;

/// map of all the available notification.
typedef std::map<std::string, CNotification *> Notification_Type;

/// iterator for map of notifications.
typedef  Notification_Type::iterator Notification_Iterator_Type;

/// map of all available persistent notification and its data.
typedef std::map<std::string, CPersistentData *> Persistent_Type;

/// Iterator for map of persistent notifications.
typedef  Persistent_Type::iterator Persistent_Iterator_Type;

/**
 *  This class is used to manage the operations related to notification
 *  on registration, subscription, publication, etc.
 */
class CNotificationManager {
 public:
  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// CNotificationManager
  /// Constructor of CNotificationManager class
  ///
  /// \param
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CNotificationManager();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// ~CNotificationManager
  /// Destructor of CNotificationManager class
  ///
  /// \param
  ///
  /// \return
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  ~CNotificationManager();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnRegisterEvents
  /// This function creates notification object depending on its type and if already created it
  /// adds the service name to the list in the notification object.
  ///
  /// \param  [IN] f_cservicename
  ///     std::string - name of service registering for notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \param  [IN] f_uimsglength
  ///     UI_32 - Maximum length of Message
  ///
  /// \param  [IN] f_enotificationtype
  ///     EFrameworkunifiedPersistentVarType - type of notification
  ///
  /// \param  [IN] f_uidelay
  ///     UI_32 - Delay time for persistence
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnRegisterEvents(const std::string &f_cservicename,
                                        const std::string &f_cnotificationname,
                                        const UI_32 f_uimsglength,
                                        const EFrameworkunifiedNotificationType f_enotificationtype,
                                        const UI_32 f_uidelay = 0);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnUnRegisterEvents
  /// This function removes the name of the service from the notification object.
  ///
  /// \param  [IN] f_cservicename
  ///     std::string - name of service unregistering from notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnUnRegisterEvents(const std::string &f_cservicename,
                                          const std::string &f_cnotificationname);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnPublishEvent
  /// This function stores the published data in the notification object in case of state and
  /// persistent notification.
  ///
  /// \param  [IN] f_cservicename
  ///     std::string - name of service registering for notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \param  [IN] f_pmessage
  ///     PVOID - pointer to message
  ///
  /// \param  f_uimsgsize
  ///     UI_32 - size of Message
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnPublishEvent(const std::string &f_cservicename,
                                      const std::string &f_cnotificationname,
                                      PVOID f_pmessage,
                                      const UI_32 f_uimsgsize);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnSubscribeToEvent
  /// This function adds the name of the application to subscribers list in notification object.
  ///
  /// \param  [IN] f_csubscribername
  ///     std::string - name of application subscribing to notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnSubscribeToEvent(const std::string &f_csubscribername,
                                          const std::string &f_cnotificationname);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnUnSubscribeFromEvent
  /// This function adds the name of the application to subscribers list in notification object.
  ///
  /// \param  [IN] f_csubscribername
  ///     std::string - name of application subscribing to notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnUnSubscribeFromEvent(const std::string &f_csubscribername,
                                              const std::string &f_cnotificationname);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NPGetPersistentNotificationData
  /// Get data for notification name
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - name of notification
  /// \param  [OUT] f_pnotificationdata
  ///     PVOID - data corresponding to notification name
  /// \param  [IN] f_uidatasize
  ///     UI_32 - size of data
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NPGetPersistentNotificationData(const std::string &f_cnotificationname,
                                             PVOID f_pnotificationdata, const UI_32 f_uidatasize);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceServiceOnGetPersistentData
  /// This function is used to get the persistent data stored related to notification.
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - Notification Name
  ///
  /// \param  [IN] f_creceivername
  ///     std::string - Source Name
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceServiceOnGetPersistentData(const std::string &f_cnotificationname,
                                           const std::string &f_creceivername);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceGetPersistentNotificationData
  /// This function is used to get the list of persistent notifications and the data associated
  /// with it.
  ///
  /// \param  [OUT] f_pvpersistnotification
  ///     CNotificationsToPersist - vector containing list of persistent notifications and
  ///     data associated with it.
  ///
  /// \param  [IN] f_enotificationtype
  ///     EFrameworkunifiedNotificationType - Type of notification
  ///
  /// \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 EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceGetPersistentNotificationData(std::vector<CNotificationsToPersist *> *f_pvpersistnotification,
                                              const EFrameworkunifiedNotificationType f_enotificationtype,
                                              UI_32 f_uinotificationpersistentservicepersistcategoryflag);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceSetPersistentNotificationData
  /// This function is used to create the persistent notifications object and fill the data
  /// related with it on system load.
  ///
  /// \param  [IN] f_pvpersistnotification
  ///     vector<CNotificationsToPersist> - vector containing list of notifications and data associated with it
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceSetPersistentNotificationData(std::vector<CNotificationsToPersist *> *f_pvpersistnotification);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// GetNotificationInfo
  /// This function is used to get the notification information.
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - Notification Name
  ///
  /// \param  [IN] l_pnotificationstopersist
  ///     CNotificationsToPersist - Notification info structure
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus GetNotificationInfo(const std::string &f_cnotificationname,
                                 CNotificationsToPersist *&l_pnotificationstopersist); // NOLINT (runtime/references)

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceSetDefaultPersistentNotificationData
  /// This function is used to set the default data of persistent notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  /// \param  [IN] f_pmessage
  ///     PVOID - message data
  /// \param  [IN] f_uimsgsize
  ///     UI_32 - message size
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceSetDefaultPersistentNotificationData(const std::string &f_cnotificationname,
                                                     PVOID f_pmessage,
                                                     const UI_32 f_uimsgsize);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentserviceSetPersistentCategory
  /// This function is used to set the persistent type of persistent notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  /// \param  [IN] f_epersistenttype
  ///     EFrameworkunifiedPersistCategory - persistent category
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentserviceSetPersistentCategory(const std::string &f_cnotificationname,
                                      const EFrameworkunifiedPersistCategory f_epersistcategory);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// NotificationpersistentservicePublishImmediateNotification
  /// This function publish the immediate notification f_cnotificationname to all its subscribers.
  /// This API is called when service updates the immediate notification data in persistent memory
  /// using synchronous API.
  ///
  /// \param  [IN] f_cservicename
  ///         const std::string& - name of service registering for notification
  ///
  /// \param  [IN] f_cnotificationname
  ///         const std::string& - notification name
  ///
  /// \param  [IN] f_pmessage
  ///         PVOID - pointer to message
  ///
  /// \param  f_uimsgsize
  ///         UI_32 - size of Message
  ///
  /// \return EFrameworkunifiedStatus
  //          EFrameworkunifiedStatus - eFrameworkunifiedStatusOK on success
  ///                      eFrameworkunifiedStatusInvldParam - invalid parameter
  ///                      eFrameworkunifiedStatusNullPointer - if notification not found
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus NotificationpersistentservicePublishImmediateNotification(const std::string &f_cservicename,
                                             const std::string &f_cnotificationname,
                                             PVOID f_pmessage,
                                             const UI_32 f_uimsgsize);

#ifdef NPP_PROFILEINFO_ENABLE

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// GetNotificationProfilingData
  /// This function is used to get the notification profiling information.
  ///
  /// \param  [OUT] f_tNotificationProfileInfo
  ///     std::string - all the notification info of all applications concated in a string
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus GetNotificationProfilingData(std::string &f_cnotificationprofileInfo); // NOLINT (runtime/references)

#endif

 private:
  Notification_Type *m_pmNotificationList;      /// < map containing list of all notifications.

  std::vector<std::string> *m_pvPersistentList;   /// < vector containing list of all persistent notifications.

  std::vector<std::string> *m_pvUserPersistentList;   /// < vector containing list of all user persistent notifications.

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// CreateNotificationObject
  /// This function is used to get notification object from map if it exists else create new
  /// object as per type of notification.
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \param  [IN] f_uimsglength
  ///     UI_32 - Maximum size of notification message
  ///
  /// \param  [IN] f_enotificationtype
  ///     EFrameworkunifiedPersistentVarType - Delay time for persistence
  ///
  /// \param  [IN] f_uidelay
  ///     UI_32 - Persistence Delay
  ///
  /// \return CNotification
  //      CNotification - pointer of notification object
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CNotification *CreateNotificationObject(const std::string &f_cnotificationname,
                                          const UI_32 f_uimsglength,
                                          const EFrameworkunifiedNotificationType f_enotificationtype,
                                          const UI_32 f_uidelay = 0);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// SearchNotification
  /// This function is used to search whether notification object is present in map or not.
  /// If present it sends the reference.    CNotification - reference to pointer of notification object
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \return CNotification
  //      CNotification - pointer of notification object
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CNotification *SearchNotification(const std::string &f_cnotificationname);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// SearchPersistenceNotification
  /// This function is used to search whether the given persistent notification object
  /// is present in map or not.
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \return CStateNotification
  //      CStateNotification - pointer of notification object
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CStateNotification *SearchPersistenceNotification(const std::string &f_cnotificationname);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// CreateNotificationObjectToPersist
  /// Creates the CNotificationsToPersist object from notification object and the persistent data.
  ///
  /// \param  [IN] f_pnotification
  ///     CStateNotification - notification object ptr
  /// \param  [IN] f_pdata
  ///     CPersistentData - persistent data
  ///
  /// \return CNotification
  //      CNotification - pointer of notification object
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  CNotificationsToPersist *CreateNotificationObjectToPersist(CStateNotification *f_pnotification,
                                                             const CPersistentData *f_pdata);

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// RemoveUserSpecificNotificationEntry
  /// This function is used to get the singleton instance of class.
  ///
  /// \param
  ///
  /// \return EFrameworkunifiedStatus
  ///     EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus RemoveUserSpecificNotificationEntry();

  ////////////////////////////////////////////////////////////////////////////////////////////////
  /// ChangeNotificationType
  /// This function creates new notification object depending on the type and replaces the old one.
  /// The subscribers list is copied from the old notification object is copied to the new one.
  ///
  /// \param  [IN] f_pnotification
  ///     CNotification* - old notification object
  ///
  /// \param  [IN] f_cservicename
  ///     std::string - name of service registering for notification
  ///
  /// \param  [IN] f_cnotificationname
  ///     std::string - notification name
  ///
  /// \param  [IN] f_uimsglength
  ///     UI_32 - Maximum length of Message
  ///
  /// \param  [IN] f_enotificationtype
  ///     EFrameworkunifiedPersistentVarType - new type of notification
  ///
  /// \param  [IN] f_uidelay
  ///     UI_32 - Delay time for persistence
  ///
  /// \return EFrameworkunifiedStatus
  //      EFrameworkunifiedStatus - success or failure status
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////////
  EFrameworkunifiedStatus ChangeNotificationType(CNotification *f_pnotification,
                                    const std::string &f_cservicename,
                                    const std::string &f_cnotificationname,
                                    const UI_32 f_uimsglength,
                                    const EFrameworkunifiedNotificationType f_enotificationtype,
                                    const UI_32 f_uidelay);
};

#endif  // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_NOTIFICATION_MANAGER_H_