Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import roslib; roslib.load_manifest('k-saap_pkg')
00020
00021
00022 import os, xmlrpclib
00023
00024
00025 import rospy
00026
00027
00028 import auction_msgs.msg
00029
00030
00031 import auction_srvs.srv
00032
00033
00034 import auctioneer
00035 import buyer_k_saap
00036
00037
00038 import random
00039 import math
00040
00041
00042 role_assigned = False
00043 actual_role = 'none'
00044 master_server = ''
00045 buyer_server = ''
00046 auctioneer_server = ''
00047 auctioneer_bid_reception_server = ''
00048
00049
00050
00051
00052
00053 def handle_auction_server_callback(auction_req):
00054
00055 global role_assigned, actual_role
00056 global master_server, buyer_server
00057
00058
00059
00060 if rospy.has_param('/num_messages'):
00061 num_messages = rospy.get_param('/num_messages')
00062 num_messages += 2
00063 rospy.set_param('/num_messages', num_messages)
00064
00065
00066 if rospy.has_param('/auction_closed'):
00067 if rospy.get_param('/auction_closed') == True:
00068 role_assigned = False
00069
00070 rospy.loginfo(rospy.get_name()+' '+str(role_assigned))
00071
00072
00073 if not role_assigned:
00074 role_assigned = True
00075
00076 if auction_req.role == 'be_auctioneer':
00077 return auctioneer.handle_auction_server_callback(auction_req)
00078
00079 elif auction_req.role == 'be_buyer':
00080 return buyer_k_saap.handle_auction_server_callback(auction_req)
00081
00082 else:
00083 return {'response_info':'invalid role requested'}
00084
00085 else:
00086 return {'response_info':'node already have a role'}
00087
00088
00089
00090
00091
00092
00093
00094
00095 if __name__ == "__main__":
00096
00097
00098 rospy.init_node('node', anonymous=True)
00099
00100
00101 service_path = rospy.get_name()+"/auction_server"
00102
00103 auctioneer_response = rospy.Service(service_path,
00104 auction_srvs.srv.AuctionService,
00105 handle_auction_server_callback)
00106
00107
00108
00109
00110
00111 rospy.spin()
00112
00113