Skip to content

Commit 7ca0997

Browse files
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>
1 parent 1d7a589 commit 7ca0997

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
@@ -140,7 +140,8 @@ class _ConnectorBinding {
140140
RTI_Connector_free_string: ['void', ['char *']],
141141
RTIDDSConnector_getJSONInstance:['char *', ['pointer', 'string']],
142142
// This API is only used in the unit tests
143-
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']]
143+
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']],
144+
RTI_Connector_get_build_versions: ['int', [ref.refType('char *'), ref.refType('char *')]]
144145
})
145146
}
146147
}
@@ -2063,6 +2064,38 @@ class Connector extends EventEmitter {
20632064
*/
20642065
static setMaxObjectsPerThread (value) {
20652066
}
2067+
2068+
/**
2069+
* Returns the version of Connector.
2070+
*
2071+
* This static method provides the build IDs of the native libraries being used
2072+
* by Connector, as well as the version of the Connector API.
2073+
*
2074+
* .. note::
2075+
* This is a static method. It can be called before creating a
2076+
* :class:`Connector` instance.
2077+
*
2078+
* @returns {string} A string containing information about the version of Connector.
2079+
*/
2080+
static get_version() {
2081+
// Obtain version of Connector from package.json
2082+
const versionString = require('./package.json').version
2083+
// Parse numbers out of string
2084+
const versionNumbers = versionString.split('.')
2085+
// Now get the build IDs of the native libraries
2086+
const nativeConnectorVersion = ref.alloc('char *')
2087+
const nativeCoreCVersion = ref.alloc('char *')
2088+
_checkRetcode(connectorBinding.api.RTI_Connector_get_build_versions(
2089+
nativeCoreCVersion,
2090+
nativeConnectorVersion))
2091+
2092+
// Now create the string containing all of the above information
2093+
let versionStr = "RTI Connector for JavaScript, version "
2094+
+ versionNumbers[0] + "." + versionNumbers[1] + "." + versionNumbers[2] + "\n"
2095+
versionStr += ref.readCString(nativeCoreCVersion.deref()) + "\n"
2096+
versionStr += ref.readCString(nativeConnectorVersion.deref())
2097+
return versionStr
2098+
}
20662099
}
20672100

20682101
// 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)