Init basesystem source codes.
[staging/basesystem.git] / nsframework / notification_persistent_service / server / src / notificationpersistentservice_application.cpp
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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup  tag_NS_NPPService
20 /// .
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
22
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup  tag_NS_NPPService
25 /// \brief
26 ///
27 ///
28 ///
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
30
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
32 // Include Files
33 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 #include <native_service/frameworkunified_application.h>
35 #include <native_service/frameworkunified_framework_if.h>
36 #include <native_service/ns_np_service_protocol.h>
37 #include <native_service/ns_np_service_notification.h>
38
39 #include "app_states.h"
40 #include "ns_npp.h"
41 #include "ns_npp_notificationpersistentservicelog.h"
42 #include "ns_npp_persistence_manager.h"
43
44 using std::malloc;
45
46 #ifdef NPP_PROFILEINFO_ENABLE
47 #include "ns_npp_profiling_protocols_internal.h"
48 #endif
49
50 ////////////////////////////////////////////////////////////////////////////////////////////////////
51 //  Function : FrameworkunifiedOnInitialization
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE happ) {
54   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
55   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
56
57   if (NULL != happ) {  // LCOV_EXCL_BR_LINE 4: happ can't be null
58     FrameworkunifiedProtocolEvent ns_npp_protocol_handlers[] = {
59       {NPS_REGISTER_EV_REQ,         EVENT(evNPRegisterNotifications)},
60       {NPS_PUBLISH_EV_REQ,        EVENT(evNPPublishNotification)},
61       {NPS_SUBSCRIBE_TO_EV_REQ,         EVENT(evNPSubscribeToNotification)},
62       {NPS_BATCH_SUBSCRIBE_TO_EV_REQ,   EVENT(evNPSubscribeToNotifications)},
63       {NPS_UNSUBSCRIBE_FROM_EV_REQ,     EVENT(evNPUnSubscribeFromNotification)},
64       {NPS_UNREGISTER_EV_REQ,           EVENT(evNPUnRegisterNotifications)},
65       {NPS_GET_PERS_DATA_REQ,           EVENT(evNPReadPersistedData)},
66       {NPS_SET_PERSIST_FILE_PATH_REQ,   EVENT(evNPRegisterPersistentFile)},
67       {NPS_RELEASE_PERS_FILE_REQ,       EVENT(evNPReleasePersistentFile)},
68       {NPS_GET_PERS_FILE_REQ,           EVENT(evNPLoadPersistentFile)},
69       {NPS_SET_PERSIST_FOLDER_PATH_REQ,   EVENT(evNPRegisterPersistentFolder)},
70       {NPS_GET_PERS_FOLDER_REQ,         EVENT(evNPLoadPersistentFolder)},
71       {NPS_RELEASE_PERS_FOLDER_REQ,     EVENT(evNPReleasePersistentFolder)},
72       {NPS_CHANGE_PERSONALITY_REQ,      EVENT(evUserChange)},
73       {NPS_NPP_STOP_REQ,            EVENT(evShutdown)},
74       {NPS_BATCH_UNSUBSCRIBE_FROM_EV_REQ, EVENT(evNPUnSubscribeFromNotifications)},
75       {NPS_GET_READYSTATUS_REQ,     EVENT(evNPGetReadyStatus)},
76       {NPS_REGISTER_NOR_EV_REQ,       EVENT(evNPRegisterImmediateNotifications)},
77       {NPS_DELETE_PERSISTED_DATA_REQ,   EVENT(evNPClearPersistedData)},
78       {NPS_SET_DEFAULT_PERS_DATA,     EVENT(evNPSetDefaultPersistentData)},
79       {NPS_SET_NOTFN_PERSISTENT_TYPE,   EVENT(evNPSetNotfnPersistentType)},
80       {NPS_SET_FILE_PERSISTENT_TYPE,    EVENT(evNPSetFilePersistentType)},
81       {NPS_SET_FOLDER_PERSISTENT_TYPE,  EVENT(evNPSetFolderPersistentType)},
82       {NPS_SYNCHRONOUS_WRITE_NOTIFY_REQ,  EVENT(evNPPublishImmediateNotification)},
83       {NPS_NPP_SYNC_REQ,                  EVENT(evNPPersistentSync)}
84     };
85
86 #ifdef NPP_PROFILEINFO_ENABLE
87
88     FrameworkunifiedProtocolEvent ns_npp_profile_protocol_handlers[] = {
89       {NPS_PROFILE_NOTIFICATION_REQ, EVENT(evNPProfileNotification)},
90       {NPS_PROFILE_PERSISTENCE_REQ,  EVENT(evNPProfilePersistence)},
91     };
92
93     if (eFrameworkunifiedStatusOK == FrameworkunifiedAttachHSMEventsToDispatcher(happ,
94                                                        "NSProfileUtil",
95                                                        ns_npp_profile_protocol_handlers,
96                                                        _countof(ns_npp_profile_protocol_handlers))) {
97       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Profile info messages are attached to events");
98     } else {
99       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to attach profile info messages to events");
100     }
101
102 #endif
103
104     if (eFrameworkunifiedStatusOK == (l_estatus = FrameworkunifiedAttachHSMEventsToDispatcher(happ, FRAMEWORKUNIFIED_ANY_SOURCE, ns_npp_protocol_handlers, static_cast<UI_32>(_countof(ns_npp_protocol_handlers))))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
105       CNSNPP *l_pnsnpp =  new(std::nothrow) CNSNPP(happ);
106       if (NULL != l_pnsnpp) {   // LCOV_EXCL_BR_LINE 5: new's error case.
107         FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "l_pnsnpp object created");
108
109         if (eFrameworkunifiedStatusOK == (l_estatus = l_pnsnpp->Init(happ))) {  // LCOV_EXCL_BR_LINE 200: can't test
110           FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "l_pnsnpp object initialized");
111
112           if (eFrameworkunifiedStatusOK == (l_estatus = l_pnsnpp->FrameworkunifiedCreate())) {  // LCOV_EXCL_BR_LINE 200: the result of l_pnsnpp->FrameworkunifiedCreate() is always eFrameworkunifiedStatusOK  // NOLINT[whitespace/line_length]
113             FrameworkunifiedSetStateMachine(happ, l_pnsnpp);
114
115             l_pnsnpp->FrameworkunifiedStart();
116           } else {
117             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
118             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NSNPP statemachine not created, status: 0x%x", l_estatus);  // LCOV_EXCL_LINE 200: the result of l_pnsnpp->FrameworkunifiedCreate() is always eFrameworkunifiedStatusOK  // NOLINT[whitespace/line_length]
119           }
120         } else {
121           // LCOV_EXCL_START 200: can't test
122           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
123           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pnsnpp object initialization error, status: %d", l_estatus);
124
125           // de-initialize the partially initialize object
126           l_pnsnpp->DeInit(happ);
127
128           delete l_pnsnpp;
129           l_pnsnpp = NULL;
130           // LCOV_EXCL_STOP
131         }
132       } else {
133         // LCOV_EXCL_START 5: malloc's error case.
134         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
135         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pnsnpp object not created");
136         l_estatus = eFrameworkunifiedStatusNullPointer;
137         // LCOV_EXCL_STOP
138       }
139     } else {
140       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
141       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedAttachHSMEventsToDispatcher Failed Status:0x%x ", l_estatus);  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
142     }
143   } else {
144     // LCOV_EXCL_START 4: happ can't be null
145     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
146     l_estatus = eFrameworkunifiedStatusInvldParam;
147     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Application handle happ is NULL");
148     // LCOV_EXCL_STOP
149   }
150
151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
152   return l_estatus;
153 }
154
155 ////////////////////////////////////////////////////////////////////////////////////////////////////
156 ////////////////////////////////////////////////////////////////////////////////////////////////////
157 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE happ) {    // LCOV_EXCL_START 14: Resident process, not called by NSFW
158   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
159   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
160   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
161   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
162   return l_estatus;
163 }
164 // LCOV_EXCL_STOP
165
166 ////////////////////////////////////////////////////////////////////////////////////////////////////
167 //  Function : FrameworkunifiedOnDebugDump
168 ////////////////////////////////////////////////////////////////////////////////////////////////////
169 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE happ) {    // LCOV_EXCL_START 7: debug code
170   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
171   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
172   /// << Dump internal tables!
173   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
174   return eFrameworkunifiedStatusOK;
175 }
176 // LCOV_EXCL_STOP
177
178 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE happ) {
179   return eFrameworkunifiedStatusOK;
180 }
181
182 EFrameworkunifiedStatus FrameworkunifiedSSFrameworkInterface(HANDLE happ) {
183   return eFrameworkunifiedStatusOK;
184 }
185
186 ////////////////////////////////////////////////////////////////////////////////////////////////////
187 //  Function : FrameworkunifiedOnStart
188 ////////////////////////////////////////////////////////////////////////////////////////////////////
189 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE happ) {
190   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
191
192   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
193   return eFrameworkunifiedStatusOK;
194 }
195
196 ////////////////////////////////////////////////////////////////////////////////////////////////////
197 //  Function : FrameworkunifiedOnStop
198 ////////////////////////////////////////////////////////////////////////////////////////////////////
199 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE happ) {
200   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
201
202   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
203   return eFrameworkunifiedStatusOK;
204 }
205
206 ////////////////////////////////////////////////////////////////////////////////////////////////////
207 //  Function : FrameworkunifiedOnPreStart
208 ////////////////////////////////////////////////////////////////////////////////////////////////////
209 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) {
210   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
211
212   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
213   return eFrameworkunifiedStatusOK;
214 }
215
216 ////////////////////////////////////////////////////////////////////////////////////////////////////
217 //  Function : FrameworkunifiedOnPreStop
218 ////////////////////////////////////////////////////////////////////////////////////////////////////
219 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) {
220   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
221
222   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
223   return eFrameworkunifiedStatusOK;
224 }
225
226 ////////////////////////////////////////////////////////////////////////////////////////////////////
227 //  Function : FrameworkunifiedOnBackgroundStart
228 ////////////////////////////////////////////////////////////////////////////////////////////////////
229 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) {
230   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
231
232   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
233   return eFrameworkunifiedStatusOK;
234 }
235
236 ////////////////////////////////////////////////////////////////////////////////////////////////////
237 //  Function : FrameworkunifiedOnBackgroundStop
238 ////////////////////////////////////////////////////////////////////////////////////////////////////
239 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) {
240   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
241
242   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
243   return eFrameworkunifiedStatusOK;
244 }
245
246 extern const FrameworkunifiedDefaultCallbackHandler kDefaultCbHandler = {  // NOLINT (readability/naming)
247   FrameworkunifiedOnInitialization,
248   FrameworkunifiedOnDestroy,
249   FrameworkunifiedOnStart,
250   FrameworkunifiedOnStop,
251   FrameworkunifiedOnPreStart,
252   FrameworkunifiedOnPreStop,
253   FrameworkunifiedOnBackgroundStart,
254   FrameworkunifiedOnBackgroundStop,
255   FrameworkunifiedOnDebugDump,
256   FrameworkunifiedCreateStateMachine,
257   FrameworkunifiedSSFrameworkInterface
258 };  // LCOV_EXCL_BR_LINE 10: The final line