- Gutted the Hooks object.
- Commented out on-launch and on-exit triggers.
This commit is contained in:
Paul Beckingham 2014-05-13 16:23:50 -04:00
parent 7f3e42e4e1
commit bfb19e0a64
3 changed files with 5 additions and 170 deletions

View file

@ -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;
}

View file

@ -25,68 +25,14 @@
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <iostream>
#include <algorithm>
#include <Context.h>
#include <Hooks.h>
#include <Timer.h>
#include <text.h>
#include <i18n.h>
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;
// "<type>.<name>"
Nibbler n (it->first);
if (n.getUntil ('.', type) &&
type == "hook" &&
n.skip ('.') &&
n.getUntilEOS (name))
{
Nibbler n (it->second);
// <path>:<function> [, ...]
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.
////////////////////////////////////////////////////////////////////////////////

View file

@ -27,25 +27,6 @@
#ifndef INCLUDED_HOOKS
#define INCLUDED_HOOKS
#include <vector>
#include <string>
// 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 <Hook> _all; // All current hooks.
std::vector <std::string> _validProgramEvents;
std::vector <std::string> _validTaskEvents;
};
#endif