59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#ifndef OH_BS_TRANSMITTER_H
|
|
#define OH_BS_TRANSMITTER_H
|
|
|
|
#include "CCSocket.h"
|
|
#include "Configuration/Config.h"
|
|
#include "CCByteArray.h"
|
|
|
|
class AIMInfo{
|
|
public:
|
|
int TermID = -1;
|
|
CTL::String IP = "";
|
|
int Port = -1;
|
|
bool TCP = false;
|
|
CTL::ByteArray Data;
|
|
int buffer_length = 0;
|
|
};
|
|
|
|
class Transmitter {
|
|
public:
|
|
static bool Send_Massage(AIMInfo* info){
|
|
if(!info){
|
|
return false;
|
|
}
|
|
if(!info->TCP){
|
|
const auto Setting = Config::getConfig();
|
|
if (Setting->m_socket_udp) {
|
|
CTL::DatagramPacket packet;
|
|
const CTL::InetAddress address(info->IP);
|
|
packet.setAddress(address);
|
|
packet.setData(info->Data);
|
|
packet.setPort(info->Port);
|
|
std::shared_lock<std::shared_mutex> lock(Config::m_mutex_udp);
|
|
return Setting->m_socket_udp->send(packet);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
static bool Send_Stream(AIMInfo* info){
|
|
if(!info){
|
|
return false;
|
|
}
|
|
if(!info->TCP){
|
|
const auto Setting = Config::getConfig();
|
|
if (Setting->m_socket_udp) {
|
|
CTL::DatagramPacket packet;
|
|
const CTL::InetAddress address(info->IP);
|
|
packet.setAddress(address);
|
|
packet.setData(info->Data);
|
|
packet.setPort(info->Port);
|
|
std::shared_lock<std::shared_mutex> lock(Config::m_mutex_udp);
|
|
return Setting->m_socket_udp->send(packet);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
#endif
|