25#ifndef DBT_ENDPOINT_HPP_
26#define DBT_ENDPOINT_HPP_
33#include <catch2/catch_amalgamated.hpp>
69 virtual void close(
const std::string& msg) = 0;
91 REQUIRE(
true == adapter->isInitialized() );
92 REQUIRE(
true == adapter->isPowered() );
93 REQUIRE( BTRole::Master == adapter->getRole() );
94 REQUIRE( 4 <= adapter->getBTMajorVersion() );
103 if(
nullptr == endpt->getAdapter() ) {
104 if( endpt->initAdapter( adapter ) ) {
105 endpt->setAdapter(adapter);
106 jau::fprintf_td(stderr,
"****** Adapter ADDED__: InitOK: %s\n", adapter->toString().c_str());
111 jau::fprintf_td(stderr,
"****** Adapter ADDED__: Ignored: %s\n", adapter->toString().c_str());
114 if(
nullptr != endpt->getAdapter() && *adapter == *endpt->getAdapter() ) {
115 endpt->setAdapter(
nullptr);
116 jau::fprintf_td(stderr,
"****** Adapter REMOVED: %s\n", adapter->toString().c_str());
120 jau::fprintf_td(stderr,
"****** Adapter REMOVED: Ignored: %s\n", adapter->toString().c_str());
128 manager->addChangedAdapterSetCallback(casc);
130 REQUIRE(
nullptr != endpt->getAdapter() );
136 REQUIRE(
false == adapter->isAdvertising() );
137 REQUIRE( current_exp_discovering_state == adapter->isDiscovering());
139 REQUIRE( HCIStatusCode::SUCCESS == adapter->startDiscovery() );
140 while( !adapter->isDiscovering() ) {
143 REQUIRE(
false == adapter->isAdvertising() );
144 REQUIRE(
true == adapter->isDiscovering() );
145 REQUIRE( BTRole::Master == adapter->getRole() );
149 REQUIRE(
false == adapter->isAdvertising() );
150 REQUIRE( current_exp_discovering_state == adapter->isDiscovering() );
151 REQUIRE( BTRole::Master == adapter->getRole() );
153 REQUIRE( HCIStatusCode::SUCCESS == adapter->stopDiscovery() );
154 while( adapter->isDiscovering() ) {
157 REQUIRE(
false == adapter->isAdvertising() );
158 REQUIRE(
false == adapter->isDiscovering() );
159 REQUIRE( BTRole::Master == adapter->getRole() );
virtual std::string getName()=0
Return name of this endpoint, which becomes the adapter's name.
static void checkInitializedState(const DBTEndpointRef &endp)
virtual ~DBTEndpoint()=default
static void myChangedAdapterSetFunc(const bool added, BTAdapterRef &adapter)
virtual void setAdapter(BTAdapterRef a)=0
Set the server adapter for this endpoint.
static void stopDiscovery(const BTAdapterRef &adapter, const bool current_exp_discovering_state)
virtual int getDisconnectCount()=0
virtual void close(const std::string &msg)=0
virtual int getProtocolSessionsLeft()=0
static std::mutex mtx_cas_endpts
virtual int getProtocolSessionsDoneTotal()=0
static ChangedAdapterSetCallback initChangedAdapterSetListener(const BTManagerRef &manager, std::vector< DBTEndpointRef > endpts)
virtual void setProtocolSessionsLeft(const int v)=0
virtual int getProtocolSessionsDoneSuccess()=0
static void startDiscovery(const BTAdapterRef &adapter, const bool current_exp_discovering_state)
static std::vector< DBTEndpointRef > cas_endpts
virtual bool initAdapter(BTAdapterRef adapter)=0
Initialize the given adapter for this endpoint.
virtual BTAdapterRef getAdapter()=0
Return the adapter for this endpoint.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
std::shared_ptr< DBTEndpoint > DBTEndpointRef
std::shared_ptr< BTManager > BTManagerRef
std::shared_ptr< BTAdapter > BTAdapterRef
jau::function< R(A...)> bind_free(R(*func)(A...)) noexcept
Bind given non-void free-function to an anonymous function using func::free_target_t.
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
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.