gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

serverList.h (1005B)


      1 #pragma once
      2 
      3 #include <mutex>
      4 #include <set>
      5 #include <string>
      6 #include <chrono>
      7 
      8 #include "udpClient.h"
      9 
     10 #include "bridgeLib/commands.h"
     11 
     12 namespace bridgeClient
     13 {
     14 	class ServerList
     15 	{
     16 	public:
     17 		using Clock = std::chrono::system_clock;
     18 		using Timestamp = Clock::time_point;
     19 
     20 		struct Entry
     21 		{
     22 			std::string host;
     23 			bridgeLib::ServerInfo serverInfo;
     24 			bridgeLib::Error err;
     25 			Timestamp lastSeen;
     26 
     27 			bool operator < (const Entry& _e) const
     28 			{
     29 				return host < _e.host;
     30 			}
     31 
     32 			bool operator == (const Entry& _e) const
     33 			{
     34 				return serverInfo.portTcp == _e.serverInfo.portTcp && host == _e.host;
     35 			}
     36 		};
     37 
     38 		ServerList(const bridgeLib::PluginDesc& _desc);
     39 
     40 		std::set<Entry> getEntries() const;
     41 
     42 		static void removeExpiredEntries(std::set<Entry>& _entries);
     43 
     44 	private:
     45 		void onServerFound(const std::string& _host, const bridgeLib::ServerInfo& _serverInfo, const bridgeLib::Error& _error);
     46 
     47 		UdpClient m_udpClient;
     48 
     49 		mutable std::mutex m_entriesMutex;
     50 		std::set<Entry> m_entries;
     51 	};
     52 }