Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * net_thread.h - Fawkes WorldModel Plugin Network Thread 00004 * 00005 * Created: Fri Jun 29 16:55:52 2007 (on flight to RoboCup 2007, Atlanta) 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_WORLDMODEL_NET_THREAD_H_ 00024 #define __PLUGINS_WORLDMODEL_NET_THREAD_H_ 00025 00026 #include <core/threading/thread.h> 00027 #include <aspect/blackboard.h> 00028 #include <aspect/logging.h> 00029 #include <aspect/configurable.h> 00030 #include <aspect/clock.h> 00031 #include <aspect/network.h> 00032 #include <netcomm/worldinfo/handler.h> 00033 #include <core/utils/lock_map.h> 00034 00035 00036 #include <map> 00037 #include <string> 00038 00039 namespace fawkes { 00040 class WorldInfoTransceiver; 00041 class ObjectPositionInterface; 00042 class GameStateInterface; 00043 } 00044 00045 class WorldModelNetworkThread 00046 : public fawkes::Thread, 00047 public fawkes::LoggingAspect, 00048 public fawkes::ConfigurableAspect, 00049 public fawkes::ClockAspect, 00050 public fawkes::NetworkAspect, 00051 public fawkes::BlackBoardAspect, 00052 public fawkes::WorldInfoHandler 00053 { 00054 public: 00055 WorldModelNetworkThread(); 00056 virtual ~WorldModelNetworkThread(); 00057 00058 virtual void init(); 00059 virtual void loop(); 00060 virtual void finalize(); 00061 00062 fawkes::WorldInfoTransceiver* get_transceiver(); 00063 00064 /* WorldInfoHandler methods follow */ 00065 virtual void pose_rcvd(const char *from_host, 00066 float x, float y, float theta, 00067 float *covariance); 00068 00069 virtual void velocity_rcvd(const char *from_host, float vel_x, 00070 float vel_y, float vel_theta, float *covariance); 00071 00072 virtual void ball_pos_rcvd(const char *from_host, 00073 bool visible, int visibility_history, 00074 float dist, float bearing, float slope, 00075 float *covariance); 00076 00077 virtual void global_ball_pos_rcvd(const char *from_host, 00078 bool visible, int visibility_history, 00079 float x, float y, float z, 00080 float *covariance); 00081 00082 virtual void ball_velocity_rcvd(const char *from_host, 00083 float vel_x, float vel_y, float vel_z, 00084 float *covariance); 00085 00086 virtual void global_ball_velocity_rcvd(const char *from_host, 00087 float vel_x, float vel_y, float vel_z, 00088 float *covariance); 00089 00090 virtual void opponent_pose_rcvd(const char *from_host, 00091 unsigned int uid, 00092 float distance, float bearing, 00093 float *covariance); 00094 00095 virtual void opponent_disapp_rcvd(const char *from_host, unsigned int uid); 00096 00097 virtual void gamestate_rcvd(const char *from_host, 00098 unsigned int game_state, 00099 fawkes::worldinfo_gamestate_team_t state_team, 00100 unsigned int score_cyan, unsigned int score_magenta, 00101 fawkes::worldinfo_gamestate_team_t our_team, 00102 fawkes::worldinfo_gamestate_goalcolor_t our_goal_color, 00103 fawkes::worldinfo_gamestate_half_t half); 00104 00105 virtual void penalty_rcvd(const char *from_host, 00106 unsigned int player, unsigned int penalty, 00107 unsigned int seconds_remaining); 00108 00109 private: 00110 fawkes::WorldInfoTransceiver *__worldinfo_transceiver; 00111 00112 unsigned int __cfg_sleep_time_msec; 00113 unsigned int __cfg_max_msgs_per_recv; 00114 unsigned int __cfg_flush_time_sec; 00115 bool __cfg_multicast_loopback; 00116 00117 typedef std::pair<fawkes::Time, fawkes::ObjectPositionInterface *> TimeObjPosPair; 00118 typedef std::map<unsigned int, TimeObjPosPair> UidTimeObjPosMap; 00119 00120 // host -> if 00121 fawkes::LockMap<std::string, fawkes::ObjectPositionInterface *> __pose_ifs; 00122 fawkes::LockMap<std::string, fawkes::ObjectPositionInterface *> __ball_ifs; 00123 //host -> (uid -> if) 00124 fawkes::LockMap<std::string, UidTimeObjPosMap > __opponent_ifs; 00125 fawkes::GameStateInterface * __gamestate_if; 00126 00127 unsigned int __opponent_id; 00128 00129 // host -> time 00130 fawkes::LockMap<std::string, fawkes::Time> __last_seen; 00131 }; 00132 00133 00134 #endif