implementation of SESSION CREATE

This commit is contained in:
orignal 2014-09-25 13:22:25 -04:00
parent 08ff685de8
commit eb83b6e9a6
2 changed files with 150 additions and 11 deletions

27
SAM.h
View file

@ -17,6 +17,21 @@ namespace stream
const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
const char SAM_HANDSHAKE[] = "HELLO VERSION";
const char SAM_HANDSHAKE_REPLY[] = "HELLO REPLY RESULT=OK VERSION=3.1";
const char SAM_SESSION_CREATE[] = "SESSION CREATE";
const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=";
const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID";
const char SAM_STREAM_CONNECT[] = "STREAM CONNECT";
const char SAM_PARAM_STYLE[] = "STYLE";
const char SAM_PARAM_ID[] = "ID";
const char SAM_PARAM_DESTINATION[] = "DESTINATION";
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
enum SAMSocketType
{
eSAMSocketTypeUnknown,
eSAMSocketTypeSession,
eSAMSocketTypeStream
};
class SAMBridge;
class SAMSocket
@ -34,6 +49,9 @@ namespace stream
void Terminate ();
void HandleHandshakeReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleMessage (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void SendMessageReply (const char * msg, size_t len, bool close);
void HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close);
void Receive ();
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
@ -41,12 +59,18 @@ namespace stream
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void HandleWriteStreamData (const boost::system::error_code& ecode);
void ProcessSessionCreate (char * buf, size_t len);
void ProcessStreamConnect (char * buf, size_t len);
void ExtractParams (char * buf, size_t len, std::map<std::string, std::string>& params);
private:
SAMBridge& m_Owner;
boost::asio::ip::tcp::socket m_Socket;
char m_Buffer[SAM_SOCKET_BUFFER_SIZE + 1];
uint8_t m_StreamBuffer[SAM_SOCKET_BUFFER_SIZE];
SAMSocketType m_SocketType;
std::string m_ID; // nickname
Stream * m_Stream;
};
@ -68,8 +92,9 @@ namespace stream
void Stop ();
boost::asio::io_service& GetService () { return m_Service; };
bool CreateSession (const std::string& id, const char * destination = nullptr, size_t len = 0); // null means transient
SAMSession * CreateSession (const std::string& id, const std::string& destination = ""); // empty string means transient
void CloseSession (const std::string& id);
SAMSession * FindSession (const std::string& id);
private: