- Eliminated the concept of list hooks.
- Eliminated unnecessary API functions.
This commit is contained in:
Paul Beckingham 2011-04-13 23:20:55 -04:00
parent dbb556bce9
commit 17d1e59e29
4 changed files with 13 additions and 248 deletions

View file

@ -122,15 +122,6 @@ static int api_task_feature (lua_State* L)
return 1; return 1;
} }
////////////////////////////////////////////////////////////////////////////////
// Returns values from .taskrc, by name.
static int api_task_get_config (lua_State* L)
{
std::string name = luaL_checkstring (L, 1);
lua_pushstring (L, context.config.get (name).c_str ());
return 1;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int api_task_header_message (lua_State* L) static int api_task_header_message (lua_State* L)
{ {
@ -166,166 +157,6 @@ static int api_task_exit (lua_State* L)
return 0; return 0;
} }
////////////////////////////////////////////////////////////////////////////////
// -- 'id' is the task id passed to the hook function. Date attributes are
// -- returned as a numeric epoch offset. Tags and annotations are returned
// -- as tables. A nil value indicates a missing value.
static int api_task_get_uuid (lua_State* L)
{
if (the_task != NULL)
lua_pushstring (L, the_task->get ("uuid").c_str ());
else
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_description (lua_State* L)
{
if (the_task != NULL)
lua_pushstring (L, the_task->get ("description").c_str ());
else
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_project (lua_State* L)
{
if (the_task != NULL)
lua_pushstring (L, the_task->get ("project").c_str ());
else
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_priority (lua_State* L)
{
if (the_task != NULL)
lua_pushstring (L, the_task->get ("priority").c_str ());
else
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_status (lua_State* L)
{
if (the_task != NULL)
lua_pushstring (L, Task::statusToText (the_task->getStatus ()).c_str ());
else
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_due (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("due");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_entry (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("entry");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_start (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("start");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_end (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("end");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_until (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("until");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_wait (lua_State* L)
{
if (the_task != NULL)
{
unsigned int value = (unsigned int) the_task->get_ulong ("wait");
if (value)
{
lua_pushinteger (L, value);
return 1;
}
}
lua_pushnil (L);
return 1;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
API::API () API::API ()
: L (NULL) : L (NULL)
@ -354,22 +185,10 @@ void API::initialize ()
lua_pushcfunction (L, api_task_lua_version); lua_setglobal (L, "task_lua_version"); lua_pushcfunction (L, api_task_lua_version); lua_setglobal (L, "task_lua_version");
lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os"); lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os");
lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature"); lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature");
lua_pushcfunction (L, api_task_get_config); lua_setglobal (L, "task_get_config");
lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message"); lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message");
lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message"); lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message");
lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message"); lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message");
lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit"); lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit");
lua_pushcfunction (L, api_task_get_uuid); lua_setglobal (L, "task_get_uuid");
lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "task_get_description");
lua_pushcfunction (L, api_task_get_project); lua_setglobal (L, "task_get_project");
lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "task_get_priority");
lua_pushcfunction (L, api_task_get_status); lua_setglobal (L, "task_get_status");
lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "task_get_due");
lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "task_get_entry");
lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "task_get_start");
lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "task_get_end");
lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "task_get_until");
lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "task_get_wait");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -416,24 +235,6 @@ bool API::callProgramHook (
return rc == 0 ? true : false; return rc == 0 ? true : false;
} }
////////////////////////////////////////////////////////////////////////////////
// TODO No intention of implementing this before task 2.0. Why? Because we
// need to implement a Lua iterator, in C++, to iterate over a std::vector.
bool API::callListHook (
const std::string& file,
const std::string& function,
std::vector <Task>& all)
{
loadFile (file);
// TODO Get function.
// TODO Prepare args.
// TODO Make call.
// TODO Get exit status.
return true;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool API::callTaskHook ( bool API::callTaskHook (
const std::string& file, const std::string& file,

View file

@ -51,7 +51,6 @@ public:
void initialize (); void initialize ();
bool callProgramHook (const std::string&, const std::string&); bool callProgramHook (const std::string&, const std::string&);
bool callListHook (const std::string&, const std::string&, std::vector <Task>&);
bool callTaskHook (const std::string&, const std::string&, Task&); bool callTaskHook (const std::string&, const std::string&, Task&);
bool callFieldHook (const std::string&, const std::string&, const std::string&, std::string&); bool callFieldHook (const std::string&, const std::string&, const std::string&, std::string&);

View file

@ -90,9 +90,21 @@ Hooks::Hooks ()
// Obsolete 1.x hooks. // Obsolete 1.x hooks.
validProgramEvents.push_back ("post-start"); validProgramEvents.push_back ("post-start");
validProgramEvents.push_back ("pre-exit");
validProgramEvents.push_back ("pre-file-read");
validProgramEvents.push_back ("post-file-read");
validProgramEvents.push_back ("pre-file-write");
validProgramEvents.push_back ("post-file-write");
validProgramEvents.push_back ("pre-gc");
validProgramEvents.push_back ("post-gc");
validProgramEvents.push_back ("post-commit"); validProgramEvents.push_back ("post-commit");
validProgramEvents.push_back ("pre-fatal-error"); validProgramEvents.push_back ("pre-fatal-error");
validProgramEvents.push_back ("pre-exit");
validProgramEvents.push_back ("pre-command-line"); validProgramEvents.push_back ("pre-command-line");
validProgramEvents.push_back ("post-command-line"); validProgramEvents.push_back ("post-command-line");
validProgramEvents.push_back ("pre-command-line-override"); validProgramEvents.push_back ("pre-command-line-override");
@ -109,10 +121,6 @@ Hooks::Hooks ()
validProgramEvents.push_back ("post-file-lock"); validProgramEvents.push_back ("post-file-lock");
validProgramEvents.push_back ("pre-file-unlock"); validProgramEvents.push_back ("pre-file-unlock");
validProgramEvents.push_back ("post-file-unlock"); validProgramEvents.push_back ("post-file-unlock");
validProgramEvents.push_back ("pre-file-read");
validProgramEvents.push_back ("post-file-read");
validProgramEvents.push_back ("pre-file-write");
validProgramEvents.push_back ("post-file-write");
validProgramEvents.push_back ("pre-output"); validProgramEvents.push_back ("pre-output");
validProgramEvents.push_back ("post-output"); validProgramEvents.push_back ("post-output");
validProgramEvents.push_back ("pre-debug"); validProgramEvents.push_back ("pre-debug");
@ -123,8 +131,6 @@ Hooks::Hooks ()
validProgramEvents.push_back ("post-footnote"); validProgramEvents.push_back ("post-footnote");
validProgramEvents.push_back ("pre-dispatch"); validProgramEvents.push_back ("pre-dispatch");
validProgramEvents.push_back ("post-dispatch"); validProgramEvents.push_back ("post-dispatch");
validProgramEvents.push_back ("pre-gc");
validProgramEvents.push_back ("post-gc");
validProgramEvents.push_back ("pre-archive"); validProgramEvents.push_back ("pre-archive");
validProgramEvents.push_back ("post-archive"); validProgramEvents.push_back ("post-archive");
validProgramEvents.push_back ("pre-purge"); validProgramEvents.push_back ("pre-purge");
@ -212,9 +218,6 @@ Hooks::Hooks ()
validProgramEvents.push_back ("pre-version-command"); validProgramEvents.push_back ("pre-version-command");
validProgramEvents.push_back ("post-version-command"); validProgramEvents.push_back ("post-version-command");
validListEvents.push_back ("pre-filter");
validListEvents.push_back ("post-filter");
validTaskEvents.push_back ("pre-display"); validTaskEvents.push_back ("pre-display");
validTaskEvents.push_back ("pre-modification"); validTaskEvents.push_back ("pre-modification");
validTaskEvents.push_back ("post-modification"); validTaskEvents.push_back ("post-modification");
@ -365,33 +368,6 @@ bool Hooks::trigger (const std::string& event)
return true; return true;
} }
////////////////////////////////////////////////////////////////////////////////
// List hooks.
bool Hooks::trigger (const std::string& event, std::vector <Task>& tasks)
{
#ifdef HAVE_LIBLUA
std::vector <Hook>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
{
if (it->event == event)
{
Timer timer (std::string ("Hooks::trigger ") + event);
if (validListEvent (event))
{
context.debug (std::string ("Event ") + event + " triggered");
if (! api.callListHook (it->file, it->function, tasks))
return false;
}
else
throw std::string ("Unrecognized hook event '") + event + "'.";
}
}
#endif
return true;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Task hooks. // Task hooks.
bool Hooks::trigger (const std::string& event, Task& task) bool Hooks::trigger (const std::string& event, Task& task)
@ -458,14 +434,6 @@ bool Hooks::validProgramEvent (const std::string& event)
return false; return false;
} }
bool Hooks::validListEvent (const std::string& event)
{
if (std::find (validListEvents.begin (), validListEvents.end (), event) != validListEvents.end ())
return true;
return false;
}
bool Hooks::validTaskEvent (const std::string& event) bool Hooks::validTaskEvent (const std::string& event)
{ {
if (std::find (validTaskEvents.begin (), validTaskEvents.end (), event) != validTaskEvents.end ()) if (std::find (validTaskEvents.begin (), validTaskEvents.end (), event) != validTaskEvents.end ())

View file

@ -59,13 +59,11 @@ public:
void initialize (); void initialize ();
bool trigger (const std::string&); // Program bool trigger (const std::string&); // Program
bool trigger (const std::string&, std::vector <Task>&); // List
bool trigger (const std::string&, Task&); // Task bool trigger (const std::string&, Task&); // Task
bool trigger (const std::string&, const std::string&, std::string&); // Field bool trigger (const std::string&, const std::string&, std::string&); // Field
private: private:
bool validProgramEvent (const std::string&); bool validProgramEvent (const std::string&);
bool validListEvent (const std::string&);
bool validTaskEvent (const std::string&); bool validTaskEvent (const std::string&);
bool validFieldEvent (const std::string&); bool validFieldEvent (const std::string&);
@ -76,7 +74,6 @@ private:
std::vector <Hook> all; // All current hooks. std::vector <Hook> all; // All current hooks.
std::vector <std::string> validProgramEvents; std::vector <std::string> validProgramEvents;
std::vector <std::string> validListEvents;
std::vector <std::string> validTaskEvents; std::vector <std::string> validTaskEvents;
std::vector <std::string> validFieldEvents; std::vector <std::string> validFieldEvents;
}; };