task_list_stub.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 #***********************************************************
00003 #* Software License Agreement (BSD License)
00004 #*
00005 #*  Copyright (c) 2009, Willow Garage, Inc.
00006 #*  All rights reserved.
00007 #*
00008 #*  Redistribution and use in source and binary forms, with or without
00009 #*  modification, are permitted provided that the following conditions
00010 #*  are met:
00011 #*
00012 #*   * Redistributions of source code must retain the above copyright
00013 #*     notice, this list of conditions and the following disclaimer.
00014 #*   * Redistributions in binary form must reproduce the above
00015 #*     copyright notice, this list of conditions and the following
00016 #*     disclaimer in the documentation and/or other materials provided
00017 #*     with the distribution.
00018 #*   * Neither the name of Willow Garage, Inc. nor the names of its
00019 #*     contributors may be used to endorse or promote products derived
00020 #*     from this software without specific prior written permission.
00021 #*
00022 #*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 #*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 #*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 #*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 #*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 #*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 #*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 #*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 #*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 #*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 #*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 #*  POSSIBILITY OF SUCH DAMAGE.
00034 #* 
00035 #* Author: Eitan Marder-Eppstein
00036 #***********************************************************
00037 PKG = 'continuous_ops_web'
00038 NAME = 'task_list_server'
00039 import time
00040 import roslib; roslib.load_manifest(PKG)
00041 
00042 from continuous_ops_msgs.srv import *
00043 from continuous_ops_msgs.msg import *
00044 import rospy
00045 
00046 tasks = {}
00047 
00048 def get_tasks(req):
00049     print "getting task list"
00050     resp = GetTaskListResponse()
00051     for i in range(10):
00052         task = Task()
00053         task.name = 'task%d' % i
00054         task.task_id = '%d' % i
00055         task.image_file = '/wg/bwi/eitan/ros/dev/continuous_ops/continuous_ops_web/src/continuous_ops_web/images/cont.jpg'
00056         resp.tasks.append(task)
00057     available_pub.publish(resp.tasks)
00058     return resp
00059 
00060 def add_task(req):
00061     print "adding a task: %s" % req.task_id
00062     time.sleep(1)
00063     print "done sleeping"
00064     tasks['run%s' % req.task_id] = req.task_id
00065     resp = AddTaskResponse()
00066     resp.run_id = 'run%s' % req.task_id
00067     for key in tasks.keys():
00068         task = Task()
00069         task.name = 'task%s' % tasks[key]
00070         task.task_id = tasks[key]
00071         task.run_id = key
00072         resp.tasks.append(task)
00073     print resp
00074     return resp
00075 
00076 def remove_task(req):
00077     print "removing task: %s" % req.run_id
00078     time.sleep(1)
00079     del tasks[req.run_id]
00080     resp = ChangeTaskResponse()
00081     for key in tasks.keys():
00082         task = Task()
00083         task.name = 'task%s' % tasks[key]
00084         task.task_id = tasks[key]
00085         task.run_id = key
00086         resp.tasks.append(task)
00087     print resp
00088     return resp
00089 
00090 def get_scheduled_tasks(req):
00091     print "serving scheduled tasks"
00092     resp = GetTaskListResponse()
00093     for key in tasks.keys():
00094         task = Task()
00095         task.name = 'task%s' % tasks[key]
00096         task.task_id = tasks[key]
00097         task.run_id = key
00098         resp.tasks.append(task)
00099     print resp
00100     return resp
00101 
00102 def reorder_tasks(req):
00103     print "reorder"
00104     time.sleep(1)
00105     print req
00106     resp = ReorderTaskListResponse()
00107     for key in tasks.keys():
00108         task = Task()
00109         task.name = 'task%s' % tasks[key]
00110         task.task_id = tasks[key]
00111         task.run_id = key
00112         resp.tasks.append(task)
00113     print resp
00114     return resp
00115 
00116 def task_list_server():
00117     rospy.init_node(NAME)
00118     get = rospy.Service('get_available_tasks', GetTaskList, get_tasks)
00119     get_s = rospy.Service('get_scheduled_tasks', GetTaskList, get_scheduled_tasks)
00120     reorder = rospy.Service('reorder_tasks', ReorderTaskList, reorder_tasks)
00121     add = rospy.Service('add_task', AddTask, add_task)
00122     remove = rospy.Service('remove_task', ChangeTask, remove_task)
00123 
00124     global available_pub
00125     available_pub = rospy.Publisher('available_tasks', Tasks, None, False, True)
00126     rospy.spin()
00127 
00128 if __name__ == "__main__":
00129     task_list_server()


continuous_ops_web
Author(s): Eitan Marder-Eppstein
autogenerated on Fri Dec 6 2013 21:23:09