mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
refactor: extract InvokationHandler interface
This commit is contained in:
parent
8df7f08ed5
commit
cdb36eaea1
@ -1,13 +1,13 @@
|
|||||||
#ifndef WF_MOCK_INVOKATION_HANDLER_HPP
|
#ifndef WF_MOCK_INVOKATION_HANDLER_HPP
|
||||||
#define WF_MOCK_INVOKATION_HANDLER_HPP
|
#define WF_MOCK_INVOKATION_HANDLER_HPP
|
||||||
|
|
||||||
#include "webfuse/test_util/ws_server.hpp"
|
#include "webfuse/test_util/invokation_handler.hpp"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
|
|
||||||
class MockInvokationHander: public IIvokationHandler
|
class MockInvokationHander: public InvokationHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD2(Invoke, std::string(char const * method, json_t * params));
|
MOCK_METHOD2(Invoke, std::string(char const * method, json_t * params));
|
||||||
|
19
test/webfuse/test_util/invokation_handler.hpp
Normal file
19
test/webfuse/test_util/invokation_handler.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef WF_TEST_UTIL_INVOKATION_HANDLER_HPP
|
||||||
|
#define WF_TEST_UTIL_INVOKATION_HANDLER_HPP
|
||||||
|
|
||||||
|
#include <jansson.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class InvokationHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~InvokationHandler() = default;
|
||||||
|
virtual std::string Invoke(char const * method, json_t * params) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#include "webfuse/test_util/ws_server.hpp"
|
#include "webfuse/test_util/ws_server.hpp"
|
||||||
|
#include "webfuse/test_util/invokation_handler.hpp"
|
||||||
#include "webfuse/impl/util/lws_log.h"
|
#include "webfuse/impl/util/lws_log.h"
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
@ -75,7 +76,7 @@ class WsServer::Private : public IServer
|
|||||||
Private(Private const &) = delete;
|
Private(Private const &) = delete;
|
||||||
Private & operator=(Private const &) = delete;
|
Private & operator=(Private const &) = delete;
|
||||||
public:
|
public:
|
||||||
Private(IIvokationHandler & handler, std::string const & protocol, int port, bool enable_tls);
|
Private(InvokationHandler & handler, std::string const & protocol, int port, bool enable_tls);
|
||||||
~Private();
|
~Private();
|
||||||
std::string const & GetUrl() const;
|
std::string const & GetUrl() const;
|
||||||
void OnConnected(lws * wsi) override;
|
void OnConnected(lws * wsi) override;
|
||||||
@ -88,7 +89,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static void Run(Private * self);
|
static void Run(Private * self);
|
||||||
|
|
||||||
IIvokationHandler & handler_;
|
InvokationHandler & handler_;
|
||||||
std::string protocol_;
|
std::string protocol_;
|
||||||
bool is_shutdown_requested;
|
bool is_shutdown_requested;
|
||||||
lws * wsi_;
|
lws * wsi_;
|
||||||
@ -102,7 +103,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
WsServer::WsServer(
|
WsServer::WsServer(
|
||||||
IIvokationHandler& handler,
|
InvokationHandler& handler,
|
||||||
std::string const & protocol,
|
std::string const & protocol,
|
||||||
int port,
|
int port,
|
||||||
bool enable_tls)
|
bool enable_tls)
|
||||||
@ -133,7 +134,7 @@ void WsServer::SendMessage(json_t * message)
|
|||||||
|
|
||||||
|
|
||||||
WsServer::Private::Private(
|
WsServer::Private::Private(
|
||||||
IIvokationHandler & handler,
|
InvokationHandler & handler,
|
||||||
std::string const & protocol,
|
std::string const & protocol,
|
||||||
int port,
|
int port,
|
||||||
bool enable_tls)
|
bool enable_tls)
|
||||||
|
@ -7,12 +7,7 @@
|
|||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
|
|
||||||
class IIvokationHandler
|
class InvokationHandler;
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IIvokationHandler() = default;
|
|
||||||
virtual std::string Invoke(char const * method, json_t * params) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WsServer
|
class WsServer
|
||||||
{
|
{
|
||||||
@ -20,7 +15,7 @@ class WsServer
|
|||||||
WsServer & operator=(WsServer const & ) = delete;
|
WsServer & operator=(WsServer const & ) = delete;
|
||||||
public:
|
public:
|
||||||
WsServer(
|
WsServer(
|
||||||
IIvokationHandler& handler,
|
InvokationHandler& handler,
|
||||||
std::string const & protocol,
|
std::string const & protocol,
|
||||||
int port = 0,
|
int port = 0,
|
||||||
bool enable_tls = false);
|
bool enable_tls = false);
|
||||||
|
Loading…
Reference in New Issue
Block a user