Fawkes API  Fawkes Development Version
refbox_state_sender.h
00001 
00002 /***************************************************************************
00003  *  refbox_state_sender.h - Fawkes RefBox state sender
00004  *
00005  *  Created: Wed Apr 09 09:56:57 2008
00006  *  Copyright  2008  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 __TOOLS_REFBOXREP_REFBOX_STATE_SENDER_H_
00024 #define __TOOLS_REFBOXREP_REFBOX_STATE_SENDER_H_
00025 
00026 #include <core/threading/thread.h>
00027 #include <netcomm/worldinfo/enums.h>
00028 #include <map>
00029 
00030 namespace fawkes {
00031   class WorldInfoTransceiver;
00032 }
00033 
00034 class RefBoxStateSender
00035 {
00036  public:
00037   RefBoxStateSender(const char *addr, unsigned short port,
00038                     const char *key, const char *iv,
00039                     bool debug = false);
00040   virtual ~RefBoxStateSender();
00041 
00042   virtual void send();
00043   virtual void set_gamestate(int game_state,
00044                              fawkes::worldinfo_gamestate_team_t state_team);
00045   virtual void set_score(unsigned int score_cyan, unsigned int score_magenta);
00046   virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team,
00047                              fawkes::worldinfo_gamestate_goalcolor_t goal_color);
00048   virtual void set_half(fawkes::worldinfo_gamestate_half_t half);
00049   virtual void add_penalty(unsigned int player, unsigned int penalty,
00050                            unsigned int seconds_remaining);
00051 
00052   class TimeoutThread : public fawkes::Thread
00053   {
00054    public:
00055     TimeoutThread(RefBoxStateSender *rss);
00056     virtual ~TimeoutThread();
00057     virtual void loop();
00058    private:
00059     unsigned int __timeout_usec;
00060     RefBoxStateSender *__rss;
00061   };
00062 
00063  protected:
00064   RefBoxStateSender();
00065 
00066  private:
00067   void execute_send();
00068 
00069  private:
00070   bool                                    __debug;
00071   fawkes::WorldInfoTransceiver           *__transceiver;
00072   TimeoutThread                          *__timeout_thread;
00073 
00074   int                                     __game_state;
00075   fawkes::worldinfo_gamestate_team_t      __state_team;
00076   unsigned int                            __score_cyan;
00077   unsigned int                            __score_magenta;
00078   fawkes::worldinfo_gamestate_team_t      __our_team;
00079   fawkes::worldinfo_gamestate_goalcolor_t __our_goal_color;
00080   fawkes::worldinfo_gamestate_half_t      __half;
00081 
00082   /// @cond INTERNALS
00083   typedef struct {
00084     unsigned int player;
00085     unsigned int penalty;
00086     unsigned int seconds_remaining;
00087   } rss_penalty_t;
00088   /// @endcond
00089   std::map<unsigned int, rss_penalty_t> __penalties;
00090   std::map<unsigned int, rss_penalty_t>::iterator __pit;
00091 
00092 };
00093 
00094 #endif