diff options
author | 2016-03-24 21:06:49 +0100 | |
---|---|---|
committer | 2016-03-24 21:07:39 +0100 | |
commit | 315612190b68d80f68698e104b8d8fe9d382c1cd (patch) | |
tree | 9575bbc2f692c46a85b0feed4f902a8a0a237bb8 | |
parent | 5e23c377cf9ac6bf957935f58548f4761c548550 (diff) |
Added parsing of plugin json files for machine_manager (nw)
-rw-r--r-- | plugins/dummy/plugin.json | 3 | ||||
-rw-r--r-- | plugins/hiscore/plugin.json | 3 | ||||
-rw-r--r-- | plugins/json/plugin.json | 3 | ||||
-rw-r--r-- | scripts/src/emu.lua | 3 | ||||
-rw-r--r-- | src/emu/mame.cpp | 7 | ||||
-rw-r--r-- | src/emu/mame.h | 4 | ||||
-rw-r--r-- | src/emu/pluginopts.cpp | 97 | ||||
-rw-r--r-- | src/emu/pluginopts.h | 29 |
8 files changed, 145 insertions, 4 deletions
diff --git a/plugins/dummy/plugin.json b/plugins/dummy/plugin.json index 4d877fa4dfa..45c14b019e7 100644 --- a/plugins/dummy/plugin.json +++ b/plugins/dummy/plugin.json @@ -1,9 +1,10 @@ { "plugin": { "name": "dummy", + "description": "Dummy test plugin", "version": "0.0.1", "author": "Miodrag Milanovic", "type": "plugin", - "start": "false", + "start": "false" } }
\ No newline at end of file diff --git a/plugins/hiscore/plugin.json b/plugins/hiscore/plugin.json index 34871cab446..38d81289a63 100644 --- a/plugins/hiscore/plugin.json +++ b/plugins/hiscore/plugin.json @@ -1,9 +1,10 @@ { "plugin": { "name": "hiscore", + "description": "Hiscore support", "version": "1.0.0", "author": "borgar@borgar.net", "type": "plugin", - "start": "false", + "start": "false" } }
\ No newline at end of file diff --git a/plugins/json/plugin.json b/plugins/json/plugin.json index c5a0c77355d..c089e2cf178 100644 --- a/plugins/json/plugin.json +++ b/plugins/json/plugin.json @@ -1,8 +1,9 @@ { "plugin": { "name": "json", + "description": "json library", "version": "2.5.0", "author": "David Kolf", - "type": "library", + "type": "library" } }
\ No newline at end of file diff --git a/scripts/src/emu.lua b/scripts/src/emu.lua index 1ca5fa25281..a2983d4bd78 100644 --- a/scripts/src/emu.lua +++ b/scripts/src/emu.lua @@ -25,6 +25,7 @@ includedirs { MAME_DIR .. "src/devices", -- till deps are fixed MAME_DIR .. "src/lib", MAME_DIR .. "src/lib/util", + MAME_DIR .. "3rdparty/rapidjson/include", MAME_DIR .. "3rdparty", GEN_DIR .. "emu", GEN_DIR .. "emu/layout", @@ -169,6 +170,8 @@ files { MAME_DIR .. "src/emu/network.h", MAME_DIR .. "src/emu/parameters.cpp", MAME_DIR .. "src/emu/parameters.h", + MAME_DIR .. "src/emu/pluginopts.cpp", + MAME_DIR .. "src/emu/pluginopts.h", MAME_DIR .. "src/emu/output.cpp", MAME_DIR .. "src/emu/output.h", MAME_DIR .. "src/emu/render.cpp", diff --git a/src/emu/mame.cpp b/src/emu/mame.cpp index 2f313dceabb..076619cd3ae 100644 --- a/src/emu/mame.cpp +++ b/src/emu/mame.cpp @@ -110,6 +110,7 @@ machine_manager* machine_manager::instance() machine_manager::machine_manager(emu_options &options,osd_interface &osd) : m_osd(osd), m_options(options), + m_plugins(std::make_unique<plugin_options>()), m_lua(global_alloc(lua_engine)), m_new_driver_pending(nullptr), m_machine(nullptr) @@ -157,6 +158,12 @@ void machine_manager::start_luaengine() { m_lua->initialize(); { + path_iterator iter(options().plugins_path()); + std::string pluginpath; + while (iter.next(pluginpath, "")) + { + m_plugins->parse_json(pluginpath); + } emu_file file(options().plugins_path(), OPEN_FLAG_READ); osd_file::error filerr = file.open("boot.lua"); if (filerr == osd_file::error::NONE) diff --git a/src/emu/mame.h b/src/emu/mame.h index bc21d805716..bf034bfacfa 100644 --- a/src/emu/mame.h +++ b/src/emu/mame.h @@ -17,6 +17,7 @@ #define __MAME_H__ #include <time.h> +#include "pluginopts.h" class osd_interface; @@ -76,6 +77,7 @@ public: osd_interface &osd() const; emu_options &options() const { return m_options; } + plugin_options &plugins() const { return *m_plugins; } lua_engine *lua() { return m_lua; } running_machine *machine() { return m_machine; } @@ -91,7 +93,7 @@ public: private: osd_interface & m_osd; // reference to OSD system emu_options & m_options; // reference to options - + std::unique_ptr<plugin_options> m_plugins; // pointer to plugin options lua_engine * m_lua; const game_driver * m_new_driver_pending; // pointer to the next pending driver diff --git a/src/emu/pluginopts.cpp b/src/emu/pluginopts.cpp new file mode 100644 index 00000000000..d84757652c9 --- /dev/null +++ b/src/emu/pluginopts.cpp @@ -0,0 +1,97 @@ +// license:BSD-3-Clause +// copyright-holders:Miodrag Milanovic +/*************************************************************************** + + pluginopts.cpp + + Plugin options manager. + +***************************************************************************/ +#include <fstream> +#include "emu.h" +#include "pluginopts.h" + +#include <rapidjson/document.h> +#include <rapidjson/error/en.h> +#include <rapidjson/istreamwrapper.h> +#include <fstream> + +//************************************************************************** +// PLUGIN OPTIONS +//************************************************************************** + +const options_entry plugin_options::s_option_entries[] = +{ + { nullptr, nullptr, OPTION_HEADER, "PLUGINS OPTIONS" }, + { nullptr } +}; + +//------------------------------------------------- +// plugin_options - constructor +//------------------------------------------------- + +plugin_options::plugin_options() +: core_options() +{ + add_entries(plugin_options::s_option_entries); +} + + +void plugin_options::parse_json(std::string path) +{ + // first try to open as a directory + osd_directory *directory = osd_opendir(path.c_str()); + if (directory != nullptr) + { + // iterate over all files in the directory + for (const osd_directory_entry *entry = osd_readdir(directory); entry != nullptr; entry = osd_readdir(directory)) + { + if (entry->type == ENTTYPE_FILE) + { + std::string name = entry->name; + if (name == "plugin.json") + { + std::string curfile = std::string(path).append(PATH_SEPARATOR).append(entry->name); + std::ifstream ifs(curfile); + rapidjson::IStreamWrapper isw(ifs); + rapidjson::Document document; + document.ParseStream<0>(isw); + + if (document.HasParseError()) { + std::string error(GetParseError_En(document.GetParseError())); + osd_printf_error("Unable to parse plugin definition file %s. Errors returned:\n", curfile.c_str()); + osd_printf_error("%s\n", error.c_str()); + return; + } + + if (document["plugin"].IsObject()) + { + std::string name = document["plugin"]["name"].GetString(); + std::string description = document["plugin"]["description"].GetString(); + std::string type = document["plugin"]["type"].GetString(); + bool start = false; + if (document["plugin"].HasMember("start") && (std::string(document["plugin"]["start"].GetString()) == "true")) + start = true; + + if (type=="plugin") + { + add_entry(core_strdup(name.c_str()),core_strdup(description.c_str()), OPTION_BOOLEAN, start ? "1" : "0"); + } + } + + } + } + else if (entry->type == ENTTYPE_DIR) + { + std::string name = entry->name; + if (!(name == "." || name == "..")) + { + parse_json(path + PATH_SEPARATOR + name); + } + } + } + + // close the directory and be done + osd_closedir(directory); + } +}
\ No newline at end of file diff --git a/src/emu/pluginopts.h b/src/emu/pluginopts.h new file mode 100644 index 00000000000..caaf2af7123 --- /dev/null +++ b/src/emu/pluginopts.h @@ -0,0 +1,29 @@ +// license:BSD-3-Clause +// copyright-holders:Miodrag Milanovic +/*************************************************************************** + + pluginopts.cpp + + Plugin options manager. + +***************************************************************************/ + +#pragma once + +#ifndef __PLUGIN_OPTS_H__ +#define __PLUGIN_OPTS_H__ + +#include "options.h" + +class plugin_options : public core_options +{ +public: + // construction/destruction + plugin_options(); + + void parse_json(std::string path); +private: + static const options_entry s_option_entries[]; +}; + +#endif /* __PLUGIN_OPTS_H__ */ |