Files
nearby/cpp/platform_v2/impl/g3/medium_environment.h
T
Alexey Polyudov ae1c427b99 nearby: snapshot of cl/313536507
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I8936b527079074d5c3af5531b9245063767cc4a7
2020-05-28 00:03:22 -07:00

48 lines
1.4 KiB
C++

#ifndef PLATFORM_V2_IMPL_G3_MEDIUM_ENVIRONMENT_H_
#define PLATFORM_V2_IMPL_G3_MEDIUM_ENVIRONMENT_H_
#include <new>
#include <string>
#include <type_traits>
#include "platform_v2/api/bluetooth_classic.h"
#include "platform_v2/impl/g3/bluetooth_adapter.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/synchronization/mutex.h"
namespace location {
namespace nearby {
namespace g3 {
// MediumEnvironment is a simulated environment which allowes multiple instances
// of simulated HW devices to "work" together as if they are physical.
// For each medium type it provides necessary methods to implement
// advertising, discovery and establishment of a data link.
class MediumEnvironment {
public:
~MediumEnvironment() = default;
// Singleton constructor/accessor.
static MediumEnvironment& Instance();
// Clear state. No notifications are sent.
void Reset() ABSL_LOCKS_EXCLUDED(mutex_);
// Add an adapter to internal container.
// Notify BluetoothClassicMediums if any that adapter state has changed.
void OnBluetoothAdapterChangedState(BluetoothAdapter& adapter)
ABSL_LOCKS_EXCLUDED(mutex_);
private:
MediumEnvironment() = default;
absl::Mutex mutex_;
absl::flat_hash_set<BluetoothAdapter*> bluetooth_adapters_
ABSL_GUARDED_BY(mutex_);
};
} // namespace g3
} // namespace nearby
} // namespace location
#endif // PLATFORM_V2_IMPL_G3_MEDIUM_ENVIRONMENT_H_