Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/connector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ Class reference: Connector

.. autoclass:: Connector
:members:

Class reference: ConnectorVersion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: ConnectorVersion
:members:
118 changes: 118 additions & 0 deletions rticonnextdds-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ var _ConnectorOptions = StructType({
one_based_sequence_indexing: ref.types.int
})

/**
* The Node.js representation of the RTIDDSConnector_LibraryVersion structure
* within the core.
*
* @private
*/
var _NativeConnectorVersion = StructType({
major: ref.types.char,
minor: ref.types.char,
release: ref.types.char,
revision: ref.types.char
})

class _ConnectorBinding {
constructor () {
let libDir = ''
Expand Down Expand Up @@ -137,6 +150,8 @@ class _ConnectorBinding {
RTI_Connector_free_string: ['void', ['char *']],
RTI_Connector_set_max_objects_per_thread: ['int', ['int']],
RTIDDSConnector_getJSONInstance:['char *', ['pointer', 'string']],
RTI_Connector_get_library_version:[ref.refType(_NativeConnectorVersion), []],
RTI_Connector_get_build_version_string:['char *', []],
// This API is only used in the unit tests
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']]
})
Expand Down Expand Up @@ -392,6 +407,61 @@ class Infos {

// Public API

/**
* Provides information about the version of Connector.
*/
class ConnectorVersion {
/**
* This class provides information about the version of Connector being used.
*
* An instance of this class is returned by :meth:`Connector.nativeLibraryVersion`.
* In this case it will contain information regarding the release
* of the native Connext DDS Pro libraries being used by Connector (e.g.,
* 6.1.0).
*
* An instance of the class is also returned by :meth:`Connector.version`,
* providing information regarding the release of Connector
* (e.g., 1.1.0).
*
* The information is provided using 4 Number values. For example, the 1.1.0
* release of Connector would be described as: major = 1, minor = 1,
* release = 0, revision = 0.
*
* @param {Number} major The major release value
* @param {Number} minor The minor release value
* @param {Number} release The release release value
* @param {Number} revision The revision release value
*/
constructor(major = 0, minor = 0, release = 0, revision = 0) {
this.major = new Number(major)
this.minor = new Number(minor)
this.release = new Number(release)
this.revision = new Number(revision)
}

/**
* This is an internal function used to convert the _NativeConnectorVersion
* returned by the core libraries into a ConnectorVersion.
*
* @param {_NativeConnectorVersion} native
* @returns {ConnectorVersion}
* @private
*/
static fromNative(native) {
// Convert the char fields in the native version into numbers
return new ConnectorVersion(
new Number(native.major),
new Number(native.minor),
new Number(native.release),
new Number(0))
}

// Overload to string to print version in format x.x.x.x
toString() {
return this.major + '.' + this.minor + '.' + this.release + '.' + this.revision
}
}

/**
* Iterates and provides access to a data sample.
*/
Expand Down Expand Up @@ -2067,6 +2137,54 @@ class Connector extends EventEmitter {
static setMaxObjectsPerThread (value) {
_checkRetcode(connectorBinding.api.RTI_Connector_set_max_objects_per_thread(value))
}

/**
* Returns the build ID of the native libraries as a string.
*
* .. note::
* This is a static method. It can be called before creating a
* :class:`Connector` instance.
*
* @returns {string} A ``string`` containing the build ID of the native libraries
* used by Connector.
*/
static nativeLibraryBuildString() {
return ref.readCString(
connectorBinding.api.RTI_Connector_get_build_version_string())
}

/**
* Returns the version of the native libraries used by Connector in the format
* major.minor.release.revision (e.g., 6.1.0.0).
*
* .. note::
* This is a static method. It can be called before creating a
* :class:`Connector` instance.
*
* @returns {ConnectorVersion} The version of the native libraries used by Connector.
*/
static nativeLibraryVersion() {
return ConnectorVersion.fromNative(
(connectorBinding.api.RTI_Connector_get_library_version()).deref())
}

/**
* Returns the version of Connector currently in use, in the format
* major.minor.release.revision (e.g., 1.1.0.0).
*
* .. note::
* This is a static method. It can be called before creating a
* :class:`Connector` instance.
*
* @returns {ConnectorVersion} The version of Connector.
*/
static version() {
// Obtain version of Connector from package.json
const versionString = require('./package.json').version
// Parse numbers out of string
const versionNumbers = versionString.split('.')
return new ConnectorVersion(versionNumbers[0], versionNumbers[1], versionNumbers[2])
}
}

// Export the API
Expand Down
35 changes: 35 additions & 0 deletions test/nodejs/test_rticonnextdds_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,41 @@ describe('Connector Tests', function () {
expect(connector).to.be.instanceOf(rti.Connector)
})

it('is possible to obtain the build ID of native libraries', function () {
const str = rti.Connector.nativeLibraryBuildString()
expect(str).to.exist
console.log(typeof(str))
expect(str).to.be.a('string')
expect(str).to.contain('RTICONNECTOR_BUILD_')
})

it('is possible to obtain the version of native libraries', function () {
const nativeVersion = rti.Connector.nativeLibraryVersion()
expect(nativeVersion.major).to.be.a('number')
expect(nativeVersion.minor).to.be.a('number')
expect(nativeVersion.release).to.be.a('number')
expect(nativeVersion.revision).to.be.a('number')
// Confirm that the to string method creates a string in correct format
const str = nativeVersion.toString()
// [major].[minor].[release].[revision]
const regex =/[0-9][.][0-9][.][0-9][.][0-9]/
expect(regex.test(str)).deep.equals(true)
console.log(str)
})

it('is possible to obtain the current version of Connector', function () {
const version = rti.Connector.version()
expect(version.major).to.be.a('number')
expect(version.minor).to.be.a('number')
expect(version.release).to.be.a('number')
expect(version.revision).to.be.a('number')
// Confirm that the to string method creates a string in correct format
const str = version.toString()
// [major].[minor].[release].[revision]
const regex =/[0-9][.][0-9][.][0-9][.][0-9]/
expect(regex.test(str)).deep.equals(true)
})

describe('Connector callback test', function () {
let connector

Expand Down