25 #include <arpa/inet.h>
28 #ifndef VISIONTRANSFER_DATACHANNELSERVICEBASE_H
29 #define VISIONTRANSFER_DATACHANNELSERVICEBASE_H
31 namespace visiontransfer {
42 struct DataChannelMessageHeader {
47 struct DataChannelMessage {
48 DataChannelMessageHeader header;
49 unsigned char* payload;
55 class DataChannelServiceBase;
65 enum DataChannelTypesEnum {
72 typedef unsigned char Type;
73 typedef unsigned char ID;
77 inline ID getChannelID()
const {
return channelID; }
78 inline std::string getInfoString()
const {
return infoString; }
79 inline void setService(std::weak_ptr<DataChannelServiceBase> serv) { service = serv; }
80 inline void setChannelID(ID
id) { channelID = id; }
82 virtual Type getChannelType()
const = 0;
84 virtual int handleMessage(DataChannelMessage& message, sockaddr_in* sender) = 0;
92 virtual bool process() {
return true; }
93 virtual int stopService() = 0;
95 std::string infoString;
96 int sendData(
unsigned char* data,
unsigned int dataSize, sockaddr_in* recipient=
nullptr);
99 std::weak_ptr<DataChannelServiceBase> service;
107 inline DataChannelInfo(DataChannel::ID
id, DataChannel::Type type,
const std::string& info): channelID(id), channelType(type), infoString(info) { }
108 inline DataChannel::ID getChannelID()
const {
return channelID; }
109 inline DataChannel::Type getChannelType()
const {
return channelType; }
110 inline std::string getInfoString()
const {
return infoString; }
112 DataChannel::ID channelID;
113 DataChannel::Type channelType;
114 std::string infoString;
127 DataChannel::ID registerChannel(std::shared_ptr<DataChannel> channel);
128 virtual int sendDataInternal(
unsigned char* compiledMessage,
unsigned int messageSize, sockaddr_in* recipient);
129 int sendDataIsolatedPacket(DataChannel::ID
id, DataChannel::Type type,
unsigned char* data,
unsigned int dataSize, sockaddr_in* recipient);
130 virtual int handleChannel0Message(
DataChannelMessage& message, sockaddr_in* sender) = 0;
132 std::map<DataChannel::ID, std::shared_ptr<DataChannel> > channels;
134 SOCKET dataChannelSocket;
136 int dataChannelSocket;