The Battle for Wesnoth  1.15.12+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 <string>
26 
27 struct plugin;
28 
29 class plugins_context;
30 class lua_kernel_base;
32 
34 public:
37 
38  static plugins_manager * get(); //this class is a singleton
39  lua_kernel_base * get_kernel_base(); // just to mess around with lua console and debug stuff
40 
41  void play_slice(const plugins_context &);
42  void notify_event(const std::string & name, const config & data);
43 
44  MAKE_ENUM( STATUS,
45  (NONE, "not created")
46  (RUNNING, "running")
47  (STOPPED, "stopped")
48  );
49 
50  std::size_t size();
51 
52  STATUS get_status(std::size_t idx);
53  std::string get_detailed_status(std::size_t idx);
54  std::string get_name (std::size_t idx);
55 
56  bool any_running();
57 
58  std::size_t load_plugin(const std::string & name, const std::string & filename); //throws exceptions in case of failure
59  std::size_t add_plugin(const std::string & name, const std::string & prog); //throws exceptions in case of failure
60 
61  void start_plugin(std::size_t idx); //throws exceptions in case of failure
62 
63  struct event {
64  std::string name;
66  };
67 
68 private:
69  // TODO: this used to use boost::ptr_vector. Need to consider if there are some performance implications to not doing so
70  std::vector<plugin> plugins_;
71  std::shared_ptr<bool> playing_;
72  std::unique_ptr<application_lua_kernel> kernel_;
73 };
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:101
std::string get_name(std::size_t idx)
Definition: manager.cpp:94
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:64
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
std::size_t load_plugin(const std::string &name, const std::string &filename)
Definition: manager.cpp:131
STATUS get_status(std::size_t idx)
Definition: manager.cpp:72
std::size_t size()
Definition: manager.cpp:68
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:59
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:144
Defines the MAKE_ENUM macro.
std::vector< plugin > plugins_
Definition: manager.hpp:70
std::unique_ptr< application_lua_kernel > kernel_
Definition: manager.hpp:72
plugins_manager(application_lua_kernel *)
Definition: manager.cpp:43