cobia/
cape_registrar.rs

1use crate::C;
2use crate::*;
3
4/// Rust wrapper for ICapePMCRegistrar interface
5///
6/// A CapeRegistrar object is passed to the `registration_details` function
7/// of the `CapePMC` trait implementation. It is used to register the component
8/// in the COBIA registry.
9
10pub struct CapeRegistrar {
11	/// Pointer to the ICapePMCRegistrar interface
12	pub(crate) interface: *mut C::ICapePMCRegistrar,
13}
14
15impl CapeRegistrar {
16
17	/// Put the (default) name of the component
18	///
19	/// # Arguments
20	/// * `name` - The name of the component
21	///
22	/// # Returns
23	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
24
25	pub fn put_name(&self, name: &str) -> Result<(), COBIAError> {
26		let result = unsafe {
27			((*(*self.interface).vTbl).putName.unwrap())(
28				(*self.interface).me,
29				CapeStringImpl::from_string(name)
30					.as_capechar_const()
31					.cast_mut(),
32			)
33		};
34		if result == COBIAERR_NOERROR {
35			Ok(())
36		} else {
37			Err(COBIAError::Code(result))
38		}
39	}
40
41	/// Put the (default) description of the component
42	///
43	/// # Arguments
44	/// * `description` - The description of the component
45	///
46	/// # Returns
47	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
48
49	pub fn put_description(&self, description: &str) -> Result<(), COBIAError> {
50		let result = unsafe {
51			((*(*self.interface).vTbl).putDescription.unwrap())(
52				(*self.interface).me,
53				CapeStringImpl::from_string(description)
54					.as_capechar_const()
55					.cast_mut(),
56			)
57		};
58		if result == COBIAERR_NOERROR {
59			Ok(())
60		} else {
61			Err(COBIAError::Code(result))
62		}
63	}
64
65	/// Put the CAPE-OPEN version of the component
66	///
67	/// # Arguments
68	/// * `cape_version` - The CAPE-OPEN version of the component, e.g. "1.2"
69	///
70	/// # Returns
71	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
72
73	pub fn put_cape_version(&self, cape_version: &str) -> Result<(), COBIAError> {
74		let result = unsafe {
75			((*(*self.interface).vTbl).putCapeVersion.unwrap())(
76				(*self.interface).me,
77				CapeStringImpl::from_string(cape_version)
78					.as_capechar_const()
79					.cast_mut(),
80			)
81		};
82		if result == COBIAERR_NOERROR {
83			Ok(())
84		} else {
85			Err(COBIAError::Code(result))
86		}
87	}
88
89	/// Put the component software version
90	///
91	/// # Arguments
92	/// * `component_version` - The version of the component, e.g. "1.0.0"
93	///
94	/// # Returns
95	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
96
97	pub fn put_component_version(&self, component_version: &str) -> Result<(), COBIAError> {
98		let result = unsafe {
99			((*(*self.interface).vTbl).putComponentVersion.unwrap())(
100				(*self.interface).me,
101				CapeStringImpl::from_string(component_version)
102					.as_capechar_const()
103					.cast_mut(),
104			)
105		};
106		if result == COBIAERR_NOERROR {
107			Ok(())
108		} else {
109			Err(COBIAError::Code(result))
110		}
111	}
112
113	/// Put the vendor URL of the component
114	///
115	/// # Arguments
116	/// * `vendor_url` - The URL of the vendor's product website
117	///
118	/// # Returns
119	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
120
121	pub fn put_vendor_url(&self, vendor_url: &str) -> Result<(), COBIAError> {
122		let result = unsafe {
123			((*(*self.interface).vTbl).putVendorURL.unwrap())(
124				(*self.interface).me,
125				CapeStringImpl::from_string(vendor_url)
126					.as_capechar_const()
127					.cast_mut(),
128			)
129		};
130		if result == COBIAERR_NOERROR {
131			Ok(())
132		} else {
133			Err(COBIAError::Code(result))
134		}
135	}
136
137	/// Put the help URL of the component
138	///
139	/// # Arguments
140	/// * `help_url` - The URL of the component's help documentation
141	///
142	/// # Returns
143	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
144
145	pub fn put_help_url(&self, help_url: &str) -> Result<(), COBIAError> {
146		let result = unsafe {
147			((*(*self.interface).vTbl).putHelpURL.unwrap())(
148				(*self.interface).me,
149				CapeStringImpl::from_string(help_url)
150					.as_capechar_const()
151					.cast_mut(),
152			)
153		};
154		if result == COBIAERR_NOERROR {
155			Ok(())
156		} else {
157			Err(COBIAError::Code(result))
158		}
159	}
160
161	/// Put the about information of the component
162	///
163	/// # Arguments
164	/// * `about` - The about information of the component, typically a short description
165	///
166	/// # Returns
167	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
168
169	pub fn put_about(&self, about: &str) -> Result<(), COBIAError> {
170		let result = unsafe {
171			((*(*self.interface).vTbl).putAbout.unwrap())(
172				(*self.interface).me,
173				CapeStringImpl::from_string(about)
174					.as_capechar_const()
175					.cast_mut(),
176			)
177		};
178		if result == COBIAERR_NOERROR {
179			Ok(())
180		} else {
181			Err(COBIAError::Code(result))
182		}
183	}
184
185	/// Put the UUID of the component
186	///
187	/// # Arguments
188	/// * `uuid` - The UUID of the component, a unique identifier to identify the component
189	///
190	/// # Returns
191	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
192
193	pub fn put_uuid(&self, uuid: &CapeUUID) -> Result<(), COBIAError> {
194		let result = unsafe {
195			((*(*self.interface).vTbl).putUUID.unwrap())(
196				(*self.interface).me,
197				uuid as *const C::CapeUUID,
198			)
199		};
200		if result == COBIAERR_NOERROR {
201			Ok(())
202		} else {
203			Err(COBIAError::Code(result))
204		}
205	}
206
207	/// Put the ProgID of the component
208	///
209	/// The ProgID is a programmatic human readable ID that is a placeholder for the component's UUID.
210	///
211	/// The ProgID points to this specific version of the component. The version-independent ProgID
212	/// is used to identify the component regardless of its version.
213	///
214	/// # Arguments
215	/// * `prog_id` - The ProgID of the component, a string identifier used in COM
216
217	pub fn put_prog_id(&self, prog_id: &str) -> Result<(), COBIAError> {
218		let result = unsafe {
219			((*(*self.interface).vTbl).putProgId.unwrap())(
220				(*self.interface).me,
221				CapeStringImpl::from_string(prog_id)
222					.as_capechar_const()
223					.cast_mut(),
224			)
225		};
226		if result == COBIAERR_NOERROR {
227			Ok(())
228		} else {
229			Err(COBIAError::Code(result))
230		}
231	}
232
233	/// Put the version-independent ProgID of the component
234	///
235	/// The version-independent ProgID is used to identify the component regardless of its version.
236	/// If a PME chooses to store this information, a subsequent software update of the component
237	/// will cause the PME to update to the new version.
238	///s
239	/// # Arguments
240	/// * `prog_id` - The version-independent ProgID of the component, a string identifier used in COM
241	///
242	/// # Returns
243	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
244
245	pub fn put_version_independent_prog_id(&self, prog_id: &str) -> Result<(), COBIAError> {
246		let result = unsafe {
247			((*(*self.interface).vTbl)
248				.putVersionIndependentProgId
249				.unwrap())(
250				(*self.interface).me,
251				CapeStringImpl::from_string(prog_id)
252					.as_capechar_const()
253					.cast_mut(),
254			)
255		};
256		if result == COBIAERR_NOERROR {
257			Ok(())
258		} else {
259			Err(COBIAError::Code(result))
260		}
261	}
262
263	/// Add a category ID to the component
264	///
265	/// Typically a PMC registers with at least one category ID to indicate the type of component
266	/// it is, such as a unit operation, property set, or data type. Also at least one category ID
267	/// should be added to identify which CAPE-OPEN version the component supports.
268	///
269	/// # Arguments
270	/// * `cat_id` - The category ID to add, a unique identifier for the component's category
271	///
272	/// # Returns
273	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
274
275	pub fn add_cat_id(&self, cat_id: &CapeUUID) -> Result<(), COBIAError> {
276		let result = unsafe {
277			((*(*self.interface).vTbl).addCatID.unwrap())(
278				(*self.interface).me,
279				cat_id as *const C::CapeUUID,
280			)
281		};
282		if result == COBIAERR_NOERROR {
283			Ok(())
284		} else {
285			Err(COBIAError::Code(result))
286		}
287	}
288
289	/// Put the creation flags for the component
290	///
291	/// If the component has specific restrictions, such as being suitable only
292	/// for the restricted threading model, this method can be used to set those flags.
293	///
294	/// # Arguments
295	/// * `flags` - The flags to set, indicating the component's creation restrictions
296	///
297	/// # Returns
298	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
299
300	pub fn put_flags(&self, flags: CapePMCRegistrationFlags) -> Result<(), COBIAError> {
301		let result = unsafe {
302			((*(*self.interface).vTbl).putFlags.unwrap())((*self.interface).me, flags.bits())
303		};
304		if result == COBIAERR_NOERROR {
305			Ok(())
306		} else {
307			Err(COBIAError::Code(result))
308		}
309	}
310
311	/// Add a location for the component
312	///
313	/// Components can be registered for multiple service types,
314	/// such as 32-bit and 64-bit versions for Windows. Eeach
315	/// service type has its own location identifier, such as a
316	/// DLL or shared object for an in-process implementation.
317	///
318	/// # Arguments
319	/// * `service_type` - The service type for which the location is being registered
320	/// * `location` - The location identifier, such as a DLL path
321	///
322	/// # Returns
323	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
324
325	pub fn add_location(
326		&self,
327		service_type: CapePMCServiceType,
328		location: &str,
329	) -> Result<(), COBIAError> {
330		let result = unsafe {
331			((*(*self.interface).vTbl).addLocation.unwrap())(
332				(*self.interface).me,
333				service_type as i32,
334				CapeStringImpl::from_string(location)
335					.as_capechar_const()
336					.cast_mut(),
337			)
338		};
339		if result == COBIAERR_NOERROR {
340			Ok(())
341		} else {
342			Err(COBIAError::Code(result))
343		}
344	}
345
346	/// Commit the registration of the component
347	///
348	/// After all the necessary information has been provided, this method is called to finalize
349	/// registration.
350	///
351	/// # Returns
352	/// * Result<(), COBIAError> - Ok if successful, Err if there was an error
353
354	pub fn commit(&self) -> Result<(), COBIAError> {
355		let result = unsafe { ((*(*self.interface).vTbl).commit.unwrap())((*self.interface).me) };
356		if result == COBIAERR_NOERROR {
357			Ok(())
358		} else {
359			Err(COBIAError::Code(result))
360		}
361	}
362}
363
364/// Release pointer
365///
366/// ICapeRegistrar derives from ICobiaBase, which contains
367/// addReference() and release(). The Drop trait calls release.
368
369impl Drop for CapeRegistrar {
370	fn drop(&mut self) {
371		unsafe {
372			((*(*self.interface).vTbl).base.release.unwrap())((*self.interface).me);
373		}
374	}
375}
376
377/// Add pointer reference
378///
379/// ICapeRegistrar derives from ICobiaBase, which contains
380/// addReference() and release(). The Clone trait calls addReference.
381
382impl Clone for CapeRegistrar {
383	fn clone(&self) -> Self {
384		unsafe {
385			((*(*self.interface).vTbl).base.addReference.unwrap())((*self.interface).me);
386		}
387		CapeRegistrar {
388			interface: self.interface,
389		}
390	}
391}