@@ -16,7 +16,12 @@ class RosMasterStub extends EventEmitter {
1616 registerSubscriber : this . _onRegisterSubscriber . bind ( this ) ,
1717 unregisterSubscriber : this . _onUnregisterSubscriber . bind ( this ) ,
1818 registerPublisher : this . _onRegisterPublisher . bind ( this ) ,
19- unregisterPublisher : this . _onUnregisterPublisher . bind ( this )
19+ unregisterPublisher : this . _onUnregisterPublisher . bind ( this ) ,
20+ deleteParam : this . _deleteParam . bind ( this ) ,
21+ setParam : this . _setParam . bind ( this ) ,
22+ getParam : this . _getParam . bind ( this ) ,
23+ hasParam : this . _hasParam . bind ( this ) ,
24+ getParamNames : this . _getParamNames . bind ( this )
2025 } ;
2126
2227 this . _providedApis = new Set ( ) ;
@@ -27,6 +32,8 @@ class RosMasterStub extends EventEmitter {
2732 pub : null
2833 } ;
2934
35+ this . _params = { } ;
36+
3037 this . listen ( ) ;
3138 }
3239
@@ -41,6 +48,7 @@ class RosMasterStub extends EventEmitter {
4148 }
4249
4350 shutdown ( ) {
51+ this . _params = { } ;
4452 this . _providedApis . clear ( ) ;
4553 this . removeAllListeners ( ) ;
4654 return new Promise ( ( resolve , reject ) => {
@@ -134,6 +142,56 @@ class RosMasterStub extends EventEmitter {
134142 callback ( null , resp ) ;
135143 this . _clientCache . pub = null ;
136144 }
145+
146+ // Param stubbing
147+ // NOTE: this is NOT a spec ParamServer implementation,
148+ // but it provides simple stubs for calls
149+
150+ _deleteParam ( err , params , callback ) {
151+ const key = params [ 1 ] ;
152+ if ( this . _params . hasOwnProperty ( key ) ) {
153+ delete this . _params [ key ] ;
154+ const resp = [ 1 , 'delete value for ' + key , 1 ] ;
155+ callback ( null , resp ) ;
156+ }
157+ else {
158+ const resp = [ 0 , 'no value for ' + key , 1 ] ;
159+ callback ( null , resp ) ;
160+ }
161+ }
162+
163+ _setParam ( err , params , callback ) {
164+ const key = params [ 1 ] ;
165+ const val = params [ 2 ] ;
166+ this . _params [ key ] = val ;
167+ const resp = [ 1 , 'set value for ' + key , 1 ] ;
168+ callback ( null , resp ) ;
169+ }
170+
171+ _getParam ( err , params , callback ) {
172+ const key = params [ 1 ] ;
173+ const val = this . _params [ key ] ;
174+ if ( val !== undefined ) {
175+ const resp = [ 1 , 'data for ' + key , val ] ;
176+ callback ( null , resp ) ;
177+ }
178+ else {
179+ const resp = [ 0 , 'no data for ' + key , null ] ;
180+ callback ( null , resp ) ;
181+ }
182+ }
183+
184+ _hasParam ( err , params , callback ) {
185+ const key = params [ 1 ] ;
186+ const resp = [ 1 , 'check param ' + key , this . _params . hasOwnProperty ( key ) ] ;
187+ callback ( null , resp ) ;
188+ }
189+
190+ _getParamNames ( err , params , callback ) {
191+ const names = Object . keys ( this . _params ) ;
192+ const resp = [ 1 , 'get param names' , names ] ;
193+ callback ( null , resp ) ;
194+ }
137195}
138196
139197module . exports = RosMasterStub ;
0 commit comments