Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simulationtasksupervisor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef _SIMULATIONTASKSUPERVISOR_H_
25 #define _SIMULATIONTASKSUPERVISOR_H_
26 
27 #include "simulationtask.h"
28 #include <string>
29 
30 namespace osg
31 {
32  class ArgumentParser;
33 }
34 
35 
36 namespace lpzrobots
37 {
38 
39  class LpzRobotsViewer;
40 
42  {
43  public:
44 
45  /**
46  * Returns the singleton instance of this class.
47  * There is no way to instantiate yourself this class.
48  * @param simTaskHandle The global SimulationTaskHandle were you can put in your needed data.
49  * This handle is shared by all parallel running simulations.
50  * @return the singleton instance of this class
51  */
53  {
54  if(singletonInstance==0)
56  return singletonInstance;
57  }
58 
59  /**
60  * Destroys the singleton instance of this class.
61  */
62  static void destroyInstance()
63  {
64  if (singletonInstance!=0)
65  {
66  delete singletonInstance;
68  }
69  }
70 
71  static void setSimTaskHandle(SimulationTaskHandle& _simTaskHandle)
72  {
73  simTaskHandle= &_simTaskHandle;
74  }
75 
76  static void setTaskedSimCreator(TaskedSimulationCreator& _taskedSimCreator)
77  {
78  taskedSimCreator = &_taskedSimCreator;
79  }
80 
81  /**
82  * Sets the number of total threads running at one time.
83  * @param numberThreads
84  */
85  static void setNumberThreads(int numberThreads);
86 
87  /**
88  * Sets the number of threads created per core. The default value is 1.
89  * So if your machine has e.g. 4 cores, 4 threads are created.
90  * If you have much code which must be synchronized, it may be
91  * useful to increase the number of threads per core, 2 is a good value.
92  * @param numberThreadsPerCore
93  */
94  static void setNumberThreadsPerCore(int numberThreadsPerCore);
95 
96  /**
97  * Creates one SimulationTask with taskId=SimulationTaskHandle.simTaskList.size().
98  * @param argc count of arguments in argv
99  * @param argv array of arguments, given to Simulation when the tasks starts
100  */
101  virtual void createSimTask()
102  {
103  SimulationTask* simTask = new SimulationTask(simTaskList.size());
104  SimulationTaskSupervisor::simTaskList.push_back(simTask);
105  }
106 
107  /**
108  * Same as createSimTask, but create more than one task at once.
109  * taskIds assigned in ascending order.
110  * @param taskCount number of tasks to create
111  * @param argc count of arguments in argv
112  * @param argv array of arguments, given to Simulation when the tasks starts
113  */
114  virtual void createSimTasks(int taskCount)
115  {
116  for (int i=0; i<taskCount; i++)
117  createSimTask();
118  }
119 
120  /**
121  * Runs all generated SimulationTasks.
122  */
123  virtual void runSimTasks(int* argc, char** argv);
124 
125  /**
126  * Sets a suffix to be appended to the window name to identify your simTask
127  */
128  virtual void setSimTaskNameSuffix(std::string name);
129 
130  protected:
131 
133 
135 
139  static std::vector<SimulationTask*> simTaskList;
140  static int* argc;
141  static char** argv;
142  static osg::ArgumentParser* parser;
143  static LpzRobotsViewer* viewer;
144  static std::string nameSuffix;
145 
146 
147  };
148 
149 } // end namespace lpzrobots
150 
151 #endif /* _SIMULATIONTASKSUPERVISOR_H_ */
static int * argc
Definition: simulationtasksupervisor.h:140
static void setSimTaskHandle(SimulationTaskHandle &_simTaskHandle)
Definition: simulationtasksupervisor.h:71
static char ** argv
Definition: simulationtasksupervisor.h:141
virtual void createSimTask()
Creates one SimulationTask with taskId=SimulationTaskHandle.simTaskList.size().
Definition: simulationtasksupervisor.h:101
virtual void setSimTaskNameSuffix(std::string name)
Sets a suffix to be appended to the window name to identify your simTask.
Definition: simulationtasksupervisor.cpp:113
static TaskedSimulationCreator * taskedSimCreator
Definition: simulationtasksupervisor.h:138
Definition: simulationtask.h:37
Definition: simulationtasksupervisor.h:41
static SimulationTaskHandle * simTaskHandle
Definition: simulationtasksupervisor.h:137
static std::string nameSuffix
Definition: simulationtasksupervisor.h:144
virtual void runSimTasks(int *argc, char **argv)
Runs all generated SimulationTasks.
Definition: simulationtasksupervisor.cpp:54
static osg::ArgumentParser * parser
Definition: simulationtasksupervisor.h:142
static SimulationTaskSupervisor * singletonInstance
Definition: simulationtasksupervisor.h:136
SimulationTaskSupervisor()
Definition: simulationtasksupervisor.h:132
static void setTaskedSimCreator(TaskedSimulationCreator &_taskedSimCreator)
Definition: simulationtasksupervisor.h:76
static LpzRobotsViewer * viewer
Definition: simulationtasksupervisor.h:143
struct which holds all structural data for the simulations.
Definition: simulationtaskhandle.h:37
virtual ~SimulationTaskSupervisor()
Definition: simulationtasksupervisor.h:134
static void destroyInstance()
Destroys the singleton instance of this class.
Definition: simulationtasksupervisor.h:62
virtual void createSimTasks(int taskCount)
Same as createSimTask, but create more than one task at once.
Definition: simulationtasksupervisor.h:114
static void setNumberThreadsPerCore(int numberThreadsPerCore)
Sets the number of threads created per core.
Definition: simulationtasksupervisor.cpp:107
static void setNumberThreads(int numberThreads)
Sets the number of total threads running at one time.
Definition: simulationtasksupervisor.cpp:101
static SimulationTaskSupervisor * getInstance()
Returns the singleton instance of this class.
Definition: simulationtasksupervisor.h:52
Defines a method to construct a TaskedSimulation.
Definition: taskedsimulationcreator.h:36
static std::vector< SimulationTask * > simTaskList
Definition: simulationtasksupervisor.h:139