mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Add heartbeat cpp bindings
This commit is contained in:
40
cpp/include/idevice++/heartbeat.hpp
Normal file
40
cpp/include/idevice++/heartbeat.hpp
Normal 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
48
cpp/src/heartbeat.cpp
Normal 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
|
||||||
Reference in New Issue
Block a user