cobia/cobia_identification.rs
1use crate::C;
2use crate::*;
3use cape_smart_pointer::CapeSmartPointer;
4
5const ICOBIAIDENTIFICATION_UUID:CapeUUID=CapeUUID::from_slice(&[0xa9u8,0xb3u8,0x9eu8,0x4au8,0x7du8,0x48u8,0x40u8,0x81u8,0xa1u8,0x7fu8,0x65u8,0x22u8,0x82u8,0x40u8,0x85u8,0xb5u8]);
6
7/// CobiaIdentification interface smart pointer
8///
9/// Smart pointer for ICobiaIdentification interface.
10///
11/// ICobiaIdentification is typically implemented
12/// in objects in ICobiaCollections.
13
14#[cape_smart_pointer(ICOBIAIDENTIFICATION_UUID)]
15pub struct CobiaIdentification {
16 pub(crate) interface: *mut C::ICobiaIdentification,
17}
18
19impl CobiaIdentification {
20
21 /// Create a new CobiaIdentification from an interface pointer
22 ///
23 /// Not typically called directly. Used by CapeSmartPointer.
24 ///
25 /// # Safety
26 ///
27 /// The interface pointer must be valid and must point to an object
28 /// that implements the ICobiaIdentification interface.
29 ///
30 /// # Panics
31 ///
32 /// Panics if the interface pointer is null.
33 ///
34 /// # Example
35 ///
36 /// ```
37 /// use cobia::*;
38 /// use cobia::prelude::*;
39 /// cobia::cape_open_initialize().unwrap();
40 /// let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
41 /// let libraries = library_enumerator.libraries().unwrap();
42 /// if libraries.size() > 0 {
43 /// let library = libraries.at(0).unwrap();
44 /// println!("Library name: {}", library.get_name().unwrap());
45 /// //create CobiaIdentification from library, undirectly calls from_interface_pointer()
46 /// let iden = cobia::CobiaIdentification::from_object(&library).unwrap();
47 /// println!("Library name: {}", iden.get_component_name().unwrap());
48 /// }
49 /// cobia::cape_open_cleanup();
50 /// ```
51
52 pub(crate) fn from_interface_pointer(interface: *mut C::ICobiaIdentification) -> Self {
53 if interface.is_null() {
54 panic!("Null pointer in creation of CobiaIdentification");
55 }
56 unsafe {((*(*interface).vTbl).base.addReference.unwrap())((*interface).me)};
57 Self {
58 interface
59 }
60 }
61
62 /// Create a new CobiaIdentification from an interface pointer without adding a reference
63 ///
64 /// Not typically called directly. Used by CapeSmartPointer.
65 ///
66 /// # Safety
67 ///
68 /// The interface pointer must be valid and must point to an object
69 /// that implements the ICobiaIdentification interface.
70 ///
71 /// # Panics
72 ///
73 /// Panics if the interface pointer is null.
74
75 pub(crate) fn attach(interface: *mut C::ICobiaIdentification) -> Self {
76 if interface.is_null() {
77 panic!("Null pointer in creation of CobiaIdentification");
78 }
79 Self {
80 interface
81 }
82 }
83
84 /// Get the component name
85 ///
86 /// Gets the name of the component
87 ///
88 /// # Example
89 ///
90 /// ```
91 /// use cobia::*;
92 /// use cobia::prelude::*;
93 /// cobia::cape_open_initialize().unwrap();
94 /// let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
95 /// let libraries = library_enumerator.libraries().unwrap();
96 /// if libraries.size() > 0 {
97 /// let library = libraries.at(0).unwrap();
98 /// println!("Library name: {}", library.get_name().unwrap());
99 /// let iden = cobia::CobiaIdentification::from_object(&library).unwrap();
100 /// println!("Library name: {}", iden.get_component_name().unwrap());
101 /// }
102 /// cobia::cape_open_cleanup();
103 /// ```
104
105 pub fn get_component_name(&self) -> Result<String, COBIAError> {
106 let mut name = CapeStringImpl::new();
107 let result = unsafe {
108 ((*(*self.interface).vTbl).getComponentName.unwrap())((*self.interface).me, (&name.as_cape_string_out() as *const C::ICapeString).cast_mut())
109 };
110 if result == COBIAERR_NOERROR {
111 Ok(name.as_string())
112 } else {
113 Err(COBIAError::from_object(result,self))
114 }
115 }
116
117 /// Set the component name
118 ///
119 /// Sets the name of the component; typically disallowed.
120 ///
121 /// Only primary PMC objects typically allow for a name change.
122 ///
123 /// This interface however is implemented on object from ICobiaCollection.
124 /// The put_component_name method is typically not implemented on objects.
125
126 pub fn put_component_name(&self,name: &str) -> Result<(), COBIAError> {
127 let name=CapeStringImpl::from(name);
128 let result = unsafe {
129 ((*(*self.interface).vTbl).getComponentName.unwrap())((*self.interface).me, (&name.as_cape_string_in() as *const C::ICapeString).cast_mut())
130 };
131 if result == COBIAERR_NOERROR {
132 Ok(())
133 } else {
134 Err(COBIAError::from_object(result,self))
135 }
136 }
137
138 /// Get the component description
139 ///
140 /// Gets the description of the component
141 ///
142 /// # Example
143 ///
144 /// ```
145 /// use cobia::*;
146 /// use cobia::prelude::*;
147 /// cobia::cape_open_initialize().unwrap();
148 /// let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
149 /// let libraries = library_enumerator.libraries().unwrap();
150 /// if libraries.size() > 0 {
151 /// let library = libraries.at(0).unwrap();
152 /// println!("Library name: {}", library.get_name().unwrap());
153 /// let iden = cobia::CobiaIdentification::from_object(&library).unwrap();
154 /// println!("Library description: {}", iden.get_component_description().unwrap());
155 /// }
156 /// cobia::cape_open_cleanup();
157 /// ```
158
159
160 pub fn get_component_description(&self) -> Result<String, COBIAError> {
161 let mut description = CapeStringImpl::new();
162 let result = unsafe {
163 ((*(*self.interface).vTbl).getComponentDescription.unwrap())((*self.interface).me, (&description.as_cape_string_out() as *const C::ICapeString).cast_mut())
164 };
165 if result == COBIAERR_NOERROR {
166 Ok(description.as_string())
167 } else {
168 Err(COBIAError::from_object(result,self))
169 }
170 }
171
172 /// Set the component description
173 ///
174 /// Sets the description of the component; typically disallowed.
175 ///
176 /// Only primary PMC objects typically allow for a description change.
177 ///
178 /// This interface however is implemented on object from ICobiaCollection.
179 /// The put_component_description method is typically not implemented on objects.
180
181
182 pub fn put_component_description(&self,description: &str) -> Result<(), COBIAError> {
183 let description=CapeStringImpl::from(description);
184 let result = unsafe {
185 ((*(*self.interface).vTbl).getComponentDescription.unwrap())((*self.interface).me,(&description.as_cape_string_in() as *const C::ICapeString).cast_mut())
186 };
187 if result == COBIAERR_NOERROR {
188 Ok(())
189 } else {
190 Err(COBIAError::from_object(result,self))
191 }
192 }
193
194}
195