missed a few files

This commit is contained in:
kidfromjupiter
2025-12-26 15:50:41 +00:00
parent 333688074a
commit 88f8133d90
3 changed files with 323 additions and 0 deletions
@@ -0,0 +1,49 @@
// filepath: /workspace/internal/platform/implementation/linux/atomics.h
//
// Created by root on 10/2/25.
//
#ifndef LINUX_ATOMIC_BOOLEAN_H
#define LINUX_ATOMIC_BOOLEAN_H
#include <atomic>
#include "internal/platform/implementation/atomic_boolean.h"
#include "internal/platform/implementation/atomic_reference.h"
namespace nearby
{
namespace linux
{
// A boolean value that may be updated atomically.
class AtomicBoolean : public api::AtomicBoolean
{
public:
explicit AtomicBoolean(bool value = false) : atomic_boolean_(value)
{
}
~AtomicBoolean() override = default;
// Atomically read and return current value.
[[nodiscard]] bool Get() const override { return atomic_boolean_; };
// Atomically exchange original value with a new one. Return previous value.
bool Set(bool value) override { return atomic_boolean_.exchange(value); };
private:
std::atomic_bool atomic_boolean_ = false;
};
class AtomicUint32 : public api::AtomicUint32
{
public:
explicit AtomicUint32(std::uint32_t value = 0) : atomic_uint32_(value) {}
~AtomicUint32() override = default;
// Atomically reads and returns stored value.
[[nodiscard]] std::uint32_t Get() const override { return atomic_uint32_.load(); }
// Atomically stores value.
void Set(std::uint32_t value) override { atomic_uint32_.store(value); }
private:
std::atomic<std::uint32_t> atomic_uint32_{0};
};
} // namespace api
} // namespace nearby
#endif //LINUX_ATOMIC_BOOLEAN_H
@@ -0,0 +1,184 @@
/*
* This file was automatically generated by sdbus-c++-xml2cpp; DO NOT EDIT!
*/
#ifndef __sdbuscpp___home_lasan_Dev_nearby_latest_internal_platform_implementation_linux_generated_bluez_adapter_client_glue_h__proxy__H__
#define __sdbuscpp___home_lasan_Dev_nearby_latest_internal_platform_implementation_linux_generated_bluez_adapter_client_glue_h__proxy__H__
#include <sdbus-c++/sdbus-c++.h>
#include <string>
#include <tuple>
namespace org {
namespace bluez {
class Adapter1_proxy
{
public:
static constexpr const char* INTERFACE_NAME = "org.bluez.Adapter1";
protected:
Adapter1_proxy(sdbus::IProxy& proxy)
: proxy_(&proxy)
{
}
Adapter1_proxy(const Adapter1_proxy&) = delete;
Adapter1_proxy& operator=(const Adapter1_proxy&) = delete;
Adapter1_proxy(Adapter1_proxy&&) = default;
Adapter1_proxy& operator=(Adapter1_proxy&&) = default;
~Adapter1_proxy() = default;
public:
void StartDiscovery()
{
proxy_->callMethod("StartDiscovery").onInterface(INTERFACE_NAME);
}
void SetDiscoveryFilter(const std::map<std::string, sdbus::Variant>& properties)
{
proxy_->callMethod("SetDiscoveryFilter").onInterface(INTERFACE_NAME).withArguments(properties);
}
void StopDiscovery()
{
proxy_->callMethod("StopDiscovery").onInterface(INTERFACE_NAME);
}
void RemoveDevice(const sdbus::ObjectPath& device)
{
proxy_->callMethod("RemoveDevice").onInterface(INTERFACE_NAME).withArguments(device);
}
std::vector<std::string> GetDiscoveryFilters()
{
std::vector<std::string> result;
proxy_->callMethod("GetDiscoveryFilters").onInterface(INTERFACE_NAME).storeResultsTo(result);
return result;
}
void ConnectDevice(const std::map<std::string, sdbus::Variant>& properties)
{
proxy_->callMethod("ConnectDevice").onInterface(INTERFACE_NAME).withArguments(properties);
}
public:
std::string Address() const
{
return proxy_->getProperty("Address").onInterface(INTERFACE_NAME);
}
std::string AddressType()
{
return proxy_->getProperty("AddressType").onInterface(INTERFACE_NAME);
}
std::string Name()
{
return proxy_->getProperty("Name").onInterface(INTERFACE_NAME);
}
std::string Alias() const
{
return proxy_->getProperty("Alias").onInterface(INTERFACE_NAME);
}
void Alias(const std::string& value)
{
proxy_->setProperty("Alias").onInterface(INTERFACE_NAME).toValue(value);
}
uint32_t Class()
{
return proxy_->getProperty("Class").onInterface(INTERFACE_NAME);
}
bool Powered() const
{
return proxy_->getProperty("Powered").onInterface(INTERFACE_NAME);
}
void Powered(const bool& value)
{
proxy_->setProperty("Powered").onInterface(INTERFACE_NAME).toValue(value);
}
std::string PowerState()
{
return proxy_->getProperty("PowerState").onInterface(INTERFACE_NAME);
}
bool Discoverable() const
{
return proxy_->getProperty("Discoverable").onInterface(INTERFACE_NAME);
}
void Discoverable(const bool& value)
{
proxy_->setProperty("Discoverable").onInterface(INTERFACE_NAME).toValue(value);
}
uint32_t DiscoverableTimeout()
{
return proxy_->getProperty("DiscoverableTimeout").onInterface(INTERFACE_NAME);
}
void DiscoverableTimeout(const uint32_t& value)
{
proxy_->setProperty("DiscoverableTimeout").onInterface(INTERFACE_NAME).toValue(value);
}
bool Pairable()
{
return proxy_->getProperty("Pairable").onInterface(INTERFACE_NAME);
}
void Pairable(const bool& value)
{
proxy_->setProperty("Pairable").onInterface(INTERFACE_NAME).toValue(value);
}
uint32_t PairableTimeout()
{
return proxy_->getProperty("PairableTimeout").onInterface(INTERFACE_NAME);
}
void PairableTimeout(const uint32_t& value)
{
proxy_->setProperty("PairableTimeout").onInterface(INTERFACE_NAME).toValue(value);
}
bool Discovering()
{
return proxy_->getProperty("Discovering").onInterface(INTERFACE_NAME);
}
std::vector<std::string> UUIDs()
{
return proxy_->getProperty("UUIDs").onInterface(INTERFACE_NAME);
}
std::string Modalias()
{
return proxy_->getProperty("Modalias").onInterface(INTERFACE_NAME);
}
std::vector<std::string> Roles()
{
return proxy_->getProperty("Roles").onInterface(INTERFACE_NAME);
}
std::vector<std::string> ExperimentalFeatures()
{
return proxy_->getProperty("ExperimentalFeatures").onInterface(INTERFACE_NAME);
}
private:
sdbus::IProxy* proxy_;
};
}} // namespaces
#endif
@@ -0,0 +1,90 @@
#ifndef PLATFORM_IMPL_LINUX_MULTI_THREAD_EXECUTOR_H_
#define PLATFORM_IMPL_LINUX_MULTI_THREAD_EXECUTOR_H_
#include <atomic>
#include <condition_variable>
#include <cstddef>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
#include "internal/platform/implementation/submittable_executor.h"
#include "internal/platform/runnable.h"
namespace nearby {
namespace linux {
class MultiThreadExecutor : public api::SubmittableExecutor {
public:
explicit MultiThreadExecutor(int max_parallelism)
: shutdown_(false) {
for (int i = 0; i < max_parallelism; ++i) {
workers_.emplace_back([this]() { WorkerLoop(); });
}
}
~MultiThreadExecutor() override {
Shutdown();
for (auto& worker : workers_) {
if (worker.joinable()) worker.join();
}
}
void Schedule(Runnable&& runnable, absl::Duration delay) {
if (shutdown_) return;
std::thread([this, runnable = std::move(runnable), delay]() mutable {
std::this_thread::sleep_for(std::chrono::nanoseconds(
absl::ToInt64Nanoseconds(delay))); // delaying execution
DoSubmit(std::move(runnable));
}).detach();
}
void Execute(Runnable&& runnable) override {
DoSubmit(std::move(runnable));
}
bool DoSubmit(Runnable&& runnable) override {
{
std::lock_guard<std::mutex> lock(mutex_);
if (shutdown_) return false;
tasks_.emplace(std::move(runnable));
}
cv_.notify_one();
return true;
}
void Shutdown() override {
{
std::lock_guard<std::mutex> lock(mutex_);
shutdown_ = true;
}
cv_.notify_all();
}
private:
void WorkerLoop() {
while (true) {
Runnable task;
{
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return shutdown_ || !tasks_.empty(); });
if (shutdown_ && tasks_.empty()) return;
task = std::move(tasks_.front());
tasks_.pop();
}
if (task) task();
}
}
std::vector<std::thread> workers_;
std::queue<Runnable> tasks_;
std::mutex mutex_;
std::condition_variable cv_;
std::atomic<bool> shutdown_;
};
} // namespace linux
} // namespace nearby
#endif // PLATFORM_IMPL_LINUX_MULTI_THREAD_EXECUTOR_H_