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