Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

robtele.h

00001 /*
00002  * robtele.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may not be distributed.
00008  * 
00009  */
00010 // Declares RoboTour@Home related classes
00011 
00012 #ifndef __RT_ROBTELE__
00013 #define __RT_ROBTELE__
00014 
00015 #include "robfrontend.h"
00016 #include "robmanage.h"
00017 
00018 #include <rtnetwork.h>
00019 #include <rtcollect.h>
00020 #include <rtstring.h>
00021 #include <rtsystem.h>
00022 
00023 #ifdef __NETWORK__
00024 namespace rt {
00025 
00026 class JobManager;
00027 
00028 class TeleFrontend : public Frontend {
00029 
00030 public:
00031         TeleFrontend();
00032         virtual ~TeleFrontend();
00033 
00034         // from ErrorHandler
00035         virtual void handleLoadError(const String& affectedFile, const String& message) const;
00036         virtual void handleBotError(const Bot* affectedBot, ExecReturnType type) const;
00037         virtual void handleSystemError(int num, const String& message) const;
00038         virtual void handleWarning(const String& message) const;
00039 
00040         virtual void reset();
00041         virtual bool interpreteParamsImpl(const Array<String>& params, Array<bool>& used);
00042         virtual void fillOptions(SimOptions& options);
00043         virtual SimManager* getManager(); // always return a properly initialized JobManager
00044 
00045         enum Winner { TIE = 0, ROB1 = 1, ROB2 = 2};
00046 
00047         struct JobLine {
00048                 JobLine() : winner(TIE), cycles(-1) {}
00049                 JobLine(const Array<String>& strings) : rbiId1(strings[0]), rbiBase1(strings[1]), 
00050                         rbiEncoder1(strings[2]), rbiId2(strings[3]), rbiBase2(strings[4]), rbiEncoder2(strings[5]), 
00051                         winner(TIE), cycles(-1) {}
00052 
00053                 String rbiId1, rbiBase1, rbiEncoder1, rbiId2, rbiBase2, rbiEncoder2;
00054                 Winner winner;
00055                 int cycles;
00056         };
00057         struct JobData {
00058                 JobData() : jobId(0), rcoChecksum(0), jobs(0) {}
00059 
00060                 int jobId;
00061                 String competition;
00062                 String rbiSource;
00063                 String rcoSource;
00064                 unsigned int rcoChecksum;
00065                 Vector<JobLine> jobs;
00066         };
00067 
00068 protected:
00069         friend class JobManager;
00070         String user;
00071         String password;
00072         String teleServer;
00073         String workingFolder;
00074         int verbose;
00075         int requestedJobSize;
00076 
00077         JobData job;
00078 
00079         String getRobotFileName(const String& robotID, const String& robotBaseFile);
00080         bool getJob(JobData& job);
00081         bool decodeJob(const String& page, JobData& job);
00082         bool getRobotFile(const JobData& job, const String& robotID, const String& robotBaseFile, const String& enc);
00083         bool getFiles(JobData& job);
00084 
00085         unsigned int computeChecksum(const String& fileName);
00086         bool checkChecksum(const String& fileName, unsigned int shouldBeChecksum);
00087         bool checkRBI(const String& fileName, const String& shouldBeEncoder);
00088 
00089         void printHelp();
00090 };
00091 
00092 
00093 class JobManager : public SimManager {
00094 public:
00095         JobManager(TeleFrontend* parent, TeleFrontend::JobData& job);
00097         virtual void setup(SimOptions* const options);
00098         virtual void run();
00099         void sendResults();
00101         virtual ~JobManager();
00102 
00103         class JobSupervisor : public SimSupervisor {
00104         public:
00105                 JobSupervisor(TeleFrontend::JobData& job);
00106                 virtual ~JobSupervisor();
00107 
00108                 void skipOneMatch();
00109                 virtual SimSuperPosition getPreferredPosition();
00110                 virtual unsigned long getStepCycles();
00111                 virtual void initSim(Simulation* const sim);
00112                 virtual SimSupervisor::GameState exec(Simulation* const sim);
00113                 virtual void exitSim(Simulation* const sim, const GameState& simResult);
00114 
00115         protected:
00116                 TeleFrontend::JobData& job;
00117                 int currentJob;
00118         };
00119 
00120 protected:
00121         TeleFrontend* parent;
00122         JobSupervisor* sup;
00123         TeleFrontend::JobData& data;
00124 
00125         bool addAndCheck(const String& botname);
00126         virtual void createSupervisors();
00127         virtual TourInitInfo getTourInitInfo() { return TourInitInfo(0,0); } // sorry, got no idea
00128 };
00129 
00130 } // namespace
00131 #endif // NETWORK
00132 
00133 #endif

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer