worldcontroller.h
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifdef FARSA_USE_YARP_AND_ICUB
21 
22 #ifndef WORLDCONTROLLER_H
23 #define WORLDCONTROLLER_H
24 
25 #include "worldsimconfig.h"
26 #include "world.h"
27 #include "yarpobject.h"
28 #include <QThread>
29 #include <QHash>
30 #include <QString>
31 #include <QStringList>
32 #include <QQueue>
33 
34 namespace farsa {
35 
36 class WorldController;
37 class ServerWorldController;
39 typedef QHash<QString, yarp::os::Bottle (ServerWorldController::*)(const yarp::os::Bottle&)> cmdHandlerHash;
40 
51 class FARSA_WSIM_API ServerWorldController : public QThread {
52  Q_OBJECT
53 public:
59  void applyQueuedCommands();
60 protected:
62  virtual void run();
63 private:
65  yarp::os::Bottle startCmd( const yarp::os::Bottle& );
67  yarp::os::Bottle pauseCmd( const yarp::os::Bottle& );
69  yarp::os::Bottle stopCmd( const yarp::os::Bottle& );
71  yarp::os::Bottle advanceCmd( const yarp::os::Bottle& );
73  yarp::os::Bottle makeCmd( const yarp::os::Bottle& );
75  yarp::os::Bottle setCmd( const yarp::os::Bottle& );
77  yarp::os::Bottle setWorldCmd( const yarp::os::Bottle& cmd );
79  yarp::os::Bottle setObjectCmd( const yarp::os::Bottle& cmd, WObject* object );
81  WorldController* wctrl;
85  cmdHandlerHash asyn_cmds;
91  cmdHandlerHash syn_cmds;
93  QQueue<yarp::os::Bottle> queue_cmds;
94 };
95 
106 class FARSA_WSIM_API WorldController : public YarpObject {
107  Q_OBJECT
108 public:
110  WorldController( World* world, QString name );
112  ~WorldController();
114  virtual void update();
116  yarp::os::Port* inPort() {
117  return inport;
118  };
120  yarp::os::Port* outPort() {
121  return outport;
122  };
123 private:
127  yarp::os::Port* inport;
129  yarp::os::Port* outport;
130 };
131 
132 } // end namespace farsa
133 
134 #endif
135 
136 #endif // FARSA_USE_YARP_AND_ICUB