const std = @import("std"); const mem = std.mem; const heap = std.heap; const c = @import("libvirt-c.zig").c; ptr: c.virConnectPtr, allocator: mem.Allocator, pub fn connect(uri: []const u8, allocator: mem.Allocator) VirError!Connection { const connection = c.virConnectOpenAuth(@ptrCast(uri), c.virConnectAuthPtrDefault, 0); if (connection) |conn| return .{ .ptr = conn, .allocator = allocator, } else return handleError(); } pub fn close(self: *const Connection) void { _ = c.virConnectClose(self.ptr); } // pub fn getURI(self: *const Connection) ![]u8 { // const uri = c.virConnectGetURI(self.ptr); // defer std.c.free(uri); // const str = string(uri); // return if (str.len == 0) handleError() else try self.allocator.dupe(u8, str); // } // pub fn freeURI(self: *const Connection, uri: []u8) void { // self.allocator.free(uri); // } // pub fn numOfPools(self: *const Connection) !u32 { // return numOf(c.virConnectPtr, self.ptr, c.virConnectNumOfStoragePools); // } // pub fn numOfDefinedPools(self: *const Connection) !u32 { // return numOf(c.virConnectPtr, self.ptr, c.virConnectNumOfDefinedStoragePools); // } // pub fn iteratePools(self: *const Connection, flags: []const Pool.ListFlags) !Pool.PoolIterator { // return Pool.PoolIterator.init( // c.virConnect, // Connection, // Pool.ListFlags, // self, // flags, // self.allocator, // c.virConnectListAllStoragePools, // ); // } // pub fn createPool(self: *const Connection, xml: String, flags: []const Pool.CreateFlags) !Pool { // const pool = c.virStoragePoolCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Pool.CreateFlags, flags)); // return if (pool) |p| Pool.init(p, self.allocator) else handleError(); // } // pub fn definePoolFlags(self: *const Connection, xml: String, flags: []const Pool.DefineFlags) !Pool { // const pool = c.virStoragePoolCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Pool.DefineFlags, flags)); // return if (pool) |p| Pool.init(p, self.allocator) else handleError(); // } // pub fn numOfDomains(self: *const Connection) !u32 { // return numOf(c.virConnectPtr, self.ptr, c.virConnectNumOfDomains); // } // pub fn numOfDefinedDomains(self: *const Connection) !u32 { // return numOf(c.virConnectPtr, self.ptr, c.virConnectNumOfDefinedDomains); // } // pub fn iterateDomains(self: *const Connection, flags: []const Domain.ListFlags) !Domain.DomainIterator { // return Domain.DomainIterator.init( // c.virConnect, // Connection, // Domain.ListFlags, // self, // flags, // self.allocator, // c.virConnectListAllDomains, // ); // } // pub fn createDomain(self: *const Connection, xml: String, flags: []const Domain.CreateFlags) !Domain { // const domain = c.virDomainCreateXML(self.ptr, @ptrCast(xml.str), intFromFlags(Domain.CreateFlags, flags)); // return if (domain) |d| Domain.init(d, self.allocator) else handleError(); // } // pub fn defineDomain(self: *const Connection, xml: String) !Domain { // const domain = c.virDomainDefineXML(self.ptr, @ptrCast(xml.str)); // return if (domain) |d| Domain.init(d, self.allocator) else handleError(); // } // pub fn defineDomainFlags(self: *const Connection, xml: String, flags: []const Domain.DefineFlags) !Domain { // const domain = c.virDomainDefineXMLFlags(self.ptr, @ptrCast(xml.str), intFromFlags(Domain.DefineFlags, flags)); // return if (domain) |d| Domain.init(d, self.allocator) else handleError(); // }