summaryrefslogtreecommitdiffstats
path: root/communication/server/src/threads/Thread_Common.cpp
blob: 72d80eab4071824f3cba822a1089844e1a1bc207 (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
/*
 * Copyright (c) 2019 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.
 */

#include <stdint.h>
#include <boost/atomic.hpp>
#include <native_service/frameworkunified_types.h>
#include <native_service/frameworkunified_framework_if.h>
#include <native_service/frameworkunified_timer.h>
#include <agl_thread.h>
//#include <can_hal.h>
#include "communication_communicationlog.h"
#include "communication_cid.h"
#include "Thread_Common.h"

static boost::atomic<int32_t> availabilityMask;
static boost::atomic<int32_t> availabilityCurrent;

void CommSetAvailabilityMask(int32_t mask) {
  availabilityMask |= mask;
}

void CommSetAvailabilityCurrent(int32_t current) {
  availabilityCurrent |= current;
}

void CommClrAvailabilityCurrent(int32_t current) {
  availabilityCurrent &= (~current);
}

BOOL CommGetAvailabilityCurrent(int32_t current) {
  return !(!(availabilityCurrent & current));
}

static BOOL CommCheckAvailabilityMask(void) {
  return (availabilityMask == availabilityCurrent);
}

EFrameworkunifiedStatus CommonStartNotify(HANDLE h_app, PCSTR cmd) {
  EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
  const char *result = "Unknown";
  const char *called = "Unknown";
  const BOOL avail = TRUE;
  UI_16 z = ZONE_ERR;
  HANDLE hdl = NULL;
  uint8_t c = 0;

  hdl = FrameworkunifiedMcOpenSender(h_app, LAN_SERVICE_MAIN);
  result = (NULL == hdl) ? "failed" : "success";
  z = (NULL == hdl) ? ZONE_INFO : ZONE_ERR;
  called = "FrameworkunifiedMcOpenSender";
  FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s", called, result);
  if (e_status != eFrameworkunifiedStatusOK)
    return e_status;

  if (TRUE == CommCheckAvailabilityMask()) {
    e_status = FrameworkunifiedSendMsg(hdl, CID_COMMSYS_CAN_READY, c, &c);
    result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
    z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
    called = "FrameworkunifiedSendMsg";
    FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, e_status);
  }
  FrameworkunifiedMcClose(hdl);

  e_status = FrameworkunifiedNPPublishNotification(h_app, cmd, &avail , sizeof(avail));
  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
  called = "FrameworkunifiedNPPublishNotification";
  FRAMEWORKUNIFIEDLOG(z, __func__, "%s(%s) %s(%d)", called, cmd, result, e_status);
  return e_status;
}

EFrameworkunifiedStatus CommonCanHalErrorNotify(const char *msg, void *ctxid) {
  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "can_hal error : %s", msg);
  return eFrameworkunifiedStatusOK;
}

//EFrameworkunifiedStatus CommonCanHalThreadStart(HANDLE h_app,
//                                   const FrameworkunifiedProtocolCallbackHandler *cb,
//                                   UI_32 count, PCSTR cmd, CanHalParam *p) {
//  EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
//  CANHAL_RET_API ret = CANHAL_RET_NORMAL;
//  const char *result = "Unknown";
//  const char *called = "Unknown";
//  UI_16 z = ZONE_ERR;
//
//  e_status = FrameworkunifiedAttachCallbacksToDispatcher(h_app, FRAMEWORKUNIFIED_ANY_SOURCE, cb, count);
//  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
//  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
//  called = "CommunicationAttachCallbacksFromDispatcher";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
////  ret = CanOpen(p);
//  result = (ret != CANHAL_RET_NORMAL) ? "failed" : "success";
//  z = (ret != CANHAL_RET_NORMAL) ? ZONE_INFO : ZONE_ERR;
//  called = "CanOpen";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, ret);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
//  e_status = FrameworkunifiedNPRegisterNotification(h_app, cmd,
//                                       sizeof(EFrameworkunifiedStatus), eFrameworkunifiedStateVar);
//  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
//  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
//  called = "FrameworkunifiedNPRegisterNotification";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s(%s) %s(%d)", called, cmd, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
//  return e_status;
//}

//EFrameworkunifiedStatus CommonCanHalThreadStop(HANDLE h_app, const PUI_32 cb,
//                                   UI_32 count, PCSTR cmd, CanHalType type) {
//  EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
//  CANHAL_RET_API ret = CANHAL_RET_NORMAL;
//  const BOOL avail = FALSE;
//  const char *result = "Unknown";
//  const char *called = "Unknown";
//  UI_16 z = ZONE_ERR;
//
//  e_status = FrameworkunifiedNPPublishNotification(h_app, cmd, &avail , sizeof(avail));
//  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
//  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
//  called = "FrameworkunifiedNPPublishNotification";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s(%s) %s(%d)", called, cmd, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
//  e_status = FrameworkunifiedNPUnRegisterNotification(h_app, cmd);
//  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
//  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
//  called = "FrameworkunifiedNPUnRegisterNotification";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s(%s) %s(%d)", called, cmd, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
//  e_status = FrameworkunifiedDetachCallbacksFromDispatcher(h_app, FRAMEWORKUNIFIED_ANY_SOURCE, cb, count);
//  result = (e_status != eFrameworkunifiedStatusOK) ? "failed" : "success";
//  z = (e_status != eFrameworkunifiedStatusOK) ? ZONE_INFO : ZONE_ERR;
//  called = "FrameworkunifiedDetachCallbacksFromDispatcher";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
////  ret = CanClose(type);
//  result = (ret != CANHAL_RET_NORMAL) ? "failed" : "success";
//  z = (ret != CANHAL_RET_NORMAL) ? ZONE_INFO : ZONE_ERR;
//  called = "CanClose";
//  FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, e_status);
//  if (e_status != eFrameworkunifiedStatusOK)
//    return e_status;
//
//  return e_status;
//}