1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use std::borrow::Cow;
use std::ffi::CStr;
use std::marker::PhantomData;
use std::mem;
use ::libc::c_void;
#[derive(Debug,PartialEq,Eq,Clone,Copy,Hash)]
pub enum PortType {
Serial,
USB,
Disk,
PTPIP,
Direct,
SCSI,
Other,
}
pub struct Port<'a> {
inner: ::gphoto2::GPPortInfo,
__phantom: PhantomData<&'a c_void>,
}
impl<'a> Port<'a> {
pub fn port_type(&self) -> PortType {
let mut port_type = unsafe { mem::uninitialized() };
unsafe {
assert_eq!(::gphoto2::GP_OK, ::gphoto2::gp_port_info_get_type(self.inner, &mut port_type));
}
match port_type {
::gphoto2::GP_PORT_SERIAL => PortType::Serial,
::gphoto2::GP_PORT_USB => PortType::USB,
::gphoto2::GP_PORT_DISK => PortType::Disk,
::gphoto2::GP_PORT_PTPIP => PortType::PTPIP,
::gphoto2::GP_PORT_USB_DISK_DIRECT => PortType::Direct,
::gphoto2::GP_PORT_USB_SCSI => PortType::SCSI,
::gphoto2::GP_PORT_NONE | _ => PortType::Other,
}
}
pub fn name(&self) -> Cow<str> {
let mut name = unsafe { mem::uninitialized() };
unsafe {
assert_eq!(::gphoto2::GP_OK, ::gphoto2::gp_port_info_get_name(self.inner, &mut name));
String::from_utf8_lossy(CStr::from_ptr(name).to_bytes())
}
}
pub fn path(&self) -> Cow<str> {
let mut path = unsafe { mem::uninitialized() };
unsafe {
assert_eq!(::gphoto2::GP_OK, ::gphoto2::gp_port_info_get_path(self.inner, &mut path));
String::from_utf8_lossy(CStr::from_ptr(path).to_bytes())
}
}
}
#[doc(hidden)]
pub fn from_libgphoto2<'a>(_camera: &'a ::camera::Camera, ptr: ::gphoto2::GPPortInfo) -> Port<'a> {
Port {
inner: ptr,
__phantom: PhantomData,
}
}