The Battle for Wesnoth  1.17.0-dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * Manages a collection of lua kernels containing plugin modules running
18  * as coroutines, running in various engine contexts.
19  */
20 
21 #pragma once
22 
23 #include "config.hpp"
24 #include "utils/make_enum.hpp"
25 
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  // TODO: this used to use boost::ptr_vector. Need to consider if there are some performance implications to not doing so
71  std::vector<plugin> plugins_;
72  std::shared_ptr<bool> playing_;
73  std::unique_ptr<application_lua_kernel> kernel_;
74 };
MAKE_ENUM(STATUS,(NONE, "not created")(RUNNING, "running")(STOPPED, "stopped"))
Definitions for the interface to Wesnoth Markup Language (WML).
void start_plugin(std::size_t idx)
Definition: manager.cpp:102
std::string get_name(std::size_t idx)
Definition: manager.cpp:95
std::size_t add_plugin(const std::string &name, const std::string &prog)
Definition: manager.cpp:119
Default, unset return value.
Definition: retval.hpp:32
std::string name
Definition: manager.hpp:65
void play_slice(const plugins_context &)
Definition: manager.cpp:159
std::shared_ptr< bool > playing_
Definition: manager.hpp:72
bool any_running()
Definition: manager.cpp:207
std::string get_detailed_status(std::size_t idx)
Definition: manager.cpp:84
std::size_t load_plugin(const std::string &name, const std::string &filename)
Definition: manager.cpp:132
STATUS get_status(std::size_t idx)
Definition: manager.cpp:73
std::size_t size()
Definition: manager.cpp:69
lua_kernel_base * get_kernel_base()
Definition: manager.cpp:64
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:145
Defines the MAKE_ENUM macro.
std::vector< plugin > plugins_
Definition: manager.hpp:71
std::unique_ptr< application_lua_kernel > kernel_
Definition: manager.hpp:73
plugins_manager(application_lua_kernel *)
Definition: manager.cpp:44