1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 #include <lib/fit/result.h>
17 
18 #include <functional>
19 #include <unordered_map>
20 
21 #include "pw_bluetooth_sapphire/internal/host/common/error.h"
22 #include "pw_bluetooth_sapphire/internal/host/l2cap/scoped_channel.h"
23 #include "pw_bluetooth_sapphire/internal/host/sdp/pdu.h"
24 #include "pw_bluetooth_sapphire/internal/host/sdp/sdp.h"
25 
26 namespace bt::sdp {
27 
28 // The SDP client connects to the SDP server on a remote device and can perform
29 // search requests and returns results.  It is expected to be short-lived.
30 // More than one client can be connected to the same host.
31 class Client {
32  public:
33   // Create a new SDP client on the given |channel|.  |channel| must be
34   // un-activated. |channel| must not be null.
35   static std::unique_ptr<Client> Create(l2cap::Channel::WeakPtr channel,
36                                         pw::async::Dispatcher& dispatcher);
37 
38   virtual ~Client() = default;
39 
40   // Perform a ServiceSearchAttribute transaction, searching for the UUIDs in
41   // |search_pattern|, and requesting the attributes in |req_attributes|.
42   // If |req_attributes| is empty, all attributes will be requested.
43   // Results are returned asynchronously:
44   //   - |result_cb| is called for each service which matches the pattern with
45   //     the attributes requested. As long as true is returned, it can still
46   //     be called.
47   //   - when no more services remain, the result_cb status will be
48   //     HostError::kNotFound. The return value is ignored.
49   using SearchResultFunction = fit::function<bool(
50       fit::result<
51           Error<>,
52           std::reference_wrapper<const std::map<AttributeId, DataElement>>>)>;
53   virtual void ServiceSearchAttributes(
54       std::unordered_set<UUID> search_pattern,
55       const std::unordered_set<AttributeId>& req_attributes,
56       SearchResultFunction result_cb) = 0;
57 };
58 
59 }  // namespace bt::sdp
60