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