mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
renamed ThreadedWsServer -> WsServer
This commit is contained in:
parent
4d277701cb
commit
cd76427f83
@ -209,7 +209,7 @@ alltests = executable('alltests',
|
||||
'test/webfuse/utils/timeout_watcher.cc',
|
||||
'test/webfuse/utils/path.c',
|
||||
'test/webfuse/utils/static_filesystem.c',
|
||||
'test/webfuse/utils/threaded_ws_server.cc',
|
||||
'test/webfuse/utils/ws_server.cc',
|
||||
'test/webfuse/mocks/fake_invokation_context.cc',
|
||||
'test/webfuse/mocks/mock_authenticator.cc',
|
||||
'test/webfuse/mocks/mock_request.cc',
|
||||
|
@ -3,9 +3,9 @@
|
||||
#include "webfuse/adapter/client.h"
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
#include "webfuse/utils/threaded_ws_server.h"
|
||||
#include "webfuse/utils/ws_server.h"
|
||||
|
||||
using webfuse_test::ThreadedWsServer;
|
||||
using webfuse_test::WsServer;
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -111,7 +111,7 @@ TEST(client, general_usage)
|
||||
|
||||
TEST(client, connect)
|
||||
{
|
||||
ThreadedWsServer server(WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
|
||||
context ctx;
|
||||
ctx.state = connection_state::connecting;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <webfuse/provider/client_protocol.h>
|
||||
#include <webfuse/provider/client_config.h>
|
||||
#include "webfuse/utils/threaded_ws_server.h"
|
||||
#include "webfuse/utils/ws_server.h"
|
||||
#include "webfuse/mocks/mock_provider_client.hpp"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
#include "webfuse/utils/timeout_watcher.hpp"
|
||||
@ -12,7 +12,7 @@
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
using webfuse_test::ThreadedWsServer;
|
||||
using webfuse_test::WsServer;
|
||||
using webfuse_test::MockProviderClient;
|
||||
using webfuse_test::IProviderClient;
|
||||
using webfuse_test::TimeoutWatcher;
|
||||
@ -32,7 +32,7 @@ class ClientProtocolFixture
|
||||
public:
|
||||
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
|
||||
{
|
||||
server = new ThreadedWsServer(WF_PROTOCOL_NAME_ADAPTER_SERVER);
|
||||
server = new WsServer(WF_PROTOCOL_NAME_ADAPTER_SERVER);
|
||||
|
||||
config = wfp_client_config_create();
|
||||
client.AttachTo(config, enableAuthentication);
|
||||
@ -168,7 +168,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
ThreadedWsServer * server;
|
||||
WsServer * server;
|
||||
wfp_client_config * config;
|
||||
wfp_client_protocol * protocol;
|
||||
struct lws_context_creation_info info;
|
||||
|
@ -1,30 +0,0 @@
|
||||
#ifndef WF_TEST_UTILS_THREADED_WS_SERVER_HPP
|
||||
#define WF_TEST_UTILS_THREADED_WS_SERVER_HPP
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class ThreadedWsServer
|
||||
{
|
||||
ThreadedWsServer(ThreadedWsServer const &) = delete;
|
||||
ThreadedWsServer & operator=(ThreadedWsServer const &) = delete;
|
||||
public:
|
||||
ThreadedWsServer(std::string const & protocol, int port = 0);
|
||||
~ThreadedWsServer();
|
||||
bool IsConnected();
|
||||
std::string GetUrl() const;
|
||||
void SendMessage(json_t * message);
|
||||
json_t * ReceiveMessage();
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "webfuse/utils/threaded_ws_server.h"
|
||||
#include "webfuse/utils/ws_server.h"
|
||||
#include "webfuse/core/lws_log.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
@ -29,7 +29,7 @@ public:
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class ThreadedWsServer::Private : IServer
|
||||
class WsServer::Private : IServer
|
||||
{
|
||||
Private(Private const &) = delete;
|
||||
Private & operator=(Private const &) = delete;
|
||||
@ -66,7 +66,7 @@ private:
|
||||
extern "C"
|
||||
{
|
||||
|
||||
static int wf_test_utils_threaded_ws_server_callback(
|
||||
static int wf_test_utils_ws_server_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * user,
|
||||
@ -110,39 +110,39 @@ static int wf_test_utils_threaded_ws_server_callback(
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
ThreadedWsServer::ThreadedWsServer(std::string const & protocol, int port)
|
||||
WsServer::WsServer(std::string const & protocol, int port)
|
||||
: d(new Private(protocol, port))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ThreadedWsServer::~ThreadedWsServer()
|
||||
WsServer::~WsServer()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool ThreadedWsServer::IsConnected()
|
||||
bool WsServer::IsConnected()
|
||||
{
|
||||
return d->IsConnected();
|
||||
}
|
||||
|
||||
void ThreadedWsServer::SendMessage(json_t * message)
|
||||
void WsServer::SendMessage(json_t * message)
|
||||
{
|
||||
d->SendMessage(message);
|
||||
}
|
||||
|
||||
json_t * ThreadedWsServer::ReceiveMessage()
|
||||
json_t * WsServer::ReceiveMessage()
|
||||
{
|
||||
return d->ReceiveMessage();
|
||||
}
|
||||
|
||||
std::string ThreadedWsServer::GetUrl() const
|
||||
std::string WsServer::GetUrl() const
|
||||
{
|
||||
return d->GetUrl();
|
||||
}
|
||||
|
||||
|
||||
ThreadedWsServer::Private::Private(std::string const & protocol, int port)
|
||||
WsServer::Private::Private(std::string const & protocol, int port)
|
||||
: protocol_(protocol)
|
||||
, port_(port)
|
||||
, is_connected(false)
|
||||
@ -154,7 +154,7 @@ ThreadedWsServer::Private::Private(std::string const & protocol, int port)
|
||||
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );
|
||||
|
||||
ws_protocols[0].name = protocol_.c_str();
|
||||
ws_protocols[0].callback = &wf_test_utils_threaded_ws_server_callback;
|
||||
ws_protocols[0].callback = &wf_test_utils_ws_server_callback;
|
||||
ws_protocols[0].per_session_data_size = 0;
|
||||
ws_protocols[0].user = reinterpret_cast<void*>(server);
|
||||
|
||||
@ -175,7 +175,7 @@ ThreadedWsServer::Private::Private(std::string const & protocol, int port)
|
||||
context = std::thread(&run, this);
|
||||
}
|
||||
|
||||
ThreadedWsServer::Private::~Private()
|
||||
WsServer::Private::~Private()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
@ -187,7 +187,7 @@ ThreadedWsServer::Private::~Private()
|
||||
lws_context_destroy(ws_context);
|
||||
}
|
||||
|
||||
void ThreadedWsServer::Private::run(Private * self)
|
||||
void WsServer::Private::run(Private * self)
|
||||
{
|
||||
bool is_running = true;
|
||||
while (is_running)
|
||||
@ -200,20 +200,20 @@ void ThreadedWsServer::Private::run(Private * self)
|
||||
}
|
||||
}
|
||||
|
||||
bool ThreadedWsServer::Private::IsConnected()
|
||||
bool WsServer::Private::IsConnected()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
return is_connected;
|
||||
}
|
||||
|
||||
void ThreadedWsServer::Private::OnConnected(lws * wsi)
|
||||
void WsServer::Private::OnConnected(lws * wsi)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
is_connected = true;
|
||||
wsi_ = wsi;
|
||||
}
|
||||
|
||||
void ThreadedWsServer::Private::OnConnectionClosed(lws * wsi)
|
||||
void WsServer::Private::OnConnectionClosed(lws * wsi)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (wsi == wsi_)
|
||||
@ -223,7 +223,7 @@ void ThreadedWsServer::Private::OnConnectionClosed(lws * wsi)
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadedWsServer::Private::OnWritable(struct lws * wsi)
|
||||
void WsServer::Private::OnWritable(struct lws * wsi)
|
||||
{
|
||||
bool notify = false;
|
||||
|
||||
@ -251,7 +251,7 @@ void ThreadedWsServer::Private::OnWritable(struct lws * wsi)
|
||||
}
|
||||
|
||||
|
||||
void ThreadedWsServer::Private::SendMessage(json_t * message)
|
||||
void WsServer::Private::SendMessage(json_t * message)
|
||||
{
|
||||
lws * wsi = nullptr;
|
||||
|
||||
@ -274,7 +274,7 @@ void ThreadedWsServer::Private::SendMessage(json_t * message)
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadedWsServer::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
|
||||
void WsServer::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (wsi == wsi_)
|
||||
@ -283,7 +283,7 @@ void ThreadedWsServer::Private::OnMessageReceived(struct lws * wsi, char const *
|
||||
}
|
||||
}
|
||||
|
||||
json_t * ThreadedWsServer::Private::ReceiveMessage()
|
||||
json_t * WsServer::Private::ReceiveMessage()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
|
||||
@ -298,7 +298,7 @@ json_t * ThreadedWsServer::Private::ReceiveMessage()
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ThreadedWsServer::Private::GetUrl() const
|
||||
std::string WsServer::Private::GetUrl() const
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "ws://localhost:" << port_ << "/";
|
30
test/webfuse/utils/ws_server.h
Normal file
30
test/webfuse/utils/ws_server.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef WF_TEST_UTILS_WS_SERVER_HPP
|
||||
#define WF_TEST_UTILS_WS_SERVER_HPP
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class WsServer
|
||||
{
|
||||
WsServer(WsServer const &) = delete;
|
||||
WsServer & operator=(WsServer const &) = delete;
|
||||
public:
|
||||
WsServer(std::string const & protocol, int port = 0);
|
||||
~WsServer();
|
||||
bool IsConnected();
|
||||
std::string GetUrl() const;
|
||||
void SendMessage(json_t * message);
|
||||
json_t * ReceiveMessage();
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user