Add heartbeat cpp bindings

This commit is contained in:
Jackson Coxson
2025-09-30 19:02:56 -06:00
parent 9ed4cd8a55
commit c6d63d1f5d
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
#pragma once
#include <idevice++/bindings.hpp>
#include <idevice++/ffi.hpp>
#include <idevice++/provider.hpp>
#include <memory>
#include <sys/_types/_u_int64_t.h>
namespace IdeviceFFI {
using HeartbeatPtr =
std::unique_ptr<HeartbeatClientHandle, FnDeleter<HeartbeatClientHandle, heartbeat_client_free>>;
class Heartbeat {
public:
// Factory: connect via Provider
static Result<Heartbeat, FfiError> connect(Provider& provider);
// Factory: wrap an existing Idevice socket (consumes it on success)
static Result<Heartbeat, FfiError> from_socket(Idevice&& socket);
// Ops
Result<void, FfiError> send_polo();
Result<u_int64_t, FfiError> get_marco(u_int64_t interval);
// RAII / moves
~Heartbeat() noexcept = default;
Heartbeat(Heartbeat&&) noexcept = default;
Heartbeat& operator=(Heartbeat&&) noexcept = default;
Heartbeat(const Heartbeat&) = delete;
Heartbeat& operator=(const Heartbeat&) = delete;
HeartbeatClientHandle* raw() const noexcept { return handle_.get(); }
static Heartbeat adopt(HeartbeatClientHandle* h) noexcept { return Heartbeat(h); }
private:
explicit Heartbeat(HeartbeatClientHandle* h) noexcept : handle_(h) {}
HeartbeatPtr handle_{};
};
} // namespace IdeviceFFI

48
cpp/src/heartbeat.cpp Normal file
View File

@@ -0,0 +1,48 @@
// Jackson Coxson
#include <idevice++/bindings.hpp>
#include <idevice++/ffi.hpp>
#include <idevice++/heartbeat.hpp>
#include <idevice++/provider.hpp>
#include <sys/_types/_u_int64_t.h>
namespace IdeviceFFI {
Result<Heartbeat, FfiError> Heartbeat::connect(Provider& provider) {
HeartbeatClientHandle* out = nullptr;
FfiError e(::heartbeat_connect(provider.raw(), &out));
if (e) {
provider.release();
return Err(e);
}
return Ok(Heartbeat::adopt(out));
}
Result<Heartbeat, FfiError> Heartbeat::from_socket(Idevice&& socket) {
HeartbeatClientHandle* out = nullptr;
FfiError e(::heartbeat_new(socket.raw(), &out));
if (e) {
return Err(e);
}
socket.release();
return Ok(Heartbeat::adopt(out));
}
Result<void, FfiError> Heartbeat::send_polo() {
FfiError e(::heartbeat_send_polo(handle_.get()));
if (e) {
return Err(e);
}
return Ok();
}
Result<u_int64_t, FfiError> Heartbeat::get_marco(u_int64_t interval) {
u_int64_t new_interval = 0;
FfiError e(::heartbeat_get_marco(handle_.get(), interval, &new_interval));
if (e) {
return Err(e);
}
return Ok(new_interval);
}
} // namespace IdeviceFFI