• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 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_TEST_TEST_EVENT_LOOP_H
17 #define PANDA_TOOLING_INSPECTOR_TEST_TEST_EVENT_LOOP_H
18 
19 #include "../event_loop.h"
20 #include "test_config.h"
21 
22 #include "websocketpp/connection.hpp"
23 
24 #include <deque>
25 #include <string>
26 #include <string_view>
27 #include <tuple>
28 #include <utility>
29 #include <vector>
30 
31 namespace panda::tooling::inspector::test {
32 class TestLogger;
33 
34 class TestEventLoop : public virtual EventLoop {
35 public:
TestEventLoop(std::string_view name,TestLogger & logger)36     TestEventLoop(std::string_view name, TestLogger &logger) : logger_(logger), name_(name) {}
37 
GetName()38     const std::string &GetName() const
39     {
40         return name_;
41     }
42 
43     bool Poll() override;
44 
Push(const websocketpp::connection<TestConfig>::ptr & connection,std::vector<char> && buffer)45     void Push(const websocketpp::connection<TestConfig>::ptr &connection, std::vector<char> &&buffer)
46     {
47         messages_.emplace_back(connection, std::move(buffer));
48     }
49 
50     bool RunOne() override;
51 
52 private:
53     using Message = std::tuple<websocketpp::connection<TestConfig>::ptr, std::vector<char>>;
54 
55     TestLogger &logger_;
56     std::string name_;
57     std::deque<Message> messages_;
58 };
59 }  // namespace panda::tooling::inspector::test
60 
61 #endif  // PANDA_TOOLING_INSPECTOR_TEST_TEST_EVENT_LOOP_H
62