-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServerFactory for better decoupling from server implementation
- Loading branch information
Showing
10 changed files
with
100 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
foxglove_bridge_base/include/foxglove_bridge/server_factory.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <websocketpp/common/connection_hdl.hpp> | ||
|
||
#include "common.hpp" | ||
#include "server_interface.hpp" | ||
|
||
namespace foxglove { | ||
|
||
class ServerFactory { | ||
public: | ||
template <typename ConnectionHandle> | ||
static std::unique_ptr<ServerInterface<ConnectionHandle>> createServer( | ||
const std::string& name, const std::function<void(WebSocketLogLevel, char const*)>& logHandler, | ||
const ServerOptions& options); | ||
}; | ||
|
||
} // namespace foxglove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
#include "foxglove_bridge/foxglove_bridge.hpp" | ||
|
||
#define ASIO_STANDALONE | ||
#include "foxglove_bridge/websocket_notls.hpp" | ||
#include "foxglove_bridge/websocket_server.hpp" | ||
#include "foxglove_bridge/websocket_tls.hpp" | ||
#include "websocketpp/version.hpp" | ||
|
||
namespace foxglove { | ||
|
||
const char* WebSocketUserAgent() { | ||
return websocketpp::user_agent; | ||
} | ||
|
||
// Explicit template instantiation for common server configurations | ||
template class Server<WebSocketTls>; | ||
template class Server<WebSocketNoTls>; | ||
|
||
} // namespace foxglove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <websocketpp/common/connection_hdl.hpp> | ||
|
||
#include <foxglove_bridge/server_factory.hpp> | ||
|
||
#define ASIO_STANDALONE | ||
#include <foxglove_bridge/websocket_server.hpp> | ||
|
||
namespace foxglove { | ||
|
||
template <> | ||
std::unique_ptr<ServerInterface<websocketpp::connection_hdl>> ServerFactory::createServer( | ||
const std::string& name, const std::function<void(WebSocketLogLevel, char const*)>& logHandler, | ||
const ServerOptions& options) { | ||
if (options.useTls) { | ||
return std::make_unique<foxglove::Server<foxglove::WebSocketTls>>(name, logHandler, options); | ||
} else { | ||
return std::make_unique<foxglove::Server<foxglove::WebSocketNoTls>>(name, logHandler, options); | ||
} | ||
} | ||
|
||
} // namespace foxglove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.