Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "tsd_message_parse_interface.h"
12 : #include "tsd_log.h"
13 : #include "tsd_util_func.h"
14 :
15 : namespace tsd {
16 : /**
17 : * @ingroup MessageParseInterface
18 : * @brief MessageParseInterface基类构造函数
19 : */
20 1 : MessageParseInterface::MessageParseInterface() {}
21 :
22 : /**
23 : * @ingroup RegisterMsgProcess
24 : * @brief RegisterMsgProcess注册HDC消息处理函数
25 : * @return 无
26 : */
27 22 : void MessageParseInterface::RegisterMsgProcess(const HDCMessage::MsgType type, const ParseFuncType func)
28 : {
29 22 : parseFuncMap_[type] = func;
30 22 : }
31 :
32 : /**
33 : * @ingroup ProcessMessage
34 : * @brief 处理消息
35 : * @param [in]sessionID: session标识
36 : * @param [in]msg:消息数据
37 : * @return 无
38 : */
39 92 : void MessageParseInterface::ProcessMessage(const uint32_t sessionID, const HDCMessage& msg) const
40 : {
41 92 : ParseFuncType func = nullptr;
42 : {
43 92 : const HDCMessage::MsgType type = msg.type();
44 92 : const auto pos = parseFuncMap_.find(type);
45 92 : if (pos != parseFuncMap_.end()) {
46 87 : func = pos->second;
47 : } else {
48 5 : TSD_RUN_INFO(
49 : "Version is not matched(message_type:%u), you need update the software, "
50 : "FuncMap size = %zu",
51 : static_cast<uint32_t>(type), parseFuncMap_.size());
52 5 : uint32_t i = 0;
53 110 : for (auto iter = parseFuncMap_.begin(); iter != parseFuncMap_.end(); iter++, i++) {
54 105 : TSD_RUN_INFO("func type = %u\n", static_cast<uint32_t>(iter->first));
55 : }
56 : }
57 : }
58 92 : if (func != nullptr) {
59 87 : (*func)(sessionID, msg);
60 : }
61 92 : }
62 : } // namespace tsd
|