mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
merge resolved
This commit is contained in:
@ -3,9 +3,13 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <netdb.h>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
namespace sls {
|
||||
|
||||
/* Base class for TCP socket, this is used to send data between detector, client
|
||||
and receiver. Specific protocols inherit from this class.*/
|
||||
|
||||
class DataSocket {
|
||||
public:
|
||||
DataSocket(int socketId);
|
||||
@ -13,14 +17,36 @@ class DataSocket {
|
||||
virtual ~DataSocket();
|
||||
DataSocket &operator=(DataSocket &&move) noexcept;
|
||||
void swap(DataSocket &other) noexcept;
|
||||
|
||||
//No copy since the class manage the underlying socket
|
||||
DataSocket(const DataSocket &) = delete;
|
||||
DataSocket &operator=(DataSocket const &) = delete;
|
||||
int getSocketId() const {
|
||||
return socketId_;
|
||||
int getSocketId() const { return socketId_; }
|
||||
|
||||
|
||||
int Send(const void *buffer, size_t size);
|
||||
template <typename T> int Send(T &&data) {
|
||||
return Send(&data, sizeof(data));
|
||||
}
|
||||
int sendData(const void *buffer, size_t size);
|
||||
int receiveData(void *buffer, size_t size);
|
||||
// Variadic template to send all arguments
|
||||
template <class... Args> int SendAll(Args &&... args) {
|
||||
auto l = std::initializer_list<int>{Send(args)...};
|
||||
auto sum = std::accumulate(begin(l), end(l), 0);
|
||||
return sum;
|
||||
}
|
||||
int Receive(void *buffer, size_t size);
|
||||
template <typename T> int Receive(T &arg) {
|
||||
return Receive(&arg, sizeof(arg));
|
||||
}
|
||||
|
||||
template <typename T> T Receive() {
|
||||
T arg;
|
||||
Receive(&arg, sizeof(arg));
|
||||
return arg;
|
||||
}
|
||||
|
||||
int read(void *buffer, size_t size);
|
||||
int write(void *buffer, size_t size);
|
||||
int setTimeOut(int t_seconds);
|
||||
int setReceiveTimeout(int us);
|
||||
void close();
|
||||
@ -30,9 +56,4 @@ class DataSocket {
|
||||
int socketId_ = -1;
|
||||
};
|
||||
|
||||
int ConvertHostnameToInternetAddress(const char *const hostname, struct ::addrinfo **res);
|
||||
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip, const int ipsize);
|
||||
|
||||
struct ::sockaddr_in ConvertHostnameToInternetAddress(const std::string &hostname);
|
||||
|
||||
}; // namespace sls
|
||||
|
@ -13,16 +13,19 @@ class ServerInterface2 : public DataSocket {
|
||||
using defs = slsDetectorDefs;
|
||||
|
||||
public:
|
||||
ServerInterface2(int socketId) : DataSocket(socketId){}
|
||||
ServerInterface2(int socketId) : DataSocket(socketId) {}
|
||||
|
||||
int sendResult(bool update, int ret, void *retval, int retvalSize,
|
||||
char *mess = nullptr);
|
||||
int receiveArg(int &ret, char *mess, void *arg, int sizeofArg);
|
||||
int sendResult(int ret, void *retval, int retvalSize, char *mess = nullptr);
|
||||
|
||||
template <typename T> int sendResult(int ret, T &retval) {
|
||||
return sendResult(ret, &retval, sizeof(retval, nullptr));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template <typename T> int sendResult(T &&retval) {
|
||||
Send(defs::OK);
|
||||
Send(retval);
|
||||
return defs::OK;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace sls
|
@ -15,13 +15,13 @@ class ServerSocket : public DataSocket {
|
||||
public:
|
||||
ServerSocket(int port);
|
||||
ServerInterface2 accept();
|
||||
IpAddr getLastClient() noexcept { return lastClient; }
|
||||
IpAddr getThisClient() noexcept { return thisClient; }
|
||||
IpAddr getLockedBy() noexcept { return lockedBy; }
|
||||
IpAddr getLastClient() const noexcept { return lastClient; }
|
||||
IpAddr getThisClient() const noexcept { return thisClient; }
|
||||
IpAddr getLockedBy() const noexcept { return lockedBy; }
|
||||
bool differentClients() const noexcept {return lastClient != thisClient;}
|
||||
void setLockedBy(IpAddr addr) { lockedBy = addr; }
|
||||
void setLastClient(IpAddr addr) { lastClient = addr; }
|
||||
int getPort() const;
|
||||
void SendResult(int &ret, void *retval, int retvalSize, char *mess);
|
||||
int getPort() const noexcept { return serverPort; }
|
||||
|
||||
private:
|
||||
IpAddr thisClient;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
namespace sls {
|
||||
|
||||
@ -15,6 +16,7 @@ class IpAddr {
|
||||
IpAddr(const char *address);
|
||||
std::string str() const;
|
||||
std::string hex() const;
|
||||
std::array<char, 16u> arr() const;
|
||||
constexpr bool operator==(const IpAddr &other) const noexcept {
|
||||
return addr_ == other.addr_;
|
||||
}
|
||||
@ -56,7 +58,7 @@ class MacAddr {
|
||||
constexpr uint64_t uint64() const noexcept { return addr_; }
|
||||
};
|
||||
|
||||
uint32_t HostnameToIp(const char *hostname);
|
||||
IpAddr HostnameToIp(const char *hostname);
|
||||
std::string IpToInterfaceName(const std::string& ip);
|
||||
MacAddr InterfaceNameToMac(std::string inf);
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
/** API versions */
|
||||
#define GITBRANCH "refgui"
|
||||
#define APIMOENCH 0x181108
|
||||
#define APILIB 0x190405
|
||||
#define APIRECEIVER 0x190405
|
||||
#define APILIB 0x190604
|
||||
#define APIRECEIVER 0x190604
|
||||
#define APIGUI 0x190405
|
||||
#define APIGOTTHARD 0x190604
|
||||
#define APIJUNGFRAU 0x190604
|
||||
#define APIEIGER 0x190604
|
||||
#define APICTB 0x190604
|
||||
#define APIEIGER 0x190604
|
||||
#define APIJUNGFRAU 0x190604
|
||||
#define APIGOTTHARD 0x190604
|
Reference in New Issue
Block a user