mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
replace udpDestination struct with a class that accepts ipaddr
This commit is contained in:
@ -55,9 +55,6 @@ std::ostream &operator<<(std::ostream &os,
|
||||
std::string ToString(const slsDetectorDefs::currentSrcParameters &r);
|
||||
std::ostream &operator<<(std::ostream &os,
|
||||
const slsDetectorDefs::currentSrcParameters &r);
|
||||
std::string ToString(const slsDetectorDefs::udpDestination &r);
|
||||
std::ostream &operator<<(std::ostream &os,
|
||||
const slsDetectorDefs::udpDestination &r);
|
||||
const std::string &ToString(const std::string &s);
|
||||
|
||||
/** Convert std::chrono::duration with specified output unit */
|
||||
|
@ -59,11 +59,70 @@ class MacAddr {
|
||||
constexpr uint64_t uint64() const noexcept { return addr_; }
|
||||
};
|
||||
|
||||
class UdpDestination {
|
||||
private:
|
||||
uint32_t entry_{};
|
||||
uint32_t port_{};
|
||||
uint32_t port2_{};
|
||||
uint32_t ip_{};
|
||||
uint32_t ip2_{};
|
||||
uint64_t mac_{};
|
||||
uint64_t mac2_{};
|
||||
|
||||
public:
|
||||
constexpr UdpDestination() noexcept = default;
|
||||
explicit constexpr UdpDestination(uint32_t entry, uint32_t port = 0,
|
||||
IpAddr ip = {}, MacAddr mac = {},
|
||||
uint32_t port2 = 0, IpAddr ip2 = {},
|
||||
MacAddr mac2 = {})
|
||||
: entry_(entry), port_(port), port2_(port2), ip_(ip.uint32()),
|
||||
ip2_(ip2.uint32()), mac_(mac.uint64()), mac2_(mac2.uint64()) {}
|
||||
|
||||
uint32_t getEntry() const noexcept { return entry_; }
|
||||
|
||||
void setEntry(const uint32_t value) { entry_ = value; }
|
||||
|
||||
uint32_t getPort() const noexcept { return port_; }
|
||||
|
||||
void setPort(const uint32_t value) { port_ = value; }
|
||||
|
||||
uint32_t getPort2() const noexcept { return port2_; }
|
||||
|
||||
void setPort2(const uint32_t value) { port2_ = value; }
|
||||
|
||||
IpAddr getIp() const noexcept { return IpAddr(ip_); }
|
||||
|
||||
void setIp(const IpAddr value) { ip_ = value.uint32(); }
|
||||
|
||||
IpAddr getIp2() const noexcept { return IpAddr(ip2_); }
|
||||
|
||||
void setIp2(const IpAddr value) { ip2_ = value.uint32(); }
|
||||
|
||||
MacAddr getMac() const noexcept { return MacAddr(mac_); }
|
||||
|
||||
void setMac(const MacAddr value) { mac_ = value.uint64(); }
|
||||
|
||||
MacAddr getMac2() const noexcept { return MacAddr(mac2_); }
|
||||
|
||||
void setMac2(const MacAddr value) { mac2_ = value.uint64(); }
|
||||
|
||||
std::string str() const;
|
||||
|
||||
constexpr bool operator==(const UdpDestination &other) const {
|
||||
return ((entry_ == other.entry_) && (port_ == other.port_) &&
|
||||
(port2_ == other.port2_) && (ip_ == other.ip_) &&
|
||||
(ip2_ == other.ip2_) && (mac_ == other.mac_) &&
|
||||
(mac2_ == other.mac2_));
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
|
||||
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
|
||||
std::ostream &operator<<(std::ostream &out, const UdpDestination &dest);
|
||||
|
||||
IpAddr HostnameToIp(const char *hostname);
|
||||
std::string IpToInterfaceName(const std::string &ip);
|
||||
MacAddr InterfaceNameToMac(const std::string &inf);
|
||||
IpAddr InterfaceNameToIp(const std::string &ifn);
|
||||
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
|
||||
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
|
||||
|
||||
} // namespace sls
|
||||
|
@ -494,28 +494,6 @@ typedef struct {
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
struct udpDestination {
|
||||
uint32_t entry_{};
|
||||
uint32_t port_{};
|
||||
uint32_t port2_{};
|
||||
uint32_t ip_{};
|
||||
uint32_t ip2_{};
|
||||
uint64_t mac_{};
|
||||
uint64_t mac2_{};
|
||||
udpDestination() {}
|
||||
udpDestination(uint32_t entry, uint32_t port = 0, uint32_t ip = 0, uint64_t mac = 0,
|
||||
uint32_t port2 = 0, uint32_t ip2 = 0, uint64_t mac2 = 0)
|
||||
: entry_(entry), port_(port), port2_(port2), ip_(ip), ip2_(ip2),
|
||||
mac_(mac), mac2_(mac2) {}
|
||||
|
||||
bool operator==(const udpDestination &other) const {
|
||||
return ((entry_ == other.entry_) && (port_ == other.port_) &&
|
||||
(port2_ == other.port2_) && (ip_ == other.ip_) &&
|
||||
(ip2_ == other.ip2_) && (mac_ == other.mac_) &&
|
||||
(mac2_ == other.mac2_));
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* structure to udpate receiver
|
||||
*/
|
||||
|
@ -148,31 +148,6 @@ std::ostream &operator<<(std::ostream &os,
|
||||
return os << ToString(r);
|
||||
}
|
||||
|
||||
std::string ToString(const slsDetectorDefs::udpDestination &r) {
|
||||
std::ostringstream oss;
|
||||
oss << '[' << std::endl
|
||||
<< "entry " << r.entry_ << std::endl
|
||||
<< "ip " << IpAddr(r.ip_) << std::endl
|
||||
<< "mac " << MacAddr(r.mac_) << std::endl
|
||||
<< "port " << r.port_ << std::endl;
|
||||
if (r.port2_ != 0) {
|
||||
oss << "port2 " << r.port2_ << std::endl;
|
||||
}
|
||||
if (r.ip2_ != 0) {
|
||||
oss << "ip2 " << IpAddr(r.ip2_) << std::endl;
|
||||
}
|
||||
if (r.mac2_ != 0) {
|
||||
oss << "mac2 " << MacAddr(r.mac2_) << std::endl;
|
||||
}
|
||||
oss << ']';
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os,
|
||||
const slsDetectorDefs::udpDestination &r) {
|
||||
return os << ToString(r);
|
||||
}
|
||||
|
||||
std::string ToString(const defs::runStatus s) {
|
||||
switch (s) {
|
||||
case defs::ERROR:
|
||||
|
@ -69,6 +69,26 @@ std::string MacAddr::str() const { return to_hex(':'); }
|
||||
|
||||
std::string MacAddr::hex() const { return to_hex(); }
|
||||
|
||||
std::string UdpDestination::str() const {
|
||||
std::ostringstream oss;
|
||||
oss << '[' << std::endl
|
||||
<< "entry " << entry_ << std::endl
|
||||
<< "ip " << ip_ << std::endl
|
||||
<< "mac " << mac_ << std::endl
|
||||
<< "port " << port_ << std::endl;
|
||||
if (port2_ != 0) {
|
||||
oss << "port2 " << port2_ << std::endl;
|
||||
}
|
||||
if (ip2_ != 0) {
|
||||
oss << "ip2 " << ip2_ << std::endl;
|
||||
}
|
||||
if (mac2_ != 0) {
|
||||
oss << "mac2 " << mac2_ << std::endl;
|
||||
}
|
||||
oss << ']';
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const IpAddr &addr) {
|
||||
return out << addr.str();
|
||||
}
|
||||
@ -77,6 +97,10 @@ std::ostream &operator<<(std::ostream &out, const MacAddr &addr) {
|
||||
return out << addr.str();
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const UdpDestination &dest) {
|
||||
return out << dest.str();
|
||||
}
|
||||
|
||||
IpAddr HostnameToIp(const char *hostname) {
|
||||
addrinfo hints;
|
||||
addrinfo *result = nullptr;
|
||||
|
Reference in New Issue
Block a user