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 2012 Open Source Robotics Foundation
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 
31 #include "gazebo/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 
57  public: bool PreLoad();
58 
62  public: bool LoadFile(const std::string &_filename="worlds/empty.world",
63  const std::string &_physics="");
64 
65  public: bool LoadString(const std::string &_sdfString);
66  public: void Init();
67  public: void Run();
68  public: void Stop();
69  public: void Fini();
70 
71  public: void SetParams(const common::StrStr_M &params);
72 
73  public: bool GetInitialized() const;
74 
78  private: bool LoadImpl(sdf::ElementPtr _elem,
79  const std::string &_physics="");
80 
81  private: static void SigInt(int _v);
82 
83  private: void ProcessParams();
84 
85  private: void OnControl(ConstServerControlPtr &_msg);
86 
87  private: bool OpenWorld(const std::string &_filename);
88 
89  private: void ProcessControlMsgs();
90 
91  private: static bool stop;
92 
93  private: Master *master;
94  private: boost::thread *masterThread;
95  private: transport::NodePtr node;
96  private: transport::SubscriberPtr serverSub;
97  private: transport::PublisherPtr worldModPub;
98 
99  private: boost::mutex *receiveMutex;
100  private: std::list<msgs::ServerControl> controlMsgs;
101 
102  private: gazebo::common::StrStr_M params;
103  private: po::variables_map vm;
104 
105  // save argc and argv for access by system plugins
106  public: int systemPluginsArgc;
107  public: char** systemPluginsArgv;
108  };
109 }
110 
111 #endif