Skip to content

Commit 304ce56

Browse files
committed
CON-92: Added APIs to obtain versions used by Connector (#61)
* CON-92: Added APIs to obtain versions used by Connector + tests + docs * CON-92: Changed output to return BUILD IDs as a single string Co-authored-by: Sam Raeburn <sam@rti.com> (cherry picked from commit 7ca0997)
1 parent 3d83c65 commit 304ce56

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

rticonnextdds-connector.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class _ConnectorBinding {
138138
RTI_Connector_set_max_objects_per_thread: ['int', ['int']],
139139
RTIDDSConnector_getJSONInstance:['char *', ['pointer', 'string']],
140140
// This API is only used in the unit tests
141-
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']]
141+
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']],
142+
RTI_Connector_get_build_versions: ['int', [ref.refType('char *'), ref.refType('char *')]]
142143
})
143144
}
144145
}
@@ -2067,6 +2068,38 @@ class Connector extends EventEmitter {
20672068
static setMaxObjectsPerThread (value) {
20682069
_checkRetcode(connectorBinding.api.RTI_Connector_set_max_objects_per_thread(value))
20692070
}
2071+
2072+
/**
2073+
* Returns the version of Connector.
2074+
*
2075+
* This static method provides the build IDs of the native libraries being used
2076+
* by Connector, as well as the version of the Connector API.
2077+
*
2078+
* .. note::
2079+
* This is a static method. It can be called before creating a
2080+
* :class:`Connector` instance.
2081+
*
2082+
* @returns {string} A string containing information about the version of Connector.
2083+
*/
2084+
static get_version() {
2085+
// Obtain version of Connector from package.json
2086+
const versionString = require('./package.json').version
2087+
// Parse numbers out of string
2088+
const versionNumbers = versionString.split('.')
2089+
// Now get the build IDs of the native libraries
2090+
const nativeConnectorVersion = ref.alloc('char *')
2091+
const nativeCoreCVersion = ref.alloc('char *')
2092+
_checkRetcode(connectorBinding.api.RTI_Connector_get_build_versions(
2093+
nativeCoreCVersion,
2094+
nativeConnectorVersion))
2095+
2096+
// Now create the string containing all of the above information
2097+
let versionStr = "RTI Connector for JavaScript, version "
2098+
+ versionNumbers[0] + "." + versionNumbers[1] + "." + versionNumbers[2] + "\n"
2099+
versionStr += ref.readCString(nativeCoreCVersion.deref()) + "\n"
2100+
versionStr += ref.readCString(nativeConnectorVersion.deref())
2101+
return versionStr
2102+
}
20702103
}
20712104

20722105
// Export the API

test/nodejs/test_rticonnextdds_connector.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ describe('Connector Tests', function () {
101101
expect(connector).to.be.instanceOf(rti.Connector)
102102
})
103103

104+
it('is possible to obtain the current version of Connector', function () {
105+
const version = rti.Connector.get_version()
106+
expect(version).to.be.a.string
107+
108+
// The returned version string should contain four pieces of information:
109+
// - the API version of Connector
110+
// - the build ID of core.1.0
111+
// - the build ID of dds_c.1.0
112+
// - the build ID of lua_binding.1.0
113+
// Expect "RTI Connector for JavaScript, version X.X.X"
114+
let regex = /RTI Connector for JavaScript, version ([0-9][.]){2}[0-9]/
115+
expect(regex.test(version)).deep.equals(true)
116+
// Expect "NDDSCORE_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
117+
regex = /.*NDDSCORE_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
118+
expect(regex.test(version)).deep.equals(true)
119+
// Expect "NDDSC_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
120+
regex = /.*NDDSC_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
121+
expect(regex.test(version)).deep.equals(true)
122+
// Expect "RTICONNECTOR_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
123+
regex = /.*RTICONNECTOR_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
124+
expect(regex.test(version)).deep.equals(true)
125+
})
126+
104127
// Test for CON-200
105128
it('Connector should not segfault if deleted twice', async function () {
106129
const xmlProfile1 = path.join(__dirname, '/../xml/TestConnector.xml')

0 commit comments

Comments
 (0)