libuav original

Dependents:   UAVCAN UAVCAN_Subscriber

Embed: (wiki syntax)

« Back to documentation index

GlobalDataTypeRegistry Class Reference

GlobalDataTypeRegistry Class Reference

This singleton is shared among all existing node instances. More...

#include <global_data_type_registry.hpp>

Inherits uavcan::Noncopyable.

Public Types

enum  RegistrationResult { RegistrationResultOk, RegistrationResultCollision, RegistrationResultInvalidParams, RegistrationResultFrozen }
 

Result of data type registration.

More...

Public Member Functions

template<typename Type >
RegistrationResult registerDataType (DataTypeID id)
 Register a data type 'Type' with ID 'id'.
void freeze ()
 Data Type registry needs to be frozen before a node instance can use it in order to prevent accidental change in data type configuration on a running node.
const DataTypeDescriptorfind (const char *name) const
 Finds data type descriptor by full data type name, e.g.
const DataTypeDescriptorfind (DataTypeKind kind, const char *name) const
 Finds data type descriptor by full data type name, e.g.
const DataTypeDescriptorfind (DataTypeKind kind, DataTypeID dtid) const
 Finds data type descriptor by data type ID.
unsigned getNumMessageTypes () const
 Returns the number of registered message types.
unsigned getNumServiceTypes () const
 Returns the number of registered service types.
void reset ()
 Required for unit testing.

Static Public Member Functions

static GlobalDataTypeRegistryinstance ()
 Returns the reference to the singleton.

Detailed Description

This singleton is shared among all existing node instances.

It is instantiated automatically when the C++ runtime executes contstructors before main().

Its purpose is to keep the list of all UAVCAN data types known and used by this application.

Also, the mapping between Data Type name and its Data Type ID is also stored in this singleton. UAVCAN data types with default Data Type ID that are autogenerated by the libuavcan DSDL compiler are registered automatically before main() (refer to the generated headers to see how exactly). Data types that don't have a default Data Type ID must be registered manually using the methods of this class (read the method documentation).

Attempt to use a data type that was not registered with this singleton (e.g. publish, subscribe, perform a service call etc.) will fail with an error code ErrUnknownDataType.

Definition at line 35 of file global_data_type_registry.hpp.


Member Enumeration Documentation

Result of data type registration.

Enumerator:
RegistrationResultOk 

Success, data type is now registered and can be used.

RegistrationResultCollision 

Data type name or ID is not unique.

RegistrationResultInvalidParams 

Invalid input parameters.

RegistrationResultFrozen 

Data Type Registery has been frozen and can't be modified anymore.

Definition at line 67 of file global_data_type_registry.hpp.


Member Function Documentation

const DataTypeDescriptor * find ( const char *  name ) const

Finds data type descriptor by full data type name, e.g.

"uavcan.protocol.NodeStatus". Messages are searched first, then services. Returns null pointer if the data type with this name is not registered.

Parameters:
nameFull data type name
Returns:
Descriptor for this data type or null pointer if not found

Definition at line 144 of file uc_global_data_type_registry.cpp.

const DataTypeDescriptor * find ( DataTypeKind  kind,
const char *  name 
) const

Finds data type descriptor by full data type name, e.g.

"uavcan.protocol.NodeStatus", and data type kind. Returns null pointer if the data type with this name is not registered.

Parameters:
kindData Type Kind - message or service
nameFull data type name
Returns:
Descriptor for this data type or null pointer if not found

Definition at line 154 of file uc_global_data_type_registry.cpp.

const DataTypeDescriptor * find ( DataTypeKind  kind,
DataTypeID  dtid 
) const

Finds data type descriptor by data type ID.

Returns null pointer if the data type with this ID is not registered.

Parameters:
kindData Type Kind - message or service
dtidData Type ID
Returns:
Descriptor for this data type or null pointer if not found

Definition at line 179 of file uc_global_data_type_registry.cpp.

void freeze (  )

Data Type registry needs to be frozen before a node instance can use it in order to prevent accidental change in data type configuration on a running node.

This method will be called automatically by the node during start up, so the user does not need to call it from the application manually. Subsequent calls will not have any effect.

Once frozen, data type registry can't be unfrozen.

Definition at line 134 of file uc_global_data_type_registry.cpp.

unsigned getNumMessageTypes (  ) const

Returns the number of registered message types.

Definition at line 151 of file global_data_type_registry.hpp.

unsigned getNumServiceTypes (  ) const

Returns the number of registered service types.

Definition at line 156 of file global_data_type_registry.hpp.

GlobalDataTypeRegistry & instance (  ) [static]

Returns the reference to the singleton.

Definition at line 128 of file uc_global_data_type_registry.cpp.

GlobalDataTypeRegistry::RegistrationResult registerDataType ( DataTypeID  id )

Register a data type 'Type' with ID 'id'.

If this data type was registered earlier, its old registration will be overridden. This method will fail if the data type registry is frozen.

Template Parameters:
TypeAutogenerated UAVCAN data type to register. Data types are generated by the libuavcan DSDL compiler from DSDL definitions.
Parameters:
idData Type ID for this data type.

Definition at line 208 of file global_data_type_registry.hpp.

void reset (  )

Required for unit testing.

Definition at line 160 of file global_data_type_registry.hpp.