diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/ssdp/SSDPAPI.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/ssdp/SSDPAPI.h')
-rw-r--r-- | Src/replicant/ssdp/SSDPAPI.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Src/replicant/ssdp/SSDPAPI.h b/Src/replicant/ssdp/SSDPAPI.h new file mode 100644 index 00000000..d4d37f13 --- /dev/null +++ b/Src/replicant/ssdp/SSDPAPI.h @@ -0,0 +1,61 @@ +#pragma once +#include "nx/nxstring.h" +#include "nx/nxuri.h" +#include <vector> +#include "nu/AutoLock.h" +#include "nx/nxthread.h" +#include "foundation/error.h" +#include "jnetlib/jnetlib.h" +#include "cb_ssdp.h" +#include "nu/ThreadLoop.h" +#include "api_ssdp.h" +#include "nswasabi/ServiceName.h" + +class SSDPAPI : public api_ssdp +{ +public: + SSDPAPI(); + ~SSDPAPI(); + WASABI_SERVICE_NAME("SSDP API"); + int Initialize(); + + int WASABICALL SSDP_RegisterService(nx_uri_t location, nx_string_t st, nx_string_t usn); + int WASABICALL SSDP_RegisterCallback(cb_ssdp *callback); + int WASABICALL SSDP_UnregisterCallback(cb_ssdp *callback); + int WASABICALL SSDP_Search(nx_string_t st); +private: + struct Service + { + nx_uri_t location; + nx_string_t type; + nx_string_t usn; + time_t last_seen; + time_t expiry; + }; + + // TODO: map it off of USN + typedef std::vector<Service> ServiceList; + typedef std::vector<cb_ssdp*> CallbackList; + nx_thread_return_t Internal_Run(); + ns_error_t Internal_Notify(const char *st, sockaddr *addr, socklen_t length); + void Internal_RegisterCallback(cb_ssdp *callback); + void Internal_UnregisterCallback(cb_ssdp *callback); + void Internal_Search(nx_string_t st); + static nx_thread_return_t NXTHREADCALL SSDPThread(nx_thread_parameter_t parameter); + int FindUSN(ServiceList &service_list, const char *usn, Service *&service); + + ThreadLoop thread_loop; + CallbackList callbacks; + ServiceList services; + ServiceList found_services; + nu::LockGuard services_lock; + nx_thread_t ssdp_thread; + jnl_udp_t listener; + const char *user_agent; + + + + static void APC_RegisterCallback(void *_this, void *_callback, double) { ((SSDPAPI *)_this)->Internal_RegisterCallback((cb_ssdp *)_callback); } + static void APC_UnregisterCallback(void *_this, void *_callback, double) { ((SSDPAPI *)_this)->Internal_UnregisterCallback((cb_ssdp *)_callback); } + static void APC_Search(void *_this, void *st, double) { ((SSDPAPI *)_this)->Internal_Search((nx_string_t)st); } +}; |