The Battle for Wesnoth  1.15.0+dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * Manages a collection of lua kernels containing plugin modules running
17  * as coroutines, running in various engine contexts.
18  */
19 
20 #pragma once
21 
22 #include "config.hpp"
23 #include "utils/make_enum.hpp"
24 
25 #include <boost/ptr_container/ptr_vector.hpp>
26 #include <string>
27 
28 struct plugin;
29 
30 class plugins_context;
31 class lua_kernel_base;
33 
35 public:
38 
39  static plugins_manager * get(); //this class is a singleton
40  lua_kernel_base * get_kernel_base(); // just to mess around with lua console and debug stuff
41 
42  void play_slice(const plugins_context &);
43  void notify_event(const std::string & name, const config & data);
44 
45  MAKE_ENUM( STATUS,
46  (NONE, "not created")
47  (RUNNING, "running")
48  (STOPPED, "stopped")
49  )
50 
51  std::size_t size();
52 
53  STATUS get_status(std::size_t idx);
54  std::string get_detailed_status(std::size_t idx);
55  std::string get_name (std::size_t idx);
56 
57  bool any_running();
58 
59  std::size_t load_plugin(const std::string & name, const std::string & filename); //throws exceptions in case of failure
60  std::size_t add_plugin(const std::string & name, const std::string & prog); //throws exceptions in case of failure
61 
62  void start_plugin(std::size_t idx); //throws exceptions in case of failure
63 
64  struct event {
65  std::string name;
67  };
68 
69 private:
70  boost::ptr_vector<plugin> plugins_;
71  std::shared_ptr<bool> playing_;
72  std::unique_ptr<application_lua_kernel> kernel_;
73 };
Definitions for the interface to Wesnoth Markup Language (WML).
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
void start_plugin(std::size_t idx)
Definition: manager.cpp:101
std::string get_name(std::size_t idx)
Definition: manager.cpp:94
boost::ptr_vector< plugin > plugins_
Definition: manager.hpp:70
std::size_t add_plugin(const std::string &name, const std::string &prog)
Definition: manager.cpp:118
Default, unset return value.
Definition: retval.hpp:31
std::string name
Definition: manager.hpp:65
void play_slice(const plugins_context &)
Definition: manager.cpp:158
std::shared_ptr< bool > playing_
Definition: manager.hpp:71
bool any_running()
Definition: manager.cpp:206
std::string get_detailed_status(std::size_t idx)
Definition: manager.cpp:83
MAKE_ENUM(ALIGNMENT_FEMALE_VARIATION,(LAWFUL, N_("female^lawful"))(FEMALE_NEUTRAL, N_("female^neutral"))(CHAOTIC, N_("female^chaotic"))(LIMINAL, N_("female^liminal"))) std
Implementation detail of unit_type::alignment_description.
Definition: types.cpp:909
std::size_t load_plugin(const std::string &name, const std::string &filename)
Definition: manager.cpp:131
lua_kernel_base * get_kernel_base()
Definition: manager.cpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:144
Defines the MAKE_ENUM macro.
std::unique_ptr< application_lua_kernel > kernel_
Definition: manager.hpp:72
plugins_manager(application_lua_kernel *)
Definition: manager.cpp:43