handlers.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #     _____
00004 #    /  _  \
00005 #   / _/ \  \
00006 #  / / \_/   \
00007 # /  \_/  _   \  ___  _    ___   ___   ____   ____   ___   _____  _   _
00008 # \  / \_/ \  / /  _\| |  | __| / _ \ | ┌┐ \ | ┌┐ \ / _ \ |_   _|| | | |
00009 #  \ \_/ \_/ /  | |  | |  | └─┐| |_| || └┘ / | └┘_/| |_| |  | |  | └─┘ |
00010 #   \  \_/  /   | |_ | |_ | ┌─┘|  _  || |\ \ | |   |  _  |  | |  | ┌─┐ |
00011 #    \_____/    \___/|___||___||_| |_||_| \_\|_|   |_| |_|  |_|  |_| |_|
00012 #            ROBOTICS™
00013 #
00014 #
00015 #  Copyright © 2012 Clearpath Robotics, Inc. 
00016 #  All Rights Reserved
00017 #  
00018 # Redistribution and use in source and binary forms, with or without
00019 # modification, are permitted provided that the following conditions are met:
00020 #     * Redistributions of source code must retain the above copyright
00021 #       notice, this list of conditions and the following disclaimer.
00022 #     * Redistributions in binary form must reproduce the above copyright
00023 #       notice, this list of conditions and the following disclaimer in the
00024 #       documentation and/or other materials provided with the distribution.
00025 #     * Neither the name of Clearpath Robotics, Inc. nor the
00026 #       names of its contributors may be used to endorse or promote products
00027 #       derived from this software without specific prior written permission.
00028 # 
00029 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00030 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00031 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00032 # DISCLAIMED. IN NO EVENT SHALL CLEARPATH ROBOTICS, INC. BE LIABLE FOR ANY
00033 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 #
00040 # Please send comments, questions, or patches to skynet@clearpathrobotics.com
00041 #
00042 import translator
00043 import rospy
00044 
00045 from applanix_msgs.msg import Ack
00046 
00047 
00048 class Handler:
00049   def handle(self, data):
00050     raise NotImplementedError
00051 
00052 
00053 class NullHandler(Handler):
00054   def handle(self, data):
00055     pass
00056 
00057 
00058 class GroupHandler(Handler):
00059   def __init__(self, name, data_class, listener):
00060     self.publisher = rospy.Publisher(name, data_class, subscriber_listener=listener)
00061     self.message = self.publisher.data_class()
00062 
00063   def handle(self, buff):
00064     self.message.translator().deserialize(buff)
00065     self.publisher.publish(self.message)
00066 
00067 
00068 class MessageHandler(Handler):
00069   def __init__(self, name, data_class, all_msgs):
00070     self.name = name
00071     if data_class.in_all_msgs:
00072       self.message = getattr(all_msgs, name) 
00073     else:
00074       self.message = data_class()
00075 
00076     # Keep a reference to the all_msgs aggregate message.
00077     self.all_msgs = all_msgs
00078 
00079   def handle(self, buff):
00080     self.message.translator().deserialize(buff)
00081     self.all_msgs.last_changed = rospy.get_rostime()
00082 
00083 
00084 class AckHandler(Handler):
00085   def __init__(self):
00086     self.message = Ack()
00087 
00088   def handle(self, buff):
00089     self.message.translator().deserialize(buff)
00090 


applanix_bridge
Author(s): Mike Purvis
autogenerated on Thu Jan 2 2014 11:05:14