Greetings,
I have an api which handles the execution of any rpc invocations (via the lovely crossbar:), so I can see my ApplicationSession class is going to be mostly boilerplate code consisting of registering rpc methods with api methods, like this:
class SensorAppSession(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
self.api = api.Api(self)
def get_sensor_config():
response = self.api.call('get_sensor_config', self.context)
return response.encode()
reg_config = yield self.api.register(get_sensor_config)
There's a helper method in the api to use a convention based approach:
class Api(object):
def register(self, method):
name = 'io.github.si618.pi-time.{}'.format(method.__name__)
return self.session.register(method, name)
What would be nice is to do this:
class Api(object):
def auto_register(self, method, context, params=None):
reg = lambda name, context, params: self.call(method, context, params).encode()
name = 'io.github.si618.pi-time.{}'.format(method)
return self.session.register(reg, name)
Then my app session code just becomes a single line:
reg_config = yield self.api.auto_register('get_sensor_config', self.context)
The idea being the registration process creates the anonymous method to make the rpc call via the api, as well as return and json encode the response (since this process is the same for all api methods)
Getting a runtime error back from the client, so I'm just not sure if my py-fu is not strong enough, or it's not possible in autobahn...
No big deal though, would just be nice to keep the line count down...
cheers, si