mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Separate headers into cpp source files
This commit is contained in:
63
cpp/include/idevice++/idevice.hpp
Normal file
63
cpp/include/idevice++/idevice.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Jackson Coxson
|
||||
|
||||
#ifndef IDEVICE_CPP
|
||||
#define IDEVICE_CPP
|
||||
|
||||
#include <idevice++/ffi.hpp>
|
||||
#include <idevice++/pairing_file.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// MSVC doesn't have BSD u_int* types
|
||||
using u_int8_t = std::uint8_t;
|
||||
using u_int16_t = std::uint16_t;
|
||||
using u_int32_t = std::uint32_t;
|
||||
using u_int64_t = std::uint64_t;
|
||||
#endif
|
||||
|
||||
namespace IdeviceFFI {
|
||||
|
||||
// Generic “bind a free function” deleter
|
||||
template <class T, void (*FreeFn)(T*)> struct FnDeleter {
|
||||
void operator()(T* p) const noexcept {
|
||||
if (p)
|
||||
FreeFn(p);
|
||||
}
|
||||
};
|
||||
|
||||
using IdevicePtr = std::unique_ptr<IdeviceHandle, FnDeleter<IdeviceHandle, idevice_free>>;
|
||||
|
||||
class Idevice {
|
||||
public:
|
||||
static std::optional<Idevice>
|
||||
create(IdeviceSocketHandle* socket, const std::string& label, FfiError& err);
|
||||
|
||||
static std::optional<Idevice>
|
||||
create_tcp(const sockaddr* addr, socklen_t addr_len, const std::string& label, FfiError& err);
|
||||
|
||||
// Methods
|
||||
std::optional<std::string> get_type(FfiError& err) const;
|
||||
bool rsd_checkin(FfiError& err);
|
||||
bool start_session(const PairingFile& pairing_file, FfiError& err);
|
||||
|
||||
// Ownership/RAII
|
||||
~Idevice() noexcept = default;
|
||||
Idevice(Idevice&&) noexcept = default;
|
||||
Idevice& operator=(Idevice&&) noexcept = default;
|
||||
Idevice(const Idevice&) = delete;
|
||||
Idevice& operator=(const Idevice&) = delete;
|
||||
|
||||
static Idevice adopt(IdeviceHandle* h) noexcept { return Idevice(h); }
|
||||
|
||||
// Accessor
|
||||
IdeviceHandle* raw() const noexcept { return handle_.get(); }
|
||||
IdeviceHandle* release() noexcept { return handle_.release(); }
|
||||
|
||||
private:
|
||||
explicit Idevice(IdeviceHandle* h) noexcept : handle_(h) {}
|
||||
IdevicePtr handle_{};
|
||||
};
|
||||
|
||||
} // namespace IdeviceFFI
|
||||
#endif
|
||||
Reference in New Issue
Block a user