$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 
29 #include "stack.hpp" // for ServerConf
30 #include "utility/defer.hpp" // for Defer
31 
32 namespace engine {
33 
41  public:
42  virtual ~ServerRegistrar() = default;
43 
44  virtual std::unique_ptr<ServerRegistrar> clone() const = 0;
45 
46  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 cloe::ServerConf& config) : config_(config) {}
63  virtual ~Server() = default;
64 
68  const cloe::ServerConf& config() const { return config_; }
69 
73  virtual bool is_listening() const = 0;
74 
80  virtual bool is_streaming() const = 0;
81 
85  virtual void start() = 0;
86 
90  virtual void stop() = 0;
91 
96  virtual void init_stream(const std::string& filename) = 0;
97 
101  virtual void enroll(cloe::Registrar& r) = 0;
102 
107  virtual std::unique_ptr<ServerRegistrar> server_registrar() = 0;
108 
112  virtual void refresh_buffer_start_stream() = 0;
113 
117  virtual void refresh_buffer() = 0;
118 
127  virtual Defer lock() = 0;
128 
129  protected:
130  cloe::Logger logger() const { return cloe::logger::get("cloe"); }
131  cloe::ServerConf config_;
132 };
133 
137 std::unique_ptr<Server> make_server(const cloe::ServerConf&);
138 
139 } // namespace engine
Definition: registrar.hpp:116
Definition: defer.hpp:28
Definition: server.hpp:40
Definition: server.hpp:60
virtual void stop()=0
virtual void start()=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:68
virtual bool is_streaming() const =0
std::function< void(const Request &, Response &)> Handler
Definition: cloe_fwd.hpp:58
HandlerType
Definition: registrar.hpp:83
Definition: stack.hpp:197