From bd4a20b643183f46c1d4cbcc1ba9a6a0ed36bdf0 Mon Sep 17 00:00:00 2001 From: JDierkse Date: Fri, 31 Jan 2020 22:17:11 +0100 Subject: [PATCH] Initial commit --- .gitignore | 7 +++++++ Libraries/asio | 1 + Libraries/asio.h | 6 ++++++ Makefile | 1 + Makefile.conf | 6 ++++++ Makefile.target | 13 +++++++++++++ Makefiles | 1 + Network/BroadcastClient.cpp | 30 ++++++++++++++++++++++++++++++ Network/BroadcastServer.cpp | 30 ++++++++++++++++++++++++++++++ Network/IcmpClient.cpp | 20 ++++++++++++++++++++ Network/Makefile | 1 + Network/MulticastClient.cpp | 30 ++++++++++++++++++++++++++++++ Network/UdpClient.cpp | 30 ++++++++++++++++++++++++++++++ include/BroadcastClient.h | 32 ++++++++++++++++++++++++++++++++ include/BroadcastServer.h | 32 ++++++++++++++++++++++++++++++++ include/IcmpClient.h | 28 ++++++++++++++++++++++++++++ include/MulticastClient.h | 32 ++++++++++++++++++++++++++++++++ include/UdpClient.h | 32 ++++++++++++++++++++++++++++++++ 18 files changed, 332 insertions(+) create mode 100644 .gitignore create mode 120000 Libraries/asio create mode 100644 Libraries/asio.h create mode 120000 Makefile create mode 100644 Makefile.conf create mode 100644 Makefile.target create mode 120000 Makefiles create mode 100644 Network/BroadcastClient.cpp create mode 100644 Network/BroadcastServer.cpp create mode 100644 Network/IcmpClient.cpp create mode 120000 Network/Makefile create mode 100644 Network/MulticastClient.cpp create mode 100644 Network/UdpClient.cpp create mode 100644 include/BroadcastClient.h create mode 100644 include/BroadcastServer.h create mode 100644 include/IcmpClient.h create mode 100644 include/MulticastClient.h create mode 100644 include/UdpClient.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..233b8d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o.* +*.d.* +*.a.* +.*.swp +.AppleDouble +lib +fixPermissions.sh diff --git a/Libraries/asio b/Libraries/asio new file mode 120000 index 0000000..5f2d84d --- /dev/null +++ b/Libraries/asio @@ -0,0 +1 @@ +../../asio/asio \ No newline at end of file diff --git a/Libraries/asio.h b/Libraries/asio.h new file mode 100644 index 0000000..895e43d --- /dev/null +++ b/Libraries/asio.h @@ -0,0 +1,6 @@ +#ifndef LIBRARIES_ASIO_H +#define LIBRARIES_ASIO_H + +#include "asio.hpp" + +#endif // LIBRARIES_ASIO_H diff --git a/Makefile b/Makefile new file mode 120000 index 0000000..6aa5187 --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +Makefiles/Makefile \ No newline at end of file diff --git a/Makefile.conf b/Makefile.conf new file mode 100644 index 0000000..810e4e0 --- /dev/null +++ b/Makefile.conf @@ -0,0 +1,6 @@ +# +# Makefile.conf +# + +CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include -I$(ROOTPATH)/Libraries -I$(ROOTPATH)/Libraries/asio/include -I$(ROOTPATH)/Libraries/Logging/include +DEBUGDIR := .debug diff --git a/Makefile.target b/Makefile.target new file mode 100644 index 0000000..82c334b --- /dev/null +++ b/Makefile.target @@ -0,0 +1,13 @@ +# +# Makefile.target +# + +Network.a.$(ARCH) : $(OBJECTS) + $(call build_target_library_arch,$@,$^) + +Network.a: + $(call build_target,$@) + +.DEFAULT_GOAL := Network.a + +TARGETS += Network.a diff --git a/Makefiles b/Makefiles new file mode 120000 index 0000000..2c30269 --- /dev/null +++ b/Makefiles @@ -0,0 +1 @@ +../../Makefiles \ No newline at end of file diff --git a/Network/BroadcastClient.cpp b/Network/BroadcastClient.cpp new file mode 100644 index 0000000..849d2a6 --- /dev/null +++ b/Network/BroadcastClient.cpp @@ -0,0 +1,30 @@ +#include "BroadcastClientImpl.h" +#include "BroadcastClient.h" + + +namespace Network { + +BroadcastClient::BroadcastClient(const std::string& listenAddress, int broadcastPort, std::function callback) : + m_pBroadcastClientImpl(new BroadcastClientImpl(listenAddress, broadcastPort, callback)) +{ +} + +BroadcastClient::~BroadcastClient() = default; + +void BroadcastClient::Receive() +{ + m_pBroadcastClientImpl->Receive(); +} + +std::string BroadcastClient::Send(const std::string& data, int sourcePort) +{ + return m_pBroadcastClientImpl->Send(data, sourcePort); +} + +void BroadcastClient::Broadcast(const std::string& data, int sourcePort) +{ + m_pBroadcastClientImpl->Broadcast(data, sourcePort); +} + +} // namespace Network + diff --git a/Network/BroadcastServer.cpp b/Network/BroadcastServer.cpp new file mode 100644 index 0000000..0ff4e1f --- /dev/null +++ b/Network/BroadcastServer.cpp @@ -0,0 +1,30 @@ +#include "BroadcastServerImpl.h" +#include "BroadcastServer.h" + + +namespace Network { + +BroadcastServer::BroadcastServer(const std::string& listenAddress, int broadcastPort, std::function callback) : + m_pBroadcastServerImpl(new BroadcastServerImpl(listenAddress, broadcastPort, callback)) +{ +} + +BroadcastServer::~BroadcastServer() = default; + +void BroadcastServer::Receive() +{ + m_pBroadcastServerImpl->Receive(); +} + +std::string BroadcastServer::Send(const std::string& data, int sourcePort) +{ + return m_pBroadcastServerImpl->Send(data, sourcePort); +} + +void BroadcastServer::Broadcast(const std::string& data, int sourcePort) +{ + m_pBroadcastServerImpl->Broadcast(data, sourcePort); +} + +} // namespace Network + diff --git a/Network/IcmpClient.cpp b/Network/IcmpClient.cpp new file mode 100644 index 0000000..2ff12e2 --- /dev/null +++ b/Network/IcmpClient.cpp @@ -0,0 +1,20 @@ +#include "IcmpClientImpl.h" +#include "IcmpClient.h" + + +namespace Network { + +IcmpClient::IcmpClient() : + m_pIcmpClientImpl(new IcmpClientImpl()) +{ +} + +IcmpClient::~IcmpClient() = default; + +bool IcmpClient::Ping(const std::string& targetAddress) +{ + return m_pIcmpClientImpl->Ping(targetAddress); +} + +} // namespace Network + diff --git a/Network/Makefile b/Network/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/Network/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/Network/MulticastClient.cpp b/Network/MulticastClient.cpp new file mode 100644 index 0000000..6024bdd --- /dev/null +++ b/Network/MulticastClient.cpp @@ -0,0 +1,30 @@ +#include "MulticastClientImpl.h" +#include "MulticastClient.h" + + +namespace Network { + +MulticastClient::MulticastClient(const std::string& listenAddress, const std::string& multicastAddress, int multicastPort, std::function callback) : + m_pMulticastClientImpl(new MulticastClientImpl(listenAddress, multicastAddress, multicastPort, callback)) +{ +} + +MulticastClient::~MulticastClient() = default; + +void MulticastClient::Receive() +{ + m_pMulticastClientImpl->Receive(); +} + +std::string MulticastClient::Send(const std::string& data, int sourcePort) +{ + return m_pMulticastClientImpl->Send(data, sourcePort); +} + +void MulticastClient::Broadcast(const std::string& data, int sourcePort) +{ + m_pMulticastClientImpl->Broadcast(data, sourcePort); +} + +} // namespace Network + diff --git a/Network/UdpClient.cpp b/Network/UdpClient.cpp new file mode 100644 index 0000000..390de1d --- /dev/null +++ b/Network/UdpClient.cpp @@ -0,0 +1,30 @@ +#include "UdpClientImpl.h" +#include "UdpClient.h" + + +namespace Network { + +UdpClient::UdpClient(const std::string& listenAddress, const std::string& targetAddress, int targetPort, std::function callback) : + m_pUdpClientImpl(new UdpClientImpl(listenAddress, targetAddress, targetPort, callback)) +{ +} + +UdpClient::~UdpClient() = default; + +void UdpClient::Receive() +{ + m_pUdpClientImpl->Receive(); +} + +std::string UdpClient::Send(const std::string& data, int sourcePort) +{ + return m_pUdpClientImpl->Send(data, sourcePort); +} + +void UdpClient::Broadcast(const std::string& data, int sourcePort) +{ + m_pUdpClientImpl->Broadcast(data, sourcePort); +} + +} // namespace Network + diff --git a/include/BroadcastClient.h b/include/BroadcastClient.h new file mode 100644 index 0000000..7454219 --- /dev/null +++ b/include/BroadcastClient.h @@ -0,0 +1,32 @@ +#ifndef BROADCASTCLIENT_H +#define BROADCASTCLIENT_H + +#include +#include +#include + + +namespace Network { + +class BroadcastClientImpl; + +class BroadcastClient +{ +public: + BroadcastClient(const std::string& listenAddress, int broadcastPort, std::function callback); + ~BroadcastClient(); + +public: + void Receive(); + + std::string Send(const std::string& data, int sourcePort = 0); + void Broadcast(const std::string& data, int sourcePort = 0); + +private: + std::unique_ptr m_pBroadcastClientImpl; +}; + +} // namespace Network + +#endif // BROADCASTCLIENT_H + diff --git a/include/BroadcastServer.h b/include/BroadcastServer.h new file mode 100644 index 0000000..66f60c5 --- /dev/null +++ b/include/BroadcastServer.h @@ -0,0 +1,32 @@ +#ifndef BROADCASTSERVER_H +#define BROADCASTSERVER_H + +#include +#include +#include + + +namespace Network { + +class BroadcastServerImpl; + +class BroadcastServer +{ +public: + BroadcastServer(const std::string& listenAddress, int broadcastPort, std::function callback); + ~BroadcastServer(); + +public: + void Receive(); + + std::string Send(const std::string& data, int sourcePort = 0); + void Broadcast(const std::string& data, int sourcePort = 0); + +private: + std::unique_ptr m_pBroadcastServerImpl; +}; + +} // namespace Network + +#endif // BROADCASTSERVER_H + diff --git a/include/IcmpClient.h b/include/IcmpClient.h new file mode 100644 index 0000000..b86bab9 --- /dev/null +++ b/include/IcmpClient.h @@ -0,0 +1,28 @@ +#ifndef ICMPCLIENT_H +#define ICMPCLIENT_H + +#include +#include + + +namespace Network { + +class IcmpClientImpl; + +class IcmpClient +{ +public: + IcmpClient(); + ~IcmpClient(); + +public: + bool Ping(const std::string& targetAddress); + +private: + std::unique_ptr m_pIcmpClientImpl; +}; + +} // namespace Network + +#endif // ICMPCLIENT_H + diff --git a/include/MulticastClient.h b/include/MulticastClient.h new file mode 100644 index 0000000..25afaff --- /dev/null +++ b/include/MulticastClient.h @@ -0,0 +1,32 @@ +#ifndef MULTICASTCLIENT_H +#define MULTICASTCLIENT_H + +#include +#include +#include + + +namespace Network { + +class MulticastClientImpl; + +class MulticastClient +{ +public: + MulticastClient(const std::string& listenAddress, const std::string& multicastAddress, int multicastPort, std::function callback); + ~MulticastClient(); + +public: + void Receive(); + + std::string Send(const std::string& data, int sourcePort = 0); + void Broadcast(const std::string& data, int sourcePort = 0); + +private: + std::unique_ptr m_pMulticastClientImpl; +}; + +} // namespace Network + +#endif // MULTICASTCLIENT_H + diff --git a/include/UdpClient.h b/include/UdpClient.h new file mode 100644 index 0000000..2c2fe18 --- /dev/null +++ b/include/UdpClient.h @@ -0,0 +1,32 @@ +#ifndef UDPCLIENT_H +#define UDPCLIENT_H + +#include +#include +#include + + +namespace Network { + +class m_pUdpClientImpl; + +class UdpClient +{ +public: + UdpClient(const std::string& listenAddress, const std::string& targetAddress, int targetPort, std::function callback); + ~UdpClient(); + +public: + void Receive(); + + std::string Send(const std::string& data, int sourcePort = 0); + void Broadcast(const std::string& data, int sourcePort = 0); + +private: + std::unique_ptr m_pUdpClientImpl; +}; + +} // namespace Network + +#endif // UDPCLIENT_H +