00001 /* 00002 Copyright (c) 2000-2002, Jelle Kok, University of Amsterdam 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are met: 00007 00008 1. Redistributions of source code must retain the above copyright notice, this 00009 list of conditions and the following disclaimer. 00010 00011 2. Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation 00013 and/or other materials provided with the distribution. 00014 00015 3. Neither the name of the University of Amsterdam nor the names of its 00016 contributors may be used to endorse or promote products derived from this 00017 software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00023 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00046 #ifndef _SENSEHANDLER_ 00047 #define _SENSEHANDLER_ 00048 00049 #include "Connection.h" 00050 #include "WorldModel.h" 00051 00052 extern Logger Log; 00054 void* sense_callback( void *v ); 00055 00056 /******************************************************************************/ 00057 /********************** CLASS SENSEHANDLER ************************************/ 00058 /******************************************************************************/ 00059 00069 class SenseHandler { 00070 WorldModel *WM; 00071 ServerSettings *SS; 00072 PlayerSettings *PS; 00073 Connection* connection; 00074 int iTimeSignal; 00075 int iTriCounter; 00076 int m_iSeeCounter; 00077 int iSimStep; 00078 struct itimerval itv; 00080 public: 00081 SenseHandler( Connection* c, WorldModel* wm, ServerSettings *ss, 00082 PlayerSettings *ps ); 00083 00084 // start the loop to handle the messages from the server 00085 void handleMessagesFromServer ( ); 00086 00087 // methods to determine when the next action should be sent to the server. 00088 void setTimeSignal ( ); 00089 00090 // method to analyze incoming messages 00091 bool analyzeMessage ( char *strMsg ); 00092 bool analyzeSeeGlobalMessage ( char *strMsg ); 00093 bool analyzeSeeMessage ( char *strMsg ); 00094 bool analyzeSenseMessage ( char *strMsg ); 00095 bool analyzeInitMessage ( char *strMsg ); 00096 bool analyzeHearMessage ( char *strMsg ); 00097 bool analyzePlayerMessage ( char *strMsg ); 00098 bool analyzeChangePlayerTypeMessage( char *strMsg ); 00099 bool analyzeServerParamMessage ( char *strMsg ); 00100 bool analyzeCheckBall ( char *strMsg ); 00101 bool analyzePlayerTypeMessage ( char *strMsg ); 00102 bool analyzePlayerParamMessage ( char *strMsg ); 00103 00104 // utility functions 00105 bool readServerParam ( char *strParam, 00106 char *strMsg ); 00107 }; 00108 00109 #endif