All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Server.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _SERVER_HH_
18 #define _SERVER_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <list>
23 #include <map>
24 
25 #include <boost/program_options.hpp>
26 #include <boost/thread.hpp>
27 
29 #include "common/CommonTypes.hh"
30 #include "physics/PhysicsTypes.hh"
31 #include "physics/World.hh"
32 
33 namespace po = boost::program_options;
34 
35 namespace boost
36 {
37  class mutex;
38 }
39 
40 namespace gazebo
41 {
42  class Master;
43 
47  class Server
48  {
49  public: Server();
50  public: virtual ~Server();
51 
52  public: void PrintUsage();
53  public: bool ParseArgs(int argc, char **argv);
54 
55  public: bool Load(const std::string &_filename="worlds/empty.world");
56  public: void Init();
57  public: void Run();
58  public: void Stop();
59  public: void Fini();
60 
61  public: void SetParams(const common::StrStr_M &params);
62 
63  public: bool GetInitialized() const;
64 
65  private: static void SigInt(int _v);
66 
67  private: void ProcessParams();
68 
69  private: void OnControl(ConstServerControlPtr &_msg);
70 
71  private: bool OpenWorld(const std::string &_filename);
72 
73  private: void ProcessControlMsgs();
74 
75  private: static bool stop;
76 
77  private: Master *master;
78  private: boost::thread *masterThread;
79  private: transport::NodePtr node;
80  private: transport::SubscriberPtr serverSub;
81  private: transport::PublisherPtr worldModPub;
82 
83  private: boost::mutex *receiveMutex;
84  private: std::list<msgs::ServerControl> controlMsgs;
85  private: std::map<std::string, std::string> worldFilenames;
86 
87  private: gazebo::common::StrStr_M params;
88  private: po::variables_map vm;
89 
90  // save argc and argv for access by system plugins
91  public: int systemPluginsArgc;
92  public: char** systemPluginsArgv;
93  };
94 }
95 
96 #endif