Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
dbt_client_test.hpp
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef DBT_CLIENT_TEST_HPP_
26#define DBT_CLIENT_TEST_HPP_
27
28#include "dbt_endpoint.hpp"
29
30class DBTClientTest;
31typedef std::shared_ptr<DBTClientTest> DBTClientTestRef;
32
33class DBTClientTest : public DBTEndpoint {
34
35 public:
36 /**
37 * Set DiscoveryPolicy
38 *
39 * Default is {@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_READY}
40 */
41 virtual void setDiscoveryPolicy(const DiscoveryPolicy v) = 0;
42
43 /**
44 * Set disconnect after processing.
45 *
46 * Default is `true`.
47 */
48 virtual void setDisconnectDevice(const bool v) = 0;
49
50 /**
51 * Set remove device when disconnecting.
52 *
53 * This removes the device from all instances within adapter
54 * and hence all potential side-effects of the current instance.
55 *
56 * Default is `false`, since it is good to test whether such side-effects exists.
57 */
58 virtual void setRemoveDevice(const bool v) = 0;
59
60 virtual HCIStatusCode startDiscovery(const std::string& msg) = 0;
61
62 virtual HCIStatusCode stopDiscovery(const std::string& msg) = 0;
63
64 static void startDiscovery(const DBTClientTestRef& client, const bool current_exp_discovering_state, const std::string& msg) {
65 BTAdapterRef adapter = client->getAdapter();
66 REQUIRE( false == adapter->isAdvertising() );
67 REQUIRE( current_exp_discovering_state == adapter->isDiscovering() );
68
69 REQUIRE( HCIStatusCode::SUCCESS == client->startDiscovery(msg) );
70 while( !adapter->isDiscovering() ) { // pending action
71 jau::sleep_for( 100_ms );
72 }
73 REQUIRE( false == adapter->isAdvertising() );
74 REQUIRE( true == adapter->isDiscovering() );
75 REQUIRE( BTRole::Master == adapter->getRole() );
76 }
77
78 static void stopDiscovery(const DBTClientTestRef& client, const bool current_exp_discovering_state, const std::string& msg) {
79 BTAdapterRef adapter = client->getAdapter();
80 REQUIRE( false == adapter->isAdvertising() );
81 REQUIRE( current_exp_discovering_state == adapter->isDiscovering() );
82 REQUIRE( BTRole::Master == adapter->getRole() );
83
84 REQUIRE( HCIStatusCode::SUCCESS == client->stopDiscovery(msg) );
85 while( adapter->isDiscovering() ) { // pending action
86 jau::sleep_for( 100_ms );
87 }
88 REQUIRE( false == adapter->isAdvertising() );
89 REQUIRE( false == adapter->isDiscovering() );
90 REQUIRE( BTRole::Master == adapter->getRole() );
91 }
92};
93
94#endif /* #define DBT_CLIENT_TEST_HPP_ */
virtual HCIStatusCode startDiscovery(const std::string &msg)=0
static void stopDiscovery(const DBTClientTestRef &client, const bool current_exp_discovering_state, const std::string &msg)
virtual HCIStatusCode stopDiscovery(const std::string &msg)=0
virtual void setDiscoveryPolicy(const DiscoveryPolicy v)=0
Set DiscoveryPolicy.
virtual void setRemoveDevice(const bool v)=0
Set remove device when disconnecting.
static void startDiscovery(const DBTClientTestRef &client, const bool current_exp_discovering_state, const std::string &msg)
virtual void setDisconnectDevice(const bool v)=0
Set disconnect after processing.
std::shared_ptr< DBTClientTest > DBTClientTestRef
DiscoveryPolicy
Discovery policy defines the BTAdapter discovery mode after connecting a remote BTDevice:
Definition: BTAdapter.hpp:82
std::shared_ptr< BTAdapter > BTAdapterRef
Definition: BTAdapter.hpp:1354
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Definition: HCITypes.hpp:138
bool sleep_for(const fraction_timespec &relative_time, const bool monotonic=true, const bool ignore_irq=true) noexcept
sleep_for causes the current thread to block until a specific amount of time has passed.