Expand description
§Crate cobia - RUST Language binding for CO-LaN’s COBIA middleware.
CAPE-OPEN consists of a series of specifications to expand the range of application of process simulation technologies. The CAPE-OPEN specifications specify a set of software interfaces that allow plug and play inter-operability between a given process modelling environment (PME) and a third-party process modelling component (PMC).
The CAPE-OPEN specifications are supported by the non-profit organization CO-LaN: http://www.colan.org
The COBIA middle-ware is a platform independent object model and request broker implementation to facilitate the inter-operation of CAPE-OPEN compliant PMEs and PMCs.
This create provides the following:
- Safe Rust wrappers around the raw C FFI bindings to COBIA’s API routines
- Rust based implementation of the CAPE-OPEN data types
- Rust based wrappers around externally implemented CAPE-OPEN data types
- A Rust code generator utility that utilizes COBIA’s public type API to generate Rust bindings
- Rust traits representing COBIA interfaces
- Rust native implementations of COBIA based interfaces using objects that provide the Rust traits
- Smart pointers to COBIA objects
- Rust definitions for externall implemented COBIA objects
- Macros to make implementing CAPE-OPEN components in Rust
§Prerequisites
To compile against this create, the following prerequisites must be installed:
- The COBIA SDK (available for download from https://colan.repositoryhosting.com/trac/colan_cobia/downloads
- The required ingredients for bindgen, including a valid CLANG installation, see https://rust-lang.github.io/rust-bindgen/requirements.html
This package uses bindgen to generate Rust access to the C-API of COBIA. As with most Rust implementations that refer to C/C++ code, all external access is unsafe, and marked as such in the cobia crate itself. Typically one does not need to use the unsafe keyword in implementations that use cobia, with a few exceptions.
§Interface implementation considerations
COBIA is a middle-ware that allows objects implemented in different languages to inter-operate. They do so through the use of reference counted interfaces, much like other middle-wares such as COM or CORBA.
To allow the Rust compiler to check the life time and validity of pointers, interface pointers are passed by reference. A Rust object that implements one or more COBIA interface is allocated on the heap by boxing it as part of its creation. Once the object is boxed, its vTable pointers are initialized to point to the correct memory location. The boxed object is then converted to a raw pointer; this raw pointer is the interface pointer’s ‘me’ member, and is used by the raw interface methods to access the Rust object. The raw interface methods require Rust traits to be implemented on the Rust object, to provide the actual functionality.
Data that requires heap allocations (strings, arrays, …) are handled a little differently. They too have a vTable, but at the design of this crate it was decided not to box the data objects, as the heap allocation for the object itself may well not be needed and may hamper performance.
As a result, it is quite possible, and even likely, for data object implementations to be moved around after its creation. When passed to a foreign function, the vTable for the data object is created on the fly, pointing to where the data object is currently located. The reference to the vTable requires a reference to the data object implementation, so Rust’s life span checking is used to ensure that the data object implementation remains valid during the life span of the vTable, and the vTable remains valid for the duration of the external call.
To further leverage Rust’s safety features, data objects have In and Out versions. The In version cannot be modified by the receiver, whereas the intent of the Out version is exactly to be modified. Functions that require an In data type, can do so by a reference to it. Function that require an Out data type on the other hand, require a mutable reference; this ensures that an Out data object is not modified unexpectedly.
§Rust code generation
To generate Rust bindings for interfaces described by CAPE-OPEN IDL (either in a .cidl file or a library in the COBIA registry), the cidl.exe tool can be used. This tool is part of the current crate. This tool is used during the build process to generate the bindings for the default cape_open and cape_open_1_2 modules, containing all known CAPE-OPEN interfaces in the installed COBIA SDK.
The cidl tool can also be used to generate bindings for custom CAPE-OPEN interfaces; this functionality is currently untested, arising a business case.
§CAPE-OPEN object implementations
To implement a CAPE-OPEN object in rust, one can use the cape_object_implementation macro. This macro takes as
arguments the interfaces that are implemented by the object, as well as some optional constructor details.
To implement the entry points for a COBIA dynamic link library, one can use the pmc_entry_points macro.
The reader is directed to the Salt Water Property Package example and the Distillation Shortcut Unit Operation examples in the repository for further details.
Extenally implemented COBIA objects are accessed through smart pointers; an interface specific smart pointer is generated for each known COBIA interface, along with the Rust methods that represent the interface methods.
§Acknowledgements
This package uses process_path, to get the path of the currently executing process or dynamic library, (C) Copyright Wesley Wiser and process_path contributors
This package uses bindgen, to automatically generates Rust FFI bindings to C and C++ libraries, (C) Jyun-Yan You
Re-exports§
pub use C::CapeBoolean;pub use C::CapeReal;pub use C::CapeInteger;pub use C::CapeResult;pub use C::CapeCharacter;pub use C::CapeByte;pub use C::CapeEnumeration;pub use cape_value_impl::CapeValueImpl;pub use cape_value_impl::CapeValueContent;pub use C::CapeUUID;
Modules§
- C
- cape_
array 🔒 - cape_
array_ 🔒boolean - cape_
array_ 🔒byte - cape_
array_ 🔒enumeration - cape_
array_ 🔒integer - cape_
array_ 🔒object_ vec - cape_
array_ 🔒real - cape_
array_ 🔒real_ scalar - cape_
array_ 🔒slice - cape_
array_ 🔒string - cape_
array_ 🔒value - cape_
array_ 🔒vec - cape_
data_ 🔒from_ provider - cape_
data_ 🔒traits - cape_
error 🔒 - cape_
error_ 🔒impl - cape_
object 🔒 - cape_
object_ 🔒impl - cape_
open - cape_
open_ 1_ 2 - cape_
pmc_ 🔒enumerator - cape_
pmc_ 🔒registration_ details - cape_
registrar 🔒 - cape_
registry_ 🔒key - cape_
registry_ 🔒key_ writer - cape_
registry_ 🔒writer - cape_
result_ 🔒value - cape_
smart_ 🔒pointer - cape_
string 🔒 - cape_
string_ 🔒const - cape_
string_ 🔒impl - cape_
string_ 🔒map - cape_
type_ 🔒library_ details - cape_
type_ 🔒library_ enumerator - cape_
value 🔒 - cape_
value_ impl - cape_
window_ 🔒id - cobia_
collection 🔒 - cobia_
enums 🔒 - cobia_
error 🔒 - cobia_
identification 🔒 - cobia_
pmc_ 🔒helpers - prelude
Macros§
- pmc_
entry_ points - Generate PMC entry points
Structs§
- Cape
Array Boolean InFrom Provider - CapeArrayBooleanInFromProvider
- Cape
Array Boolean OutFrom Provider - CapeArrayBooleanOutFromProvider
- Cape
Array Byte InFrom Provider - CapeArrayByteInFromProvider
- Cape
Array Byte OutFrom Provider - CapeArrayByteOutFromProvider
- Cape
Array Enumeration In - CapeArrayEnumerationIn wraps an ICapeArrayEnumeration interface pointer.
- Cape
Array Enumeration InFrom Provider - CapeArrayEnumerationInFromProvider
- Cape
Array Enumeration Out - CapeArrayEnumerationOut wraps an ICapeArrayEnumeration interface pointer.
- Cape
Array Enumeration OutFrom Provider - CapeArrayEnumerationOutFromProvider
- Cape
Array In - CapeArrayIn wraps an ICapeArray interface pointer.
- Cape
Array Integer InFrom Provider - CapeArrayIntegerInFromProvider
- Cape
Array Integer OutFrom Provider - CapeArrayIntegerOutFromProvider
- Cape
Array Object Vec - Base implementation for CapeArrayStringVec and CapeArrayValueVec
- Cape
Array Out - CapeArrayOut wraps an ICapeArray interface pointer.
- Cape
Array Real InFrom Provider - CapeArrayRealInFromProvider
- Cape
Array Real OutFrom Provider - CapeArrayRealOutFromProvider
- Cape
Array Real Scalar - Scalar based CapeArrayRealOut implementation
- Cape
Array Slice - Slice based implementation of ICapeArray
- Cape
Array String In - CapeArrayStringIn wraps an ICapeArrayString interface pointer in a read-only manner
- Cape
Array String InFrom Provider - CapeArrayStringInFromProvider
- Cape
Array String Out - CapeArrayStringOut wraps an ICapeArrayString interface pointer.
- Cape
Array String OutFrom Provider - CapeArrayStringOutFromProvider
- Cape
Array Value In - CapeArrayValueIn wraps an ICapeArrayValue interface pointer in a read-only manner
- Cape
Array Value InFrom Provider - CapeArrayValueInFromProvider
- Cape
Array Value Out - CapeArrayValueOut wraps an ICapeArrayValue interface pointer.
- Cape
Array Value OutFrom Provider - CapeArrayValueOutFromProvider
- Cape
Array Vec - Vector based implementation of ICapeArray
- Cape
Error - Error description from CAPE-OPEN object
- Cape
Error Impl - CAPE-OPEN Error object implementation
- Cape
Library Details - CapeLibraryDetails provides details about a registered COBIA type library
- Cape
Object - Generic Cape Object smart pointer
- Cape
Object Data - Internal data for CAPE-OPEN object implementations.
- Cape
Open Map - Class to store a platform dependent string encoding for use in case insensitive hash maps or for use of case insensitive comparisons.
- CapePMC
Creation Flags - CapePMC
Enumerator - Enumerator for all registered PMCs.
- CapePMC
Registration Details - PMC registration details
- CapePMC
Registration Flags - CapePMC
Service Type Iterator - CapePMCServiceType iterator
- Cape
Registrar - Rust wrapper for ICapePMCRegistrar interface
- Cape
Registry Key - A class that provides access to a COBIA registry key in a read-only manner
- Cape
Registry KeyWriter - A writable COBIA registry key
- Cape
Registry Value Type Iterator - CapeRegistryValueType iterator
- Cape
Registry Writer - Opens the COBIA registry for writing
- Cape
String Const NoCase - Class to store a platform dependent string encoding for use in case insensitive hash maps or for use of case insensitive comparisons.
- Cape
String Impl - Default ICapeString implementation
- Cape
String In - CapeStringIn wraps an ICapeString interface pointer as read-only.
- Cape
String InFrom Provider - CapeStringInFromProvider
- Cape
String Out - CapeStringOut wraps an ICapeString interface pointer.
- Cape
String OutFrom Provider - CapeStringOutFromProvider
- Cape
Type Libraries - Enumerator for all registered type libraries.
- Cape
Value In - CapeValueIn wraps a reference to an ICapeValue interface pointer.
- Cape
Value InFrom Provider - CapeValueInFromProvider
- Cape
Value Out - CapeValueOut wraps an ICapeValue interface pointer.
- Cape
Value OutFrom Provider - CapeValueOutFromProvider
- Cape
Value Type Iterator - CapeValueType iterator
- Cobia
Identification - CobiaIdentification interface smart pointer
- PMCInfo
- PMCInfo is a struct that contains the information required to register a PMC.
Enums§
- COBIA
Error - A COBIA error, with description
- CapePMC
Service Type - Service provider types
- Cape
Registry Value Type - Registry value type
- Cape
String Hash Key - Class to store a platform dependent string encoding for use in case insensitive hash maps or for use of case insensitive comparisons.
- Cape
Value Type - CapeValue data types
Constants§
- COBIAERR_
CAPEOPENERROR - COBIAERR_
CRITICALERROR - COBIAERR_
DENIED - COBIAERR_
DENIEDBECAUSEOFELEVATION - COBIAERR_
INVALIDARGUMENT - COBIAERR_
INVALIDCONCURRENTACCESS - COBIAERR_
INVALIDOPERATION - COBIAERR_
INVALIDTYPELIBRARY - COBIAERR_
MARSHAL_ CONNECTIONCLOSED - COBIAERR_
MARSHAL_ CONNECTIONTIMEDOUT - COBIAERR_
MARSHAL_ ERROR - COBIAERR_
NOERROR - COBIAERR_
NOSERVICE - COBIAERR_
NOSUCHINTERFACE - COBIAERR_
NOSUCHITEM - COBIAERR_
NOTIMPLEMENTED - COBIAERR_
NULLPOINTER - COBIAERR_
OUTOFMEMORY - COBIAERR_
PERSISTENCEERROR - COBIAERR_
PERSISTENCESAVEDWITHNEWERVERSION - COBIAERR_
REGISTRY_ ACCESSDENIED - COBIAERR_
REGISTRY_ CANNOTCREATE - COBIAERR_
REGISTRY_ CORRUPT - COBIAERR_
REGISTRY_ INSUFFICIENTDATA - COBIAERR_
REGISTRY_ INVALIDNAME - COBIAERR_
REGISTRY_ INVALIDVALUE - COBIAERR_
REGISTRY_ INVALIDVALUETYPE - COBIAERR_
REGISTRY_ NOTFOUND - COBIAERR_
UNEXPECTEDDATATYPE - COBIAERR_
UNEXPECTEDNUMBEROFVALUES - COBIAERR_
UNKNOWNERROR
Traits§
- Cape
Array Boolean Provider In - Any object that implements this trait can be converted to an ICapeArrayBoolean input argument
- Cape
Array Boolean Provider Out - Any object that implements this trait can be converted to an ICapeArrayBoolean output argument
- Cape
Array Byte Provider In - Any object that implements this trait can be converted to an ICapeArrayByte input argument
- Cape
Array Byte Provider Out - Any object that implements this trait can be converted to an ICapeArrayByte output argument
- Cape
Array Enumeration Provider In - Any object that implements this trait can be converted to an ICapeArrayEnumeration input argument
- Cape
Array Enumeration Provider Out - Any object that implements this trait can be converted to an ICapeArrayEnumeration output argument
- Cape
Array Integer Provider In - Any object that implements this trait can be converted to an ICapeArrayInteger input argument
- Cape
Array Integer Provider Out - Any object that implements this trait can be converted to an ICapeArrayInteger output argument
- Cape
Array Real Provider In - Any object that implements this trait can be converted to an ICapeArrayReal input argument
- Cape
Array Real Provider Out - Any object that implements this trait can be converted to an ICapeArrayReal output argument
- Cape
Array String Provider In - Any object that implements this trait can be converted to an ICapeArrayString input argument
- Cape
Array String Provider Out - Any object that implements this trait can be converted to an ICapeArrayString output argument
- Cape
Array Value Provider In - Any object that implements this trait can be converted to an ICapeArrayValue input argument
- Cape
Array Value Provider Out - Any object that implements this trait can be converted to an ICapeArrayValue output argument
- Cape
Create Instance - CapeCreateInstance is creates an instance of a PMC object. This trait is typically implemented by the cape_object_implementation! macro and only for objects created with the cape_object_implementation! macro, which do not take any arguments for construction.
- Cape
Registry KeyReader - Public trait that provides methods to read from the registry key
- Cape
String Const Provider - Any object that implements this trait can be compared to any CapeString type object
- Cape
String Provider In - Any object that implements this trait can be converted to an ICapeString input argument
- Cape
String Provider Out - Any object that implements this trait can be converted to an ICapeString output argument
- Cape
Value Provider In - Any object that implements this trait can be converted to an ICapeValue input argument
- Cape
Value Provider Out - Any object that implements this trait can be converted to an ICapeValue output argument
- ICape
Interface Impl - This trait is implemented by all CAPE-OPEN objects.
- PMCRegisteration
Info - PMCRegisterationInfo is a trait that must be implemented by a struct that implements a PMC. The trait provides the information required to register the PMC with the COBIA registry.
Functions§
- Cape
Window IdFrom Raw - Cape
Window IdTo Raw - cape_
open_ cleanup - #COBIA clean-up routine
- cape_
open_ initialize - #COBIA initialization routine
- get_
cobia_ folder - #get COBIA installation folder
- get_
cobia_ language - #get COBIA language
- get_
cobia_ system_ data_ folder - #get COBIA system data folder
- get_
cobia_ user_ data_ folder - #get COBIA user data folder
- get_
cobia_ version - #get COBIA version
- inproc_
service_ type - Service function to get in-process service type for current bitness
- pmc_
info - class factory for a pmc_info object from a CAPE-OPEN object class
- register_
pmc - register a PMC into the COBIA registry
- unregister_
pmc - unregister a PMC from the COBIA registry
Type Aliases§
- Cape
Array Boolean In - CapeArrayBooleanIn wraps an ICapeArrayBoolean interface pointer.
- Cape
Array Boolean Out - CapeArrayBooleanOut wraps an ICapeArrayBoolean interface pointer.
- Cape
Array Boolean Slice - Slice based CapeArrayBooleanIn implementation
- Cape
Array Boolean Vec - Vector based CapeArrayBooleanOut implementation
- Cape
Array Byte In - CapeArrayByteIn wraps an ICapeArrayByte interface pointer.
- Cape
Array Byte Out - CapeArrayByteOut wraps an ICapeArrayByte interface pointer.
- Cape
Array Byte Slice - Slice based CapeArrayByteIn implementation
- Cape
Array Byte Vec - Vector based CapeArrayByteOut implementation
- Cape
Array Enumeration Slice - Slice based CapeArrayEnumerationIn implementation
- Cape
Array Enumeration Vec - Vector based CapeArrayEnumerationOut implementation
- Cape
Array Integer In - CapeArrayIntegerIn wraps an ICapeArrayInteger interface pointer.
- Cape
Array Integer Out - CapeArrayIntegerOut wraps an ICapeArrayInteger interface pointer.
- Cape
Array Integer Slice - Slice based CapeArrayIntegerIn implementation
- Cape
Array Integer Vec - Vector based CapeArrayIntegerOut implementation
- Cape
Array Real In - CapeArrayRealIn wraps an ICapeArrayReal interface pointer.
- Cape
Array Real Out - CapeArrayRealOut wraps an ICapeArrayReal interface pointer.
- Cape
Array Real Slice - Slice based CapeArrayRealIn implementation
- Cape
Array Real Vec - Vector based CapeArrayRealOut implementation
- Cape
Array String Vec - Vector based CapeArrayStringOut implementation
- Cape
Array Value Vec - Vector based CapeArrayValueOut implementation
- Cape
Window Id - Cobia
Collection - CobiaCollection wraps an ICobiaCollection interface
Attribute Macros§
- cape_
object_ implementation - The cape_object_implementation macro generates the necessary code to implement a COBIA object.
- cape_
smart_ pointer - The cape_smart_pointer macro generates the necessary code to implement a COBIA smart pointer.