/*
 * CenosServer.hpp
 *
 *  Created on: May 11, 2017
 *      Author: vadims
 */

#ifndef CENOSSERVER_HPP_
#define CENOSSERVER_HPP_

#include <WinSock2.h>
#include <Windows.h>
#include <boost/thread.hpp>
#include <iostream>
#include <thread>
#include <string>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <websocketpp/common/thread.hpp>
#include <queue>
#include <fstream>



using namespace std;

typedef websocketpp::server<websocketpp::config::asio>::message_ptr message_ptr;

class cenosServer {
public:
	// initialize server with port number, start listening and accepting connections
	static bool init(int);
	// run server
	void run();
	// stop server
	static void stop();
	cenosServer();
	static const void readClientNames();
	void setLoggingFile(std::string);


private:
	static websocketpp::connection_hdl getHdlById(const string& id);
	static websocketpp::server<websocketpp::config::asio> server;
	static boost::mutex wsMutex;
	static map<string, websocketpp::connection_hdl> websockets;
	static int portNr;
	static std::vector<std::string> clientNames;
	std::ofstream logFile;


	// callbacks
	static bool on_validate(websocketpp::connection_hdl hdl);
	static void on_fail(websocketpp::connection_hdl hdl);
	static void on_close();
	static void on_message(websocketpp::connection_hdl, message_ptr);

};


#endif /* CENOSSERVER_HPP_ */