snapcast/server/controlServer.h
(no author) 001bfa6aba start stream
git-svn-id: svn://elaine/murooma/trunk@282 d8a302eb-03bc-478d-80e4-98257eca68ef
2014-09-21 07:45:09 +00:00

77 lines
1.5 KiB
C++

#ifndef CONTROL_SERVER_H
#define CONTROL_SERVER_H
#include <boost/asio.hpp>
#include <vector>
#include <thread>
#include <memory>
#include <set>
#include <sstream>
#include <mutex>
#include "serverSession.h"
#include "common/timeUtils.h"
#include "common/queue.h"
#include "common/message.h"
#include "common/headerMessage.h"
#include "common/sampleFormat.h"
#include "common/serverSettings.h"
using boost::asio::ip::tcp;
typedef std::shared_ptr<tcp::socket> socket_ptr;
using namespace std;
class ControlServer : public MessageReceiver
{
public:
ControlServer(unsigned short port);
void start();
void stop();
void send(shared_ptr<BaseMessage> message);
virtual void onMessageReceived(ServerSession* connection, const BaseMessage& baseMessage, char* buffer);
void setHeader(HeaderMessage* header);
void setFormat(SampleFormat* format);
void setServerSettings(ServerSettings* settings);
private:
void acceptor();
mutable std::mutex mutex;
set<shared_ptr<ServerSession>> sessions;
boost::asio::io_service io_service_;
unsigned short port_;
HeaderMessage* headerChunk;
SampleFormat* sampleFormat;
ServerSettings* serverSettings;
thread* acceptThread;
Queue<shared_ptr<BaseMessage>> messages;
};
class ServerException : public std::exception
{
public:
ServerException(const std::string& what) : what_(what)
{
}
virtual ~ServerException() throw()
{
}
virtual const char* what() const throw()
{
return what_.c_str();
}
private:
std::string what_;
};
#endif