$darkmode
server.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
23 #pragma once
24 
25 #include <memory> // for unique_ptr<>
26 
27 #include <cloe/registrar.hpp> // for Registrar
28 #include <cloe/stack.hpp>
29 
30 #include "utility/defer.hpp" // for Defer
31 
32 namespace engine {
33 
41  public:
42  virtual ~ServerRegistrar() = default;
43 
44  [[nodiscard]] virtual std::unique_ptr<ServerRegistrar> clone() const = 0;
45 
46  [[nodiscard]] virtual std::unique_ptr<ServerRegistrar> with_prefix(const std::string& static_prefix,
47  const std::string& api_prefix) const = 0;
48 
49  virtual void register_static_handler(const std::string& endpoint, cloe::Handler h) = 0;
50 
51  virtual void register_api_handler(const std::string& endpoint, cloe::HandlerType t,
52  cloe::Handler h) = 0;
53 };
54 
60 class Server {
61  public:
62  Server(const Server&) = default;
63  Server(Server&&) = delete;
64  Server& operator=(const Server&) = default;
65  Server& operator=(Server&&) = delete;
66  Server(cloe::ServerConf config) : config_(std::move(config)) {}
67  virtual ~Server() = default;
68 
72  [[nodiscard]] const cloe::ServerConf& config() const { return config_; }
73 
77  [[nodiscard]] virtual bool is_listening() const = 0;
78 
84  [[nodiscard]] virtual bool is_streaming() const = 0;
85 
89  virtual void start() = 0;
90 
94  virtual void stop() = 0;
95 
100  virtual void init_stream(const std::string& filename) = 0;
101 
105  virtual void enroll(cloe::Registrar& r) = 0;
106 
111  [[nodiscard]] virtual std::unique_ptr<ServerRegistrar> server_registrar() = 0;
112 
116  virtual void refresh_buffer_start_stream() = 0;
117 
121  virtual void refresh_buffer() = 0;
122 
126  [[nodiscard]] virtual std::vector<std::string> endpoints() const = 0;
127 
136  [[nodiscard]] virtual Defer lock() = 0;
137 
138  protected:
139  cloe::Logger logger() const { return cloe::logger::get("cloe"); }
140  cloe::ServerConf config_;
141 };
142 
146 std::unique_ptr<Server> make_server(const cloe::ServerConf&);
147 
148 } // namespace engine
Definition: registrar.hpp:121
Definition: defer.hpp:28
Definition: server.hpp:40
Definition: server.hpp:60
virtual void stop()=0
virtual void start()=0
virtual std::vector< std::string > endpoints() const =0
virtual void enroll(cloe::Registrar &r)=0
virtual bool is_listening() const =0
virtual void refresh_buffer()=0
virtual void refresh_buffer_start_stream()=0
virtual std::unique_ptr< ServerRegistrar > server_registrar()=0
virtual Defer lock()=0
virtual void init_stream(const std::string &filename)=0
const cloe::ServerConf & config() const
Definition: server.hpp:72
virtual bool is_streaming() const =0
std::function< void(const Request &, Response &)> Handler
Definition: cloe_fwd.hpp:65
HandlerType
Definition: registrar.hpp:88