core¶
- class cyclonedds.core.Listener(**kwargs)[source]¶
Bases:
cyclonedds.internal.DDS
Listeners are callback containers for entities.
- __init__(**kwargs)[source]¶
Create a Listener object. The initializer takes override function lambdas.
Please note that all listener callbacks are dispatched synchronously from DDS receive thread(s). You can get away with doing tiny amounts of processing in these callback methods, but aquiring the Python GIL from the DDS receive thread will severely hurt your DDS performance. Furthermore, deleting entities or writing data inside listener callbacks can get you into deadlocks.
- Parameters
on_data_available (Callable) – Set on_data_available callback.
on_inconsistent_topic (Callable) – Set on_inconsistent_topic callback.
on_liveliness_lost (Callable) – Set on_liveliness_lost callback.
on_liveliness_changed (Callable) – Set on_liveliness_changed callback.
on_offered_deadline_missed (Callable) – Set on_offered_deadline_missed callback.
on_offered_incompatible_qos (Callable) – Set on_offered_incompatible_qos callback.
on_data_on_readers (Callable) – Set on_data_on_readers callback.
on_sample_lost (Callable) – Set on_sample_lost callback.
on_sample_rejected (Callable) – Set on_sample_rejected callback.
on_requested_deadline_missed (Callable) – Set on_requested_deadline_missed callback.
on_requested_incompatible_qos (Callable) – Set on_requested_incompatible_qos callback.
on_publication_matched (Callable) – Set on_publication_matched callback.
on_subscription_matched (Callable) – Set on_subscription_matched callback.
- copy_to(listener)[source]¶
- Parameters
listener (cyclonedds.core.Listener) –
- Return type
None
- merge(listener)[source]¶
Copies any configured (non-default) callbacks from the given listener to self, replacing existing callbacks already configured on this listener.
- Parameters
listener (cyclonedds.core.Listener) –
- Return type
None
- on_inconsistent_topic(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.inconsistent_topic_status) –
- Return type
None
- set_on_inconsistent_topic(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader], None]) –
- on_data_available(reader)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
- Return type
None
- set_on_data_available(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader], None]) –
- on_liveliness_lost(writer, status)[source]¶
- Parameters
writer (cyclonedds.pub.DataWriter) –
status (cyclonedds.internal.dds_c_t.liveliness_lost_status) –
- Return type
None
- set_on_liveliness_lost(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.pub.DataWriter, cyclonedds.internal.dds_c_t.liveliness_lost_status], None]) –
- on_liveliness_changed(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.liveliness_changed_status) –
- Return type
None
- set_on_liveliness_changed(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader, cyclonedds.internal.dds_c_t.liveliness_changed_status], None]) –
- on_offered_deadline_missed(writer, status)[source]¶
- Parameters
writer (cyclonedds.pub.DataWriter) –
status (cyclonedds.internal.dds_c_t.offered_deadline_missed_status) –
- Return type
None
- set_on_offered_deadline_missed(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.pub.DataWriter, cyclonedds.internal.dds_c_t.offered_deadline_missed_status], None]) –
- on_offered_incompatible_qos(writer, status)[source]¶
- Parameters
writer (cyclonedds.pub.DataWriter) –
status (cyclonedds.internal.dds_c_t.offered_incompatible_qos_status) –
- Return type
None
- set_on_offered_incompatible_qos(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.pub.DataWriter, cyclonedds.internal.dds_c_t.offered_incompatible_qos_status], None]) –
- on_data_on_readers(subscriber)[source]¶
- Parameters
subscriber (cyclonedds.sub.Subscriber) –
- Return type
None
- set_on_data_on_readers(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.Subscriber], None]) –
- on_sample_lost(writer, status)[source]¶
- Parameters
writer (cyclonedds.pub.DataWriter) –
- Return type
None
- set_on_sample_lost(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.pub.DataWriter, cyclonedds.internal.dds_c_t.sample_lost_status], None]) –
- on_sample_rejected(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.sample_rejected_status) –
- Return type
None
- set_on_sample_rejected(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader, cyclonedds.internal.dds_c_t.sample_rejected_status], None]) –
- on_requested_deadline_missed(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.requested_deadline_missed_status) –
- Return type
None
- set_on_requested_deadline_missed(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader, cyclonedds.internal.dds_c_t.requested_deadline_missed_status], None]) –
- on_requested_incompatible_qos(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.requested_incompatible_qos_status) –
- Return type
None
- set_on_requested_incompatible_qos(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader, cyclonedds.internal.dds_c_t.requested_incompatible_qos_status], None]) –
- on_publication_matched(writer, status)[source]¶
- Parameters
writer (cyclonedds.pub.DataWriter) –
status (cyclonedds.internal.dds_c_t.publication_matched_status) –
- Return type
None
- set_on_publication_matched(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.pub.DataWriter, cyclonedds.internal.dds_c_t.publication_matched_status], None]) –
- on_subscription_matched(reader, status)[source]¶
- Parameters
reader (cyclonedds.sub.DataReader) –
status (cyclonedds.internal.dds_c_t.subscription_matched_status) –
- Return type
None
- set_on_subscription_matched(callable)[source]¶
- Parameters
callable (Callable[[cyclonedds.sub.DataReader, cyclonedds.internal.dds_c_t.subscription_matched_status], None]) –
- class cyclonedds.core.GuardCondition(domain_participant)[source]¶
Bases:
cyclonedds.core.Entity
A GuardCondition is a manually triggered condition that can be added to a
WaitSet
.- Parameters
domain_participant (cyclonedds.domain.DomainParticipant) –
- __init__(domain_participant)[source]¶
Initialize a GuardCondition
- Parameters
domain_participant (DomainParticipant) – The domain in which the GuardCondition should be active.
- set(triggered)[source]¶
Set the status of the GuardCondition to triggered or untriggered.
- Parameters
triggered (bool) – Wether to trigger this condition.
- Return type
None
- Raises
- read()[source]¶
Read the status of the GuardCondition.
- Returns
Wether this condition is triggered.
- Return type
- Raises
- class cyclonedds.core.ReadCondition(reader, mask)[source]¶
Bases:
cyclonedds.core._Condition
Condition that triggers when new data is available to read according to the mask. Construct a mask using InstanceState, ViewState and SampleState.
- Parameters
reader (cyclonedds.sub.DataReader) –
mask (int) –
- Return type
None
- __init__(reader, mask)[source]¶
Construct a ReadCondition.
- Parameters
reader (cyclonedds.sub.DataReader) –
mask (int) –
- Return type
None
- class cyclonedds.core.QueryCondition(reader, mask, filter)[source]¶
Bases:
cyclonedds.core._Condition
Condition that triggers when new data is available to read according to the mask. Construct a mask using InstanceState, ViewState and SampleState. Add a filter function that receives the sample and returns a boolean whether to accept or reject the sample.
- Parameters
reader (cyclonedds.sub.DataReader) –
mask (int) –
- Return type
None
- class cyclonedds.core.WaitSet(domain_participant)[source]¶
Bases:
cyclonedds.core.Entity
A WaitSet is a way to provide synchronous access to events happening in the DDS system. You can attach almost any kind of entity to a WaitSet and then perform a blocking wait on the waitset. When one or more of the entities in the waitset trigger the wait is unblocked. What a ‘trigger’ is depends on the type of entity, you can find out more in
todo(DDS) triggers
.- Parameters
domain_participant (cyclonedds.domain.DomainParticipant) –
- Return type
None
- __init__(domain_participant)[source]¶
Make a new WaitSet. It starts of empty. An empty waitset will never trigger.
- Parameters
domain_participant (DomainParticipant) – The domain in which you want to make a WaitSet
- Return type
None
- attach(entity)[source]¶
Attach an entity to this WaitSet. This is a no-op if the entity was already attached.
- Parameters
entity (Entity) – The entity you wish to attach.
- Raises
DDSException – When you try to attach a non-triggerable entity.:
- Return type
None
- detach(entity)[source]¶
Detach an entity from this WaitSet. If it was not attach this is a no-op. Note that this operation is not atomic, a trigger for the detached entity could still occurr right after detaching it.
- Parameters
entity (Entity) – The entity you wish to attach
- Return type
None
- wait_until(abstime)[source]¶
Block execution and wait for one of the entities in this waitset to trigger.
- class cyclonedds.core.InstanceState[source]¶
InstanceState constants for building condition masks. This class is static and there should never be a need to instantiate it. It operates on the state of an instance.
- NotAliveDisposed¶
Only consider samples belonging to an instance that is not alive because it was actively disposed.
- Type
- NotAliveNoWriters¶
Only consider samples belonging to an instance that is not alive because it has no writers.
- Type
- class cyclonedds.core.ViewState[source]¶
ViewState constants for building condition masks. This class is static and there should never be a need to instantiate it. It operates on the state of an instance.
- class cyclonedds.core.SampleState[source]¶
SampleState constants for building condition masks. This class is static and there should never be a need to instantiate it. It operates on the state of a single sample.
- class cyclonedds.core.DDSStatus[source]¶
DDSStatus contains constants to build status masks. It is static and should never need to be instantiated.
- All = (1 << 14) - 1
- class cyclonedds.core.Entity(ref, listener=None)[source]¶
Bases:
cyclonedds.internal.DDS
Base class for all entities in the DDS API. The lifetime of the underlying DDS API object is linked to the lifetime of the Python entity object.
- subscriber¶
If this entity is associated with a DataReader retrieve it. It is read-only. This is a proxy for get_subscriber().
- Type
Optional[cyclonedds.sub.Subscriber]
- publisher¶
If this entity is associated with a Publisher retrieve it. It is read-only. This is a proxy for get_publisher().
- Type
Optional[cyclonedds.pub.Publisher]
- datareader¶
If this entity is associated with a DataReader retrieve it. It is read-only. This is a proxy for get_datareader().
- Type
Optional[cyclonedds.sub.DataReader]
- guid¶
Return the globally unique identifier for this entity. It is read-only. This is a proxy for get_guid().
- Type
- status_mask¶
The status mask for this entity. It is a set of bits formed from
DDSStatus
. This is a proxy for get/set_status_mask().- Type
- parent¶
The entity that is this entities parent. For example: the subscriber for a datareader, the participant for a topic. It is read-only. This is a proxy for get_parent().
- Type
Optional[Entity]
- participant¶
Get the participant for any entity, will only fail for a
Domain
. It is read-only. This is a proxy for get_participant().- Type
Optional[cyclonedds.domain.DomainParticipant]
- children¶
Get a list of children belonging to this entity. It is the opposite as
parent
. It is read-only. This is a proxy for get_children().- Type
List[Entity]
- __init__(ref, listener=None)[source]¶
Initialize an Entity. You should never need to initialize an Entity manually.
- Parameters
ref (int) – The reference id as returned by the DDS API.
listener (Listener) – Listener for this entity. We retain the python object to avoid it being garbage collected if the listener goes out of scope but the entity doesn’t. If we don’t the python function will be freed, causing C to call into freed memory -> segfault.
- Raises
DDSException – If an invalid reference id is passed to this function this means instantiation of some other object failed.
- Return type
None
- get_subscriber()[source]¶
Retrieve the subscriber associated with this entity.
- Returns
Not all entities are associated with a subscriber, so this method may return None.
- Return type
Optional[Subscriber]
- Raises
- get_publisher()[source]¶
Retrieve the publisher associated with this entity.
- Returns
Not all entities are associated with a publisher, so this method may return None.
- Return type
Optional[Publisher]
- Raises
- get_datareader()[source]¶
Retrieve the datareader associated with this entity.
- Returns
Not all entities are associated with a datareader, so this method may return None.
- Return type
Optional[DataReader]
- Raises
- get_instance_handle()[source]¶
Retrieve the instance associated with this entity.
- Returns
The integer handle is just a number you can use in writer/reader calls.
- Return type
- Raises
- property instance_handle: int¶
Retrieve the instance associated with this entity.
- Returns
The integer handle is just a number you can use in writer/reader calls.
- Return type
- Raises
- get_guid()[source]¶
Get a globally unique identifier for this entity.
- Returns
View the python documentation for this class for detailed usage.
- Return type
- Raises
- read_status(mask=None)[source]¶
Read the status bits set on this Entity. You can build a mask by using
DDSStatus
.
- take_status(mask=None)[source]¶
Take the status bits set on this Entity, after which they will be set to 0 again. You can build a mask by using
DDSStatus
.
- get_status_changes()[source]¶
Get all status changes since the last read_status() or take_status().
- Returns
The
DDSStatus
bits that were set.- Return type
- Raises
- get_status_mask()[source]¶
Get the status mask for this Entity.
- Returns
The
DDSStatus
bits that are enabled.- Return type
- Raises
- set_status_mask(mask)[source]¶
- Set the status mask for this Entity. By default the mask is 0. Only the status changes
for the bits in this mask are tracked on this entity.
- Parameters
- Raises
- Return type
None
- get_qos()[source]¶
Get the
Qos
associated with this entity. Note that the object returned is not the same python object that you used to set theQos
on this object. Modifications to theQos
object that is returned does not modify the Qos of the Entity.- Returns
The
Qos
object associated with this entity.- Return type
- Raises
- set_qos(qos)[source]¶
Set
Qos
policies on this entity. Note, only a limited number ofQos
policies can be set after the object is created (Policy.LatencyBudget
andPolicy.OwnershipStrength
). Any policies not set explicitly in the suppliedQos
remain unchanged.- Parameters
- Raises
DDSException – If you pass an immutable policy or cause the total collection of qos policies to become inconsistent an exception will be raised.
- Return type
None
- get_listener()[source]¶
Return a listener with the right methods set. Modifying the returned listener object does not modify this entity, you will have to call set_listener() with the changed object.
- Returns
A listener with which you can add additional callbacks.
- Return type
- set_listener(listener)[source]¶
Update the listener for this object. If a listener already exist for this object only the fields you explicitly have set on your new listener are overwritten. Passing None will remove this entity’s Listener.
Future changes to the passed Listener object will not affect the Listener associated with this Entity.
- Parameters
listener (Optional[cyclonedds.core.Listener]) – The listener object to use, or None to remove the current listener from this Entity.
- Raises
- Return type
None
- get_parent()[source]¶
Get the parent entity associated with this entity. A
Domain
object is the only object without parent, but if the domain is not created through the Python API this call won’t find it and return None from the DomainParticipant.- Returns
The parent of this entity. This would be the Subscriber for a DataReader, DomainParticipant for a Topic etc.
- Return type
Optional[Entity]
- Raises
- get_participant()[source]¶
Get the domain participant for this entity. This should work on all valid Entity objects except a Domain.
- Returns
Only fails for a Domain object.
- Return type
Optional[cyclonedds.domain.DomainParticipant]
- Raises
- get_children()[source]¶
Get the list of children of this entity. For example, the list of datareaders belonging to a subscriber. Opposite of parent.
- Returns
All the entities considered children of this entity.
- Return type
List[Entity]
- Raises
- get_domain_id()[source]¶
Get the id of the domain this entity resides in.
- Returns
The domain id.
- Return type
- Raises
- begin_coherent()[source]¶
Begin coherent publishing or begin accessing a coherent set in a Subscriber.
This can only be invoked on Publishers, Subscribers, DataWriters and DataReaders. Invoking on a DataWriter or DataReader behaves as if it was invoked on its parent Publisher or Subscriber respectively.
- Return type
None
- end_coherent()[source]¶
End coherent publishing or end accessing a coherent set in a Subscriber.
This can only be invoked on Publishers, Subscribers, DataWriters and DataReaders. Invoking on a DataWriter or DataReader behaves as if it was invoked on its parent Publisher or Subscriber respectively.
- Return type
None
- class cyclonedds.core.DDSException(code, msg=None, **kwargs)[source]¶
Bases:
Exception
This exception is thrown when a return code from the underlying C api indicates non-valid use of the API. Print the exception directly or convert it to string for a detailed description.
- DDS_RETCODE_OK = 0¶
- DDS_RETCODE_ERROR = -1¶
- DDS_RETCODE_UNSUPPORTED = -2¶
- DDS_RETCODE_BAD_PARAMETER = -3¶
- DDS_RETCODE_PRECONDITION_NOT_MET = -4¶
- DDS_RETCODE_OUT_OF_RESOURCES = -5¶
- DDS_RETCODE_NOT_ENABLED = -6¶
- DDS_RETCODE_IMMUTABLE_POLICY = -7¶
- DDS_RETCODE_INCONSISTENT_POLICY = -8¶
- DDS_RETCODE_ALREADY_DELETED = -9¶
- DDS_RETCODE_TIMEOUT = -10¶
- DDS_RETCODE_NO_DATA = -11¶
- DDS_RETCODE_ILLEGAL_OPERATION = -12¶
- DDS_RETCODE_NOT_ALLOWED_BY_SECURITY = -13¶
- error_message_mapping = {-13: ('DDS_RETCODE_NOT_ALLOWED_BY_SECURITY', 'Insufficient credentials supplied to use the function'), -12: ('DDS_RETCODE_ILLEGAL_OPERATION', 'A function was called when it should not be'), -11: ('DDS_RETCODE_NO_DATA', 'Expected data is not provided'), -10: ('DDS_RETCODE_TIMEOUT', 'A timeout has occurred'), -9: ('DDS_RETCODE_ALREADY_DELETED', 'An attempt was made to delete something more than once'), -8: ('DDS_RETCODE_INCONSISTENT_POLICY', 'A policy with inconsistent values was used'), -7: ('DDS_RETCODE_IMMUTABLE_POLICY', 'An attempt was made to modify an immutable policy'), -6: ('DDS_RETCODE_NOT_ENABLED', 'A configurable feature is not enabled'), -5: ('DDS_RETCODE_OUT_OF_RESOURCES', 'Operation failed because of a lack of resources'), -4: ('DDS_RETCODE_PRECONDITION_NOT_MET', 'Precondition for operation not met'), -3: ('DDS_RETCODE_BAD_PARAMETER', 'Bad parameter value'), -2: ('DDS_RETCODE_UNSUPPORTED', 'Feature unsupported'), -1: ('DDS_RETCODE_ERROR', 'Non specific error'), 0: ('DDS_RETCODE_OK', 'Success')}¶