summaryrefslogtreecommitdiffstats
path: root/communication/server/src/threads/Thread_Common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'communication/server/src/threads/Thread_Common.cpp')
-rw-r--r--communication/server/src/threads/Thread_Common.cpp232
1 files changed, 122 insertions, 110 deletions
diff --git a/communication/server/src/threads/Thread_Common.cpp b/communication/server/src/threads/Thread_Common.cpp
index 72d80eab..718d9481 100644
--- a/communication/server/src/threads/Thread_Common.cpp
+++ b/communication/server/src/threads/Thread_Common.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2019-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.
@@ -16,20 +16,50 @@
#include <stdint.h>
#include <boost/atomic.hpp>
+#include <pthread.h>
+
#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 <can_hal.h>
#include "communication_communicationlog.h"
#include "communication_cid.h"
#include "Thread_Common.h"
-static boost::atomic<int32_t> availabilityMask;
+static std::map<std::string, HANDLE> g_map_sender;
+static pthread_mutex_t g_sender_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
static boost::atomic<int32_t> availabilityCurrent;
-void CommSetAvailabilityMask(int32_t mask) {
- availabilityMask |= mask;
+void CommonInit(void) {
+ pthread_mutex_lock(&g_sender_mutex);
+ g_map_sender.clear();
+ pthread_mutex_unlock(&g_sender_mutex);
+}
+
+HANDLE CommonFindSender(HANDLE h_app, std::string s) {
+ HANDLE ret = NULL;
+ std::string app(FrameworkunifiedGetAppName(h_app));
+ std::string key = s + app;
+ std::map<std::string, HANDLE>::iterator it = g_map_sender.find(key);
+
+ pthread_mutex_lock(&g_sender_mutex);
+
+ if (it != g_map_sender.end()) {
+ ret = g_map_sender[key];
+ goto cleanup;
+ }
+
+ ret = FrameworkunifiedMcOpenSender(h_app, s.c_str());
+ if (ret) {
+ g_map_sender[key] = ret;
+ } else {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender Error(to:%s)", s.c_str());
+ }
+
+cleanup:
+ pthread_mutex_unlock(&g_sender_mutex);
+ return ret;
}
void CommSetAvailabilityCurrent(int32_t current) {
@@ -44,35 +74,12 @@ 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";
@@ -82,89 +89,94 @@ EFrameworkunifiedStatus CommonStartNotify(HANDLE h_app, PCSTR cmd) {
return e_status;
}
-EFrameworkunifiedStatus CommonCanHalErrorNotify(const char *msg, void *ctxid) {
+EFrameworkunifiedStatus CommonCanHalErrorNotify(HANDLE h_app) {
+ char msg[CANHAL_ERROR_MESSAGE_LEN] = {0};
+ EFrameworkunifiedStatus err = eFrameworkunifiedStatusOK;
+
+ err = FrameworkunifiedGetMsgDataOfSize(h_app, &msg, sizeof(msg), eSMRRelease);
+ if (err != eFrameworkunifiedStatusOK) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedGetMsgDataOfSize is failed, err=%d", err);
+ }
+
+ if (err == eFrameworkunifiedStatusInvldBufSize) {
+ FrameworkunifiedClearMsgData(h_app);
+ return eFrameworkunifiedStatusFail;
+ } else if (err != eFrameworkunifiedStatusOK) {
+ return eFrameworkunifiedStatusFail;
+ }
FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "can_hal error : %s", msg);
- return eFrameworkunifiedStatusOK;
+ return err;
+}
+
+EFrameworkunifiedStatus CommonThreadStart(HANDLE h_app, const FrameworkunifiedProtocolCallbackHandler *cb,
+ UI_32 count, PCSTR cmd, EFrameworkunifiedStatus (*open_func)(HANDLE)) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ 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 = "FrameworkunifiedAttachCallbacksFromDispatcher";
+ FRAMEWORKUNIFIEDLOG(z, __func__, "%s %s(%d)", called, result, e_status);
+ if (e_status != eFrameworkunifiedStatusOK)
+ return e_status;
+
+ e_status = open_func(h_app);
+ 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 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;
-//}
+EFrameworkunifiedStatus CommonThreadStop(HANDLE h_app, const PUI_32 cb,
+ UI_32 count, PCSTR cmd, EFrameworkunifiedStatus (*close_func)(HANDLE)) {
+ EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
+ 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;
+
+ e_status = close_func(h_app);
+ if (e_status != eFrameworkunifiedStatusOK){
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: close_func() failed");
+ return e_status;
+ }
+
+ return e_status;
+}