From afff6206922e89ceeb4e611faf3321ce30b38d97 Mon Sep 17 00:00:00 2001 From: Brian Caine Date: Fri, 16 May 2008 10:14:45 -0400 Subject: [PATCH] So. H'ok I've done alot of stuff. Running ``scons'' in the root directory will build it. But it doesn't do anything yet. But yeah. The SettingsDB class needs to be fixed up. But yeah... We have infrastructure. --- SConstruct | 57 ++++------ source/include/core/Engine.h | 27 +++++ source/include/core/Event.h | 4 +- .../media/MediaLoader.h => core/EventPipeline.h} | 22 ++-- .../core/{EventManager.h => EventReceiver.h} | 11 +- .../media/LoadedMedia.h => core/LoadedData.h} | 8 +- .../include/{plugins/media => core}/MediaLoader.h | 7 +- source/include/core/Plugin.h | 82 ++++++++++++++ .../core/{ScriptObjectManager.h => PluginLoader.h} | 28 +++-- .../{ScriptObjectManager.h => ScriptedClass.h} | 23 ++-- source/include/core/SettingsDB.h | 59 ++++++++++ .../{core/Event.h => plugins/audio/Audio.h} | 17 +-- .../{media/MediaLoader.h => graphics/GUI.h} | 22 ++-- source/include/plugins/graphics/Graphics.h | 7 ++ source/include/plugins/input/InputManager.h | 1 + source/include/plugins/media/CustomizedLoader.h | 10 -- .../{input/InputManager.h => media/MediaSource.h} | 18 +-- .../{core/ScriptObject.h => plugins/ui/UI.h} | 14 ++- source/src/core/Engine.cpp | 124 +++++++++++++++++++++ .../{main/Engine.cpp => core/EventPipeline.cpp} | 22 ++-- source/src/core/Plugin.cpp | 81 ++++++++++++++ source/src/core/PluginLoader.cpp | 105 +++++++++++++++++ source/src/core/SConscript | 31 ++++++ source/src/core/SettingsDB.cpp | 118 ++++++++++++++++++++ source/src/{main/Engine.cpp => core/Variant.cpp} | 46 ++++++-- source/src/{main => core}/main.cpp | 0 26 files changed, 802 insertions(+), 142 deletions(-) rewrite SConstruct (98%) copy source/include/{plugins/media/MediaLoader.h => core/EventPipeline.h} (71%) rename source/include/core/{EventManager.h => EventReceiver.h} (81%) rename source/include/{plugins/media/LoadedMedia.h => core/LoadedData.h} (88%) copy source/include/{plugins/media => core}/MediaLoader.h (85%) create mode 100644 source/include/core/Plugin.h copy source/include/core/{ScriptObjectManager.h => PluginLoader.h} (61%) rename source/include/core/{ScriptObjectManager.h => ScriptedClass.h} (60%) create mode 100644 source/include/core/SettingsDB.h copy source/include/{core/Event.h => plugins/audio/Audio.h} (75%) rename source/include/plugins/{media/MediaLoader.h => graphics/GUI.h} (70%) delete mode 100644 source/include/plugins/media/CustomizedLoader.h copy source/include/plugins/{input/InputManager.h => media/MediaSource.h} (75%) rename source/include/{core/ScriptObject.h => plugins/ui/UI.h} (78%) create mode 100644 source/src/core/Engine.cpp copy source/src/{main/Engine.cpp => core/EventPipeline.cpp} (65%) create mode 100644 source/src/core/Plugin.cpp create mode 100644 source/src/core/PluginLoader.cpp create mode 100644 source/src/core/SConscript create mode 100644 source/src/core/SettingsDB.cpp rename source/src/{main/Engine.cpp => core/Variant.cpp} (51%) rename source/src/{main => core}/main.cpp (100%) diff --git a/SConstruct b/SConstruct dissimilarity index 98% index f2639ab..d40dfbc 100644 --- a/SConstruct +++ b/SConstruct @@ -1,34 +1,23 @@ -# potpourri sconstruct - -output = 'bin/potpourri' -sauces = """ - -src/main.cpp - -src/Engine.cpp -src/Sprite.cpp -src/XMLParser.cpp -src/Variant.cpp - -""" -libs_string = """ - -SDL SDL_image SDL_gfx -xml2 z m - -""" - -# more complicated stuff - -include_list = ["/usr/include/SDL", "/usr/include/libxml2"] - -sauce_list = Split(sauces) -lib_list = Split(libs_string) - -debug = Environment(CCFLAGS='-g', CPPPATH = include_list) -normal = Environment(CPPPATH = include_list) - -if 'release' in COMMAND_LINE_TARGETS: - normal.Program(output, sauce_list, LIBS=lib_list) -else: - debug.Program(output + '-dbg', sauce_list, LIBS=lib_list) +# Copyright 2008 Brian Caine + +# This file is part of Potpourri. + +# Potpourri is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Potpourri is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Potpourri. If not, see . + +import glob, os + +for dir in os.listdir("source/src"): + path = "source/src/" + dir + "/SConscript" + if os.path.exists(path): + SConscript(path) diff --git a/source/include/core/Engine.h b/source/include/core/Engine.h index 8e64027..bec64d5 100644 --- a/source/include/core/Engine.h +++ b/source/include/core/Engine.h @@ -23,16 +23,41 @@ #ifndef __ENGINE_H #define __ENGINE_H +#include +#include + +#include "PluginLoader.h" +#include "SettingsDB.h" + namespace fragrant { + const std::string DBLOC = ".settings.db"; + const std::string PLUGINFOLDER = "./plugins"; + const std::string GAME = "GAME"; + const std::string UIPLUGIN = "iostream"; + enum EngineResults { ER_Good, ER_Bad }; + enum EngineSubResults // lulz, esr + { + ESR_UI, + ESR_Game, + ESR_Quit + }; + + struct EngineSub + { + EngineSubResults type; + std::string data; + }; + struct EngineParams { + std::map params; }; class Engine @@ -45,6 +70,8 @@ namespace fragrant EngineResults run(EngineParams params); private: + SettingsDB* d_settings; + PluginLoader* d_plugin_loader; }; } diff --git a/source/include/core/Event.h b/source/include/core/Event.h index 8803c3c..2dad843 100644 --- a/source/include/core/Event.h +++ b/source/include/core/Event.h @@ -23,6 +23,8 @@ #ifndef __EVENT_H #define __EVENT_H +#include "Variant.h" + #include #include @@ -31,7 +33,7 @@ namespace fragrant struct Event { std::string name; - std::map + std::map data; }; } diff --git a/source/include/plugins/media/MediaLoader.h b/source/include/core/EventPipeline.h similarity index 71% copy from source/include/plugins/media/MediaLoader.h copy to source/include/core/EventPipeline.h index eda80f9..7e29e6c 100644 --- a/source/include/plugins/media/MediaLoader.h +++ b/source/include/core/EventPipeline.h @@ -18,28 +18,24 @@ // NOTES: -// A class that loads media from sauces +// EventPipeline, well named, no? -#ifndef __MEDIALOADER_H -#define __MEDIALOADER_H +#ifndef __EVENTPIPELINE_H +#define __EVENTPIPELINE_H -#include "../Global.h" - -#include "LoadedMedia.h" +#include "EventReceiver.h" +#include namespace fragrant { - class MediaLoader + class EventPipeline : public EventReceiver { public: - - MediaLoader(); - ~MediaLoader(); - - LoadedMedia loadMedia() = 0; - void addLoader(media_loading_function nfunc, std::string type); + void raiseEvent(Event new_event); + std::vector& getTargetVector(); private: + std::vector targets; }; } diff --git a/source/include/core/EventManager.h b/source/include/core/EventReceiver.h similarity index 81% rename from source/include/core/EventManager.h rename to source/include/core/EventReceiver.h index d3dad2a..0f9a538 100644 --- a/source/include/core/EventManager.h +++ b/source/include/core/EventReceiver.h @@ -18,18 +18,21 @@ // NOTES: -// EventManager, well named, no? +// Defines the event structure -#ifndef __EVENTMANAGER_H -#define __EVENTMANAGER_H +#ifndef __EVENTRECEIVER_H +#define __EVENTRECEIVER_H +#include "Variant.h" #include "Event.h" namespace fragrant { - class EventManager + class EventReceiver { public: + virtual void raiseEvent(Event event) = 0; + private: }; } diff --git a/source/include/plugins/media/LoadedMedia.h b/source/include/core/LoadedData.h similarity index 88% rename from source/include/plugins/media/LoadedMedia.h rename to source/include/core/LoadedData.h index 66d8468..e6a3adf 100644 --- a/source/include/plugins/media/LoadedMedia.h +++ b/source/include/core/LoadedData.h @@ -17,16 +17,16 @@ // NOTES: -// A struct that holds some loaded media +// A struct that holds some loaded data -#ifndef __LOADEDMEDIA_H -#define __LOADEDMEDIA_H +#ifndef __LOADEDDATA_H +#define __LOADEDDATA_H #include namespace fragrant { - struct LoadedMedia + struct LoadedData { std::string data; std::string source; diff --git a/source/include/plugins/media/MediaLoader.h b/source/include/core/MediaLoader.h similarity index 85% copy from source/include/plugins/media/MediaLoader.h copy to source/include/core/MediaLoader.h index eda80f9..00fed8f 100644 --- a/source/include/plugins/media/MediaLoader.h +++ b/source/include/core/MediaLoader.h @@ -23,9 +23,12 @@ #ifndef __MEDIALOADER_H #define __MEDIALOADER_H +#include + #include "../Global.h" #include "LoadedMedia.h" +#include "../include/media/MediaSource.h" namespace fragrant { @@ -36,8 +39,8 @@ namespace fragrant MediaLoader(); ~MediaLoader(); - LoadedMedia loadMedia() = 0; - void addLoader(media_loading_function nfunc, std::string type); + LoadedMedia loadMedia(std::string source) = 0; + std::map& getSources(); private: }; diff --git a/source/include/core/Plugin.h b/source/include/core/Plugin.h new file mode 100644 index 0000000..1e0a0fb --- /dev/null +++ b/source/include/core/Plugin.h @@ -0,0 +1,82 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// A plugin system + +#ifndef __PLUGIN_H +#define __PLUGIN_H + +#include +#include +#include + +#include "Variant.h" + +namespace fragrant +{ + const std::string PLUGIN_FUNC_NAME = "loadPluginPayload"; + const std::string PLUGIN_INFO_NAME = "queryPlugin"; + + enum PluginType + { + PT_Audio, + PT_Graphics, + PT_Input, + PT_Media, + PT_Script, + PT_UI + }; + + struct PluginData + { + std::string name; + PluginType type; + std::string version; + std::vector authors; + std::vector requirements; + }; + + typedef PluginData (*plugin_query)(); + typedef Variant* (*plugin_payload)(); + + class Plugin + { + public: + Plugin(std::string sofile); + ~Plugin(); + + PluginData getData(); + fragrant::Variant* getPayload(); + + private: + PluginData data; + + void* lib; + plugin_payload payload; + }; +} + +extern "C" +{ + fragrant::PluginData queryPlugin(); + fragrant::Variant* loadPluginPayload(); +} + +#endif diff --git a/source/include/core/ScriptObjectManager.h b/source/include/core/PluginLoader.h similarity index 61% copy from source/include/core/ScriptObjectManager.h copy to source/include/core/PluginLoader.h index edf5dfd..9ab8260 100644 --- a/source/include/core/ScriptObjectManager.h +++ b/source/include/core/PluginLoader.h @@ -18,27 +18,35 @@ // NOTES: -// ScriptObjectManager provides wrappers and stuff +// It loads plugins -#ifndef __SCRIPTOBJECTMANAGER_H -#define __SCRIPTOBJECTMANAGEr_H +#ifndef __PLUGINLOADER_H +#define __PLUGINLOADER_H -#include "ScriptObject.h" -#include "../plugins/script/ScriptVM.h" +#include +#include +#include +#include + +#include "Plugin.h" namespace fragrant { - class ScriptObjectManager + const std::string SOFILE = "application/x-sharedlib"; + + class PluginLoader { public: - ScriptObjectManager(ScriptVM* vmptr); - ~ScriptObjectManager(); + PluginLoader(std::string folder); + ~PluginLoader(); - void addScriptObject(ScriptObject* object); - ScriptObject* removeScriptObject(); + Plugin* getPlugin(std::string name); + std::vector getPluginFromType(PluginType type); private: + std::map plugins; + magic_t cookie; }; } diff --git a/source/include/core/ScriptObjectManager.h b/source/include/core/ScriptedClass.h similarity index 60% rename from source/include/core/ScriptObjectManager.h rename to source/include/core/ScriptedClass.h index edf5dfd..2f3527e 100644 --- a/source/include/core/ScriptObjectManager.h +++ b/source/include/core/ScriptedClass.h @@ -17,26 +17,29 @@ // NOTES: +// A class that inherits from this can be scripted -// ScriptObjectManager provides wrappers and stuff +#ifndef __SCRIPTEDCLASS_H +#define __SCRIPTEDCLASS_H -#ifndef __SCRIPTOBJECTMANAGER_H -#define __SCRIPTOBJECTMANAGEr_H - -#include "ScriptObject.h" #include "../plugins/script/ScriptVM.h" +typedef fragrant::Variant* (*func)(std::vector); + namespace fragrant { - class ScriptObjectManager + class ScriptVM; + class ScriptedClass { public: + virtual func getConstructor() = 0; + virtual void destroy() = 0; - ScriptObjectManager(ScriptVM* vmptr); - ~ScriptObjectManager(); + virtual std::string getClassName() = 0; + virtual std::vector getClassFunctions() = 0; - void addScriptObject(ScriptObject* object); - ScriptObject* removeScriptObject(); + virtual Variant* callFunction(std::string funcname, + std::vector params, ScriptVM* script_vm) = 0; private: }; diff --git a/source/include/core/SettingsDB.h b/source/include/core/SettingsDB.h new file mode 100644 index 0000000..f0efa1b --- /dev/null +++ b/source/include/core/SettingsDB.h @@ -0,0 +1,59 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// This is the SettingsDB class +// So, the db has the following tables: +// General Settings, with the format of string key, string value, named general + +#ifndef __SETTINGSDB_H +#define __SETTINGSDB_H + +#include +#include + +namespace fragrant +{ + class SettingsDB + { + public: + + SettingsDB(std::string dblocation); + ~SettingsDB(); + + std::string& pluginFolder(); + + private: + std::string plugin_folder; + + sqlite3* db; + + std::string getValueFromGeneral(std::string value); + void setValueFromGeneral(std::string key, std::string newvalue); + + static std::string sanitizeString(std::string the_string); + + static int generalcallback(void* sdb, int argc, char** argv, + char** colname); + std::string general_callback_result; + bool general_callback_called; + }; +} + +#endif diff --git a/source/include/core/Event.h b/source/include/plugins/audio/Audio.h similarity index 75% copy from source/include/core/Event.h copy to source/include/plugins/audio/Audio.h index 8803c3c..8fc2eab 100644 --- a/source/include/core/Event.h +++ b/source/include/plugins/audio/Audio.h @@ -17,21 +17,24 @@ // NOTES: +// This is the top level audio header -// Defines the event structure +#include "AudioDevice.h" +#include "AudioSample.h" -#ifndef __EVENT_H -#define __EVENT_H +#include "../Global.h" #include -#include + +#ifndef __AUDIO_H +#define __AUDIO_H namespace fragrant { - struct Event + struct Audio { - std::string name; - std::map + AudioDevice* device; + virtual AudioSample* makeSample(std::string filename) = 0; }; } diff --git a/source/include/plugins/media/MediaLoader.h b/source/include/plugins/graphics/GUI.h similarity index 70% rename from source/include/plugins/media/MediaLoader.h rename to source/include/plugins/graphics/GUI.h index eda80f9..08a6eca 100644 --- a/source/include/plugins/media/MediaLoader.h +++ b/source/include/plugins/graphics/GUI.h @@ -18,28 +18,30 @@ // NOTES: -// A class that loads media from sauces +// A gui -#ifndef __MEDIALOADER_H -#define __MEDIALOADER_H +#ifndef __GUI_H +#define __GUI_H -#include "../Global.h" +#include -#include "LoadedMedia.h" +#include "Target.h" +#include "../../core/EventPipeline.h" namespace fragrant { - class MediaLoader + class GUI { public: - MediaLoader(); - ~MediaLoader(); + GUI(); - LoadedMedia loadMedia() = 0; - void addLoader(media_loading_function nfunc, std::string type); + virtual void init(std::string data = "") = 0; + virtual void draw(Target& target) = 0; + virtual void event(Event nevent) = 0; private: + EventPipeline& pipeline; }; } diff --git a/source/include/plugins/graphics/Graphics.h b/source/include/plugins/graphics/Graphics.h index 659f37d..c4d2a1f 100644 --- a/source/include/plugins/graphics/Graphics.h +++ b/source/include/plugins/graphics/Graphics.h @@ -8,4 +8,11 @@ typedef Pair GraphicsPair; typedef Rect GraphicsRect; +namespace fragrant +{ + struct Graphics + { + }; +} + #endif diff --git a/source/include/plugins/input/InputManager.h b/source/include/plugins/input/InputManager.h index 2e2acb5..a4351c0 100644 --- a/source/include/plugins/input/InputManager.h +++ b/source/include/plugins/input/InputManager.h @@ -22,6 +22,7 @@ #ifndef __INPUTMANAGER_H #define __INPUTMANAGER_H +#include "../../core/EventPipeline.h" #include "../../Global.h" namespace fragrant diff --git a/source/include/plugins/media/CustomizedLoader.h b/source/include/plugins/media/CustomizedLoader.h deleted file mode 100644 index 16130ca..0000000 --- a/source/include/plugins/media/CustomizedLoader.h +++ /dev/null @@ -1,10 +0,0 @@ -// yeah... - -#include "LoadedMedia.h" - -#ifndef __CUSTOMIZEDLOADER_H -#define __CUSTOMIZEDLOADER_H - -typedef LoadedMedia (*media_loading_function)(std::string); - -#endif diff --git a/source/include/plugins/input/InputManager.h b/source/include/plugins/media/MediaSource.h similarity index 75% copy from source/include/plugins/input/InputManager.h copy to source/include/plugins/media/MediaSource.h index 2e2acb5..6b1a51e 100644 --- a/source/include/plugins/input/InputManager.h +++ b/source/include/plugins/media/MediaSource.h @@ -17,26 +17,28 @@ // NOTES: -// A class that reads input events and stashes them in a queue somewhere +// A class that loads data -#ifndef __INPUTMANAGER_H -#define __INPUTMANAGER_H +#ifndef __MEDIASOURCE_H +#define __MEDIASOURCE_H -#include "../../Global.h" +#include "../../core/MediaLoader.h" + +#include namespace fragrant { - class InputManager + class MediaSource { public: - virtual void init(EventPipeline& pipeline) = 0; + virtual void init() = 0; virtual void close() = 0; - virtual void pump() = 0; + LoadedMedia loadMedia(std::string resource); private: - }; + }; } #endif diff --git a/source/include/core/ScriptObject.h b/source/include/plugins/ui/UI.h similarity index 78% rename from source/include/core/ScriptObject.h rename to source/include/plugins/ui/UI.h index 6156718..e1dfa2f 100644 --- a/source/include/core/ScriptObject.h +++ b/source/include/plugins/ui/UI.h @@ -18,17 +18,21 @@ // NOTES: -// Anything that inherits from a ScriptObject can be added and dealt -// with in the scripting language +// The interface for a UI component -#ifndef __SCRIPTOBJECT_H -#define __SCRIPTOBJECT_H +#ifndef __UI_H +#define __UI_H + +#include "../../core/Engine.h" +#include "../../core/PluginLoader.h" namespace fragrant { - class ScriptObject + class UI { public: + virtual EngineSub run(PluginLoader& plugin_loader) = 0; + private: }; } diff --git a/source/src/core/Engine.cpp b/source/src/core/Engine.cpp new file mode 100644 index 0000000..e9cf8ae --- /dev/null +++ b/source/src/core/Engine.cpp @@ -0,0 +1,124 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// The Engine sauce + +#include "../../include/core/Engine.h" +#include "../../include/core/SettingsDB.h" +#include "../../include/plugins/ui/UI.h" + +#include // debug +#include + +using namespace fragrant; + +Engine::Engine() +{ + d_settings = 0; + d_plugin_loader = 0; +} + +Engine::~Engine() +{ + if (d_settings) + delete d_settings; + + if (d_plugin_loader) + delete d_plugin_loader; +} + +EngineResults Engine::run(EngineParams params) +{ + try + { + d_settings = new SettingsDB( + params.params.find(DBLOC) == params.params.end() ? + (SettingsDB(DBLOC)) : SettingsDB(params.params[DBLOC])); + } + + catch (std::runtime_error& error) + { + return ER_Bad; + } + + SettingsDB& settings = *d_settings; + + try + { + if (params.params.find(PLUGINFOLDER) == params.params.end()) + d_plugin_loader = new PluginLoader(settings.pluginFolder()); + else + d_plugin_loader = new PluginLoader(PLUGINFOLDER); + } + + catch (std::runtime_error& error) + { + return ER_Bad; + } + + PluginLoader& plugin_loader = *d_plugin_loader; + + Plugin* ui_plugin = 0; + if (params.params.find(UIPLUGIN) == params.params.end()) + ui_plugin = plugin_loader.getPlugin(UIPLUGIN); + + else + ui_plugin = plugin_loader.getPlugin(params.params[UIPLUGIN]); + + if (!ui_plugin) + ui_plugin = plugin_loader.getPlugin(UIPLUGIN); + + if (!ui_plugin && plugin_loader.getPluginFromType(PT_UI).size()) + ui_plugin = plugin_loader.getPluginFromType(PT_UI).at(0); + + if (!ui_plugin) + { + std::cerr << "Engine::run(): No UI plugin found" << std::endl; + return ER_Bad; + } + + UI* the_ui = ui_plugin->getPayload()->get(); + + EngineSubResults results; + + if (params.params.find(GAME) == params.params.end()) + results = ESR_UI; + else + results = ESR_Game; + + while (results != ESR_Quit) + { + EngineSub sub_return; + + if (results == ESR_Game) + { + std::cout << "Engine::run(): ESR_Game not implemented yet" + << std::endl; + sub_return.type = ESR_Quit; + } + + if (results == ESR_UI) + sub_return = the_ui->run(plugin_loader); + + results = sub_return.type; + } + + return ER_Good; +} diff --git a/source/src/main/Engine.cpp b/source/src/core/EventPipeline.cpp similarity index 65% copy from source/src/main/Engine.cpp copy to source/src/core/EventPipeline.cpp index 957275f..c5ab1ce 100644 --- a/source/src/main/Engine.cpp +++ b/source/src/core/EventPipeline.cpp @@ -18,26 +18,22 @@ // NOTES: -// The Engine sauce +// The source for the event pipeline -#include "../../include/core/Engine.h" - -#include // debug +#include "../../include/core/EventPipeline.h" using namespace fragrant; -Engine::Engine() +void EventPipeline::raiseEvent(Event newevent) { - std::cout << "Engine::Engine(): Constructor stub..." << std::endl; -} + std::vector::iterator iter; + for (iter = targets.begin(); iter != targets.end(); iter++) + (*iter)->raiseEvent(newevent); -Engine::~Engine() -{ - std::cout << "Engine::~Engine(): Destructor stub..." << std::endl; + return; } -EngineResults Engine::run(EngineParams params) +std::vector& EventPipeline::getTargetVector() { - std::cout << "Engine::run(): run stub..." << std::endl; - return ER_Good; + return targets; } diff --git a/source/src/core/Plugin.cpp b/source/src/core/Plugin.cpp new file mode 100644 index 0000000..e439245 --- /dev/null +++ b/source/src/core/Plugin.cpp @@ -0,0 +1,81 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// The plugin sauce + +#include +#include + +#include "../../include/core/Plugin.h" + +using namespace fragrant; + +Plugin::Plugin(std::string sofile) +{ + payload = 0; + lib = dlopen(sofile.c_str(), RTLD_GLOBAL|RTLD_LAZY); + if (lib) + { + void* func = dlsym(lib, PLUGIN_FUNC_NAME.c_str()); + if (!func) + { + std::cerr << "Plugin::Plugin(): Error getting function, " + << PLUGIN_FUNC_NAME << dlerror() << std::endl; + dlclose(lib); + lib = 0; + } + + else + payload = (plugin_payload)func; + + void* infofunc = dlsym(lib, PLUGIN_INFO_NAME.c_str()); + if (!infofunc) + std::cerr << "Plugin::Plugin(): Error getting function, " + << PLUGIN_INFO_NAME << dlerror() << std::endl; + else + { + plugin_query function = (plugin_query)infofunc; + data = function(); + } + + } + else + std::cerr << "Plugin::Plugin(): Error opening sofile, " + << sofile << std::endl; + + if (!lib) + throw std::runtime_error(""); +} + +Plugin::~Plugin() +{ + if (lib) + dlclose(lib); +} + +PluginData Plugin::getData() +{ + return data; +} + +fragrant::Variant* Plugin::getPayload() +{ + return payload(); +} diff --git a/source/src/core/PluginLoader.cpp b/source/src/core/PluginLoader.cpp new file mode 100644 index 0000000..79593b7 --- /dev/null +++ b/source/src/core/PluginLoader.cpp @@ -0,0 +1,105 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// The plugin loader sauce + +#include +#include +#include +#include + +#include "../../include/core/PluginLoader.h" + +using namespace fragrant; + +PluginLoader::PluginLoader(std::string folder) +{ + DIR* dp = opendir(folder.c_str()); + std::vector results; + + if (!dp) + { + throw std::runtime_error(""); + } + + dirent* dirp = readdir(dp); + + while (dirp) + { + results.push_back(std::string(dirp->d_name)); + dirp = readdir(dp); + } + + closedir(dp); + + cookie = magic_open(MAGIC_DEBUG|MAGIC_MIME); + if (!magic_error(cookie)) + throw std::runtime_error(""); + + int cur; + for (cur = 0; cur < results.size(); cur++) + if (std::string(magic_file(cookie, results.at(cur).c_str())) == SOFILE) + try + { + Plugin* nplugin = new Plugin(results.at(cur)); + plugins[results.at(cur)] = nplugin; + } + catch (std::runtime_error& d) + {} +} + +PluginLoader::~PluginLoader() +{ + std::map::iterator iter; + + for (iter = plugins.begin(); iter != plugins.end(); iter++) + delete iter->second; + + magic_close(cookie); +} + +Plugin* PluginLoader::getPlugin(std::string name) +{ + if (plugins.find(name) == plugins.end()) + return 0; + + Plugin* result = plugins[name]; + PluginData data = result->getData(); + + int cur; + for (cur = 0; cur < data.requirements.size(); cur++) + if (!getPlugin(data.requirements.at(cur))) + return 0; + + return result; +} + +std::vector PluginLoader::getPluginFromType(PluginType type) +{ + std::vector results; + std::map::iterator iter; + + for (iter = plugins.begin(); iter != plugins.end(); iter++) + if (getPlugin(iter->second->getData().name) && + iter->second->getData().type == type) + results.push_back(iter->second); + + return results; +} diff --git a/source/src/core/SConscript b/source/src/core/SConscript new file mode 100644 index 0000000..6a16add --- /dev/null +++ b/source/src/core/SConscript @@ -0,0 +1,31 @@ +# Copyright 2008 Brian Caine + +# This file is part of Potpourri. + +# Potpourri is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# Potpourri is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with Potpourri. If not, see . + +import glob + +sources = glob.glob('*.cpp') +output = '../../../bin/potpourri' +libs = ['stdc++', 'sqlite3', 'dl', 'magic'] + +env = 1 + +if 'release' in COMMAND_LINE_TARGETS: + env = Environment(CCFLAGS='') +else: + env = Environment(CCFLAGS='-g') + +env.Program(output, sources, LIBS=libs) diff --git a/source/src/core/SettingsDB.cpp b/source/src/core/SettingsDB.cpp new file mode 100644 index 0000000..60c7483 --- /dev/null +++ b/source/src/core/SettingsDB.cpp @@ -0,0 +1,118 @@ +// Copyright 2008 Brian Caine + +// This file is part of Potpourri. + +// Potpourri is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Potpourri is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Potpourri. If not, see . + + +// NOTES: + +// The source for the event pipeline + +#include +#include + +#include "../../include/core/SettingsDB.h" + +using namespace fragrant; + +SettingsDB::SettingsDB(std::string dblocation) +{ + int result = sqlite3_open(dblocation.c_str(), &db); + + if (result) + { + std::cerr << "SettingsDB::SettingsDB(): Error opening db, " + << sqlite3_errmsg(db) << std::endl; + sqlite3_close(db); + throw std::runtime_error(""); + } + + plugin_folder = getValueFromGeneral("plugin_folder"); +} + +SettingsDB::~SettingsDB() +{ + setValueFromGeneral("plugin_folder", plugin_folder); + + sqlite3_close(db); +} + +std::string& SettingsDB::pluginFolder() +{ + return plugin_folder; +} + +std::string SettingsDB::getValueFromGeneral(std::string value) +{ + std::string query = "select * from general where key='" + + sanitizeString(value) + "';"; + general_callback_called = false; + sqlite3_exec(db, query.c_str(), generalcallback, this, 0); + if (general_callback_called) + return general_callback_result; + else + setValueFromGeneral(value, ""); + + return ""; +} + +void SettingsDB::setValueFromGeneral(std::string key, std::string newvalue) +{ + std::string query = "select * from general where key='" + + sanitizeString(key) + "';"; + general_callback_called = false; + sqlite3_exec(db, query.c_str(), generalcallback, this, 0); + + if (general_callback_called) + { + std::string query = "update general set value='" + + sanitizeString(newvalue) + "' key='" + sanitizeString(key) + "';"; + general_callback_called = false; + sqlite3_exec(db, query.c_str(), generalcallback, this, 0); + } + else + { + std::string query = "insert into general values('" + + sanitizeString(key) + "', '" + sanitizeString(newvalue) +"');"; + general_callback_called = false; + sqlite3_exec(db, query.c_str(), generalcallback, this, 0); + } + + return; +} + +std::string SettingsDB::sanitizeString(std::string input) +{ + int curpos = input.find(std::string("'")); + + while (curpos < input.size()) + { + input.replace(curpos, curpos + 1, std::string("''")); + curpos = input.find(std::string("'"), curpos + 2); + } + + return input; +} + +int SettingsDB::generalcallback(void* sdb, int argc, char** argv, + char** colname) +{ + SettingsDB* db = static_cast(sdb); + + db->general_callback_called = true; + db->general_callback_result = argv[1]; + + return 0; +} diff --git a/source/src/main/Engine.cpp b/source/src/core/Variant.cpp similarity index 51% rename from source/src/main/Engine.cpp rename to source/src/core/Variant.cpp index 957275f..65d9cff 100644 --- a/source/src/main/Engine.cpp +++ b/source/src/core/Variant.cpp @@ -18,26 +18,50 @@ // NOTES: -// The Engine sauce +// The implementation for Variant -#include "../../include/core/Engine.h" - -#include // debug +#include "../../include/core/Variant.h" using namespace fragrant; -Engine::Engine() +void Generic::null() +{ + // nothing +} + +Generic::~Generic() { - std::cout << "Engine::Engine(): Constructor stub..." << std::endl; + // nothing } -Engine::~Engine() +Variant::Variant() { - std::cout << "Engine::~Engine(): Destructor stub..." << std::endl; + data = 0; } -EngineResults Engine::run(EngineParams params) +Variant::Variant(Variant const &rhs) { - std::cout << "Engine::run(): run stub..." << std::endl; - return ER_Good; + if (&rhs != this) + { + Specific* pointer = new Specific(); + *pointer = const_cast(&rhs); + this->data = static_cast(pointer); + } +} + +Variant::~Variant() +{ + delete data; +} + +Variant& Variant::operator=(Variant const &rhs) +{ + if (&rhs != this) + { + Specific* pointer = new Specific(); + *pointer = const_cast(rhs.data); + this->data = static_cast(pointer); + } + + return *this; } diff --git a/source/src/main/main.cpp b/source/src/core/main.cpp similarity index 100% rename from source/src/main/main.cpp rename to source/src/core/main.cpp -- 2.11.4.GIT