Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / peripheralservice / communication / server / src / main / communication_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  * This file has been generated automatically.
19  * User hand written code entry is allowed only inside protected zones.
20  */
21
22 /*
23  * This file has been generated automatically.
24  * User hand written code entry is allowed only inside protected zones.
25  */
26
27 #include <native_service/frameworkunified_application.h>
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/frameworkunified_service_protocol.h>
30 #include <native_service/frameworkunified_multithreading.h>
31 #include <peripheral_service/communication_notifications.h>
32 #include <peripheral_service/Canif_API.h>
33 #include <stdio.h>
34 #include <signal.h>
35 #include <string>
36 #include <sstream>
37 #include <iostream>
38 #include "communication_cid.h"
39 #include "communication_communicationlog.h"
40 #include "Thread_Common.h"
41
42 extern EFrameworkunifiedStatus CANThreadStart(HANDLE h_app);
43 extern EFrameworkunifiedStatus CANThreadStop(HANDLE h_app);
44
45 HANDLE g_can_thread = NULL;
46
47 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE h_app) {
48   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
49
50   CommonInit();
51
52   // API to Register Notification for Service Availability.
53   e_status = FrameworkunifiedRegisterServiceAvailabilityNotification(h_app, 
54                                               NTFY_Communication_Availability);
55   if (eFrameworkunifiedStatusOK != e_status) {
56     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
57           "Failed to Register Service Availability Notification.");
58   } else {
59     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, 
60           "Service Availability Notification registered successfully.");
61   }
62
63   // API to Publish Service Availability Notification.
64   e_status = FrameworkunifiedPublishServiceAvailability(h_app, FALSE);
65   if (eFrameworkunifiedStatusOK != e_status) {
66     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, 
67           "Failed to Publish Service Availability Notification.");
68   } else {
69     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, 
70           "Service Availability Notification published successfully.");
71   }
72
73   g_can_thread = FrameworkunifiedCreateChildThread(h_app, LAN_SERVICE_CAN,
74                                         CANThreadStart, CANThreadStop);
75   if (g_can_thread == NULL) {
76     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to create CAN");
77   }
78
79   // API to Publish Service Availability Notification.
80   e_status = FrameworkunifiedPublishServiceAvailability(h_app, TRUE);
81   if (eFrameworkunifiedStatusOK != e_status) {
82     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
83           "Failed to Publish Service Availability Notification.");
84   } else {
85     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
86           "Service Availability Notification published successfully.");
87   }
88
89   return e_status;
90 }
91
92 EFrameworkunifiedStatus FrameworkunifiedOnWakeup(HANDLE h_app) {
93   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
94   return e_status;
95 }
96
97 EFrameworkunifiedStatus FrameworkunifiedOnShutdown(HANDLE h_app) {
98   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
99   return e_status;
100 }
101
102 EFrameworkunifiedStatus FrameworkunifiedOnEShutdown(HANDLE h_app) {
103   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
104   return e_status;
105 }
106
107 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE h_app) {
108   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
109   return e_status;
110 }
111
112 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE h_app) {
113   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
114   return e_status;
115 }
116
117 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE h_app) {
118   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
119   return e_status;
120 }
121
122 static EFrameworkunifiedStatus CommThreadCheckAndStart(HANDLE p, HANDLE c,
123                   UI_32 len, PCVOID data, BOOL current) {
124   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
125   if (TRUE != current) {
126     e_status = FrameworkunifiedStartChildThread(p, c, len, data);
127   }
128   return e_status;
129 }
130
131 static EFrameworkunifiedStatus CommThreadCheckAndStop(HANDLE p, HANDLE c,
132                   UI_32 len, PCVOID data, BOOL current) {
133   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
134   if (TRUE == current) {
135     e_status = FrameworkunifiedStopChildThread(p, c, len, data);
136   }
137   return e_status;
138 }
139
140 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE h_app) {
141   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
142   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
143
144   e_status = CommThreadCheckAndStart(h_app, g_can_thread,
145                          0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
146   if (eFrameworkunifiedStatusOK != e_status) {
147     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
148           "Fail to Start CAN Thread. Status:%#x", e_status);
149   }
150
151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
152   return e_status;
153 }
154
155 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE h_app) {
156   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
157
158   e_status = CommThreadCheckAndStop(h_app, g_can_thread,
159                          0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
160   if (eFrameworkunifiedStatusOK != e_status) {
161     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
162           "Fail to Stop CAN Thread. Status:%#x", e_status);
163   } else {
164     g_can_thread = NULL;
165   }
166
167   return e_status;
168 }
169
170 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE h_app) {
171   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
172   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
173
174   e_status = CommThreadCheckAndStart(h_app, g_can_thread,
175                          0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
176   if (eFrameworkunifiedStatusOK != e_status) {
177     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
178           "Fail to Start CAN Thread. Status:%#x", e_status);
179   }
180
181   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
182   return e_status;
183 }
184
185 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE h_app) {
186   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
187   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
188
189   e_status = CommThreadCheckAndStart(h_app, g_can_thread,
190                         0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
191   if (eFrameworkunifiedStatusOK != e_status) {
192     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
193            "Fail to Start CAN Thread. Status:%#x", e_status);
194   }
195
196   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
197   return e_status;
198 }
199
200 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE h_app) {
201   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
202   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
203
204   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
205   return e_status;
206 }
207
208 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE h_app) {
209   EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
210   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
211
212   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
213   return e_status;
214 }
215
216 std::string MessageDataOutputLog(uint8_t *msg_data, uint32_t len){
217   std::string data_log;
218   int data_buf;
219   for(uint32_t i = 0; i < len; i++){
220     std::ostringstream ss;
221     data_buf = (int)msg_data[i];
222     ss << std::hex << data_buf;
223     data_log = ss.str() + " " + data_log;
224   }
225   return data_log;
226 }