Skip to content

Commit 3171837

Browse files
committed
oak: Refactor server.hpp to move impls to source file
1 parent a183df3 commit 3171837

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

oak/include/oak/server.hpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,14 @@ class ServerImplHandler {
8989
*/
9090
class Server {
9191
public:
92-
Server(const std::string& addr, int port)
93-
: listen_addr_(addr), listen_port_(port), listen_threads_(3), listening_(false) {}
94-
95-
Server() : listen_addr_("127.0.0.1"), listen_port_(8080), listen_threads_(3), listening_(false) {}
92+
Server(const std::string& addr, int port);
93+
Server();
9694

9795
/**
9896
* When a Server goes out of scope, it will stop listening for you if you
9997
* haven't done so already.
10098
*/
101-
~Server() {
102-
if (this->is_listening()) {
103-
this->stop();
104-
}
105-
}
99+
~Server();
106100

107101
/**
108102
* Set the number of threads used for listening to connections.
@@ -138,9 +132,7 @@ class Server {
138132
/**
139133
* Return endpoint data in json format.
140134
*/
141-
cloe::Json endpoints_to_json(const std::vector<std::string>& endpoints) const {
142-
return handler_.endpoints_to_json(endpoints);
143-
};
135+
cloe::Json endpoints_to_json(const std::vector<std::string>& endpoints) const;
144136

145137
/**
146138
* Stop the server.
@@ -150,7 +142,7 @@ class Server {
150142
/**
151143
* Return a list of all registered endpoints.
152144
*/
153-
std::vector<std::string> endpoints() const { return handler_.endpoints(); }
145+
std::vector<std::string> endpoints() const;
154146

155147
protected:
156148
friend StaticRegistrar;
@@ -160,7 +152,7 @@ class Server {
160152
/**
161153
* Add a handler with the route muxer in the internal handler routine.
162154
*/
163-
void add_handler(const std::string& key, Handler h) { handler_.add(key, h); }
155+
void add_handler(const std::string& key, Handler h);
164156

165157
private:
166158
// Configuration

oak/src/oak/server.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,28 @@ void Server::stop() {
289289
listening_ = false;
290290
}
291291

292+
void Server::add_handler(const std::string& key, Handler h) {
293+
handler_->add(key, std::move(h));
294+
}
295+
296+
std::vector<std::string> Server::endpoints() const {
297+
return handler_->endpoints();
298+
}
299+
300+
cloe::Json Server::endpoints_to_json(const std::vector<std::string>& endpoints) const {
301+
return handler_->endpoints_to_json(endpoints);
302+
}
303+
304+
Server::Server(const std::string& addr, int port)
305+
: listen_addr_(addr), listen_port_(port), listen_threads_(3), listening_(false) {}
306+
307+
Server::Server()
308+
: listen_addr_("127.0.0.1"), listen_port_(8080), listen_threads_(3), listening_(false) {}
309+
310+
Server::~Server() {
311+
if (this->is_listening()) {
312+
this->stop();
313+
}
314+
}
315+
292316
} // namespace oak

0 commit comments

Comments
 (0)