cobia/cape_pmc_registration_details.rs
1use crate::C;
2use crate::*;
3use cape_smart_pointer::CapeSmartPointer;
4
5const ICAPEPMCREGISTRATIONDETAILS_UUID:CapeUUID=CapeUUID::from_slice(&[0x0eu8,0x6eu8,0x73u8,0xefu8,0xdcu8,0x77u8,0x4au8,0xcbu8,0x90u8,0x74u8,0xbbu8,0xfcu8,0x8du8,0xcbu8,0x05u8,0xe2u8]);
6
7/// PMC registration details
8///
9/// The PMC registration details are for a PMC reveal the registration
10/// of the PMC in the registry.
11///
12/// The PMC registration details can be used to create a PMC.
13///
14/// Selection of a PMC is typically done by the user, and the PME
15/// offers a list of PMCs to choose from by enumerating the PMCs
16/// of a particular kind.
17///
18/// #Example
19///
20/// ```
21/// use cobia;
22/// use cobia::prelude::*;
23/// cobia::cape_open_initialize().unwrap();
24/// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
25/// for pmc in pmc_enumerator.all_pmcs().unwrap() {
26/// println!("PMC: {}",pmc.get_name().unwrap());
27/// }
28/// cobia::cape_open_cleanup();
29/// ```
30
31#[cape_smart_pointer(ICAPEPMCREGISTRATIONDETAILS_UUID)]
32pub struct CapePMCRegistrationDetails {
33 pub(crate) interface: *mut C::ICapePMCRegistrationDetails,
34}
35
36impl CapePMCRegistrationDetails {
37
38 /// Create a new CapePMCRegistrationDetails from an interface pointer
39 ///
40 /// This member is not typically called. Instead, the CapePMCRegistrationDetails is created by the API functions that return it.
41 ///
42 /// # Safety
43 ///
44 /// The interface pointer must be valid and must point to an object that implements the ICapePMCRegistrationDetails interface.
45 ///
46 /// # Panics
47 ///
48 /// This function panics if the interface pointer is null.
49
50 pub(crate) fn from_interface_pointer(interface: *mut C::ICapePMCRegistrationDetails) -> Self {
51 if interface.is_null() {
52 panic!("Null pointer in creation of CapePMCRegistrationDetails");
53 }
54 unsafe {((*(*interface).vTbl).base.addReference.unwrap())((*interface).me)};
55 Self {
56 interface
57 }
58 }
59
60 /// Create a new CapePMCRegistrationDetails from an interface pointer without adding a reference
61 ///
62 /// This member is not typically called. Instead, the CapePMCRegistrationDetails is created by the API functions that return it.
63 ///
64 /// # Safety
65 ///
66 /// The interface pointer must be valid and must point to an object that implements the ICapePMCRegistrationDetails interface.
67 ///
68 /// # Panics
69 ///
70 /// This function panics if the interface pointer is null.
71
72 pub(crate) fn attach(interface: *mut C::ICapePMCRegistrationDetails) -> Self {
73 if interface.is_null() {
74 panic!("Null pointer in creation of CapePMCRegistrationDetails");
75 }
76 Self {
77 interface
78 }
79 }
80
81 /// Get the name of the PMC
82 ///
83 /// The name of the PMC as it is appears in the registry.
84 ///
85 /// # Errors
86 ///
87 /// Returns an error if the name cannot be retrieved.
88 ///
89 /// # Examples
90 ///
91 /// ```
92 /// use cobia;
93 /// use cobia::prelude::*;
94 /// cobia::cape_open_initialize().unwrap();
95 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
96 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
97 /// println!("PMC name: {}",pmc.get_name().unwrap());
98 /// }
99 /// cobia::cape_open_cleanup();
100 /// ```
101
102 pub fn get_name(&self) -> Result<String, COBIAError> {
103 let mut s = CapeStringImpl::new();
104 let result = unsafe {
105 ((*(*self.interface).vTbl).getName.unwrap())((*self.interface).me, (&s.as_cape_string_out() as *const C::ICapeString).cast_mut())
106 };
107 if result == COBIAERR_NOERROR {
108 Ok(s.as_string())
109 } else {
110 Err(COBIAError::from_object(result,self))
111 }
112 }
113
114 /// Get the description of the PMC
115 ///
116 /// The description of the PMC as it is appears in the registry.
117 ///
118 /// # Errors
119 ///
120 /// Returns an error if the description cannot be retrieved.
121 ///
122 /// # Examples
123 ///
124 /// ```
125 /// use cobia;
126 /// use cobia::prelude::*;
127 /// cobia::cape_open_initialize().unwrap();
128 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
129 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
130 /// match pmc.get_description() {
131 /// Ok(description) => println!("PMC {} has description: {}",pmc.get_name().unwrap(),description),
132 /// Err(err) => println!("PMC {} has no description",pmc.get_name().unwrap())
133 /// }
134 /// }
135 /// cobia::cape_open_cleanup();
136 /// ```
137
138 pub fn get_description(&self) -> Result<String, COBIAError> {
139 let mut s = CapeStringImpl::new();
140 let result = unsafe {
141 ((*(*self.interface).vTbl).getDescription.unwrap())(
142 (*self.interface).me,
143 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
144 )
145 };
146 if result == COBIAERR_NOERROR {
147 Ok(s.as_string())
148 } else {
149 Err(COBIAError::from_object(result,self))
150 }
151 }
152
153 /// Get the CAPE-OPEN version of the PMC
154 ///
155 /// This function is deprecated and should not be used.
156 ///
157 /// Instead one should inspect which CAPE-OPEN versions are supported
158 /// through category IDs.
159
160 pub fn get_cape_version(&self) -> Result<String, COBIAError> {
161 let mut s = CapeStringImpl::new();
162 let result = unsafe {
163 ((*(*self.interface).vTbl).getCapeVersion.unwrap())(
164 (*self.interface).me,
165 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
166 )
167 };
168 if result == COBIAERR_NOERROR {
169 Ok(s.as_string())
170 } else {
171 Err(COBIAError::Code(result))
172 }
173 }
174
175 /// Get the version of the PMC
176 ///
177 /// The version of the PMC as it is appears in the registry.
178 ///
179 /// # Errors
180 ///
181 /// Returns an error if the version cannot be retrieved.
182 ///
183 /// # Examples
184 ///
185 /// ```
186 /// use cobia;
187 /// use cobia::prelude::*;
188 /// cobia::cape_open_initialize().unwrap();
189 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
190 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
191 /// match pmc.get_component_version() {
192 /// Ok(version) => println!("PMC {} version: {}",pmc.get_name().unwrap(),version),
193 /// Err(err) => println!("PMC {} has no version",pmc.get_name().unwrap())
194 /// }
195 /// }
196 /// cobia::cape_open_cleanup();
197 /// ```
198
199 pub fn get_component_version(&self) -> Result<String, COBIAError> {
200 let mut s = CapeStringImpl::new();
201 let result = unsafe {
202 ((*(*self.interface).vTbl).getComponentVersion.unwrap())(
203 (*self.interface).me,
204 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
205 )
206 };
207 if result == COBIAERR_NOERROR {
208 Ok(s.as_string())
209 } else {
210 Err(COBIAError::from_object(result,self))
211 }
212 }
213
214 /// Get the vendor url of the PMC
215 ///
216 /// The vendor url of the PMC as it is appears in the registry.
217 ///
218 /// # Errors
219 ///
220 /// Returns an error if the vendor url cannot be retrieved.
221 ///
222 /// # Examples
223 ///
224 /// ```
225 /// use cobia;
226 /// use cobia::prelude::*;
227 /// cobia::cape_open_initialize().unwrap();
228 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
229 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
230 /// match pmc.get_vendor_url() {
231 /// Ok(vendor_url) => println!("PMC {} vendor_url: {}",pmc.get_name().unwrap(),vendor_url),
232 /// Err(err) => println!("PMC {} has no vendor_url",pmc.get_name().unwrap())
233 /// }
234 /// }
235 /// cobia::cape_open_cleanup();
236 /// ```
237
238 pub fn get_vendor_url(&self) -> Result<String, COBIAError> {
239 let mut s = CapeStringImpl::new();
240 let result = unsafe {
241 ((*(*self.interface).vTbl).getVendorURL.unwrap())(
242 (*self.interface).me,
243 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
244 )
245 };
246 if result == COBIAERR_NOERROR {
247 Ok(s.as_string())
248 } else {
249 Err(COBIAError::from_object(result,self))
250 }
251 }
252
253 /// Get the help url of the PMC
254 ///
255 /// The help url of the PMC as it is appears in the registry.
256 ///
257 /// # Errors
258 ///
259 /// Returns an error if the help url cannot be retrieved.
260 ///
261 /// # Examples
262 ///
263 /// ```
264 /// use cobia;
265 /// use cobia::prelude::*;
266 /// cobia::cape_open_initialize().unwrap();
267 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
268 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
269 /// match pmc.get_help_url() {
270 /// Ok(help_url) => println!("PMC {} help_url: {}",pmc.get_name().unwrap(),help_url),
271 /// Err(err) => println!("PMC {} has no help_url",pmc.get_name().unwrap())
272 /// }
273 /// }
274 /// cobia::cape_open_cleanup();
275 /// ```
276
277 pub fn get_help_url(&self) -> Result<String, COBIAError> {
278 let mut s = CapeStringImpl::new();
279 let result = unsafe {
280 ((*(*self.interface).vTbl).getHelpURL.unwrap())(
281 (*self.interface).me,
282 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
283 )
284 };
285 if result == COBIAERR_NOERROR {
286 Ok(s.as_string())
287 } else {
288 Err(COBIAError::Code(result))
289 }
290 }
291
292 /// Get the about text of the PMC
293 ///
294 /// The about text of the PMC as it is appears in the registry.
295 /// This is a descriptive text about the PMC.
296 ///
297 /// # Errors
298 ///
299 /// Returns an error if the about text cannot be retrieved.
300 ///
301 /// # Examples
302 ///
303 /// ```
304 /// use cobia;
305 /// use cobia::prelude::*;
306 /// cobia::cape_open_initialize().unwrap();
307 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
308 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
309 /// match pmc.get_about() {
310 /// Ok(about) => println!("About {}: {}",pmc.get_name().unwrap(),about),
311 /// Err(err) => println!("Nothing about PMC {}...",pmc.get_name().unwrap())
312 /// }
313 /// }
314 /// cobia::cape_open_cleanup();
315 /// ```
316
317 pub fn get_about(&self) -> Result<String, COBIAError> {
318 let mut s = CapeStringImpl::new();
319 let result = unsafe {
320 ((*(*self.interface).vTbl).getAbout.unwrap())((*self.interface).me, (&s.as_cape_string_out() as *const C::ICapeString).cast_mut())
321 };
322 if result == COBIAERR_NOERROR {
323 Ok(s.as_string())
324 } else {
325 Err(COBIAError::from_object(result,self))
326 }
327 }
328
329 /// Get the id of the PMC
330 ///
331 /// The id of the PMC. This is the main unique ID
332 /// that identifies the PMC. It is a required attribute.
333 ///
334 /// # Examples
335 ///
336 /// ```
337 /// use cobia;
338 /// use cobia::prelude::*;
339 /// cobia::cape_open_initialize().unwrap();
340 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
341 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
342 /// println!("uuid = {}, pmc = {}",pmc.get_uuid().unwrap(),pmc.get_name().unwrap());
343 /// }
344 /// cobia::cape_open_cleanup();
345 /// ```
346
347 pub fn get_uuid(&self) -> Result<CapeUUID, COBIAError> {
348 let mut uuid = CapeUUID::new();
349 let result = unsafe {
350 ((*(*self.interface).vTbl).getUUID.unwrap())(
351 (*self.interface).me,
352 &mut uuid as *mut C::CapeUUID,
353 )
354 };
355 if result == COBIAERR_NOERROR {
356 Ok(uuid)
357 } else {
358 Err(COBIAError::Code(result))
359 }
360 }
361
362 /// Get the programmatic id of the PMC
363 ///
364 /// The help programmatic id of the PMC as it is appears in the registry.
365 /// This is an optional, alternative ID to the UUID
366 ///
367 /// # Errors
368 ///
369 /// Returns an error if the programmatic id text cannot be retrieved.
370 ///
371 /// # Examples
372 ///
373 /// ```
374 /// use cobia;
375 /// use cobia::prelude::*;
376 /// cobia::cape_open_initialize().unwrap();
377 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
378 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
379 /// match pmc.get_prog_id() {
380 /// Ok(progid) => println!("PMC {} programmatic id: {}",pmc.get_name().unwrap(),progid),
381 /// Err(err) => println!("PMC {} has no programmatic id...",pmc.get_name().unwrap())
382 /// }
383 /// }
384 /// cobia::cape_open_cleanup();
385 /// ```
386
387 pub fn get_prog_id(&self) -> Result<String, COBIAError> {
388 let mut s = CapeStringImpl::new();
389 let result = unsafe {
390 ((*(*self.interface).vTbl).getProgId.unwrap())((*self.interface).me, (&s.as_cape_string_out() as *const C::ICapeString).cast_mut())
391 };
392 if result == COBIAERR_NOERROR {
393 Ok(s.as_string())
394 } else {
395 Err(COBIAError::from_object(result,self))
396 }
397 }
398
399 /// Get the version independent programmatic id of the PMC
400 ///
401 /// The help independent programmatic id of the PMC as it is appears in the registry.
402 /// This is an optional, alternative ID to the UUID that does not change between
403 /// software releases.
404 ///
405 /// # Errors
406 ///
407 /// Returns an error if the independent programmatic id text cannot be retrieved.
408 ///
409 /// # Examples
410 ///
411 /// ```
412 /// use cobia;
413 /// use cobia::prelude::*;
414 /// cobia::cape_open_initialize().unwrap();
415 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
416 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
417 /// match pmc.get_version_independent_prog_id() {
418 /// Ok(progid) => println!("PMC {} version indepndent programmatic id: {}",pmc.get_name().unwrap(),progid),
419 /// Err(err) => println!("PMC {} has no version indepndent programmatic id...",pmc.get_name().unwrap())
420 /// }
421 /// }
422 /// cobia::cape_open_cleanup();
423 /// ```
424
425 pub fn get_version_independent_prog_id(&self) -> Result<String, COBIAError> {
426 let mut s = CapeStringImpl::new();
427 let result = unsafe {
428 ((*(*self.interface).vTbl)
429 .getVersionIndependentProgId
430 .unwrap())((*self.interface).me, (&s.as_cape_string_out() as *const C::ICapeString).cast_mut())
431 };
432 if result == COBIAERR_NOERROR {
433 Ok(s.as_string())
434 } else {
435 Err(COBIAError::Code(result))
436 }
437 }
438
439 /// Get all category IDs implemented by the PMC
440 ///
441 /// This allows for checking what kind of PMC it is, and which additional properties
442 /// it has (including which CAPE-OPEN versions it supports).
443 ///
444 /// Programmatic IDs are typically defined in type librararies. All major PMC categories,
445 /// such as Unit Operation, Property Package Manager, etc, are defined in the cape_open
446 /// type library.
447 ///
448 /// # Examples
449 ///
450 /// ```
451 /// use cobia;
452 /// use cobia::prelude::*;
453 /// cobia::cape_open_initialize().unwrap();
454 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
455 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
456 /// let cat_ids = pmc.get_cat_ids().unwrap();
457 /// print!("PMC {} implements: ",pmc.get_name().unwrap());
458 /// let mut first=true;
459 /// for cat_id in cat_ids {
460 /// if first {
461 /// first=false;
462 /// } else {
463 /// print!(", ");
464 /// }
465 /// print!("{}",cat_id);
466 /// ///print the name so that we can see what it means
467 /// let cat_key=cobia::CapeRegistryKey::from_path(&format!("/types/categories/{}",cat_id));
468 /// if let Ok(cat_key) = cat_key {
469 /// let cat_name=cat_key.get_string_value("name",None);
470 /// if let Ok(cat_name) = cat_name {
471 /// print!("={}",cat_name);
472 /// }
473 /// }
474 /// }
475 /// println!("");
476 /// }
477 /// cobia::cape_open_cleanup();
478 /// ```
479
480 pub fn get_cat_ids(&self) -> Result<Vec<CapeUUID>, COBIAError> {
481 let mut a = CapeArrayStringVec::new();
482 let result = unsafe {
483 ((*(*self.interface).vTbl).getCatIDs.unwrap())(
484 (*self.interface).me,
485 (&a.as_cape_array_string_out() as *const C::ICapeArrayString).cast_mut()
486 )
487 };
488 if result == COBIAERR_NOERROR {
489 let mut catids = Vec::<CapeUUID>::new();
490 let catids_as_strings = a.as_string_vec();
491 catids.reserve(catids_as_strings.len());
492 for catid_str in catids_as_strings {
493 match CapeUUID::from_string(&catid_str) {
494 Ok(cat_id) => catids.push(cat_id),
495 Err(err) => {
496 return Err(err);
497 }
498 }
499 }
500 Ok(catids)
501 } else {
502 Err(COBIAError::from_object(result,self))
503 }
504 }
505
506 /// Check if the PMC implements a specific category ID
507 ///
508 /// This allows for checking what kind of PMC it is, and which additional properties
509 /// it has (including which CAPE-OPEN versions it supports).
510 ///
511 /// Programmatic IDs are typically defined in type librararies. All major PMC categories,
512 /// such as Unit Operation, Property Package Manager, etc, are defined in the cape_open
513 /// type library.
514 ///
515 /// # Examples
516 ///
517 /// ```
518 /// use cobia;
519 /// use cobia::prelude::*;
520 /// use cobia::cape_open;
521 /// cobia::cape_open_initialize().unwrap();
522 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
523 /// //let's create some thermo! Enumerate all Property Package Managers and stand-alone Property Packages
524 /// let pmc_types=[cape_open::CATEGORYID_PROPERTYPACKAGEMANAGER,cape_open::CATEGORYID_STANDALONEPROPERTYPACKAGE];
525 /// let pmcs = pmc_enumerator.pmcs(&pmc_types).unwrap();
526 /// for pmc in pmcs {
527 /// println!("Found {}: {} ({})",
528 /// if pmc.implements_cat_id(&cape_open::CATEGORYID_PROPERTYPACKAGEMANAGER).unwrap() {"Property Package Manager"} else {"Stand-alone Property Package"},
529 /// pmc.get_name().unwrap(),
530 /// pmc.get_description().unwrap());
531 /// }
532 /// cobia::cape_open_cleanup();
533 /// ```
534
535 pub fn implements_cat_id(&self, cat_id: &CapeUUID) -> Result<bool, COBIAError> {
536 let mut boolval = 0u32;
537 let result = unsafe {
538 ((*(*self.interface).vTbl).implementsCatID.unwrap())(
539 (*self.interface).me,
540 cat_id as *const C::CapeUUID,
541 &mut boolval as *mut u32,
542 )
543 };
544 if result == COBIAERR_NOERROR {
545 Ok(boolval != 0)
546 } else {
547 Err(COBIAError::from_object(result,self))
548 }
549 }
550
551 /// Get the supported service types for the PMC
552 ///
553 /// The service types are the types of services that the PMC can provide.
554 ///
555 /// Typically used by the PMC to find the most suitable service type in
556 /// the current context.
557 ///
558 /// # Examples
559 ///
560 /// ```
561 /// use cobia;
562 /// use cobia::prelude::*;
563 /// cobia::cape_open_initialize().unwrap();
564 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
565 /// for pmc in pmc_enumerator.all_pmcs().unwrap() {
566 /// let service_types = pmc.get_service_types().unwrap();
567 /// println!("PMC {} supports the following service types:",pmc.get_name().unwrap());
568 /// for service_type in service_types {
569 /// println!("\t{}",service_type);
570 /// }
571 /// println!("");
572 /// }
573 /// cobia::cape_open_cleanup();
574 /// ```
575
576 pub fn get_service_types(&self) -> Result<Vec<CapePMCServiceType>, COBIAError> {
577 let mut a:CapeArrayEnumerationVec<CapePMCServiceType> = CapeArrayEnumerationVec::new();
578 let result = unsafe {
579 ((*(*self.interface).vTbl).getServiceTypes.unwrap())(
580 (*self.interface).me,
581 (&a.as_cape_array_enumeration_out() as *const C::ICapeArrayEnumeration).cast_mut()
582 )
583 };
584 if result == COBIAERR_NOERROR {
585 Ok(a.as_vec().clone())
586 } else {
587 Err(COBIAError::from_object(result,self))
588 }
589 }
590
591 /// Get the location of the PMC for the specified service type
592 ///
593 /// The meaning of the location depends on the service type. For
594 /// an in-process services it is a path to a shared library. For
595 /// a COM service, it is the COM class ID.
596 ///
597 /// The location for the best suitable service type typically is
598 /// obtained by COBIA to create the PMC.
599 ///
600 /// # Errors
601 ///
602 /// Returns an error if the location cannot be retrieved; this
603 /// probably means a service is not registered for the requested
604 /// type
605 ///
606 /// # Examples
607 ///
608 /// ```
609 /// use cobia;
610 /// use cobia::prelude::*;
611 /// cobia::cape_open_initialize().unwrap();
612 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
613 /// let pmcs = pmc_enumerator.all_pmcs().unwrap();
614 /// for pmc in pmcs {
615 /// println!("{}:",pmc.get_name().unwrap());
616 /// for service_type in cobia::CapePMCServiceType::iter() {
617 /// match pmc.get_location(service_type) {
618 /// Ok(loc) => {
619 /// println!("\t{}: {}",service_type,loc);
620 /// },
621 /// Err(_) => {}
622 /// }
623 /// }
624 /// println!("");
625 /// }
626 /// cobia::cape_open_cleanup();
627 /// ```
628 pub fn get_location(&self, service_type: CapePMCServiceType) -> Result<String, COBIAError> {
629 let mut s = CapeStringImpl::new();
630 let result = unsafe {
631 ((*(*self.interface).vTbl).getLocation.unwrap())(
632 (*self.interface).me,
633 service_type as i32,
634 (&s.as_cape_string_out() as *const C::ICapeString).cast_mut(),
635 )
636 };
637 if result == COBIAERR_NOERROR {
638 Ok(s.as_string())
639 } else {
640 Err(COBIAError::from_object(result,self))
641 }
642 }
643
644 /// Check if the PMC is registered for all users for the specified service type
645 ///
646 /// This function checks if the PMC is registered for all users for the specified service type.
647 /// This can be used to check whether the registration information is obtained from the
648 /// current user registry hive or the all users registry hive. For any PMC that is registered for
649 /// both all users and the current user, the current user registration overrides the all users
650 /// registration.
651 ///
652 /// Note that this property is not available for COM service types, that are taken from the
653 /// Windows registry.
654 ///
655 /// ```
656 /// use cobia;
657 /// use cobia::prelude::*;
658 /// cobia::cape_open_initialize().unwrap();
659 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
660 /// let pmcs = pmc_enumerator.all_pmcs().unwrap();
661 /// for pmc in pmcs {
662 /// println!("{}:",pmc.get_name().unwrap());
663 /// for service_type in cobia::CapePMCServiceType::iter() {
664 /// match pmc.registered_for_all_users(service_type) {
665 /// Ok(is_all_users) => {
666 /// println!("\t{}: {}",service_type,if is_all_users {"ALL USERS"} else {"CURRENT USER"});
667 /// },
668 /// Err(_) => {}
669 /// }
670 /// }
671 /// println!("");
672 /// }
673 /// cobia::cape_open_cleanup();
674 /// ```
675
676 pub fn registered_for_all_users(
677 &self,
678 service_type: CapePMCServiceType,
679 ) -> Result<bool, COBIAError> {
680 let mut boolval = 0u32;
681 let result = unsafe {
682 ((*(*self.interface).vTbl).registeredForAllUsers.unwrap())(
683 (*self.interface).me,
684 service_type as i32,
685 &mut boolval as *mut u32,
686 )
687 };
688 if result == COBIAERR_NOERROR {
689 Ok(boolval != 0)
690 } else {
691 Err(COBIAError::from_object(result,self))
692 }
693 }
694
695 /// Get the registration flags of the PMC registration
696 ///
697 /// The registration flags provide information about the requirements
698 /// and capabilities of the PMC, for example details about its threading
699 /// model.
700
701
702 pub fn get_flags(&self) -> Result<CapePMCRegistrationFlags, COBIAError> {
703 let mut flags: C::CapePMCRegistrationFlags = 0;
704 let result = unsafe {
705 ((*(*self.interface).vTbl).getFlags.unwrap())(
706 (*self.interface).me,
707 &mut flags as *mut C::CapePMCRegistrationFlags,
708 )
709 };
710 if result == COBIAERR_NOERROR {
711 Ok(CapePMCRegistrationFlags::from_bits_truncate(flags as i32))
712 } else {
713 Err(COBIAError::from_object(result,self))
714 }
715 }
716
717 /// Create an instance of the PMC
718 ///
719 /// This function creates an instance of the PMC. The PMC is created
720 /// with the specified creation flags. The flags can be used to specify
721 /// creation options, such as the threading model requirements.
722 ///
723 /// # Parameters
724 ///
725 /// * `flags` - The PMC creation flags to use for creating the PMC.
726 ///
727 /// # Examples
728 ///
729 /// ```no_run
730 /// use cobia;
731 /// use cobia::prelude::*;
732 /// cobia::cape_open_initialize().unwrap();
733 /// let pmc_enumerator = cobia::CapePMCEnumerator::new().unwrap();
734 /// let ppm_info_result=pmc_enumerator.get_pmc_by_prog_id("COCO_TEA.PropertyPackManager");
735 /// match ppm_info_result {
736 /// Ok(ppm_info) => {
737 /// let ppm_result=ppm_info.create_instance(cobia::CapePMCCreationFlags::AllowRestrictedThreading); //we only use the object in this thread
738 /// match ppm_result {
739 /// Ok(ppm) => {
740 /// //show name
741 /// let iden_result=cobia::cape_open_1_2::CapeIdentification::from_object(&ppm);
742 /// match iden_result {
743 /// Ok(iden) => {
744 /// let mut name = cobia::CapeStringImpl::new();
745 /// iden.get_component_name(&mut name).unwrap();
746 /// println!("PPM name: {}",name);
747 /// }
748 /// Err(_) => {
749 /// eprintln!("Object does not implement CAPEOPEN_1_2::ICapeIdentification");
750 /// }
751 /// }
752 /// }
753 /// Err(err) => {
754 /// eprintln!("Cannot find TEA property package manager (not installed?): {err}");
755 /// }
756 /// };
757 /// }
758 /// Err(err) => {
759 /// eprintln!("Cannot find TEA property package manager (not installed?): {err}");
760 /// }
761 /// };
762 /// cobia::cape_open_cleanup();
763 /// ```
764
765 pub fn create_instance(&self, flags: CapePMCCreationFlags) -> Result<CapeObject, COBIAError> {
766 let mut instance: *mut C::ICapeInterface = std::ptr::null_mut();
767 let result = unsafe {
768 ((*(*self.interface).vTbl).createInstance.unwrap())(
769 (*self.interface).me,
770 flags.bits() as i32,
771 &mut instance as *mut *mut C::ICapeInterface,
772 )
773 };
774 if result == COBIAERR_NOERROR {
775 if instance.is_null() {
776 Err(COBIAError::Code(COBIAERR_NULLPOINTER))
777 } else {
778 Ok(CapeObject::attach(instance))
779 }
780 } else {
781 Err(COBIAError::from_object(result,self))
782 }
783 }
784
785
786}
787
788