Skip to content

Commit 17b04a2

Browse files
NickZchris-smith
authored andcommitted
Implement getPublishedTopics() and getTopicTypes() (#80)
Implements getTopicTypes() and getPublishedTopics() master API calls. Exposes getSystemState() call.
1 parent 712b8ce commit 17b04a2

3 files changed

Lines changed: 99 additions & 4 deletions

File tree

src/lib/MasterApiClient.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,40 @@ class MasterApiClient {
118118
});
119119
}
120120

121-
getPublishedTopics(callerId, subgraph) {
122-
throw new Error('NOT SUPPORTED');
121+
getPublishedTopics(callerId, subgraph, options) {
122+
let data = [callerId, subgraph];
123+
return new Promise((resolve,reject)=>{
124+
this._call(
125+
'getPublishedTopics',
126+
data,
127+
function(data) {
128+
return resolve({
129+
topics: data[2].map((topic) => { return {
130+
name: topic[0], type: topic[1]
131+
}})
132+
})
133+
},
134+
reject,
135+
options);
136+
})
123137
}
124138

125-
getTopicTypes(callerId) {
126-
throw new Error('NOT SUPPORTED');
139+
getTopicTypes(callerId, options) {
140+
let data = [callerId];
141+
return new Promise((resolve,reject)=>{
142+
this._call(
143+
'getTopicTypes',
144+
data,
145+
function(data) {
146+
return resolve({
147+
topics: data[2].map((topic) => { return {
148+
name: topic[0], type: topic[1]
149+
}})
150+
})
151+
},
152+
reject,
153+
options);
154+
})
127155
}
128156

129157
/** return an object containing all current publishers (by topic),

src/lib/NodeHandle.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const namespaceUtils = require('../utils/namespace_utils.js');
2323
const ActionClientInterface = require('./ActionClientInterface.js');
2424
const ActionServerInterface = require('./ActionServerInterface.js');
2525

26+
/**
27+
* Handle class for nodes created with rosnodejs
28+
* @param node {RosNode} node that handle is attached to.
29+
* @param namespace {string} namespace of node. @default null
30+
*/
2631
class NodeHandle {
2732
constructor(node, namespace=null) {
2833
this._node = node;
@@ -301,6 +306,56 @@ class NodeHandle {
301306
return this._node.getMasterUri();
302307
}
303308

309+
/**
310+
* @typedef {Object} TopicList
311+
* @property {{name: string, type: string}[]} topics Array of topics
312+
*/
313+
314+
315+
/**
316+
* Get list of topics that can be subscribed to. This does not return
317+
* topics that have no publishers.
318+
*
319+
* @param {string} subgraph Restrict topic names to match within the
320+
* specified subgraph. Subgraph namespace is
321+
* resolved relative to this node's namespace.
322+
* Will return all names if no subgraph is given.
323+
* @return {Promise.<TopicList>}
324+
*/
325+
getPublishedTopics(subgraph="") {
326+
return this._node.getPublishedTopics(subgraph);
327+
}
328+
329+
/**
330+
* Retrieve list topic names and their types.
331+
*
332+
* @return {Promise.<TopicList>}
333+
*/
334+
getTopicTypes() {
335+
return this._node.getTopicTypes();
336+
}
337+
338+
339+
/**
340+
* @typedef {Object} SystemState
341+
* @property {{...string:Array.<string>}} publishers An object with topic names as keys and
342+
* an array of publishers as values
343+
* @property {{...string:Array.<string>}} subscribers An object with topic names as keys and
344+
* an array of subscribers as values
345+
* @property {{...string:Array.<string>}} services An object with service names as keys and
346+
* an array of providers as values
347+
*/
348+
349+
/**
350+
* Retrieve list representation of system state (i.e. publishers,
351+
* subscribers, and services).
352+
*
353+
* @return {Promise.<SystemState>}
354+
*/
355+
getSystemState(){
356+
return this._node.getSystemState();
357+
}
358+
304359
//------------------------------------------------------------------
305360
// Param Interface
306361
//------------------------------------------------------------------

src/lib/RosNode.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ class RosNode extends EventEmitter {
276276
return this._masterApi.getUri(this._nodeName, options);
277277
}
278278

279+
getPublishedTopics(subgraph, options) {
280+
return this._masterApi.getPublishedTopics(this._nodeName, subgraph, options);
281+
}
282+
283+
getTopicTypes(options) {
284+
return this._masterApi.getTopicTypes(this._nodeName, options);
285+
}
286+
287+
getSystemState(options) {
288+
return this._masterApi.getSystemState(this._nodeName, options);
289+
}
290+
279291
/**
280292
* Delays xmlrpc calls until our servers are set up
281293
* Since we need their ports for most of our calls.

0 commit comments

Comments
 (0)