snapcast/server/streamServer.h
(no author) feabfee936 xxxx
git-svn-id: svn://elaine/murooma/trunk@272 d8a302eb-03bc-478d-80e4-98257eca68ef
2014-09-17 21:58:38 +00:00

82 lines
1.3 KiB
C++

#ifndef STREAM_SERVER_H
#define STREAM_SERVER_H
#include <boost/asio.hpp>
#include <vector>
#include <thread>
#include <memory>
#include <set>
#include <sstream>
#include "serverConnection.h"
#include "common/timeUtils.h"
#include "common/queue.h"
#include "common/message.h"
#include "common/headerMessage.h"
#include "common/sampleFormat.h"
using boost::asio::ip::tcp;
typedef std::shared_ptr<tcp::socket> socket_ptr;
using namespace std;
class StreamSession : public ServerConnection
{
public:
StreamSession(socket_ptr sock);
void send(shared_ptr<BaseMessage> message);
protected:
virtual void worker();
thread* senderThread;
Queue<shared_ptr<BaseMessage>> messages;
};
class StreamServer
{
public:
StreamServer(unsigned short port);
void send(shared_ptr<BaseMessage> message);
void start();
void stop();
private:
void acceptor();
set<shared_ptr<StreamSession>> sessions;
boost::asio::io_service io_service_;
unsigned short port_;
shared_ptr<HeaderMessage> headerChunk;
shared_ptr<SampleFormat> sampleFormat;
thread* acceptThread;
};
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