File: fake_floss_socket_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 3,695 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_FLOSS_FAKE_FLOSS_SOCKET_MANAGER_H_
#define DEVICE_BLUETOOTH_FLOSS_FAKE_FLOSS_SOCKET_MANAGER_H_

#include "base/logging.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/floss/floss_socket_manager.h"

namespace floss {

class DEVICE_BLUETOOTH_EXPORT FakeFlossSocketManager
    : public FlossSocketManager {
 public:
  FakeFlossSocketManager();
  ~FakeFlossSocketManager() override;

  // Recognized uuid for testing rfcomm socket.
  static const char kRfcommUuid[];

  // Recognized psm for testing l2cap socket.
  static const int kL2capPsm;

  // Uuid which will fail to be registered.
  static const char kUnregisterableUuid[];

  // Fake overrides.
  void Init(dbus::Bus* bus,
            const std::string& service_name,
            const int adapter_index,
            base::Version version,
            base::OnceClosure on_ready) override;
  void ListenUsingL2cap(const Security security_level,
                        ResponseCallback<BtifStatus> callback,
                        ConnectionStateChanged ready_cb,
                        ConnectionAccepted new_connection_cb) override;
  void ListenUsingL2capLe(const Security security_level,
                          ResponseCallback<BtifStatus> callback,
                          ConnectionStateChanged ready_cb,
                          ConnectionAccepted new_connection_cb) override;
  void ListenUsingRfcomm(const std::string& name,
                         const device::BluetoothUUID& uuid,
                         const Security security_level,
                         ResponseCallback<BtifStatus> callback,
                         ConnectionStateChanged ready_cb,
                         ConnectionAccepted new_connection_cb) override;
  void ConnectUsingL2cap(const FlossDeviceId& remote_device,
                         const int psm,
                         const Security security_level,
                         ConnectionCompleted callback) override;
  void ConnectUsingL2capLe(const FlossDeviceId& remote_device,
                           const int psm,
                           const Security security_level,
                           ConnectionCompleted callback) override;
  void ConnectUsingRfcomm(const FlossDeviceId& remote_device,
                          const device::BluetoothUUID& uuid,
                          const Security security_level,
                          ConnectionCompleted callback) override;
  void Accept(const SocketId id,
              std::optional<uint32_t> timeout_ms,
              ResponseCallback<BtifStatus> callback) override;
  void Close(const SocketId id, ResponseCallback<BtifStatus> callback) override;

  // Send ready state to a listener socket.
  void SendSocketReady(const SocketId id,
                       const device::BluetoothUUID& uuid,
                       const BtifStatus status);

  // Send closed state to a listener socket.
  void SendSocketClosed(const SocketId id, const BtifStatus status);

  // Send an incoming connection to a listener socket.
  void SendIncomingConnection(const SocketId listener_id,
                              const FlossDeviceId& remote_device,
                              const device::BluetoothUUID& uuid);

  // Gets the next id to be used for sockets.
  SocketId GetNextId() const { return socket_id_ctr_; }

 private:
  SocketId socket_id_ctr_ = 100;

  base::WeakPtrFactory<FakeFlossSocketManager> weak_ptr_factory_{this};
};

}  // namespace floss

#endif  // DEVICE_BLUETOOTH_FLOSS_FAKE_FLOSS_SOCKET_MANAGER_H_