2018-12-30 03:33:15 +01:00
|
|
|
/*
|
|
|
|
* IXTest.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2018 Machine Zone. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-08-13 19:59:18 +02:00
|
|
|
#include "IXGetFreePort.h"
|
2019-01-08 03:04:28 +01:00
|
|
|
#include <iostream>
|
2019-09-24 06:04:01 +02:00
|
|
|
#include <ixsnake/IXAppConfig.h>
|
2019-06-06 22:48:53 +02:00
|
|
|
#include <ixwebsocket/IXWebSocketServer.h>
|
2019-01-08 03:08:11 +01:00
|
|
|
#include <mutex>
|
2019-05-14 02:32:57 +02:00
|
|
|
#include <spdlog/spdlog.h>
|
2019-06-06 22:48:53 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-12-30 03:33:15 +01:00
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
// Sleep for ms milliseconds.
|
|
|
|
void msleep(int ms);
|
|
|
|
|
|
|
|
// Generate a relatively random string
|
|
|
|
std::string generateSessionId();
|
|
|
|
|
|
|
|
// Record and report websocket traffic
|
|
|
|
void setupWebSocketTrafficTrackerCallback();
|
|
|
|
void reportWebSocketTraffic();
|
2019-01-08 03:04:28 +01:00
|
|
|
|
|
|
|
struct Logger
|
|
|
|
{
|
2019-06-06 22:48:53 +02:00
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
Logger& operator<<(T const& obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << obj;
|
|
|
|
spdlog::info(ss.str());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::mutex _mutex;
|
2019-01-08 03:04:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void log(const std::string& msg);
|
2019-01-29 00:14:49 +01:00
|
|
|
|
2019-05-16 23:25:31 +02:00
|
|
|
bool startWebSocketEchoServer(ix::WebSocketServer& server);
|
2019-09-06 05:48:38 +02:00
|
|
|
|
2019-09-06 06:57:05 +02:00
|
|
|
snake::AppConfig makeSnakeServerConfig(int port);
|
2019-06-06 22:48:53 +02:00
|
|
|
} // namespace ix
|