diff options
| author | Stefan Boberg <[email protected]> | 2023-10-11 10:05:42 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-11 10:05:42 +0200 |
| commit | 6ca893920560f2e907962c0b6e9b561ba797da38 (patch) | |
| tree | 9ca574b9fb9ab1c60c0203ae2e8c714e25419874 /src | |
| parent | remove legacy compute interfaces (#461) (diff) | |
| download | zen-6ca893920560f2e907962c0b6e9b561ba797da38.tar.xz zen-6ca893920560f2e907962c0b6e9b561ba797da38.zip | |
updated plugin API class names (#462)
* renamed some interfaces to improve pluggable transport API
TransportConnectionInterface -> TransportConnection
TransportPluginInterface -> TransportPlugin
TransportServerConnectionHandler -> TransportServerConnection
TransportServerInterface -> TransportServer
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/winsock/winsock.cpp | 38 | ||||
| -rw-r--r-- | src/zenhttp/dlltransport.cpp | 39 | ||||
| -rw-r--r-- | src/zenhttp/dlltransport.h | 4 | ||||
| -rw-r--r-- | src/zenhttp/httpplugin.cpp | 38 | ||||
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 2 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpplugin.h | 4 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/transportplugin.h | 30 | ||||
| -rw-r--r-- | src/zenhttp/winsocktransport.cpp | 38 | ||||
| -rw-r--r-- | src/zenhttp/winsocktransport.h | 2 |
9 files changed, 97 insertions, 98 deletions
diff --git a/src/plugins/winsock/winsock.cpp b/src/plugins/winsock/winsock.cpp index dca1fdbe7..3ee3f0ccd 100644 --- a/src/plugins/winsock/winsock.cpp +++ b/src/plugins/winsock/winsock.cpp @@ -24,25 +24,25 @@ ZEN_THIRD_PARTY_INCLUDES_END ////////////////////////////////////////////////////////////////////////// -class SocketTransportPlugin : public TransportPluginInterface, zen::RefCounted +class SocketTransportPlugin : public TransportPlugin, zen::RefCounted { public: SocketTransportPlugin(uint16_t BasePort, unsigned int ThreadCount); ~SocketTransportPlugin(); - // TransportPluginInterface implementation + // TransportPlugin implementation virtual uint32_t AddRef() const override; virtual uint32_t Release() const override; - virtual void Initialize(TransportServerInterface* ServerInterface) override; + virtual void Initialize(TransportServer* ServerInterface) override; virtual void Shutdown() override; virtual bool IsAvailable() override; private: - TransportServerInterface* m_ServerInterface = nullptr; - bool m_IsOk = true; - uint16_t m_BasePort = 0; - int m_ThreadCount = 0; + TransportServer* m_ServerInterface = nullptr; + bool m_IsOk = true; + uint16_t m_BasePort = 0; + int m_ThreadCount = 0; SOCKET m_ListenSocket{}; std::thread m_AcceptThread; @@ -50,25 +50,25 @@ private: std::vector<std::future<void>> m_Connections; }; -struct SocketTransportConnection : public TransportConnectionInterface +struct SocketTransportConnection : public TransportConnection { public: SocketTransportConnection(); ~SocketTransportConnection(); - void Initialize(TransportServerConnectionHandler* ServerConnection, SOCKET ClientSocket); + void Initialize(TransportServerConnection* ServerConnection, SOCKET ClientSocket); void HandleConnection(); - // TransportConnectionInterface implementation + // TransportConnection implementation virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; virtual void Shutdown(bool Receive, bool Transmit) override; virtual void CloseConnection() override; private: - zen::Ref<TransportServerConnectionHandler> m_ConnectionHandler; - SOCKET m_ClientSocket{}; - bool m_IsTerminated = false; + zen::Ref<TransportServerConnection> m_ConnectionHandler; + SOCKET m_ClientSocket{}; + bool m_IsTerminated = false; }; ////////////////////////////////////////////////////////////////////////// @@ -82,7 +82,7 @@ SocketTransportConnection::~SocketTransportConnection() } void -SocketTransportConnection::Initialize(TransportServerConnectionHandler* ServerConnection, SOCKET ClientSocket) +SocketTransportConnection::Initialize(TransportServerConnection* ServerConnection, SOCKET ClientSocket) { // ZEN_ASSERT(!m_ConnectionHandler); @@ -221,7 +221,7 @@ SocketTransportPlugin::Release() const } void -SocketTransportPlugin::Initialize(TransportServerInterface* ServerInterface) +SocketTransportPlugin::Initialize(TransportServer* ServerInterface) { uint16_t Port = m_BasePort; @@ -265,8 +265,8 @@ SocketTransportPlugin::Initialize(TransportServerInterface* ServerInterface) setsockopt(ClientSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&Flag, sizeof(Flag)); // Handle new connection - SocketTransportConnection* Connection = new SocketTransportConnection(); - TransportServerConnectionHandler* ConnectionInterface{m_ServerInterface->CreateConnectionHandler(Connection)}; + SocketTransportConnection* Connection = new SocketTransportConnection(); + TransportServerConnection* ConnectionInterface{m_ServerInterface->CreateConnectionHandler(Connection)}; Connection->Initialize(ConnectionInterface, ClientSocket); m_Connections.push_back(std::async(std::launch::async, [Connection] { @@ -315,8 +315,8 @@ SocketTransportPlugin::IsAvailable() ////////////////////////////////////////////////////////////////////////// -TransportPluginInterface* -CreateTransportPluginInterface() +TransportPlugin* +CreateTransportPlugin() { return new SocketTransportPlugin(1337, 8); } diff --git a/src/zenhttp/dlltransport.cpp b/src/zenhttp/dlltransport.cpp index 0bd5e3720..04fb6caaa 100644 --- a/src/zenhttp/dlltransport.cpp +++ b/src/zenhttp/dlltransport.cpp @@ -14,24 +14,24 @@ namespace zen { -struct DllTransportConnection : public TransportConnectionInterface +struct DllTransportConnection : public TransportConnection { public: DllTransportConnection(); ~DllTransportConnection(); - void Initialize(TransportServerConnectionHandler& ServerConnection); + void Initialize(TransportServerConnection& ServerConnection); void HandleConnection(); - // TransportConnectionInterface + // TransportConnection virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; virtual void Shutdown(bool Receive, bool Transmit) override; virtual void CloseConnection() override; private: - Ref<TransportServerConnectionHandler> m_ConnectionHandler; - bool m_IsTerminated = false; + Ref<TransportServerConnection> m_ConnectionHandler; + bool m_IsTerminated = false; }; DllTransportConnection::DllTransportConnection() @@ -43,7 +43,7 @@ DllTransportConnection::~DllTransportConnection() } void -DllTransportConnection::Initialize(TransportServerConnectionHandler& ServerConnection) +DllTransportConnection::Initialize(TransportServerConnection& ServerConnection) { m_ConnectionHandler = &ServerConnection; // TODO: this is awkward } @@ -81,9 +81,9 @@ DllTransportConnection::Shutdown(bool Receive, bool Transmit) struct LoadedDll { - std::string Name; - std::filesystem::path LoadedFromPath; - Ref<TransportPluginInterface> Plugin; + std::string Name; + std::filesystem::path LoadedFromPath; + Ref<TransportPlugin> Plugin; }; class DllTransportPluginImpl @@ -92,17 +92,17 @@ public: DllTransportPluginImpl(uint16_t BasePort, unsigned int ThreadCount); ~DllTransportPluginImpl(); - uint16_t Start(TransportServerInterface* ServerInterface); + uint16_t Start(TransportServer* ServerInterface); void Stop(); bool IsAvailable(); void LoadDll(std::string_view Name); private: - TransportServerInterface* m_ServerInterface = nullptr; - RwLock m_Lock; - std::vector<LoadedDll> m_Transports; - uint16_t m_BasePort = 0; - int m_ThreadCount = 0; + TransportServer* m_ServerInterface = nullptr; + RwLock m_Lock; + std::vector<LoadedDll> m_Transports; + uint16_t m_BasePort = 0; + int m_ThreadCount = 0; }; DllTransportPluginImpl::DllTransportPluginImpl(uint16_t BasePort, unsigned int ThreadCount) @@ -116,7 +116,7 @@ DllTransportPluginImpl::~DllTransportPluginImpl() } uint16_t -DllTransportPluginImpl::Start(TransportServerInterface* ServerIface) +DllTransportPluginImpl::Start(TransportServer* ServerIface) { m_ServerInterface = ServerIface; @@ -175,10 +175,9 @@ DllTransportPluginImpl::LoadDll(std::string_view Name) throw std::system_error(Ec, fmt::format("failed to load transport DLL from '{}'", DllPath)); } - TransportPluginInterface* CreateTransportPluginInterface(); + TransportPlugin* CreateTransportPlugin(); - PfnCreateTransportPluginInterface CreatePlugin = - (PfnCreateTransportPluginInterface)GetProcAddress(DllHandle, "CreateTransportPluginInterface"); + PfnCreateTransportPlugin CreatePlugin = (PfnCreateTransportPlugin)GetProcAddress(DllHandle, "CreateTransportPlugin"); if (!CreatePlugin) { @@ -223,7 +222,7 @@ DllTransportPlugin::Release() const } void -DllTransportPlugin::Initialize(TransportServerInterface* ServerInterface) +DllTransportPlugin::Initialize(TransportServer* ServerInterface) { m_Impl->Start(ServerInterface); } diff --git a/src/zenhttp/dlltransport.h b/src/zenhttp/dlltransport.h index b13bab804..2dccdd0f9 100644 --- a/src/zenhttp/dlltransport.h +++ b/src/zenhttp/dlltransport.h @@ -13,7 +13,7 @@ class DllTransportPluginImpl; /** Transport plugin which supports dynamic loading of external transport * provider modules */ -class DllTransportPlugin : public TransportPluginInterface, RefCounted +class DllTransportPlugin : public TransportPlugin, RefCounted { public: DllTransportPlugin(uint16_t BasePort, unsigned int ThreadCount); @@ -22,7 +22,7 @@ public: virtual uint32_t AddRef() const override; virtual uint32_t Release() const override; - virtual void Initialize(TransportServerInterface* ServerInterface) override; + virtual void Initialize(TransportServer* ServerInterface) override; virtual void Shutdown() override; virtual bool IsAvailable() override; diff --git a/src/zenhttp/httpplugin.cpp b/src/zenhttp/httpplugin.cpp index 45a6c23bd..2e934473e 100644 --- a/src/zenhttp/httpplugin.cpp +++ b/src/zenhttp/httpplugin.cpp @@ -36,7 +36,7 @@ using namespace std::literals; ////////////////////////////////////////////////////////////////////////// -struct HttpPluginConnectionHandler : public TransportServerConnectionHandler, public HttpRequestParserCallbacks, RefCounted +struct HttpPluginConnectionHandler : public TransportServerConnection, public HttpRequestParserCallbacks, RefCounted { virtual uint32_t AddRef() const override; virtual uint32_t Release() const override; @@ -48,7 +48,7 @@ struct HttpPluginConnectionHandler : public TransportServerConnectionHandler, pu virtual void HandleRequest() override; virtual void TerminateConnection() override; - void Initialize(TransportConnectionInterface* Transport, HttpPluginServerImpl& Server); + void Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server); private: enum class RequestState @@ -68,19 +68,19 @@ private: uint32_t m_ConnectionId = 0; Ref<IHttpPackageHandler> m_PackageHandler; - TransportConnectionInterface* m_TransportConnection = nullptr; - HttpPluginServerImpl* m_Server = nullptr; + TransportConnection* m_TransportConnection = nullptr; + HttpPluginServerImpl* m_Server = nullptr; }; ////////////////////////////////////////////////////////////////////////// -struct HttpPluginServerImpl : public TransportServerInterface +struct HttpPluginServerImpl : public TransportServer { HttpPluginServerImpl(); ~HttpPluginServerImpl(); - void AddPlugin(Ref<TransportPluginInterface> Plugin); - void RemovePlugin(Ref<TransportPluginInterface> Plugin); + void AddPlugin(Ref<TransportPlugin> Plugin); + void RemovePlugin(Ref<TransportPlugin> Plugin); void Start(); void Stop(); @@ -94,13 +94,13 @@ struct HttpPluginServerImpl : public TransportServerInterface HttpService* Service; }; - RwLock m_Lock; - std::vector<ServiceEntry> m_UriHandlers; - std::vector<Ref<TransportPluginInterface>> m_Plugins; + RwLock m_Lock; + std::vector<ServiceEntry> m_UriHandlers; + std::vector<Ref<TransportPlugin>> m_Plugins; - // TransportServerInterface + // TransportServer - virtual TransportServerConnectionHandler* CreateConnectionHandler(TransportConnectionInterface* Connection) override; + virtual TransportServerConnection* CreateConnectionHandler(TransportConnection* Connection) override; }; /** This is the class which request handlers interface with when @@ -221,7 +221,7 @@ HttpPluginResponse::GetHeaders() ////////////////////////////////////////////////////////////////////////// void -HttpPluginConnectionHandler::Initialize(TransportConnectionInterface* Transport, HttpPluginServerImpl& Server) +HttpPluginConnectionHandler::Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server) { m_TransportConnection = Transport; m_Server = &Server; @@ -560,8 +560,8 @@ HttpPluginServerImpl::~HttpPluginServerImpl() { } -TransportServerConnectionHandler* -HttpPluginServerImpl::CreateConnectionHandler(TransportConnectionInterface* Connection) +TransportServerConnection* +HttpPluginServerImpl::CreateConnectionHandler(TransportConnection* Connection) { HttpPluginConnectionHandler* Handler{new HttpPluginConnectionHandler()}; Handler->Initialize(Connection, *this); @@ -609,14 +609,14 @@ HttpPluginServerImpl::Stop() } void -HttpPluginServerImpl::AddPlugin(Ref<TransportPluginInterface> Plugin) +HttpPluginServerImpl::AddPlugin(Ref<TransportPlugin> Plugin) { RwLock::ExclusiveLockScope _(m_Lock); m_Plugins.emplace_back(std::move(Plugin)); } void -HttpPluginServerImpl::RemovePlugin(Ref<TransportPluginInterface> Plugin) +HttpPluginServerImpl::RemovePlugin(Ref<TransportPlugin> Plugin) { RwLock::ExclusiveLockScope _(m_Lock); auto It = std::find(begin(m_Plugins), end(m_Plugins), Plugin); @@ -766,13 +766,13 @@ HttpPluginServer::RegisterService(HttpService& Service) } void -HttpPluginServer::AddPlugin(Ref<TransportPluginInterface> Plugin) +HttpPluginServer::AddPlugin(Ref<TransportPlugin> Plugin) { m_Impl->AddPlugin(Plugin); } void -HttpPluginServer::RemovePlugin(Ref<TransportPluginInterface> Plugin) +HttpPluginServer::RemovePlugin(Ref<TransportPlugin> Plugin) { m_Impl->RemovePlugin(Plugin); } diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index 523befa72..3713d2a44 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -766,7 +766,7 @@ CreateHttpServer(const HttpServerConfig& Config) Ref<HttpPluginServer> Server{new HttpPluginServer(Config.ThreadCount)}; # if 1 - Ref<TransportPluginInterface> WinsockPlugin{CreateSocketTransportPlugin(1337, Config.ThreadCount)}; + Ref<TransportPlugin> WinsockPlugin{CreateSocketTransportPlugin(1337, Config.ThreadCount)}; Server->AddPlugin(WinsockPlugin); # endif diff --git a/src/zenhttp/include/zenhttp/httpplugin.h b/src/zenhttp/include/zenhttp/httpplugin.h index 409eb1b61..de54b9042 100644 --- a/src/zenhttp/include/zenhttp/httpplugin.h +++ b/src/zenhttp/include/zenhttp/httpplugin.h @@ -33,8 +33,8 @@ public: virtual void RequestExit() override; virtual void Close() override; - void AddPlugin(Ref<TransportPluginInterface> Plugin); - void RemovePlugin(Ref<TransportPluginInterface> Plugin); + void AddPlugin(Ref<TransportPlugin> Plugin); + void RemovePlugin(Ref<TransportPlugin> Plugin); private: Event m_ShutdownEvent; diff --git a/src/zenhttp/include/zenhttp/transportplugin.h b/src/zenhttp/include/zenhttp/transportplugin.h index 38b07d471..fe17680de 100644 --- a/src/zenhttp/include/zenhttp/transportplugin.h +++ b/src/zenhttp/include/zenhttp/transportplugin.h @@ -7,10 +7,10 @@ // Important note: this header is meant to compile standalone // and should therefore not depend on anything from the Zen codebase -class TransportConnectionInterface; -class TransportPluginInterface; -class TransportServerConnectionHandler; -class TransportServerInterface; +class TransportConnection; +class TransportPlugin; +class TransportServerConnection; +class TransportServer; /************************************************************************* @@ -26,7 +26,7 @@ class TransportServerInterface; * appropriate request handlers and ultimately call into functions * which write data back to the client. */ -class TransportServerConnectionHandler +class TransportServerConnection { public: virtual uint32_t AddRef() const = 0; @@ -40,10 +40,10 @@ public: * should use this to manage lifetimes of connections and any * other resources. */ -class TransportServerInterface +class TransportServer { public: - virtual TransportServerConnectionHandler* CreateConnectionHandler(TransportConnectionInterface* Connection) = 0; + virtual TransportServerConnection* CreateConnectionHandler(TransportConnection* Connection) = 0; }; /************************************************************************* @@ -57,13 +57,13 @@ public: * This is responsible for setting up and running the communication * for a given transport. */ -class TransportPluginInterface +class TransportPlugin { public: - virtual uint32_t AddRef() const = 0; - virtual uint32_t Release() const = 0; - virtual void Initialize(TransportServerInterface* ServerInterface) = 0; - virtual void Shutdown() = 0; + virtual uint32_t AddRef() const = 0; + virtual uint32_t Release() const = 0; + virtual void Initialize(TransportServer* ServerInterface) = 0; + virtual void Shutdown() = 0; /** Check whether this transport is usable. */ @@ -75,7 +75,7 @@ public: * There will be one instance of this per established connection and * this interface is used to write response data back to the client. */ -class TransportConnectionInterface +class TransportConnection { public: virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) = 0; @@ -91,7 +91,7 @@ public: extern "C" { - DLL_TRANSPORT_API TransportPluginInterface* CreateTransportPluginInterface(); + DLL_TRANSPORT_API TransportPlugin* CreateTransportPlugin(); } -typedef TransportPluginInterface* (*PfnCreateTransportPluginInterface)(); +typedef TransportPlugin* (*PfnCreateTransportPlugin)(); diff --git a/src/zenhttp/winsocktransport.cpp b/src/zenhttp/winsocktransport.cpp index e86e4822e..ad3302550 100644 --- a/src/zenhttp/winsocktransport.cpp +++ b/src/zenhttp/winsocktransport.cpp @@ -22,7 +22,7 @@ namespace zen { class SocketTransportPluginImpl; -class SocketTransportPlugin : public TransportPluginInterface, RefCounted +class SocketTransportPlugin : public TransportPlugin, RefCounted { public: SocketTransportPlugin(uint16_t BasePort, unsigned int ThreadCount); @@ -30,7 +30,7 @@ public: virtual uint32_t AddRef() const override; virtual uint32_t Release() const override; - virtual void Initialize(TransportServerInterface* ServerInterface) override; + virtual void Initialize(TransportServer* ServerInterface) override; virtual void Shutdown() override; virtual bool IsAvailable() override; @@ -41,25 +41,25 @@ private: SocketTransportPluginImpl* m_Impl; }; -struct SocketTransportConnection : public TransportConnectionInterface +struct SocketTransportConnection : public TransportConnection { public: SocketTransportConnection(); ~SocketTransportConnection(); - void Initialize(TransportServerConnectionHandler* ServerConnection, SOCKET ClientSocket); + void Initialize(TransportServerConnection* ServerConnection, SOCKET ClientSocket); void HandleConnection(); - // TransportConnectionInterface + // TransportConnection virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; virtual void Shutdown(bool Receive, bool Transmit) override; virtual void CloseConnection() override; private: - Ref<TransportServerConnectionHandler> m_ConnectionHandler; - SOCKET m_ClientSocket{}; - bool m_IsTerminated = false; + Ref<TransportServerConnection> m_ConnectionHandler; + SOCKET m_ClientSocket{}; + bool m_IsTerminated = false; }; SocketTransportConnection::SocketTransportConnection() @@ -71,7 +71,7 @@ SocketTransportConnection::~SocketTransportConnection() } void -SocketTransportConnection::Initialize(TransportServerConnectionHandler* ServerConnection, SOCKET ClientSocket) +SocketTransportConnection::Initialize(TransportServerConnection* ServerConnection, SOCKET ClientSocket) { ZEN_ASSERT(!m_ConnectionHandler); @@ -178,14 +178,14 @@ public: SocketTransportPluginImpl(uint16_t BasePort, unsigned int ThreadCount); ~SocketTransportPluginImpl(); - uint16_t Start(uint16_t Port, TransportServerInterface* ServerInterface); + uint16_t Start(uint16_t Port, TransportServer* ServerInterface); void Stop(); private: - TransportServerInterface* m_ServerInterface = nullptr; - uint16_t m_BasePort = 0; - int m_ThreadCount = 0; - bool m_IsOk = true; + TransportServer* m_ServerInterface = nullptr; + uint16_t m_BasePort = 0; + int m_ThreadCount = 0; + bool m_IsOk = true; SOCKET m_ListenSocket{}; std::thread m_AcceptThread; @@ -222,7 +222,7 @@ SocketTransportPluginImpl::~SocketTransportPluginImpl() } uint16_t -SocketTransportPluginImpl::Start(uint16_t Port, TransportServerInterface* ServerInterface) +SocketTransportPluginImpl::Start(uint16_t Port, TransportServer* ServerInterface) { m_ServerInterface = ServerInterface; m_ListenSocket = socket(AF_INET6, SOCK_STREAM, 0); @@ -268,8 +268,8 @@ SocketTransportPluginImpl::Start(uint16_t Port, TransportServerInterface* Server setsockopt(ClientSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&Flag, sizeof(Flag)); // Handle new connection - SocketTransportConnection* Connection = new SocketTransportConnection(); - TransportServerConnectionHandler* ConnectionInterface{m_ServerInterface->CreateConnectionHandler(Connection)}; + SocketTransportConnection* Connection = new SocketTransportConnection(); + TransportServerConnection* ConnectionInterface{m_ServerInterface->CreateConnectionHandler(Connection)}; Connection->Initialize(ConnectionInterface, ClientSocket); m_WorkerThreadpool->ScheduleWork([Connection] { @@ -339,7 +339,7 @@ SocketTransportPlugin::Release() const } void -SocketTransportPlugin::Initialize(TransportServerInterface* ServerInterface) +SocketTransportPlugin::Initialize(TransportServer* ServerInterface) { m_Impl->Start(m_BasePort, ServerInterface); } @@ -356,7 +356,7 @@ SocketTransportPlugin::IsAvailable() return true; } -TransportPluginInterface* +TransportPlugin* CreateSocketTransportPlugin(uint16_t BasePort, unsigned int ThreadCount) { return new SocketTransportPlugin(BasePort, ThreadCount); diff --git a/src/zenhttp/winsocktransport.h b/src/zenhttp/winsocktransport.h index 34809cddc..2b2a55aef 100644 --- a/src/zenhttp/winsocktransport.h +++ b/src/zenhttp/winsocktransport.h @@ -8,7 +8,7 @@ namespace zen { -TransportPluginInterface* CreateSocketTransportPlugin(uint16_t BasePort, unsigned int ThreadCount); +TransportPlugin* CreateSocketTransportPlugin(uint16_t BasePort, unsigned int ThreadCount); } // namespace zen |