Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Search.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_UPnP_SSDP_Client_Search_h_
5#define _Stroika_Frameworks_UPnP_SSDP_Client_Search_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <functional>
10
11#include "Stroika/Foundation/IO/Network/InternetProtocol/IP.h"
12
13#include "Stroika/Frameworks/UPnP/Device.h"
15
16/**
17 * \file
18 *
19 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
20 *
21 * TODO:
22 * @todo must re-read ssdp spec for exact format of messages!
23 *
24 * @todo Must have some API for how often to send searches, and how long
25 * to listen for responses (maybe forever on responses?)
26 *
27 * @todo Consider adding OnError callback?
28 *
29 * @todo Fix Result object to return other interesting fields
30 *
31 * @todo Consider some synchonous API, so it sends a certian number of times, and
32 * then returns all the answers.
33 *
34 */
35
36namespace Stroika::Frameworks::UPnP::SSDP::Client {
37
38 /**
39 */
40 class Search {
41 public:
42 /**
43 * see @see Start () for possible values for initialSearch and autoRetryInterval
44 */
45 Search (IO::Network::InternetProtocol::IP::IPVersionSupport ipVersion = IO::Network::InternetProtocol::IP::IPVersionSupport::eDEFAULT);
46 Search (const function<void (const SSDP::Advertisement& d)>& callOnFinds,
47 IO::Network::InternetProtocol::IP::IPVersionSupport ipVersion = IO::Network::InternetProtocol::IP::IPVersionSupport::eDEFAULT);
48 Search (const function<void (const SSDP::Advertisement& d)>& callOnFinds, const String& initialSearch,
49 IO::Network::InternetProtocol::IP::IPVersionSupport ipVersion = IO::Network::InternetProtocol::IP::IPVersionSupport::eDEFAULT);
50 Search (const function<void (const SSDP::Advertisement& d)>& callOnFinds, const String& initialSearch,
51 const optional<Time::Duration>& autoRetryInterval,
52 IO::Network::InternetProtocol::IP::IPVersionSupport ipVersion = IO::Network::InternetProtocol::IP::IPVersionSupport::eDEFAULT);
53 Search (Search&&) = default;
54 Search (const Search&) = delete;
55
56 public:
57 /**
58 * Its OK to destroy a searcher while running. It will silently stop the running searcher thread.
59 */
60 ~Search ();
61
62 public:
63 nonvirtual const Search& operator= (const Search&) = delete;
64
65 public:
66 /**
67 * Using std::function, no way to compare for operator==, so no way to remove.
68 * @todo RETHINK!
69 * Note - the callback will be called on an arbitrary thread, so the callback must be threadsafe.
70 * This can be done after the listening has started.
71 */
72 void AddOnFoundCallback (const function<void (const SSDP::Advertisement& d)>& callOnFinds);
73
74 public:
75 /**
76 * ssdp:all - possible argument for search string
77 */
78 static const String kSSDPAny;
79
80 public:
81 /**
82 * upnp:rootdevice - possible argument for search string
83 */
84 static const String kRootDevice;
85
86 public:
87 /**
88 * Starts searcher (probably starts a thread).
89 * args - ST, strings, uuid etc.
90 *
91 * If already running, this automatically stops an existing search, and restarts it with
92 * the given serviceType parameters.
93 *
94 * ssdp:all: Search for all devices and services.
95 * \par Example Usage
96 * \code
97 * Start ("ssdp:all"); // Search for all devices and services
98 * Start (kSSDPAny); // ...
99 * \endcode
100 *
101 * \par Example Usage
102 * \code
103 * Start ("upnp:rootdevice"); // Search for all root devices
104 * Start (kRootDevice); // ...
105 * \endcode
106 *
107 * \par Example Usage
108 * \code
109 * Start ("urn:schemas-wifialliance-org:service:WFAWLANConfig:1"); // Search for all devices of this type
110 * \endcode
111 *
112 *
113 * \par Example Usage
114 * \code
115 * Start ("uuid:9cd09dd4-fd8d-5737-abc3-2faa8c11cbdb"); // Search specific device
116 * \endcode
117 *
118 */
119 nonvirtual void Start (const String& serviceType, const optional<Time::Duration>& autoRetryInterval = nullopt);
120
121 public:
122 /**
123 * Stop an already running search. Not an error to call if not already started (just does nothing).
124 * This will block until the searcher has stopped (typically milliseconds).
125 */
126 nonvirtual void Stop ();
127
128 private:
129 class Rep_;
130 shared_ptr<Rep_> fRep_;
131 };
132
133}
134
135/*
136 ********************************************************************************
137 ***************************** Implementation Details ***************************
138 ********************************************************************************
139 */
140#include "Search.inl"
141
142#endif /*_Stroika_Frameworks_UPnP_SSDP_Client_Search_h_*/
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...