comm_thread.h

00001
00002 /***************************************************************************
00003  *  comm_thread.h - Fawkes RefBox Communication Thread
00004  *
00005  *  Created: Sun Apr 19 13:10:29 2009
00006  *  Copyright  2009  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_REFBOXCOMM_COMM_THREAD_H_
00024 #define __PLUGINS_REFBOXCOMM_COMM_THREAD_H_
00025 
00026 #include "processor/state_handler.h"
00027
00028 #include <core/threading/thread.h>
00029 #include <aspect/blocked_timing.h>
00030 #include <aspect/logging.h>
00031 #include <aspect/configurable.h>
00032 #include <aspect/blackboard.h>
00033 #include <aspect/blocked_timing.h>
00034
00035 namespace fawkes {
00036   class GameStateInterface;
00037   class SplPenaltyInterface;
00038 }
00039
00040 class RefBoxProcessor;
00041
00042 class RefBoxCommThread
00043 : public fawkes::Thread,
00044   public fawkes::BlockedTimingAspect,
00045   public fawkes::LoggingAspect,
00046   public fawkes::ConfigurableAspect,
00047   public fawkes::BlackBoardAspect,
00048   public RefBoxStateHandler
00049 {
00050  public:
00051   RefBoxCommThread();
00052
00053   virtual void init();
00054   virtual void finalize();
00055   virtual void loop();
00056
00057   // RefBoxStateHandler
00058   virtual void set_gamestate(int game_state,
00059                              fawkes::worldinfo_gamestate_team_t state_team);
00060   virtual void set_score(unsigned int score_cyan, unsigned int score_magenta);
00061   virtual void set_team_goal(fawkes::worldinfo_gamestate_team_t our_team,
00062                              fawkes::worldinfo_gamestate_goalcolor_t goal_color);
00063   virtual void set_half(fawkes::worldinfo_gamestate_half_t half, bool kickoff);
00064   virtual void add_penalty(unsigned int penalty,
00065                            unsigned int seconds_remaining);
00066
00067   virtual void handle_refbox_state();
00068 
00069  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00070  protected: virtual void run() { Thread::run(); }
00071
00072  private: /* methods */
00073
00074  private: /* members */
00075   fawkes::GameStateInterface   *__gamestate_if;
00076   fawkes::SplPenaltyInterface  *__penalty_if;
00077   RefBoxProcessor              *__refboxproc;
00078
00079   bool         __gamestate_modified;
00080   int          __last_gamestate;
00081   fawkes::worldinfo_gamestate_half_t  __last_half;
00082   bool __kickoff;
00083   unsigned int __last_score_cyan;
00084   unsigned int __last_score_magenta;
00085   fawkes::worldinfo_gamestate_team_t __our_team;
00086   fawkes::worldinfo_gamestate_goalcolor_t __our_goal_color;
00087   unsigned int __team_number;
00088   unsigned int __player_number;
00089 };
00090
00091
00092 #endif