Initial commit
This commit is contained in:
+323
@@ -0,0 +1,323 @@
|
||||
#ifndef KVN_BYTEARRAY_H
|
||||
#define KVN_BYTEARRAY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace kvn {
|
||||
|
||||
/**
|
||||
* @class bytearray
|
||||
* @brief A class to handle byte arrays and their conversion from/to hex strings.
|
||||
*/
|
||||
class bytearray {
|
||||
public:
|
||||
using value_type = uint8_t;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using reference = uint8_t&;
|
||||
using const_reference = const uint8_t&;
|
||||
using pointer = uint8_t*;
|
||||
using const_pointer = const uint8_t*;
|
||||
using iterator = std::vector<uint8_t>::iterator;
|
||||
using const_iterator = std::vector<uint8_t>::const_iterator;
|
||||
|
||||
/**
|
||||
* @brief Default constructor.
|
||||
*/
|
||||
bytearray() = default;
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from a vector of uint8_t.
|
||||
* @param vec A vector of uint8_t.
|
||||
*/
|
||||
bytearray(const std::vector<uint8_t>& vec) : data_(vec) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from an initializer list of uint8_t.
|
||||
* @param list An initializer list of uint8_t.
|
||||
*/
|
||||
bytearray(std::initializer_list<uint8_t> list) : data_(list) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from a raw pointer and size.
|
||||
* @param ptr A pointer to uint8_t data.
|
||||
* @param size The size of the data.
|
||||
*/
|
||||
bytearray(const uint8_t* ptr, size_t size) : data_(ptr, ptr + size) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from iterators.
|
||||
* @tparam InputIt Iterator type.
|
||||
* @param first Iterator to the first element.
|
||||
* @param last Iterator to one past the last element.
|
||||
*/
|
||||
template <typename InputIt>
|
||||
bytearray(InputIt first, InputIt last) : data_(first, last) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from a std::string.
|
||||
* @param byteArr A string containing byte data.
|
||||
*/
|
||||
bytearray(const std::string& byteArr) : data_(byteArr.begin(), byteArr.end()) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from a C-style string and size.
|
||||
* @param byteArr A C-style string.
|
||||
* @param size The size of the string.
|
||||
*/
|
||||
bytearray(const char* byteArr, size_t size) : bytearray(std::string(byteArr, size)) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs byte array from a C-style string.
|
||||
* @param byteArr A C-style string.
|
||||
*/
|
||||
bytearray(const char* byteArr) : bytearray(std::string(byteArr)) {}
|
||||
|
||||
/**
|
||||
* @brief Constructs a byte array of specified size, initialized with zeros.
|
||||
* @param size The number of bytes to allocate.
|
||||
*/
|
||||
explicit bytearray(size_t size) : data_(size) {}
|
||||
|
||||
/**
|
||||
* @brief Creates a ByteArray from a hex string.
|
||||
*
|
||||
* Case is ignored and the string may have a '0x' hex prefix or not.
|
||||
*
|
||||
* @param hexStr A string containing hex data.
|
||||
* @return A ByteArray object.
|
||||
* @throws std::invalid_argument If the hex string contains non-hexadecimal characters.
|
||||
* @throws std::length_error If the hex string length is not even.
|
||||
*/
|
||||
static bytearray fromHex(const std::string& hexStr) {
|
||||
std::string cleanString(hexStr);
|
||||
|
||||
// Check and skip the '0x' prefix if present
|
||||
if (cleanString.size() >= 2 && cleanString.substr(0, 2) == "0x") {
|
||||
cleanString = cleanString.substr(2);
|
||||
}
|
||||
|
||||
size_t size = cleanString.size();
|
||||
if (size % 2 != 0) {
|
||||
throw std::length_error("Hex string length must be even.");
|
||||
}
|
||||
|
||||
bytearray byteArray;
|
||||
byteArray.data_.reserve(size / 2);
|
||||
|
||||
for (size_t i = 0; i < size; i += 2) {
|
||||
uint8_t byte = static_cast<uint8_t>(std::stoi(cleanString.substr(i, 2), nullptr, 16));
|
||||
byteArray.data_.push_back(byte);
|
||||
}
|
||||
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
static bytearray fromHex(const char* byteArr) { return fromHex(std::string(byteArr)); }
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
static bytearray fromHex(const char* byteArr, size_t size) { return fromHex(std::string(byteArr, size)); }
|
||||
|
||||
/**
|
||||
* @brief Converts the byte array to a lowercase hex string without '0x' prefix.
|
||||
* @param spacing Whether to include spaces between bytes.
|
||||
*
|
||||
* @return A hex string representation of the byte array.
|
||||
*/
|
||||
std::string toHex(bool spacing = false) const {
|
||||
std::ostringstream oss;
|
||||
for (auto byte : data_) {
|
||||
oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
|
||||
if (spacing) {
|
||||
oss << " ";
|
||||
}
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Slices the byte array from a specified start index to an end index.
|
||||
*
|
||||
* This method creates a new byte array containing bytes from the specified range.
|
||||
* The start index is inclusive, while the end index is exclusive.
|
||||
*
|
||||
* @param start The starting index from which to begin slicing.
|
||||
* @param end The ending index up to which to slice (exclusive).
|
||||
* @return byte array A new byte array containing the sliced segment.
|
||||
* @throws std::out_of_range If the start index is greater than the end index or if the end index is out of bounds.
|
||||
*/
|
||||
bytearray slice(size_t start, size_t end) const {
|
||||
if (start > end || end > data_.size()) {
|
||||
throw std::out_of_range("Invalid slice range");
|
||||
}
|
||||
return bytearray(data_.data() + start, end - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Slices the byte array from a specified start index to the end of the array.
|
||||
*
|
||||
* This method creates a new byte array containing all bytes from the specified start index to the end of the
|
||||
* byte array.
|
||||
*
|
||||
* @param start The starting index from which to begin slicing.
|
||||
* @return byte array A new byte array containing the sliced segment from the start index to the end.
|
||||
* @throws std::out_of_range If the start index is out of the bounds of the byte array.
|
||||
*/
|
||||
bytearray slice_from(size_t start) const { return slice(start, data_.size()); }
|
||||
|
||||
/**
|
||||
* @brief Slices the byte array from the beginning to a specified end index.
|
||||
*
|
||||
* This method creates a new byte array containing all bytes from the beginning of the byte array to the specified
|
||||
* end index.
|
||||
*
|
||||
* @param end The ending index up to which to slice (exclusive).
|
||||
* @return byte array A new byte array containing the sliced segment from the beginning to the end index.
|
||||
* @throws std::out_of_range If the end index is out of the bounds of the byte array.
|
||||
*/
|
||||
bytearray slice_to(size_t end) const { return slice(0, end); }
|
||||
|
||||
/**
|
||||
* @brief Overloaded stream insertion operator for byte array.
|
||||
* @param os The output stream.
|
||||
* @param byteArray The byte array object.
|
||||
* @return The output stream.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const bytearray& byteArray) {
|
||||
os << byteArray.toHex(true);
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conversion operator to convert byte array to std::string.
|
||||
*
|
||||
* @note This is provided to support code that relies on byte array
|
||||
* being representd as a string.
|
||||
* @return String containing the raw bytes of the byte array
|
||||
*/
|
||||
operator std::string() const { return std::string(data_.begin(), data_.end()); }
|
||||
|
||||
/**
|
||||
* @brief Conversion operator to convert byte array to std::vector<uint8_t>.
|
||||
* @return Vector containing the raw bytes of the byte array
|
||||
*/
|
||||
operator std::vector<uint8_t>() const { return data_; }
|
||||
|
||||
//! @cond Doxygen_Suppress
|
||||
// Expose vector-like functionality
|
||||
size_type size() const { return data_.size(); }
|
||||
const uint8_t* data() const { return data_.data(); }
|
||||
uint8_t* data() { return data_.data(); }
|
||||
bool empty() const { return data_.empty(); }
|
||||
void clear() { data_.clear(); }
|
||||
void reserve(size_type n) { data_.reserve(n); }
|
||||
void resize(size_type n) { data_.resize(n); }
|
||||
void resize(size_type n, uint8_t v) { data_.resize(n, v); }
|
||||
uint8_t& operator[](size_type index) { return data_[index]; }
|
||||
const uint8_t& operator[](size_type index) const { return data_[index]; }
|
||||
uint8_t& at(size_type index) { return data_.at(index); }
|
||||
const uint8_t& at(size_type index) const { return data_.at(index); }
|
||||
void push_back(uint8_t byte) { data_.push_back(byte); }
|
||||
|
||||
/**
|
||||
* @brief Appends a uint16_t value as 2 little-endian bytes.
|
||||
* @param value The uint16_t value to append.
|
||||
*/
|
||||
void push_back(uint16_t value) {
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
data_.push_back(static_cast<uint8_t>(value >> (i * 8)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Appends a uint32_t value as 4 little-endian bytes.
|
||||
* @param value The uint32_t value to append.
|
||||
*/
|
||||
void push_back(uint32_t value) {
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
data_.push_back(static_cast<uint8_t>(value >> (i * 8)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Appends a uint64_t value as 8 little-endian bytes.
|
||||
* @param value The uint64_t value to append.
|
||||
*/
|
||||
void push_back(uint64_t value) {
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
data_.push_back(static_cast<uint8_t>(value >> (i * 8)));
|
||||
}
|
||||
}
|
||||
auto begin() { return data_.begin(); }
|
||||
auto begin() const { return data_.begin(); }
|
||||
auto end() { return data_.end(); }
|
||||
auto end() const { return data_.end(); }
|
||||
|
||||
/**
|
||||
* @brief Inserts a single byte at the specified position.
|
||||
* @param pos Iterator to the position where the element is inserted.
|
||||
* @param value The byte to insert.
|
||||
* @return Iterator pointing to the inserted element.
|
||||
*/
|
||||
auto insert(iterator pos, uint8_t value) { return data_.insert(pos, value); }
|
||||
auto insert(const_iterator pos, uint8_t value) { return data_.insert(pos, value); }
|
||||
|
||||
/**
|
||||
* @brief Inserts multiple copies of a byte at the specified position.
|
||||
* @param pos Iterator to the position where the elements are inserted.
|
||||
* @param count Number of copies to insert.
|
||||
* @param value The byte to insert.
|
||||
* @return Iterator pointing to the first inserted element.
|
||||
*/
|
||||
auto insert(iterator pos, size_type count, uint8_t value) { return data_.insert(pos, count, value); }
|
||||
auto insert(const_iterator pos, size_type count, uint8_t value) { return data_.insert(pos, count, value); }
|
||||
|
||||
/**
|
||||
* @brief Inserts elements from a range at the specified position.
|
||||
* @tparam InputIt Iterator type.
|
||||
* @param pos Iterator to the position where the elements are inserted.
|
||||
* @param first Iterator to the first element of the range.
|
||||
* @param last Iterator to one past the last element of the range.
|
||||
* @return Iterator pointing to the first inserted element.
|
||||
*/
|
||||
template <typename InputIt>
|
||||
auto insert(iterator pos, InputIt first, InputIt last) {
|
||||
return data_.insert(pos, first, last);
|
||||
}
|
||||
template <typename InputIt>
|
||||
auto insert(const_iterator pos, InputIt first, InputIt last) {
|
||||
return data_.insert(pos, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts another bytearray at the specified position.
|
||||
* @param pos Iterator to the position where the elements are inserted.
|
||||
* @param other The bytearray to insert.
|
||||
* @return Iterator pointing to the first inserted element.
|
||||
*/
|
||||
auto insert(iterator pos, const bytearray& other) { return data_.insert(pos, other.begin(), other.end()); }
|
||||
auto insert(const_iterator pos, const bytearray& other) { return data_.insert(pos, other.begin(), other.end()); }
|
||||
|
||||
//! @endcond
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> data_;
|
||||
};
|
||||
|
||||
} // namespace kvn
|
||||
|
||||
#endif // KVN_BYTEARRAY_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Kevin Dewald <kevin@dewald.me>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef KVN_SAFE_CALLBACK_HPP
|
||||
#define KVN_SAFE_CALLBACK_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace kvn {
|
||||
|
||||
template <typename _Signature>
|
||||
class safe_callback;
|
||||
|
||||
template <class _Res, class... _ArgTypes>
|
||||
class safe_callback<_Res(_ArgTypes...)> {
|
||||
public:
|
||||
safe_callback() = default;
|
||||
|
||||
// Remove copy constructor and copy assignment
|
||||
safe_callback(const safe_callback&) = delete;
|
||||
safe_callback& operator=(const safe_callback&) = delete;
|
||||
|
||||
virtual ~safe_callback() { unload(); };
|
||||
|
||||
void load(std::function<_Res(_ArgTypes...)> callback) {
|
||||
if (callback == nullptr) return;
|
||||
|
||||
std::scoped_lock lock(_mutex);
|
||||
_callback = std::move(callback);
|
||||
_is_loaded = true;
|
||||
}
|
||||
|
||||
void unload() {
|
||||
std::scoped_lock lock(_mutex);
|
||||
_callback = nullptr;
|
||||
_is_loaded = false;
|
||||
}
|
||||
|
||||
bool is_loaded() const { return _is_loaded; }
|
||||
|
||||
explicit operator bool() const { return is_loaded(); }
|
||||
|
||||
_Res operator()(_ArgTypes... arguments) {
|
||||
std::scoped_lock lock(_mutex);
|
||||
if (_is_loaded) {
|
||||
return _callback(std::forward<_ArgTypes&&>(arguments)...);
|
||||
} else {
|
||||
return _Res();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::atomic_bool _is_loaded{false};
|
||||
std::function<_Res(_ArgTypes...)> _callback;
|
||||
std::recursive_mutex _mutex;
|
||||
};
|
||||
|
||||
} // namespace kvn
|
||||
|
||||
#endif // KVN_SAFE_CALLBACK_HPP
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#ifndef LOGFWD_HPP
|
||||
#define LOGFWD_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace logfwd {
|
||||
|
||||
enum level : int {
|
||||
NONE = 0,
|
||||
FATAL,
|
||||
ERROR,
|
||||
WARN,
|
||||
INFO,
|
||||
#pragma push_macro("DEBUG")
|
||||
#undef DEBUG
|
||||
DEBUG,
|
||||
#pragma pop_macro("DEBUG")
|
||||
VERBOSE,
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
|
||||
void receive(
|
||||
level level,
|
||||
const std::string& module,
|
||||
const std::string& file,
|
||||
uint32_t line,
|
||||
const std::string& function,
|
||||
const std::string& message);
|
||||
|
||||
// clang-format on
|
||||
|
||||
} // namespace logfwd
|
||||
|
||||
#endif // LOGFWD_HPP
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#ifndef SIMPLEBLE_EXPORT_H
|
||||
#define SIMPLEBLE_EXPORT_H
|
||||
|
||||
#ifdef SIMPLEBLE_STATIC_DEFINE
|
||||
# define SIMPLEBLE_EXPORT
|
||||
# define SIMPLEBLE_NO_EXPORT
|
||||
#else
|
||||
# ifndef SIMPLEBLE_EXPORT
|
||||
# ifdef simpleble_EXPORTS
|
||||
/* We are building this library */
|
||||
# define SIMPLEBLE_EXPORT
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define SIMPLEBLE_EXPORT
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef SIMPLEBLE_NO_EXPORT
|
||||
# define SIMPLEBLE_NO_EXPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SIMPLEBLE_DEPRECATED
|
||||
# define SIMPLEBLE_DEPRECATED __attribute__ ((__deprecated__))
|
||||
#endif
|
||||
|
||||
#ifndef SIMPLEBLE_DEPRECATED_EXPORT
|
||||
# define SIMPLEBLE_DEPRECATED_EXPORT SIMPLEBLE_EXPORT SIMPLEBLE_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef SIMPLEBLE_DEPRECATED_NO_EXPORT
|
||||
# define SIMPLEBLE_DEPRECATED_NO_EXPORT SIMPLEBLE_NO_EXPORT SIMPLEBLE_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */
|
||||
#if 0 /* DEFINE_NO_DEPRECATED */
|
||||
# ifndef SIMPLEBLE_NO_DEPRECATED
|
||||
# define SIMPLEBLE_NO_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* SIMPLEBLE_EXPORT_H */
|
||||
Binary file not shown.
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Exceptions.h>
|
||||
#include <simpleble/Peripheral.h>
|
||||
#include <simpleble/Types.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class AdapterBase;
|
||||
|
||||
/**
|
||||
* Bluetooth Adapter.
|
||||
*
|
||||
* A default-constructed Adapter object is not initialized. Calling any method
|
||||
* other than `initialized()` on an uninitialized Adapter will throw an exception
|
||||
* of type `SimpleBLE::NotInitialized`.
|
||||
*
|
||||
* NOTE: This class is intended to be used by the user only. Library developers
|
||||
* should use shared pointers to `AdapterBase` instead.
|
||||
*/
|
||||
class SIMPLEBLE_EXPORT Adapter {
|
||||
public:
|
||||
Adapter() = default;
|
||||
virtual ~Adapter() = default;
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
/**
|
||||
* Retrieve the underlying OS object/handle.
|
||||
*
|
||||
* For certain compatibility with external libraries, we sometimes need to
|
||||
* expose the actual OS handle to the user. This is particularly important
|
||||
* for MacOS right now.
|
||||
*/
|
||||
void* underlying() const;
|
||||
|
||||
std::string identifier();
|
||||
BluetoothAddress address();
|
||||
|
||||
/**
|
||||
* Control the power state of the adapter.
|
||||
*
|
||||
* NOTE: Power control support depends on the backend and platform.
|
||||
* Unsupported backends may do nothing.
|
||||
* NOTE: Power callbacks are supported by backends that provide power state change events.
|
||||
*/
|
||||
void power_on();
|
||||
void power_off();
|
||||
bool is_powered();
|
||||
void set_callback_on_power_on(std::function<void()> on_power_on);
|
||||
void set_callback_on_power_off(std::function<void()> on_power_off);
|
||||
|
||||
void scan_start();
|
||||
void scan_stop();
|
||||
void scan_for(int timeout_ms);
|
||||
bool scan_is_active();
|
||||
std::vector<Peripheral> scan_get_results();
|
||||
|
||||
void set_callback_on_scan_start(std::function<void()> on_scan_start);
|
||||
void set_callback_on_scan_stop(std::function<void()> on_scan_stop);
|
||||
void set_callback_on_scan_updated(std::function<void(Peripheral)> on_scan_updated);
|
||||
void set_callback_on_scan_found(std::function<void(Peripheral)> on_scan_found);
|
||||
|
||||
/**
|
||||
* Retrieve a list of all paired peripherals.
|
||||
*
|
||||
* NOTE:This method is currently only supported by the Linux, Windows and Android backends.
|
||||
*/
|
||||
std::vector<Peripheral> get_paired_peripherals();
|
||||
|
||||
/**
|
||||
* Retrieve a list of all connected peripherals.
|
||||
*
|
||||
* NOTE: This method is currently only supported by the Windows backend. (More backends coming soon.)
|
||||
*/
|
||||
std::vector<Peripheral> get_connected_peripherals();
|
||||
|
||||
static bool bluetooth_enabled();
|
||||
|
||||
/**
|
||||
* Fetches a list of all available adapters from all available backends.
|
||||
*
|
||||
* This will cause backends to be instantiated/initialized and adapters
|
||||
* too.
|
||||
*
|
||||
* @note All configuration values must be set prior to calling this function.
|
||||
* Please refer to the SimpleBLE::Config documentation for more details.
|
||||
*/
|
||||
static std::vector<Adapter> get_adapters();
|
||||
|
||||
protected:
|
||||
AdapterBase* operator->();
|
||||
const AdapterBase* operator->() const;
|
||||
|
||||
std::shared_ptr<AdapterBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Adapter.h>
|
||||
#include <simpleble/PeripheralSafe.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
namespace Safe {
|
||||
|
||||
/**
|
||||
* Wrapper around the Adapter class that provides a noexcept interface.
|
||||
*
|
||||
* We use instances of this class directly and not through shared_ptr because
|
||||
* this is just a wrapper around the Adapter class, which is already managed by
|
||||
* shared_ptr.
|
||||
*/
|
||||
class SIMPLEBLE_EXPORT Adapter {
|
||||
public:
|
||||
Adapter(SimpleBLE::Adapter& adapter);
|
||||
Adapter(SimpleBLE::Adapter&& adapter);
|
||||
virtual ~Adapter() = default;
|
||||
|
||||
std::optional<std::string> identifier() noexcept;
|
||||
std::optional<BluetoothAddress> address() noexcept;
|
||||
|
||||
bool scan_start() noexcept;
|
||||
bool scan_stop() noexcept;
|
||||
bool scan_for(int timeout_ms) noexcept;
|
||||
std::optional<bool> scan_is_active() noexcept;
|
||||
std::optional<std::vector<SimpleBLE::Safe::Peripheral>> scan_get_results() noexcept;
|
||||
|
||||
bool set_callback_on_scan_start(std::function<void()> on_scan_start) noexcept;
|
||||
bool set_callback_on_scan_stop(std::function<void()> on_scan_stop) noexcept;
|
||||
bool set_callback_on_scan_updated(std::function<void(SimpleBLE::Safe::Peripheral)> on_scan_updated) noexcept;
|
||||
bool set_callback_on_scan_found(std::function<void(SimpleBLE::Safe::Peripheral)> on_scan_found) noexcept;
|
||||
|
||||
std::optional<std::vector<SimpleBLE::Safe::Peripheral>> get_paired_peripherals() noexcept;
|
||||
|
||||
static std::optional<bool> bluetooth_enabled() noexcept;
|
||||
static std::optional<std::vector<SimpleBLE::Safe::Adapter>> get_adapters() noexcept;
|
||||
|
||||
/**
|
||||
* Cast to the underlying adapter object.
|
||||
*/
|
||||
operator SimpleBLE::Adapter() const noexcept;
|
||||
|
||||
protected:
|
||||
SimpleBLE::Adapter internal_;
|
||||
};
|
||||
|
||||
} // namespace Safe
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#if __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Advanced Features
|
||||
*
|
||||
* The functions presented in this namespace are OS-specific backdoors that are
|
||||
* not part of the standard SimpleBLE API, which allow the user to access
|
||||
* low-level details of the implementation for advanced use cases.
|
||||
*
|
||||
* These functions should be used with caution.
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
namespace SimpleBLE::Advanced::Windows {}
|
||||
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
namespace SimpleBLE::Advanced::MacOS {}
|
||||
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
namespace SimpleBLE::Advanced::iOS {}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace SimpleBLE::Advanced::Android {
|
||||
|
||||
JavaVM* SIMPLEBLE_EXPORT get_jvm();
|
||||
void SIMPLEBLE_EXPORT set_jvm(JavaVM* jvm);
|
||||
|
||||
} // namespace SimpleBLE::Advanced::Android
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
namespace SimpleBLE::Advanced::Linux {}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <simpleble/Adapter.h>
|
||||
#include <simpleble/export.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class BackendBase;
|
||||
|
||||
class SIMPLEBLE_EXPORT Backend {
|
||||
friend class Adapter;
|
||||
public:
|
||||
Backend() = default;
|
||||
virtual ~Backend() = default;
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
/**
|
||||
* Get a list of all available adapters from this backend.
|
||||
*/
|
||||
std::vector<Adapter> adapters();
|
||||
|
||||
/**
|
||||
* Check if Bluetooth is enabled for this backend.
|
||||
*/
|
||||
bool bluetooth_enabled();
|
||||
|
||||
/**
|
||||
* Get the identifier of the backend.
|
||||
*/
|
||||
std::string identifier() const noexcept;
|
||||
|
||||
/**
|
||||
* Get all available backends.
|
||||
*
|
||||
* This will cause backends to be instantiated/initialized.
|
||||
*/
|
||||
static std::vector<Backend> get_backends();
|
||||
|
||||
protected:
|
||||
BackendBase* operator->();
|
||||
const BackendBase* operator->() const;
|
||||
|
||||
std::shared_ptr<BackendBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Descriptor.h>
|
||||
#include <simpleble/Exceptions.h>
|
||||
#include <simpleble/Types.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class CharacteristicBase;
|
||||
|
||||
class SIMPLEBLE_EXPORT Characteristic {
|
||||
public:
|
||||
Characteristic() = default;
|
||||
virtual ~Characteristic() = default;
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
BluetoothUUID uuid();
|
||||
std::vector<Descriptor> descriptors();
|
||||
std::vector<std::string> capabilities();
|
||||
|
||||
bool can_read();
|
||||
bool can_write_request();
|
||||
bool can_write_command();
|
||||
bool can_notify();
|
||||
bool can_indicate();
|
||||
|
||||
protected:
|
||||
CharacteristicBase* operator->();
|
||||
const CharacteristicBase* operator->() const;
|
||||
|
||||
std::shared_ptr<CharacteristicBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <simpleble/export.h>
|
||||
|
||||
//clang-format off
|
||||
namespace SimpleBLE {
|
||||
/**
|
||||
* @namespace SimpleBLE::Config
|
||||
* @brief Configuration options for SimpleBLE.
|
||||
*
|
||||
* @note All configuration values must be set prior to any other interaction with a SimpleBLE component.
|
||||
* Changes made after an adapter has been retrieved may not take effect or could lead to undefined behavior.
|
||||
*/
|
||||
namespace Config {
|
||||
namespace SimpleBluez {
|
||||
extern SIMPLEBLE_EXPORT bool use_legacy_bluez_backend;
|
||||
extern SIMPLEBLE_EXPORT bool use_system_bus; // NOTE: This is only available in the new Bluez backend.
|
||||
extern SIMPLEBLE_EXPORT std::chrono::steady_clock::duration connection_timeout;
|
||||
extern SIMPLEBLE_EXPORT std::chrono::steady_clock::duration disconnection_timeout;
|
||||
|
||||
static void reset() {
|
||||
use_legacy_bluez_backend = false;
|
||||
use_system_bus = true;
|
||||
connection_timeout = std::chrono::seconds(2);
|
||||
disconnection_timeout = std::chrono::seconds(1);
|
||||
}
|
||||
} // namespace SimpleBluez
|
||||
|
||||
namespace WinRT {
|
||||
/**
|
||||
* @deprecated SimpleBLE uses its own MTA apartment by default. This compatibility flag will be removed in a future release.
|
||||
*/
|
||||
extern SIMPLEBLE_EXPORT bool experimental_use_own_mta_apartment;
|
||||
extern SIMPLEBLE_EXPORT bool experimental_reinitialize_winrt_apartment_on_main_thread;
|
||||
extern SIMPLEBLE_EXPORT bool use_deferred_disconnect;
|
||||
|
||||
static void reset() {
|
||||
experimental_use_own_mta_apartment = true;
|
||||
experimental_reinitialize_winrt_apartment_on_main_thread = false;
|
||||
use_deferred_disconnect = true;
|
||||
}
|
||||
} // namespace WinRT
|
||||
|
||||
namespace CoreBluetooth {
|
||||
static void reset() {}
|
||||
} // namespace CoreBluetooth
|
||||
|
||||
namespace Android {
|
||||
enum class ConnectionPriorityRequest { DISABLED = -1, BALANCED = 0, HIGH = 1, LOW_POWER = 2, DCK = 3 };
|
||||
|
||||
extern SIMPLEBLE_EXPORT ConnectionPriorityRequest connection_priority_request;
|
||||
|
||||
static void reset() { connection_priority_request = ConnectionPriorityRequest::DISABLED; }
|
||||
} // namespace Android
|
||||
|
||||
namespace Dongl {
|
||||
extern SIMPLEBLE_EXPORT bool use_dongl_backend;
|
||||
extern SIMPLEBLE_EXPORT bool auto_update;
|
||||
extern SIMPLEBLE_EXPORT bool force_update;
|
||||
static void reset() {
|
||||
use_dongl_backend = false;
|
||||
auto_update = false;
|
||||
force_update = false;
|
||||
}
|
||||
} // namespace Dongl
|
||||
|
||||
namespace Base {
|
||||
static void reset_all() {
|
||||
SimpleBluez::reset();
|
||||
WinRT::reset();
|
||||
CoreBluetooth::reset();
|
||||
Android::reset();
|
||||
Dongl::reset();
|
||||
}
|
||||
} // namespace Base
|
||||
} // namespace Config
|
||||
} // namespace SimpleBLE
|
||||
//clang-format on
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Exceptions.h>
|
||||
#include <simpleble/Types.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class DescriptorBase;
|
||||
|
||||
class SIMPLEBLE_EXPORT Descriptor {
|
||||
public:
|
||||
Descriptor() = default;
|
||||
virtual ~Descriptor() = default;
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
BluetoothUUID uuid();
|
||||
|
||||
protected:
|
||||
DescriptorBase* operator->();
|
||||
const DescriptorBase* operator->() const;
|
||||
|
||||
std::shared_ptr<DescriptorBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
namespace Exception {
|
||||
|
||||
class SIMPLEBLE_EXPORT BaseException : public std::runtime_error {
|
||||
public:
|
||||
BaseException(const std::string& __arg) : std::runtime_error(__arg) {}
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT NotInitialized : public BaseException {
|
||||
public:
|
||||
NotInitialized();
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT NotConnected : public BaseException {
|
||||
public:
|
||||
NotConnected();
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT InvalidReference : public BaseException {
|
||||
public:
|
||||
InvalidReference();
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT ServiceNotFound : public BaseException {
|
||||
public:
|
||||
ServiceNotFound(BluetoothUUID uuid);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT CharacteristicNotFound : public BaseException {
|
||||
public:
|
||||
CharacteristicNotFound(BluetoothUUID uuid);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT DescriptorNotFound : public BaseException {
|
||||
public:
|
||||
DescriptorNotFound(BluetoothUUID uuid);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT OperationNotSupported : public BaseException {
|
||||
public:
|
||||
OperationNotSupported();
|
||||
OperationNotSupported(const std::string& operation, const BluetoothUUID& characteristic_uuid);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT OperationFailed : public BaseException {
|
||||
public:
|
||||
OperationFailed();
|
||||
OperationFailed(const std::string& err_msg);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT WinRTException : public BaseException {
|
||||
public:
|
||||
WinRTException(int32_t err_code, const std::string& err_msg);
|
||||
};
|
||||
|
||||
class SIMPLEBLE_EXPORT CoreBluetoothException : public BaseException {
|
||||
public:
|
||||
CoreBluetoothException(const std::string& err_msg);
|
||||
};
|
||||
|
||||
} // namespace Exception
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
namespace Logging {
|
||||
|
||||
enum Level : int {
|
||||
None = 0,
|
||||
Fatal,
|
||||
Error,
|
||||
Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Verbose,
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
using Callback = std::function<void(
|
||||
Level,
|
||||
const std::string& module,
|
||||
const std::string& file,
|
||||
uint32_t line,
|
||||
const std::string& function,
|
||||
const std::string& message)>;
|
||||
// clang-format on
|
||||
|
||||
class SIMPLEBLE_EXPORT Logger {
|
||||
public:
|
||||
static Logger* get();
|
||||
|
||||
void set_level(Level level);
|
||||
Level get_level();
|
||||
|
||||
void set_callback(Callback callback);
|
||||
bool has_callback();
|
||||
|
||||
void log_default_stdout();
|
||||
void log_default_file();
|
||||
void log_default_file(const std::string path);
|
||||
|
||||
// clang-format off
|
||||
void log(
|
||||
Level level,
|
||||
const std::string& module,
|
||||
const std::string& file,
|
||||
uint32_t line,
|
||||
const std::string& function,
|
||||
const std::string& message);
|
||||
// clang-format on
|
||||
|
||||
private:
|
||||
Logger();
|
||||
~Logger();
|
||||
Logger(Logger& other) = delete; // Remove copy constructor
|
||||
void operator=(const Logger&) = delete; // Remove copy assignment
|
||||
|
||||
static std::string level_to_str(Level level);
|
||||
|
||||
Level level_{Level::Info};
|
||||
Callback callback_{nullptr};
|
||||
std::recursive_mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace Logging
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Exceptions.h>
|
||||
#include <simpleble/Service.h>
|
||||
#include <simpleble/Types.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class PeripheralBase;
|
||||
|
||||
class SIMPLEBLE_EXPORT Peripheral {
|
||||
public:
|
||||
Peripheral() = default;
|
||||
virtual ~Peripheral() = default;
|
||||
|
||||
bool initialized() const;
|
||||
void* underlying() const;
|
||||
|
||||
std::string identifier();
|
||||
BluetoothAddress address();
|
||||
BluetoothAddressType address_type();
|
||||
int16_t rssi();
|
||||
|
||||
/**
|
||||
* @brief Provides the advertised transmit power in dBm.
|
||||
*
|
||||
* @note If the field has not been advertised by the peripheral,
|
||||
* the returned value will be -32768.
|
||||
*/
|
||||
int16_t tx_power();
|
||||
uint16_t mtu();
|
||||
|
||||
void connect();
|
||||
void disconnect();
|
||||
bool is_connected();
|
||||
bool is_connectable();
|
||||
bool is_paired();
|
||||
void unpair();
|
||||
|
||||
/**
|
||||
* @brief Provides a list of all services that are available on the peripheral.
|
||||
*
|
||||
* @note If the peripheral is not connected, it will return a list of services
|
||||
* that were advertised by the device.
|
||||
*/
|
||||
std::vector<Service> services();
|
||||
std::map<uint16_t, ByteArray> manufacturer_data();
|
||||
|
||||
/* Calling any of the methods below when the device is not connected will throw
|
||||
Exception::NotConnected */
|
||||
// clang-format off
|
||||
ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic);
|
||||
void write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data);
|
||||
void write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data);
|
||||
void notify(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback);
|
||||
void indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback);
|
||||
void unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic);
|
||||
|
||||
ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor);
|
||||
void write(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor, ByteArray const& data);
|
||||
// clang-format on
|
||||
|
||||
void set_callback_on_connected(std::function<void()> on_connected);
|
||||
void set_callback_on_disconnected(std::function<void()> on_disconnected);
|
||||
|
||||
protected:
|
||||
PeripheralBase* operator->();
|
||||
const PeripheralBase* operator->() const;
|
||||
|
||||
std::shared_ptr<PeripheralBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Peripheral.h>
|
||||
#include <simpleble/Service.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
namespace Safe {
|
||||
|
||||
class SIMPLEBLE_EXPORT Peripheral {
|
||||
public:
|
||||
Peripheral(SimpleBLE::Peripheral& peripheral);
|
||||
Peripheral(SimpleBLE::Peripheral&& peripheral);
|
||||
virtual ~Peripheral() = default;
|
||||
|
||||
std::optional<std::string> identifier() noexcept;
|
||||
std::optional<BluetoothAddress> address() noexcept;
|
||||
std::optional<BluetoothAddressType> address_type() noexcept;
|
||||
std::optional<int16_t> rssi() noexcept;
|
||||
std::optional<int16_t> tx_power() noexcept;
|
||||
std::optional<uint16_t> mtu() noexcept;
|
||||
|
||||
bool connect() noexcept;
|
||||
bool disconnect() noexcept;
|
||||
std::optional<bool> is_connected() noexcept;
|
||||
std::optional<bool> is_connectable() noexcept;
|
||||
std::optional<bool> is_paired() noexcept;
|
||||
bool unpair() noexcept;
|
||||
|
||||
std::optional<std::vector<Service>> services() noexcept;
|
||||
std::optional<std::map<uint16_t, ByteArray>> manufacturer_data() noexcept;
|
||||
|
||||
// clang-format off
|
||||
std::optional<ByteArray> read(BluetoothUUID const& service, BluetoothUUID const& characteristic) noexcept;
|
||||
bool write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) noexcept;
|
||||
bool write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) noexcept;
|
||||
bool notify(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) noexcept;
|
||||
bool indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) noexcept;
|
||||
bool unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) noexcept;
|
||||
|
||||
std::optional<ByteArray> read(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor) noexcept;
|
||||
bool write(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor, ByteArray const& data) noexcept;
|
||||
// clang-format on
|
||||
|
||||
bool set_callback_on_connected(std::function<void()> on_connected) noexcept;
|
||||
bool set_callback_on_disconnected(std::function<void()> on_disconnected) noexcept;
|
||||
|
||||
/**
|
||||
* Get the underlying peripheral object.
|
||||
*/
|
||||
operator SimpleBLE::Peripheral() const noexcept;
|
||||
|
||||
protected:
|
||||
SimpleBLE::Peripheral internal_;
|
||||
};
|
||||
|
||||
} // namespace Safe
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Exceptions.h>
|
||||
#include <simpleble/Types.h>
|
||||
#include "simpleble/Characteristic.h"
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
class ServiceBase;
|
||||
|
||||
class SIMPLEBLE_EXPORT Service {
|
||||
public:
|
||||
Service() = default;
|
||||
virtual ~Service() = default;
|
||||
|
||||
bool initialized() const;
|
||||
|
||||
BluetoothUUID uuid();
|
||||
ByteArray data();
|
||||
std::vector<Characteristic> characteristics();
|
||||
|
||||
protected:
|
||||
const ServiceBase* operator->() const;
|
||||
ServiceBase* operator->();
|
||||
|
||||
std::shared_ptr<ServiceBase> internal_;
|
||||
};
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <simpleble/Config.h>
|
||||
#include <simpleble/Adapter.h>
|
||||
#include <simpleble/AdapterSafe.h>
|
||||
#include <simpleble/Peripheral.h>
|
||||
#include <simpleble/PeripheralSafe.h>
|
||||
#include <simpleble/Utils.h>
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "kvn/kvn_bytearray.h"
|
||||
|
||||
/**
|
||||
* @file Types.h
|
||||
* @brief Defines types and enumerations used throughout the SimpleBLE library.
|
||||
*/
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
using BluetoothAddress = std::string;
|
||||
|
||||
// IDEA: Extend BluetoothUUID to include a `uuid` function that
|
||||
// returns the same string, but provides a homogeneous interface.
|
||||
using BluetoothUUID = std::string;
|
||||
|
||||
/**
|
||||
* @typedef ByteArray
|
||||
* @brief Represents a byte array using kvn::bytearray from the external library.
|
||||
*/
|
||||
using ByteArray = kvn::bytearray;
|
||||
|
||||
#ifdef ANDROID
|
||||
#pragma push_macro("ANDROID")
|
||||
#undef ANDROID
|
||||
#define ANDROID_WAS_DEFINED
|
||||
#endif
|
||||
|
||||
enum class OperatingSystem {
|
||||
WINDOWS,
|
||||
MACOS,
|
||||
IOS,
|
||||
LINUX,
|
||||
ANDROID,
|
||||
};
|
||||
|
||||
#ifdef ANDROID_WAS_DEFINED
|
||||
#pragma pop_macro("ANDROID")
|
||||
#undef ANDROID_WAS_DEFINED
|
||||
#endif
|
||||
|
||||
// TODO: Add to_string functions for all enums.
|
||||
enum BluetoothAddressType : int32_t { PUBLIC = 0, RANDOM = 1, UNSPECIFIED = 2 };
|
||||
|
||||
} // namespace SimpleBLE
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <simpleble/export.h>
|
||||
|
||||
#include <simpleble/Types.h>
|
||||
|
||||
namespace SimpleBLE {
|
||||
|
||||
OperatingSystem SIMPLEBLE_EXPORT get_operating_system();
|
||||
|
||||
std::string SIMPLEBLE_EXPORT get_simpleble_version();
|
||||
|
||||
} // namespace SimpleBLE
|
||||
Reference in New Issue
Block a user