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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup tag_NS_NPPService
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup tag_NS_NPPService
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
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>
39 #include "app_states.h"
41 #include "ns_npp_notificationpersistentservicelog.h"
42 #include "ns_npp_persistence_manager.h"
46 #ifdef NPP_PROFILEINFO_ENABLE
47 #include "ns_npp_profiling_protocols_internal.h"
50 ////////////////////////////////////////////////////////////////////////////////////////////////////
51 // Function : FrameworkunifiedOnInitialization
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE happ) {
54 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
55 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
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)}
86 #ifdef NPP_PROFILEINFO_ENABLE
88 FrameworkunifiedProtocolEvent ns_npp_profile_protocol_handlers[] = {
89 {NPS_PROFILE_NOTIFICATION_REQ, EVENT(evNPProfileNotification)},
90 {NPS_PROFILE_PERSISTENCE_REQ, EVENT(evNPProfilePersistence)},
93 if (eFrameworkunifiedStatusOK == FrameworkunifiedAttachHSMEventsToDispatcher(happ,
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");
99 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to attach profile info messages to events");
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");
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");
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);
115 l_pnsnpp->FrameworkunifiedStart();
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]
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);
125 // de-initialize the partially initialize object
126 l_pnsnpp->DeInit(happ);
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;
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]
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");
151 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "-");
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;
178 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE happ) {
179 return eFrameworkunifiedStatusOK;
182 EFrameworkunifiedStatus FrameworkunifiedSSFrameworkInterface(HANDLE happ) {
183 return eFrameworkunifiedStatusOK;
186 ////////////////////////////////////////////////////////////////////////////////////////////////////
187 // Function : FrameworkunifiedOnStart
188 ////////////////////////////////////////////////////////////////////////////////////////////////////
189 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE happ) {
190 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
192 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
193 return eFrameworkunifiedStatusOK;
196 ////////////////////////////////////////////////////////////////////////////////////////////////////
197 // Function : FrameworkunifiedOnStop
198 ////////////////////////////////////////////////////////////////////////////////////////////////////
199 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE happ) {
200 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
202 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
203 return eFrameworkunifiedStatusOK;
206 ////////////////////////////////////////////////////////////////////////////////////////////////////
207 // Function : FrameworkunifiedOnPreStart
208 ////////////////////////////////////////////////////////////////////////////////////////////////////
209 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) {
210 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
212 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
213 return eFrameworkunifiedStatusOK;
216 ////////////////////////////////////////////////////////////////////////////////////////////////////
217 // Function : FrameworkunifiedOnPreStop
218 ////////////////////////////////////////////////////////////////////////////////////////////////////
219 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) {
220 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
222 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
223 return eFrameworkunifiedStatusOK;
226 ////////////////////////////////////////////////////////////////////////////////////////////////////
227 // Function : FrameworkunifiedOnBackgroundStart
228 ////////////////////////////////////////////////////////////////////////////////////////////////////
229 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) {
230 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
232 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
233 return eFrameworkunifiedStatusOK;
236 ////////////////////////////////////////////////////////////////////////////////////////////////////
237 // Function : FrameworkunifiedOnBackgroundStop
238 ////////////////////////////////////////////////////////////////////////////////////////////////////
239 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) {
240 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "+", __FUNCTION__);
242 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, "-", __FUNCTION__);
243 return eFrameworkunifiedStatusOK;
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