• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_WS_LOGGER_H
17 #define PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_WS_LOGGER_H
18 
19 #include <string>
20 
21 #include "websocketpp/logger/levels.hpp"
22 
23 #include "utils/logger.h"
24 
25 namespace ark::tooling::inspector {
26 class WsLogger {
27     using ChannelType = websocketpp::log::channel_type_hint::value;
28     using Level = websocketpp::log::level;
29 
30 public:
WsLogger(Level staticChannels,ChannelType channelType)31     WsLogger(Level staticChannels, ChannelType channelType) : channelType_(channelType), staticChannels_(staticChannels)
32     {
33     }
34 
35     // NOLINTNEXTLINE(readability-identifier-naming)
36     void set_channels(Level channels);
37     // NOLINTNEXTLINE(readability-identifier-naming)
static_test(Level channel)38     bool static_test(Level channel) const
39     {
40         return (channel & staticChannels_) == channel;
41     }
42     // NOLINTNEXTLINE(readability-identifier-naming)
dynamic_test(Level channel)43     bool dynamic_test(Level channel) const
44     {
45         return (channel & dynamicChannels_) == channel;
46     }
47     // NOLINTNEXTLINE(readability-identifier-naming)
48     void write(Level channel, const std::string &string) const;
49 
50 private:
51     // NOLINTNEXTLINE(readability-identifier-naming)
52     Logger::Level channel_log_level(Level channel) const;
53 
54     const ChannelType channelType_;
55     const Level staticChannels_;
56     Level dynamicChannels_ {0};
57 };
58 }  // namespace ark::tooling::inspector
59 
60 #endif  // PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_WS_LOGGER_H
61