3. API Reference¶
3.1. Introduction¶
As described in :ref:`Getting Started <Getting Started>`, the Vortex OpenSplice IDL preprocessor generates typed Streams API classes for each type that is annotated with a streams pragma.
As in the Vortex OpenSplice C++ Reference Guide, the fictional type Foo,
defined in module Space, is used as an example. When the Foo type is
annotated with a pragma streams, FooStreamDataWriter and
FooStreamDataReader classes will be generated.
This section describes the usage of all operations on these classes.
3.2. QoS Policies¶
StreamDataWriterQos |
StreamDataReaderQos |
|---|---|
|
StreamFlushQosPolicy |
Type |
Default value |
|---|---|---|
|
|
|
|
|
|
3.2.1. StreamDataWriterQos¶
3.2.1.1. StreamFlushQosPolicy¶
Scope
DDS::Streams
Synopsis
#include <streams_ccpp.h>
struct StreamFlushQosPolicy {
Duration_t max_delay;
long max_samples;
};
Description
The
StreamFlushQosPolicycan be used to set limits on the stream(s) of theStreamDataWriterit is applied to.
Attributes
Duration_t max_delayTime-based limit. The StreamDataWriter will automatically flush all of its streams each
max_delayperiod.
Note:
max_delayis not yet implemented. It is scheduled for a future release.
long max_samplesSamples-per-stream based limit. The StreamDataWriter will automatically flush a stream when, after appending a sample, the number of samples in that stream equals
max_samples.
Detailed Description
By setting the
StreamFlushQosPolicy, theStreamDataWriterwill automatically flush its stream(s) based on a particular limit. The attributes can be combined, for example amax_delayof 1 second and amax_samplesof 100 will result in a flush at least each second or sooner if 100 samples are appended to a stream.The
max_delaylimit applies to all streams in case aStreamDataWritermanages more than one stream. It is initialized when the first stream is created, and applied to all streams created after that.In case of a manual flush (when the application calls the flush operation), the
max_sampleslimit is reinitialized.
3.2.1.2. StreamDataReaderQos¶
Currently no QoS properties for a StreamDataReader have been identified,
but the StreamDataReaderQos is defined in the API to maintain
consistency with the StreamDataWriter; it is reserved for future use.
3.3. StreamDataWriter Class¶
3.3.1. Constructors¶
Scope
Space::FooStreamDataWriter
Synopsis
#include <SpaceStreamsApi.h>
ooStreamDataWriter(
DDS::Publisher_ptr publisher,
DDS::Streams::StreamDataWriterQos &sqos,
const char* streamName);
FooStreamDataWriter(
DDS::DomainId_t domainId,
DDS::Streams::StreamDataWriterQos &sqos,
const char* streamName);
FooStreamDataWriter(
DDS::Streams::StreamDataWriterQos &sqos,
const char* streamName);
FooStreamDataWriter(
DDS::Publisher_ptr publisher,
const char* streamName);
FooStreamDataWriter(
DDS::DomainId_t domainId,
const char* streamName);
Description
Multiple constructors are available to create a
FooStreamDataWriter. Depending on which parameters are supplied by the application, one of the overloaded constructors will be selected to create a new instance of theFooStreamDataWriterclass.
Parameters
in DDS::Publisher_ptr publisherA pointer to a pre-created DDS Publisher. This parameter is optional; if a publisher is not supplied the
FooStreamDataWriterwill create an internal publisher.in DDS::DomainId_t domainIdThe id of the DDS domain to attach to. The
DDS::DOMAIN_ID_DEFAULTmacro can be used to connect to the default domain, which is also used if the parameter is omitted.in DDS::Streams::StreamDataWriterQos &sqosThe QoS settings that are applied to the
FooStreamDataWriter.in const char* streamNameThe system-wide unique name of the stream that is used to create a DDS (container-)topic for the stream(s) that are handled by the
FooStreamDataWriter.
Exceptions
Constructors cannot return a value, therefore they throw exceptions when the object cannot be constructed. Besides exceptions, the regular Vortex OpenSplice error logging framework is used to report additional information when a constructor fails.
The constructors throw a
StreamsExceptionif an error occurs. The application may catch these exceptions to detect when creation of a StreamDataWriter doesn’t succeed.DDS::Streams::StreamsException { out const char *message; out DDS::ReturnCode_t id }The message contains a description of the error. The
idfield contains a DDS error code that represents the error condition.
Detailed Description
When a pre-created publisher is not supplied, the
FooStreamDataWriterwill create an internal DDS participant and DDS publisher. This will naturally consume some resources, so when a lot of streams need to be created it is recommended to supply a publisher that can be re-used for eachFooStreamDataWriterinstance.The
streamNameis a required parameter. TheFooStreamDataWriterwill create a DDS topic of the correct type and name it after the suppliedstreamName.
3.3.2. append¶
Scope
Space::FooStreamDataWriter
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
append(
StreamId id,
const Foo &data)
Description
Write a sample to the stream with the supplied
id.
Parameters
in StreamId idThe stream id.
in Foo &dataThe data to write to the stream.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_PRECONDITION_NOT_MET.
Detailed Description
Using the
appendoperation, the application can write data to a stream. Note that for each stream of a certain type, multiple instances of this stream-type can be created by assigning unique ids to each of streams. Each id then represents an instance of the stream of the associated type. So the actual stream instance is selected based on the suppliedStreamId.When the stream doesn’t exist it is automatically created based on the current QoS settings.
Return Code
When the operation returns:
RETCODE_OKThe data was successfully appended to the stream.
RETCODE_PRECONDITION_NOT_META precondition failed, data was not appended.
If the
StreamDataWriterQoS specifies an auto-flush maximum samples limit, anappendmay trigger a flush. In that case theappendcall forwards the return code of the flush to the application, so any return code that is specified in the next section may also be returned byappend.
3.3.3. flush¶
Scope
Space::FooStreamDataWriter
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
flush(
DDS::Streams::StreamId id)
Description
Write all data in a stream to the DDS subsystem.
Parameters
in StreamId idThe id of the stream.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_PRECONDITION_NOT_MET.
Detailed Description
When a stream is flushed, all data in the stream is delivered to DDS and the stream is emptied. The memory allocated will be reused the next time data is appended to the stream.
The
flushoperation results in a write call on the underlying DDS subsystem. Depending on the result of the write, this result is returned back to the application.
Return Code
RETCODE_OKThe stream was successfully flushed.
RETCODE_PRECONDITION_NOT_META precondition failed; most likely the stream doesn’t exist.
See the Vortex OpenSplice C++ Reference Guide for possible result codes returned by a DDS
writeoperation.
3.3.4. get_qos¶
Scope
Space::FooStreamDataWriter
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
get_qos(
DDS::Streams::StreamDataWriterQos &qos)
Description
This operation allows access to the existing set of QoS policies for a
FooStreamDataWriter.
Parameters
inout StreamDataWriterQos &qosA pointer to a
StreamDatatWriterQosobject to which the current QoS settings will be copied.
Return Value
ReturnCode_tPossible return code of the operation is:
DDS::RETCODE_OK.
Detailed Description
The existing list of QoS settings of the
FooStreamDataWriteris copied to the object pointed to byqos. The application can then inspect and, if necessary, modify the settings and apply the settings using theset_qosoperation.
Return Code
RETCODE_OKThe QoS settings were successfully copied to the supplied
qosobject.
3.3.5. set_qos¶
Scope
Space::FooStreamDataWriter
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
set_qos(
DDS::Streams::StreamDataWriterQos &qos)
Description
This operation allows replacing the existing set of QoS policies for a
FooStreamDataWriter.
Parameters
in StreamDataWriterQos &qosA pointer to a
qosobject with the new policies.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_UNSUPPORTED.
Detailed Description
This operation allows replacing the set of QoS policies of a
FooStreamDataWriter.
Note: A new
StreamFlushQosPolicymay decrease the value ofmax_samples, but existing streams are not allowed to violate this limit. Any streams that contain data that exceeds the newmax_samplesvalue are automatically flushed before the new policy is applied.
Return Code
RETCODE_OKThe QoS settings were successfully applied to the
FooStreamDataWriter.RETCODE_UNSUPPORTEDThe application attempted to set QoS policies or values that are not (yet) supported.
3.4. StreamDataReader Class¶
3.4.1. Constructors¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
FooStreamDataReader(
DDS::Subscriber_ptr subscriber,
DDS::Streams::StreamDataReaderQos &sqos,
const char* streamName);
FooStreamDataReader(
DDS::DomainId_t domainId,
DDS::Streams::StreamDataReaderQos &sqos,
const char* streamName);
FooStreamDataReader(
DDS::Streams::StreamDataReaderQos &sqos,
const char* streamName);
FooStreamDataReader(
DDS::Subscriber_ptr subscriber,
const char* streamName);
FooStreamDataReader(
DDS::DomainId_t domainId,
const char* streamName);
Description
Multiple constructors are available to create a
FooStreamDataReader. Depending on which parameters are supplied by the application, one of the overloaded constructors will be selected to create a new instance of aFooStreamDataReaderclass.
Parameters
in DDS::Subscriber_ptr subscriberA pointer to a pre-created DDS Subscriber. This parameter is optional; if a subscriber is not supplied the
FooStreamDataReaderwill create an internal subscriber.in DDS::DomainId_t domainIdThe id of the DDS domain to attach to. The
DDS::DOMAIN_ID_DEFAULTmacro can be used to connect to the default domain, which is also used if the parameter is omitted.in DDS::Streams::StreamDataReaderQos &sqosThe QoS settings that are applied to the
FooStreamDataReader.in const char* streamNameThe system-wide unique name of the stream which is also used to create a DDS (container-)topic for the stream(s) that are handled by the
FooStreamDataReader.
Exceptions
Constructors cannot return a value, therefore they throw exceptions when the object cannot be constructed. Besides exceptions, the regular Vortex OpenSplice error logging framework is used to report additional information when a constructor fails.
The constructors throw a
StreamsExceptionif an error occurs. The application may catch these exceptions to detect when creation of aStreamDataReaderdoesn’t succeed.DDS::Streams::StreamsException { out const char *message; out DDS::ReturnCode_t id }The message contains a description of the error. The
idfield contains a DDS error code that represents the error condition.
Detailed Description
When a pre-created subscriber is not supplied, the
FooStreamDataReaderwill create an internal DDS participant and DDS subscriber. This will naturally consume some resources, so when a lot of instances need to be created it is recommended to supply a subscriber that can be re-used for eachFooStreamDataReaderinstance.The
streamNameis a required parameter. TheFooStreamDataReaderwill create a DDS topic of the correct type and name it after the suppliedstreamName.
3.4.2. get¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
get(
DDS::Streams::StreamId id,
Space::FooStreamBuf data_values,
long max_samples,
DDS::Duration_t timeout);
Description
Check if any data is available in a stream and retrieve it, emptying the stream.
Parameters
in StreamId idThe
idof the stream instance from which to retrieve the data.inout FooStreamBuf data_valuesThe buffer in which the data is stored.
in long max_samplesThe maximum amount of data samples retrieved. Default is
DDS::LENGTH_UNLIMITED.in Duration_t timeoutBlocking time, in case no data is immediately available.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_PRECONDITION_NOT_MET.
Detailed Description
Using the
getoperation, the application can retrieve data from a stream. The stream is selected based on the suppliedStreamId.If no data is available initially, the
getoperation blocks for a maximum period specified in thetimeoutparameter. If data becomes available during thetimeoutperiod theFooStreamDataReaderproceeds to retrieve the data and return it to the application. To return immediately, the application can use the special valueDDS::DURATION_ZEROas atimeoutparameter. To block indefinitely until data is available, the valueDDS::DURATION_INFINITEshould be passed.The data is returned in a buffer that is to be supplied by the application. The application is responsible for allocating a buffer that is large enough to contain the available data. If more data is available than will fit in the buffer, the excess data will be stored by the StreamDataReader and returned to the application during the next call to get (or get_w_filter). In this state, the
StreamDataReaderwill only attempt to retrieve new data after all data that was stored internally is returned to the application.Since allocating memory for the buffer is an expensive operation, it is recommended to re-use the same buffer for each subsequent call to get or get_w_filter. The
max_samplesparameter can be used to limit the amount of data that is returned with each get or get_w_filter call.
Note: Internal pre-allocation of buffers, using a loans registry similar to the DCPS API, will be implemented in a future version.
Return Code
DDS::RETCODE_OKData is returned in the
data_valuesbuffer.DDS::RETCODE_NO_DATAThere is currently no data available.
DDS::RETCODE_PRECONDITION_NOT_METThe operation could not be performed because a precondition is not met; most likely the
data_valuesbuffer is not preallocated.The list of possible return codes includes all possible return codes of
waitset.wait()andtake_instance()calls. These DCPS calls are used internally by the Streams API. There is one exception: if thewaitset.wait()returns aDDS::RETCODE_TIMEOUT, this return code is translated to aDDS::RETCODE_NO_DATAreturn code.See the Vortex OpenSplice C++ Reference Guide for possible result codes returned by a DDS
take_instanceoperation and forwaitset.wait().
3.4.3. get_w_filter¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
get_w_filter(
DDS::Streams::StreamId id,
Space::FooStreamBuf data_values,
long max_samples,
DDS::Duration_t timeout
Space::FooStreamFilterCallback a_filter);
Description
Check if any data is available in a stream and retrieve it if it matches the filter, discard otherwise.
Parameters
in StreamId idThe
idof the stream instance of which to retrieve the data.inout FooStreamBuf data_valuesThe buffer in which the data is stored.
in long max_samplesThe maximum amount of data samples retrieved.
in Duration_t timeoutBlocking time, in case no data is immediately available.
in FooStreamFilterCallback a_filterPointer to a function that implements a filter for the data.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_PRECONDITION_NOT_MET.
Detailed Description
The
get_w_filteroperation is equivalent to the get operation, the description of get also applies toget_w_filter.The difference is that
get_w_filterallows the application to supply aFooStreamFilterCallbackinstance that implements thematch_data()operation. Each data sample is matched against the filter and only data for which the filter returnstrueis returned to the application.Samples that do not match the filter are not considered in relation to
max_samplesand thedata_valuesbuffer length; the buffer does not need to be capable of holding all available samples, just the samples that pass the filter.Samples are only evaluated once and are discarded if not matched.
Return Code
DDS::RETCODE_OKData is returned in the
data_valuesbuffer.DDS::RETCODE_NO_DATAThere is no data available during the period specified by
timeout.DDS::RETCODE_PRECONDITION_NOT_METThe operation could not be performed because a precondition is not met; most likely the
data_valuesbuffer is not preallocated.The list of possible return codes includes all possible return codes of
waitset.wait()andtake_instance()calls. These DCPS calls are used internally by the Streams API. There’s one exception: If thewaitset.wait()returns aDDS::RETCODE_TIMEOUT, this return code is translated to aDDS::RETCODE_NO_DATAreturn code.See the Vortex OpenSplice C++ Reference Guide for possible result codes returned by a DDS
take_instanceoperation andwaitset.wait().
3.4.4. return_loan¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
return_loan(
Space::FooStreamBuf data_values)
Description
The application should use this operation to indicate that it has finished accessing the sequence of
data_values.
Parameters
inout FooStreamBuf data_valuesThe data sequence which was loaned from the
FooStreamDataReader.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_PRECONDITION_NOT_MET.
Detailed Description
When the application does not pre-allocate a buffer to hold the data, the
FooStreamDataReaderwill do so itself when a get operation is invoked. The application callsreturn_loanto indicate that it has finished accessing this buffer so theFooStreamDataReadercan reclaim the resources allocated for the buffer.
Note: Internal pre-allocation will be implemented in a future release. This operation has no effect on buffers allocated by the application.
3.4.5. get_qos¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
get_qos(
DDS::Streams::StreamDataReaderQos &qos)
Description
This operation allows access to the existing set of QoS policies for a
FooStreamDataReader.
Parameters
inout StreamDataReaderQos &qosA pointer to a
StreamDataReaderQosobject to which the current QoS settings will be copied.
Return Value
ReturnCode_tPossible return code of the operation is:
DDS::RETCODE_OK.
Detailed Description
The existing list of QoS settings of the
FooStreamDataReaderis copied to the object pointed to byqos. The application can then inspect and, if necessary, modify the settings and apply the settings using theset_qosoperation.
Return Code
RETCODE_OKThe QoS settings were successfully copied to the supplied
qosobject.
3.4.6. set_qos¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
set_qos(
DDS::Streams::StreamDataReaderQos &qos)
Description
This operation allows replacing the existing set of QoS policies for a
FooStreamDataReader.
Parameters
in StreamDataReaderQos &qosA pointer to a
qosobject with the new policies.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_UNSUPPORTED.
Detailed Description
This operation allows replacing the set of QoS policies of a
FooStreamDataReader.
Return Code
RETCODE_OKThe QoS settings were successfully applied to the
FooStreamDataWriter.RETCODE_UNSUPPORTEDThe application attempted to set QoS policies or values that are not (yet) supported.
3.4.7. interrupt¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
DDS::ReturnCode_t
interrupt();
Description
Interrupt a blocking get operation from a different thread.
Return Value
ReturnCode_tPossible return codes of the operation are:
DDS::RETCODE_OK,DDS::RETCODE_ERROR.
Detailed Description
The get operation accepts a
timeoutparameter which causes theFooStreamDataReaderto block until data becomes available. It can block indefinitely when an infinite timeout is supplied and data never becomes available because there are simply no compatible writers.In such cases it can be desirable to interrupt the get operation from the application, i.e. for termination or reclaiming of resources.
The
interruptcall triggers an internalGuardConditionby callingDDS::GuardCondition::set_trigger_value(true). This causes the get operation to return with aDDS::RETCODE_NO_DATAresult.
Return Code
The return code of this operation is determined by the result of
DDS::GuardCondition::set_trigger_value()
DDS::RETCODE_OKThe
GuardConditionwas triggered successfullyDDS::RETCODE_ERRORAn internal error occurred
3.5. FooStreamFilterCallback Interface¶
Scope
Space::FooStreamDataReader
Synopsis
#include <SpaceStreamsApi.h>
boolean
a_filter(
const Space::Foo &data)
Description
Function interface for filters that are passed to the get_w_filter and/or
peek_w_filteroperations.
Parameters
in const Foo &dataA data sample.
Return Value
booleanReturn
trueif the supplied data matches,falseif it doesn’t match.
Detailed Description
The application can supply any function that adheres to the
FooStreamFilterCallbackinterface, to filter data that is retrieved by the get_w_filter operation. If the data matches the filter, the function returnstrueand the data is added to thedata_valuesbuffer that is returned by the get_w_filter operation. Data that doesn’t match the filter is discarded.