diff --git a/src/Context.cpp b/src/Context.cpp index 3a9f48211..7a2e21c8d 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -221,10 +221,12 @@ int Context::initialize (int argc, const char** argv) // Initialize the database. tdb2.set_location (data_dir); +/* // Hook system init, plus post-start event occurring at the first possible // moment after hook initialization. hooks.initialize (); hooks.trigger ("on-launch"); +*/ } catch (const std::string& message) @@ -384,8 +386,9 @@ int Context::run () std::cerr << colorizeError (*e) << "\n"; else std::cerr << *e << "\n"; - +/* hooks.trigger ("on-exit"); +*/ return rc; } diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 55eda25e5..0609b826e 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -25,68 +25,14 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include -#include #include #include -#include -#include -#include extern Context context; -//////////////////////////////////////////////////////////////////////////////// -Hook::Hook () -: _event ("") -, _file ("") -, _function ("") -{ -} - -//////////////////////////////////////////////////////////////////////////////// -Hook::Hook (const std::string& e, const std::string& f, const std::string& fn) -: _event (e) -, _file (f) -, _function (fn) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -Hook::Hook (const Hook& other) -{ - _event = other._event; - _file = other._file; - _function = other._function; -} - -//////////////////////////////////////////////////////////////////////////////// -Hook& Hook::operator= (const Hook& other) -{ - if (this != &other) - { - _event = other._event; - _file = other._file; - _function = other._function; - } - - return *this; -} - //////////////////////////////////////////////////////////////////////////////// Hooks::Hooks () { - // New 2.x hooks. - _validTaskEvents.push_back ("on-task-add"); // Unimplemented - _validTaskEvents.push_back ("on-task-modify"); // Unimplemented - _validTaskEvents.push_back ("on-task-complete"); // Unimplemented - _validTaskEvents.push_back ("on-task-delete"); // Unimplemented - - _validProgramEvents.push_back ("on-launch"); - _validProgramEvents.push_back ("on-exit"); - _validProgramEvents.push_back ("on-file-read"); // Unimplemented - _validProgramEvents.push_back ("on-file-write"); // Unimplemented - _validProgramEvents.push_back ("on-synch"); // Unimplemented - _validProgramEvents.push_back ("on-gc"); // Unimplemented } //////////////////////////////////////////////////////////////////////////////// @@ -94,87 +40,5 @@ Hooks::~Hooks () { } -//////////////////////////////////////////////////////////////////////////////// -// Enumerate all hooks, and tell API about the script files it must load in -// order to call them. Note that API will perform a deferred read, which means -// that if it isn't called, a script will not be loaded. -void Hooks::initialize () -{ - // Allow a master switch to turn the whole thing off. - bool big_red_switch = context.config.getBoolean ("extensions"); - if (big_red_switch) - { - Config::const_iterator it; - for (it = context.config.begin (); it != context.config.end (); ++it) - { - std::string type; - std::string name; - std::string value; - - // "." - Nibbler n (it->first); - if (n.getUntil ('.', type) && - type == "hook" && - n.skip ('.') && - n.getUntilEOS (name)) - { - Nibbler n (it->second); - - // : [, ...] - while (!n.depleted ()) - { - std::string file; - std::string function; - if (n.getUntil (':', file) && - n.skip (':') && - n.getUntil (',', function)) - { - context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function); - Hook h (name, Path::expand (file), function); - _all.push_back (h); - - (void) n.skip (','); - } - else - ; // Was: throw std::string (format ("Malformed hook definition '{1}'.", it->first)); - } - } - } - } - else - context.debug ("Hooks::initialize --> off"); -} - -//////////////////////////////////////////////////////////////////////////////// -// Program hooks. -bool Hooks::trigger (const std::string& event) -{ - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Task hooks. -bool Hooks::trigger (const std::string& event, Task& task) -{ - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Hooks::validProgramEvent (const std::string& event) -{ - if (std::find (_validProgramEvents.begin (), _validProgramEvents.end (), event) != _validProgramEvents.end ()) - return true; - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -bool Hooks::validTaskEvent (const std::string& event) -{ - if (std::find (_validTaskEvents.begin (), _validTaskEvents.end (), event) != _validTaskEvents.end ()) - return true; - - return false; -} - +// TODO Time the hook runs. //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Hooks.h b/src/Hooks.h index 02b67adec..6103fffab 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -27,25 +27,6 @@ #ifndef INCLUDED_HOOKS #define INCLUDED_HOOKS -#include -#include - -// Hook class representing a single hook, which is just a three-way map. -class Hook -{ -public: - Hook (); - Hook (const std::string&, const std::string&, const std::string&); - Hook (const Hook&); - Hook& operator= (const Hook&); - -public: - std::string _event; - std::string _file; - std::string _function; -}; - -// Hooks class for managing the loading and calling of hook functions. class Hooks { public: @@ -54,20 +35,7 @@ public: Hooks (const Hooks&); // Deliberately unimplemented Hooks& operator= (const Hooks&); // Deliberately unimplemented - void initialize (); - - bool trigger (const std::string&); // Program - bool trigger (const std::string&, Task&); // Task - private: - bool validProgramEvent (const std::string&); - bool validTaskEvent (const std::string&); - -private: - std::vector _all; // All current hooks. - - std::vector _validProgramEvents; - std::vector _validTaskEvents; }; #endif