GameStateInterface.cpp

00001 
00002 /***************************************************************************
00003  *  GameStateInterface.cpp - Fawkes BlackBoard Interface - GameStateInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2008  Tim Niemueller
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. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <interfaces/GameStateInterface.h>
00025 
00026 #include <core/exceptions/software.h>
00027 
00028 #include <cstring>
00029 #include <cstdlib>
00030 
00031 namespace fawkes {
00032 
00033 /** @class GameStateInterface <interfaces/GameStateInterface.h>
00034  * GameStateInterface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides access to the current game state. It is closely related to
00037       the WorldInfo network protocol.
00038       @see WorldInfoTransceiver
00039     
00040  * @ingroup FawkesInterfaces
00041  */
00042 
00043 
00044 /** GS_FROZEN constant */
00045 const uint32_t GameStateInterface::GS_FROZEN = 0u;
00046 /** GS_PLAY constant */
00047 const uint32_t GameStateInterface::GS_PLAY = 1u;
00048 /** GS_KICK_OFF constant */
00049 const uint32_t GameStateInterface::GS_KICK_OFF = 2u;
00050 /** GS_DROP_BALL constant */
00051 const uint32_t GameStateInterface::GS_DROP_BALL = 3u;
00052 /** GS_PENALTY constant */
00053 const uint32_t GameStateInterface::GS_PENALTY = 4u;
00054 /** GS_CORNER_KICK constant */
00055 const uint32_t GameStateInterface::GS_CORNER_KICK = 5u;
00056 /** GS_THROW_IN constant */
00057 const uint32_t GameStateInterface::GS_THROW_IN = 6u;
00058 /** GS_FREE_KICK constant */
00059 const uint32_t GameStateInterface::GS_FREE_KICK = 7u;
00060 /** GS_GOAL_KICK constant */
00061 const uint32_t GameStateInterface::GS_GOAL_KICK = 8u;
00062 /** GS_HALF_TIME constant */
00063 const uint32_t GameStateInterface::GS_HALF_TIME = 9u;
00064 /** GS_SPL_INITIAL constant */
00065 const uint32_t GameStateInterface::GS_SPL_INITIAL = 0u;
00066 /** GS_SPL_READY constant */
00067 const uint32_t GameStateInterface::GS_SPL_READY = 1u;
00068 /** GS_SPL_SET constant */
00069 const uint32_t GameStateInterface::GS_SPL_SET = 2u;
00070 /** GS_SPL_PLAY constant */
00071 const uint32_t GameStateInterface::GS_SPL_PLAY = 3u;
00072 /** GS_SPL_FINISHED constant */
00073 const uint32_t GameStateInterface::GS_SPL_FINISHED = 4u;
00074 
00075 /** Constructor */
00076 GameStateInterface::GameStateInterface() : Interface()
00077 {
00078   data_size = sizeof(GameStateInterface_data_t);
00079   data_ptr  = malloc(data_size);
00080   data      = (GameStateInterface_data_t *)data_ptr;
00081   data_ts   = (interface_data_ts_t *)data_ptr;
00082   memset(data_ptr, 0, data_size);
00083   add_fieldinfo(IFT_UINT32, "game_state", 1, &data->game_state);
00084   add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t");
00085   add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t");
00086   add_fieldinfo(IFT_ENUM, "our_goal_color", 1, &data->our_goal_color, "if_gamestate_goalcolor_t");
00087   add_fieldinfo(IFT_ENUM, "half", 1, &data->half, "if_gamestate_half_t");
00088   add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
00089   add_fieldinfo(IFT_ENUM, "role", 1, &data->role, "if_gamestate_role_t");
00090   add_fieldinfo(IFT_UINT32, "score_cyan", 1, &data->score_cyan);
00091   add_fieldinfo(IFT_UINT32, "score_magenta", 1, &data->score_magenta);
00092   add_messageinfo("SetTeamColorMessage");
00093   add_messageinfo("SetKickoffMessage");
00094   add_messageinfo("SetStateTeamMessage");
00095   unsigned char tmp_hash[] = {0xf5, 0x19, 0x26, 0x77, 0x6, 0x54, 0x44, 0xb4, 0xe1, 0x61, 0x40, 0x2a, 0x65, 0xfc, 0xaf, 0xa1};
00096   set_hash(tmp_hash);
00097 }
00098 
00099 /** Destructor */
00100 GameStateInterface::~GameStateInterface()
00101 {
00102   free(data_ptr);
00103 }
00104 /** Convert if_gamestate_team_t constant to string.
00105  * @param value value to convert to string
00106  * @return constant value as string.
00107  */
00108 const char *
00109 GameStateInterface::tostring_if_gamestate_team_t(if_gamestate_team_t value) const
00110 {
00111   switch (value) {
00112   case TEAM_NONE: return "TEAM_NONE";
00113   case TEAM_CYAN: return "TEAM_CYAN";
00114   case TEAM_MAGENTA: return "TEAM_MAGENTA";
00115   case TEAM_BOTH: return "TEAM_BOTH";
00116   default: return "UNKNOWN";
00117   }
00118 }
00119 /** Convert if_gamestate_goalcolor_t constant to string.
00120  * @param value value to convert to string
00121  * @return constant value as string.
00122  */
00123 const char *
00124 GameStateInterface::tostring_if_gamestate_goalcolor_t(if_gamestate_goalcolor_t value) const
00125 {
00126   switch (value) {
00127   case GOAL_BLUE: return "GOAL_BLUE";
00128   case GOAL_YELLOW: return "GOAL_YELLOW";
00129   default: return "UNKNOWN";
00130   }
00131 }
00132 /** Convert if_gamestate_half_t constant to string.
00133  * @param value value to convert to string
00134  * @return constant value as string.
00135  */
00136 const char *
00137 GameStateInterface::tostring_if_gamestate_half_t(if_gamestate_half_t value) const
00138 {
00139   switch (value) {
00140   case HALF_FIRST: return "HALF_FIRST";
00141   case HALF_SECOND: return "HALF_SECOND";
00142   default: return "UNKNOWN";
00143   }
00144 }
00145 /** Convert if_gamestate_role_t constant to string.
00146  * @param value value to convert to string
00147  * @return constant value as string.
00148  */
00149 const char *
00150 GameStateInterface::tostring_if_gamestate_role_t(if_gamestate_role_t value) const
00151 {
00152   switch (value) {
00153   case ROLE_GOALIE: return "ROLE_GOALIE";
00154   case ROLE_DEFENDER: return "ROLE_DEFENDER";
00155   case ROLE_MID_LEFT: return "ROLE_MID_LEFT";
00156   case ROLE_MID_RIGHT: return "ROLE_MID_RIGHT";
00157   case ROLE_ATTACKER: return "ROLE_ATTACKER";
00158   default: return "UNKNOWN";
00159   }
00160 }
00161 /* Methods */
00162 /** Get game_state value.
00163  * Current game state
00164  * @return game_state value
00165  */
00166 uint32_t
00167 GameStateInterface::game_state() const
00168 {
00169   return data->game_state;
00170 }
00171 
00172 /** Get maximum length of game_state value.
00173  * @return length of game_state value, can be length of the array or number of 
00174  * maximum number of characters for a string
00175  */
00176 size_t
00177 GameStateInterface::maxlenof_game_state() const
00178 {
00179   return 1;
00180 }
00181 
00182 /** Set game_state value.
00183  * Current game state
00184  * @param new_game_state new game_state value
00185  */
00186 void
00187 GameStateInterface::set_game_state(const uint32_t new_game_state)
00188 {
00189   data->game_state = new_game_state;
00190   data_changed = true;
00191 }
00192 
00193 /** Get state_team value.
00194  * Team referred to by game state
00195  * @return state_team value
00196  */
00197 GameStateInterface::if_gamestate_team_t
00198 GameStateInterface::state_team() const
00199 {
00200   return data->state_team;
00201 }
00202 
00203 /** Get maximum length of state_team value.
00204  * @return length of state_team value, can be length of the array or number of 
00205  * maximum number of characters for a string
00206  */
00207 size_t
00208 GameStateInterface::maxlenof_state_team() const
00209 {
00210   return 1;
00211 }
00212 
00213 /** Set state_team value.
00214  * Team referred to by game state
00215  * @param new_state_team new state_team value
00216  */
00217 void
00218 GameStateInterface::set_state_team(const if_gamestate_team_t new_state_team)
00219 {
00220   data->state_team = new_state_team;
00221   data_changed = true;
00222 }
00223 
00224 /** Get our_team value.
00225  * Our team color
00226  * @return our_team value
00227  */
00228 GameStateInterface::if_gamestate_team_t
00229 GameStateInterface::our_team() const
00230 {
00231   return data->our_team;
00232 }
00233 
00234 /** Get maximum length of our_team value.
00235  * @return length of our_team value, can be length of the array or number of 
00236  * maximum number of characters for a string
00237  */
00238 size_t
00239 GameStateInterface::maxlenof_our_team() const
00240 {
00241   return 1;
00242 }
00243 
00244 /** Set our_team value.
00245  * Our team color
00246  * @param new_our_team new our_team value
00247  */
00248 void
00249 GameStateInterface::set_our_team(const if_gamestate_team_t new_our_team)
00250 {
00251   data->our_team = new_our_team;
00252   data_changed = true;
00253 }
00254 
00255 /** Get our_goal_color value.
00256  * Our own goal color
00257  * @return our_goal_color value
00258  */
00259 GameStateInterface::if_gamestate_goalcolor_t
00260 GameStateInterface::our_goal_color() const
00261 {
00262   return data->our_goal_color;
00263 }
00264 
00265 /** Get maximum length of our_goal_color value.
00266  * @return length of our_goal_color value, can be length of the array or number of 
00267  * maximum number of characters for a string
00268  */
00269 size_t
00270 GameStateInterface::maxlenof_our_goal_color() const
00271 {
00272   return 1;
00273 }
00274 
00275 /** Set our_goal_color value.
00276  * Our own goal color
00277  * @param new_our_goal_color new our_goal_color value
00278  */
00279 void
00280 GameStateInterface::set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color)
00281 {
00282   data->our_goal_color = new_our_goal_color;
00283   data_changed = true;
00284 }
00285 
00286 /** Get half value.
00287  * Current game half
00288  * @return half value
00289  */
00290 GameStateInterface::if_gamestate_half_t
00291 GameStateInterface::half() const
00292 {
00293   return data->half;
00294 }
00295 
00296 /** Get maximum length of half value.
00297  * @return length of half value, can be length of the array or number of 
00298  * maximum number of characters for a string
00299  */
00300 size_t
00301 GameStateInterface::maxlenof_half() const
00302 {
00303   return 1;
00304 }
00305 
00306 /** Set half value.
00307  * Current game half
00308  * @param new_half new half value
00309  */
00310 void
00311 GameStateInterface::set_half(const if_gamestate_half_t new_half)
00312 {
00313   data->half = new_half;
00314   data_changed = true;
00315 }
00316 
00317 /** Get kickoff value.
00318  * Whether we have kickoff
00319  * @return kickoff value
00320  */
00321 bool
00322 GameStateInterface::is_kickoff() const
00323 {
00324   return data->kickoff;
00325 }
00326 
00327 /** Get maximum length of kickoff value.
00328  * @return length of kickoff value, can be length of the array or number of 
00329  * maximum number of characters for a string
00330  */
00331 size_t
00332 GameStateInterface::maxlenof_kickoff() const
00333 {
00334   return 1;
00335 }
00336 
00337 /** Set kickoff value.
00338  * Whether we have kickoff
00339  * @param new_kickoff new kickoff value
00340  */
00341 void
00342 GameStateInterface::set_kickoff(const bool new_kickoff)
00343 {
00344   data->kickoff = new_kickoff;
00345   data_changed = true;
00346 }
00347 
00348 /** Get role value.
00349  * Current role of this robot
00350  * @return role value
00351  */
00352 GameStateInterface::if_gamestate_role_t
00353 GameStateInterface::role() const
00354 {
00355   return data->role;
00356 }
00357 
00358 /** Get maximum length of role value.
00359  * @return length of role value, can be length of the array or number of 
00360  * maximum number of characters for a string
00361  */
00362 size_t
00363 GameStateInterface::maxlenof_role() const
00364 {
00365   return 1;
00366 }
00367 
00368 /** Set role value.
00369  * Current role of this robot
00370  * @param new_role new role value
00371  */
00372 void
00373 GameStateInterface::set_role(const if_gamestate_role_t new_role)
00374 {
00375   data->role = new_role;
00376   data_changed = true;
00377 }
00378 
00379 /** Get score_cyan value.
00380  * Score of team cyan
00381  * @return score_cyan value
00382  */
00383 uint32_t
00384 GameStateInterface::score_cyan() const
00385 {
00386   return data->score_cyan;
00387 }
00388 
00389 /** Get maximum length of score_cyan value.
00390  * @return length of score_cyan value, can be length of the array or number of 
00391  * maximum number of characters for a string
00392  */
00393 size_t
00394 GameStateInterface::maxlenof_score_cyan() const
00395 {
00396   return 1;
00397 }
00398 
00399 /** Set score_cyan value.
00400  * Score of team cyan
00401  * @param new_score_cyan new score_cyan value
00402  */
00403 void
00404 GameStateInterface::set_score_cyan(const uint32_t new_score_cyan)
00405 {
00406   data->score_cyan = new_score_cyan;
00407   data_changed = true;
00408 }
00409 
00410 /** Get score_magenta value.
00411  * Score of team magenta
00412  * @return score_magenta value
00413  */
00414 uint32_t
00415 GameStateInterface::score_magenta() const
00416 {
00417   return data->score_magenta;
00418 }
00419 
00420 /** Get maximum length of score_magenta value.
00421  * @return length of score_magenta value, can be length of the array or number of 
00422  * maximum number of characters for a string
00423  */
00424 size_t
00425 GameStateInterface::maxlenof_score_magenta() const
00426 {
00427   return 1;
00428 }
00429 
00430 /** Set score_magenta value.
00431  * Score of team magenta
00432  * @param new_score_magenta new score_magenta value
00433  */
00434 void
00435 GameStateInterface::set_score_magenta(const uint32_t new_score_magenta)
00436 {
00437   data->score_magenta = new_score_magenta;
00438   data_changed = true;
00439 }
00440 
00441 /* =========== message create =========== */
00442 Message *
00443 GameStateInterface::create_message(const char *type) const
00444 {
00445   if ( strncmp("SetTeamColorMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00446     return new SetTeamColorMessage();
00447   } else if ( strncmp("SetKickoffMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00448     return new SetKickoffMessage();
00449   } else if ( strncmp("SetStateTeamMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00450     return new SetStateTeamMessage();
00451   } else {
00452     throw UnknownTypeException("The given type '%s' does not match any known "
00453                                "message type for this interface type.", type);
00454   }
00455 }
00456 
00457 
00458 /** Copy values from other interface.
00459  * @param other other interface to copy values from
00460  */
00461 void
00462 GameStateInterface::copy_values(const Interface *other)
00463 {
00464   const GameStateInterface *oi = dynamic_cast<const GameStateInterface *>(other);
00465   if (oi == NULL) {
00466     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00467                                 type(), other->type());
00468   }
00469   memcpy(data, oi->data, sizeof(GameStateInterface_data_t));
00470 }
00471 
00472 const char *
00473 GameStateInterface::enum_tostring(const char *enumtype, int val) const
00474 {
00475   if (strcmp(enumtype, "if_gamestate_team_t") == 0) {
00476     return tostring_if_gamestate_team_t((if_gamestate_team_t)val);
00477   }
00478   if (strcmp(enumtype, "if_gamestate_goalcolor_t") == 0) {
00479     return tostring_if_gamestate_goalcolor_t((if_gamestate_goalcolor_t)val);
00480   }
00481   if (strcmp(enumtype, "if_gamestate_half_t") == 0) {
00482     return tostring_if_gamestate_half_t((if_gamestate_half_t)val);
00483   }
00484   if (strcmp(enumtype, "if_gamestate_role_t") == 0) {
00485     return tostring_if_gamestate_role_t((if_gamestate_role_t)val);
00486   }
00487   throw UnknownTypeException("Unknown enum type %s", enumtype);
00488 }
00489 
00490 /* =========== messages =========== */
00491 /** @class GameStateInterface::SetTeamColorMessage <interfaces/GameStateInterface.h>
00492  * SetTeamColorMessage Fawkes BlackBoard Interface Message.
00493  * 
00494     
00495  */
00496 
00497 
00498 /** Constructor with initial values.
00499  * @param ini_our_team initial value for our_team
00500  */
00501 GameStateInterface::SetTeamColorMessage::SetTeamColorMessage(const if_gamestate_team_t ini_our_team) : Message("SetTeamColorMessage")
00502 {
00503   data_size = sizeof(SetTeamColorMessage_data_t);
00504   data_ptr  = malloc(data_size);
00505   memset(data_ptr, 0, data_size);
00506   data      = (SetTeamColorMessage_data_t *)data_ptr;
00507   data_ts   = (message_data_ts_t *)data_ptr;
00508   data->our_team = ini_our_team;
00509   add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t");
00510 }
00511 /** Constructor */
00512 GameStateInterface::SetTeamColorMessage::SetTeamColorMessage() : Message("SetTeamColorMessage")
00513 {
00514   data_size = sizeof(SetTeamColorMessage_data_t);
00515   data_ptr  = malloc(data_size);
00516   memset(data_ptr, 0, data_size);
00517   data      = (SetTeamColorMessage_data_t *)data_ptr;
00518   data_ts   = (message_data_ts_t *)data_ptr;
00519   add_fieldinfo(IFT_ENUM, "our_team", 1, &data->our_team, "if_gamestate_team_t");
00520 }
00521 
00522 /** Destructor */
00523 GameStateInterface::SetTeamColorMessage::~SetTeamColorMessage()
00524 {
00525   free(data_ptr);
00526 }
00527 
00528 /** Copy constructor.
00529  * @param m message to copy from
00530  */
00531 GameStateInterface::SetTeamColorMessage::SetTeamColorMessage(const SetTeamColorMessage *m) : Message("SetTeamColorMessage")
00532 {
00533   data_size = m->data_size;
00534   data_ptr  = malloc(data_size);
00535   memcpy(data_ptr, m->data_ptr, data_size);
00536   data      = (SetTeamColorMessage_data_t *)data_ptr;
00537   data_ts   = (message_data_ts_t *)data_ptr;
00538 }
00539 
00540 /* Methods */
00541 /** Get our_team value.
00542  * Our team color
00543  * @return our_team value
00544  */
00545 GameStateInterface::if_gamestate_team_t
00546 GameStateInterface::SetTeamColorMessage::our_team() const
00547 {
00548   return data->our_team;
00549 }
00550 
00551 /** Get maximum length of our_team value.
00552  * @return length of our_team value, can be length of the array or number of 
00553  * maximum number of characters for a string
00554  */
00555 size_t
00556 GameStateInterface::SetTeamColorMessage::maxlenof_our_team() const
00557 {
00558   return 1;
00559 }
00560 
00561 /** Set our_team value.
00562  * Our team color
00563  * @param new_our_team new our_team value
00564  */
00565 void
00566 GameStateInterface::SetTeamColorMessage::set_our_team(const if_gamestate_team_t new_our_team)
00567 {
00568   data->our_team = new_our_team;
00569 }
00570 
00571 /** Clone this message.
00572  * Produces a message of the same type as this message and copies the
00573  * data to the new message.
00574  * @return clone of this message
00575  */
00576 Message *
00577 GameStateInterface::SetTeamColorMessage::clone() const
00578 {
00579   return new GameStateInterface::SetTeamColorMessage(this);
00580 }
00581 /** @class GameStateInterface::SetKickoffMessage <interfaces/GameStateInterface.h>
00582  * SetKickoffMessage Fawkes BlackBoard Interface Message.
00583  * 
00584     
00585  */
00586 
00587 
00588 /** Constructor with initial values.
00589  * @param ini_kickoff initial value for kickoff
00590  */
00591 GameStateInterface::SetKickoffMessage::SetKickoffMessage(const bool ini_kickoff) : Message("SetKickoffMessage")
00592 {
00593   data_size = sizeof(SetKickoffMessage_data_t);
00594   data_ptr  = malloc(data_size);
00595   memset(data_ptr, 0, data_size);
00596   data      = (SetKickoffMessage_data_t *)data_ptr;
00597   data_ts   = (message_data_ts_t *)data_ptr;
00598   data->kickoff = ini_kickoff;
00599   add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
00600 }
00601 /** Constructor */
00602 GameStateInterface::SetKickoffMessage::SetKickoffMessage() : Message("SetKickoffMessage")
00603 {
00604   data_size = sizeof(SetKickoffMessage_data_t);
00605   data_ptr  = malloc(data_size);
00606   memset(data_ptr, 0, data_size);
00607   data      = (SetKickoffMessage_data_t *)data_ptr;
00608   data_ts   = (message_data_ts_t *)data_ptr;
00609   add_fieldinfo(IFT_BOOL, "kickoff", 1, &data->kickoff);
00610 }
00611 
00612 /** Destructor */
00613 GameStateInterface::SetKickoffMessage::~SetKickoffMessage()
00614 {
00615   free(data_ptr);
00616 }
00617 
00618 /** Copy constructor.
00619  * @param m message to copy from
00620  */
00621 GameStateInterface::SetKickoffMessage::SetKickoffMessage(const SetKickoffMessage *m) : Message("SetKickoffMessage")
00622 {
00623   data_size = m->data_size;
00624   data_ptr  = malloc(data_size);
00625   memcpy(data_ptr, m->data_ptr, data_size);
00626   data      = (SetKickoffMessage_data_t *)data_ptr;
00627   data_ts   = (message_data_ts_t *)data_ptr;
00628 }
00629 
00630 /* Methods */
00631 /** Get kickoff value.
00632  * Whether we have kickoff
00633  * @return kickoff value
00634  */
00635 bool
00636 GameStateInterface::SetKickoffMessage::is_kickoff() const
00637 {
00638   return data->kickoff;
00639 }
00640 
00641 /** Get maximum length of kickoff value.
00642  * @return length of kickoff value, can be length of the array or number of 
00643  * maximum number of characters for a string
00644  */
00645 size_t
00646 GameStateInterface::SetKickoffMessage::maxlenof_kickoff() const
00647 {
00648   return 1;
00649 }
00650 
00651 /** Set kickoff value.
00652  * Whether we have kickoff
00653  * @param new_kickoff new kickoff value
00654  */
00655 void
00656 GameStateInterface::SetKickoffMessage::set_kickoff(const bool new_kickoff)
00657 {
00658   data->kickoff = new_kickoff;
00659 }
00660 
00661 /** Clone this message.
00662  * Produces a message of the same type as this message and copies the
00663  * data to the new message.
00664  * @return clone of this message
00665  */
00666 Message *
00667 GameStateInterface::SetKickoffMessage::clone() const
00668 {
00669   return new GameStateInterface::SetKickoffMessage(this);
00670 }
00671 /** @class GameStateInterface::SetStateTeamMessage <interfaces/GameStateInterface.h>
00672  * SetStateTeamMessage Fawkes BlackBoard Interface Message.
00673  * 
00674     
00675  */
00676 
00677 
00678 /** Constructor with initial values.
00679  * @param ini_state_team initial value for state_team
00680  */
00681 GameStateInterface::SetStateTeamMessage::SetStateTeamMessage(const if_gamestate_team_t ini_state_team) : Message("SetStateTeamMessage")
00682 {
00683   data_size = sizeof(SetStateTeamMessage_data_t);
00684   data_ptr  = malloc(data_size);
00685   memset(data_ptr, 0, data_size);
00686   data      = (SetStateTeamMessage_data_t *)data_ptr;
00687   data_ts   = (message_data_ts_t *)data_ptr;
00688   data->state_team = ini_state_team;
00689   add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t");
00690 }
00691 /** Constructor */
00692 GameStateInterface::SetStateTeamMessage::SetStateTeamMessage() : Message("SetStateTeamMessage")
00693 {
00694   data_size = sizeof(SetStateTeamMessage_data_t);
00695   data_ptr  = malloc(data_size);
00696   memset(data_ptr, 0, data_size);
00697   data      = (SetStateTeamMessage_data_t *)data_ptr;
00698   data_ts   = (message_data_ts_t *)data_ptr;
00699   add_fieldinfo(IFT_ENUM, "state_team", 1, &data->state_team, "if_gamestate_team_t");
00700 }
00701 
00702 /** Destructor */
00703 GameStateInterface::SetStateTeamMessage::~SetStateTeamMessage()
00704 {
00705   free(data_ptr);
00706 }
00707 
00708 /** Copy constructor.
00709  * @param m message to copy from
00710  */
00711 GameStateInterface::SetStateTeamMessage::SetStateTeamMessage(const SetStateTeamMessage *m) : Message("SetStateTeamMessage")
00712 {
00713   data_size = m->data_size;
00714   data_ptr  = malloc(data_size);
00715   memcpy(data_ptr, m->data_ptr, data_size);
00716   data      = (SetStateTeamMessage_data_t *)data_ptr;
00717   data_ts   = (message_data_ts_t *)data_ptr;
00718 }
00719 
00720 /* Methods */
00721 /** Get state_team value.
00722  * Team referred to by game state
00723  * @return state_team value
00724  */
00725 GameStateInterface::if_gamestate_team_t
00726 GameStateInterface::SetStateTeamMessage::state_team() const
00727 {
00728   return data->state_team;
00729 }
00730 
00731 /** Get maximum length of state_team value.
00732  * @return length of state_team value, can be length of the array or number of 
00733  * maximum number of characters for a string
00734  */
00735 size_t
00736 GameStateInterface::SetStateTeamMessage::maxlenof_state_team() const
00737 {
00738   return 1;
00739 }
00740 
00741 /** Set state_team value.
00742  * Team referred to by game state
00743  * @param new_state_team new state_team value
00744  */
00745 void
00746 GameStateInterface::SetStateTeamMessage::set_state_team(const if_gamestate_team_t new_state_team)
00747 {
00748   data->state_team = new_state_team;
00749 }
00750 
00751 /** Clone this message.
00752  * Produces a message of the same type as this message and copies the
00753  * data to the new message.
00754  * @return clone of this message
00755  */
00756 Message *
00757 GameStateInterface::SetStateTeamMessage::clone() const
00758 {
00759   return new GameStateInterface::SetStateTeamMessage(this);
00760 }
00761 /** Check if message is valid and can be enqueued.
00762  * @param message Message to check
00763  * @return true if the message is valid, false otherwise.
00764  */
00765 bool
00766 GameStateInterface::message_valid(const Message *message) const
00767 {
00768   const SetTeamColorMessage *m0 = dynamic_cast<const SetTeamColorMessage *>(message);
00769   if ( m0 != NULL ) {
00770     return true;
00771   }
00772   const SetKickoffMessage *m1 = dynamic_cast<const SetKickoffMessage *>(message);
00773   if ( m1 != NULL ) {
00774     return true;
00775   }
00776   const SetStateTeamMessage *m2 = dynamic_cast<const SetStateTeamMessage *>(message);
00777   if ( m2 != NULL ) {
00778     return true;
00779   }
00780   return false;
00781 }
00782 
00783 /// @cond INTERNALS
00784 EXPORT_INTERFACE(GameStateInterface)
00785 /// @endcond
00786 
00787 
00788 } // end namespace fawkes

Generated on Tue Feb 22 13:32:24 2011 for Fawkes API by  doxygen 1.4.7