use super::base::{Id, NSString};
use objc::rc::StrongPtr;
use objc::runtime::YES;
use objc::{class, msg_send, sel, sel_impl};
pub trait VZDirectorySharingDeviceConfiguration {
fn id(&self) -> Id;
}
pub struct VZVirtioFileSystemDeviceConfiguration(StrongPtr);
impl VZVirtioFileSystemDeviceConfiguration {
pub fn new(tag: &str) -> Self {
unsafe {
let tag_ns = NSString::new(tag);
let alloc: Id = msg_send![class!(VZVirtioFileSystemDeviceConfiguration), alloc];
let p = StrongPtr::new(msg_send![alloc, initWithTag:*tag_ns.0]);
VZVirtioFileSystemDeviceConfiguration(p)
}
}
pub fn set_share(&mut self, share: VZSingleDirectoryShare) {
unsafe {
let _: () = msg_send![*self.0, setShare:*share.0];
}
}
}
impl VZDirectorySharingDeviceConfiguration for VZVirtioFileSystemDeviceConfiguration {
fn id(&self) -> Id {
*self.0
}
}
pub struct VZSingleDirectoryShare(StrongPtr);
impl VZSingleDirectoryShare {
pub fn new(directory: VZSharedDirectory) -> Self {
unsafe {
let alloc: Id = msg_send![class!(VZSingleDirectoryShare), alloc];
let p = StrongPtr::new(msg_send![alloc, initWithDirectory:*directory.0]);
VZSingleDirectoryShare(p)
}
}
}
pub struct VZSharedDirectory(StrongPtr);
impl VZSharedDirectory {
pub fn new(path: &str, read_only: bool) -> Self {
unsafe {
let url = super::base::NSURL::file_url_with_path(path, true);
let ro = if read_only { YES } else { objc::runtime::NO };
let alloc: Id = msg_send![class!(VZSharedDirectory), alloc];
let p = StrongPtr::new(msg_send![alloc, initWithURL:*url.0 readOnly:ro]);
VZSharedDirectory(p)
}
}
}