Flatland
plugin_manager.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name plugin_manager.h
11  * @brief Definition for plugin manager
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef FLATLAND_PLUGIN_MANAGER_H
48 #define FLATLAND_PLUGIN_MANAGER_H
49 
50 #include <Box2D/Box2D.h>
51 #include <flatland_server/model.h>
52 #include <flatland_server/model_plugin.h>
53 #include <flatland_server/timekeeper.h>
54 #include <flatland_server/world_plugin.h>
55 #include <flatland_server/yaml_reader.h>
56 #include <pluginlib/class_loader.h>
57 #include <yaml-cpp/yaml.h>
58 
59 namespace flatland_server {
60 
61 // forward declaration
62 class World;
63 
65  public:
66  std::vector<boost::shared_ptr<ModelPlugin>> model_plugins_;
67  pluginlib::ClassLoader<flatland_server::ModelPlugin> *model_plugin_loader_;
68 
69  std::vector<boost::shared_ptr<WorldPlugin>> world_plugins_;
70  pluginlib::ClassLoader<flatland_server::WorldPlugin> *world_plugin_loader_;
74  PluginManager();
75 
80 
85  void BeforePhysicsStep(const Timekeeper &timekeeper);
86 
91  void AfterPhysicsStep(const Timekeeper &timekeeper);
92 
97  void DeleteModelPlugin(Model *model);
98 
105  void LoadModelPlugin(Model *model, YamlReader &plugin_reader);
106 
107  /*
108  * @brief load world plugins
109  * @param[in] world, the world that thsi plugin is tied to
110  * @param[in] plugin_reader, the YAML reader with node containing the plugin
111  * @param[in] world_config, the yaml reader of world.yaml
112  */
113  void LoadWorldPlugin(World *world, YamlReader &plugin_reader,
114  YamlReader &world_config);
115 
120  void BeginContact(b2Contact *contact);
121 
126  void EndContact(b2Contact *contact);
127 
133  void PreSolve(b2Contact *contact, const b2Manifold *oldManifold);
134 
140  void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse);
141 };
142 }; // namespace flatland_server
143 #endif // FLATLAND_PLUGIN_MANAGER_H
void PreSolve(b2Contact *contact, const b2Manifold *oldManifold)
Method called for Box2D presolve.
Definition: plugin_manager.cpp:232
void DeleteModelPlugin(Model *model)
This method removes all model plugins associated with a given mode.
Definition: plugin_manager.cpp:96
Definition: body.h:55
void EndContact(b2Contact *contact)
Method called for a box2D end contact.
Definition: plugin_manager.cpp:226
Definition: model.h:67
PluginManager()
Plugin manager constructor.
Definition: plugin_manager.cpp:57
~PluginManager()
Plugin manager destructor.
Definition: plugin_manager.cpp:66
void BeginContact(b2Contact *contact)
Method called for a box2D begin contact.
Definition: plugin_manager.cpp:220
void AfterPhysicsStep(const Timekeeper &timekeeper)
This method is called after the Box2D physics step.
Definition: plugin_manager.cpp:87
Definition: plugin_manager.h:64
Definition: world.h:69
Definition: timekeeper.h:55
void LoadModelPlugin(Model *model, YamlReader &plugin_reader)
Load model plugins.
Definition: plugin_manager.cpp:105
void BeforePhysicsStep(const Timekeeper &timekeeper)
This method is called before the Box2D physics step.
Definition: plugin_manager.cpp:78
Definition: yaml_reader.h:76
void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse)
Method called for Box2D Postsolve.
Definition: plugin_manager.cpp:239