Go to the documentation of this file.00001
00002
00003
00004 from __future__ import print_function, division
00005
00006 import sys
00007 import sqlalchemy
00008 from lama_interfaces.interface_factory import DBInterface as SerInterface
00009 from lama_interfaces.cleartext_interface_factory import DBInterface as CtInterface
00010
00011 _services = {
00012 'sensor_msgs/LaserScan[]': ('lama_interfaces/GetVectorLaserScan',
00013 'lama_interfaces/SetVectorLaserScan'),
00014 'lama_msgs/Crossing': ('lama_msgs/GetCrossing', 'lama_msgs/SetCrossing'),
00015 'float64': ('lama_interfaces/GetDouble',
00016 'lama_interfaces/SetDouble'),
00017 }
00018
00019
00020 def read_map_interfaces(metadata):
00021 table = metadata.tables['map_interfaces']
00022 query = table.select()
00023 connection = metadata.bind.connect()
00024 transaction = connection.begin()
00025 results = connection.execute(query).fetchall()
00026 transaction.commit()
00027 connection.close()
00028 if not results:
00029 return None
00030 classes = {
00031 'serialization': SerInterface,
00032 'cleartext': CtInterface,
00033 }
00034 interfaces = {}
00035 for result in results:
00036 iface_name = result['interface_name']
00037 cls = classes[result['interface_type']]
00038 interfaces[iface_name] = cls(
00039 metadata.bind,
00040 iface_name,
00041 _services[result['message_type']][0],
00042 _services[result['message_type']][1],
00043 start=False)
00044 return interfaces
00045
00046
00047 def getter(id_, interface_name):
00048 interface = interfaces[interface_name]
00049 request = interface.getter_service_class._request_class()
00050 request.id = id_
00051 response = interface.getter(request)
00052 return response.descriptor
00053
00054 if __name__ == '__main__':
00055 if len(sys.argv) > 1:
00056 engine_name = 'sqlite:///' + sys.argv[1]
00057 engine = sqlalchemy.create_engine(engine_name)
00058 metadata = sqlalchemy.MetaData(engine)
00059 metadata.reflect()
00060 interfaces = read_map_interfaces(metadata)