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/timeout_watcher.cc',
|
||||||
'test/webfuse/utils/path.c',
|
'test/webfuse/utils/path.c',
|
||||||
'test/webfuse/utils/static_filesystem.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/fake_invokation_context.cc',
|
||||||
'test/webfuse/mocks/mock_authenticator.cc',
|
'test/webfuse/mocks/mock_authenticator.cc',
|
||||||
'test/webfuse/mocks/mock_request.cc',
|
'test/webfuse/mocks/mock_request.cc',
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include "webfuse/adapter/client.h"
|
#include "webfuse/adapter/client.h"
|
||||||
#include "webfuse/adapter/credentials.h"
|
#include "webfuse/adapter/credentials.h"
|
||||||
#include "webfuse/core/protocol_names.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
|
namespace
|
||||||
{
|
{
|
||||||
@ -111,7 +111,7 @@ TEST(client, general_usage)
|
|||||||
|
|
||||||
TEST(client, connect)
|
TEST(client, connect)
|
||||||
{
|
{
|
||||||
ThreadedWsServer server(WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
WsServer server(WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||||
|
|
||||||
context ctx;
|
context ctx;
|
||||||
ctx.state = connection_state::connecting;
|
ctx.state = connection_state::connecting;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <webfuse/provider/client_protocol.h>
|
#include <webfuse/provider/client_protocol.h>
|
||||||
#include <webfuse/provider/client_config.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/mocks/mock_provider_client.hpp"
|
||||||
#include "webfuse/core/protocol_names.h"
|
#include "webfuse/core/protocol_names.h"
|
||||||
#include "webfuse/utils/timeout_watcher.hpp"
|
#include "webfuse/utils/timeout_watcher.hpp"
|
||||||
@ -12,7 +12,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
using webfuse_test::ThreadedWsServer;
|
using webfuse_test::WsServer;
|
||||||
using webfuse_test::MockProviderClient;
|
using webfuse_test::MockProviderClient;
|
||||||
using webfuse_test::IProviderClient;
|
using webfuse_test::IProviderClient;
|
||||||
using webfuse_test::TimeoutWatcher;
|
using webfuse_test::TimeoutWatcher;
|
||||||
@ -32,7 +32,7 @@ class ClientProtocolFixture
|
|||||||
public:
|
public:
|
||||||
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
|
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();
|
config = wfp_client_config_create();
|
||||||
client.AttachTo(config, enableAuthentication);
|
client.AttachTo(config, enableAuthentication);
|
||||||
@ -168,7 +168,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ThreadedWsServer * server;
|
WsServer * server;
|
||||||
wfp_client_config * config;
|
wfp_client_config * config;
|
||||||
wfp_client_protocol * protocol;
|
wfp_client_protocol * protocol;
|
||||||
struct lws_context_creation_info info;
|
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 "webfuse/core/lws_log.h"
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
@ -29,7 +29,7 @@ public:
|
|||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
|
|
||||||
class ThreadedWsServer::Private : IServer
|
class WsServer::Private : IServer
|
||||||
{
|
{
|
||||||
Private(Private const &) = delete;
|
Private(Private const &) = delete;
|
||||||
Private & operator=(Private const &) = delete;
|
Private & operator=(Private const &) = delete;
|
||||||
@ -66,7 +66,7 @@ private:
|
|||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
static int wf_test_utils_threaded_ws_server_callback(
|
static int wf_test_utils_ws_server_callback(
|
||||||
struct lws * wsi,
|
struct lws * wsi,
|
||||||
enum lws_callback_reasons reason,
|
enum lws_callback_reasons reason,
|
||||||
void * user,
|
void * user,
|
||||||
@ -110,39 +110,39 @@ static int wf_test_utils_threaded_ws_server_callback(
|
|||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
|
|
||||||
ThreadedWsServer::ThreadedWsServer(std::string const & protocol, int port)
|
WsServer::WsServer(std::string const & protocol, int port)
|
||||||
: d(new Private(protocol, port))
|
: d(new Private(protocol, port))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadedWsServer::~ThreadedWsServer()
|
WsServer::~WsServer()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThreadedWsServer::IsConnected()
|
bool WsServer::IsConnected()
|
||||||
{
|
{
|
||||||
return d->IsConnected();
|
return d->IsConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadedWsServer::SendMessage(json_t * message)
|
void WsServer::SendMessage(json_t * message)
|
||||||
{
|
{
|
||||||
d->SendMessage(message);
|
d->SendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t * ThreadedWsServer::ReceiveMessage()
|
json_t * WsServer::ReceiveMessage()
|
||||||
{
|
{
|
||||||
return d->ReceiveMessage();
|
return d->ReceiveMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ThreadedWsServer::GetUrl() const
|
std::string WsServer::GetUrl() const
|
||||||
{
|
{
|
||||||
return d->GetUrl();
|
return d->GetUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ThreadedWsServer::Private::Private(std::string const & protocol, int port)
|
WsServer::Private::Private(std::string const & protocol, int port)
|
||||||
: protocol_(protocol)
|
: protocol_(protocol)
|
||||||
, port_(port)
|
, port_(port)
|
||||||
, is_connected(false)
|
, 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 );
|
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );
|
||||||
|
|
||||||
ws_protocols[0].name = protocol_.c_str();
|
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].per_session_data_size = 0;
|
||||||
ws_protocols[0].user = reinterpret_cast<void*>(server);
|
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);
|
context = std::thread(&run, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadedWsServer::Private::~Private()
|
WsServer::Private::~Private()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
@ -187,7 +187,7 @@ ThreadedWsServer::Private::~Private()
|
|||||||
lws_context_destroy(ws_context);
|
lws_context_destroy(ws_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadedWsServer::Private::run(Private * self)
|
void WsServer::Private::run(Private * self)
|
||||||
{
|
{
|
||||||
bool is_running = true;
|
bool is_running = true;
|
||||||
while (is_running)
|
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);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
return is_connected;
|
return is_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadedWsServer::Private::OnConnected(lws * wsi)
|
void WsServer::Private::OnConnected(lws * wsi)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
is_connected = true;
|
is_connected = true;
|
||||||
wsi_ = wsi;
|
wsi_ = wsi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadedWsServer::Private::OnConnectionClosed(lws * wsi)
|
void WsServer::Private::OnConnectionClosed(lws * wsi)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
if (wsi == wsi_)
|
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;
|
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;
|
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);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
if (wsi == wsi_)
|
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);
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ json_t * ThreadedWsServer::Private::ReceiveMessage()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ThreadedWsServer::Private::GetUrl() const
|
std::string WsServer::Private::GetUrl() const
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "ws://localhost:" << port_ << "/";
|
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