Enhancements - TDB2::gc

- Stubbed TDB2::gc.
- Fixed broken tests Makefile
- Added handleCustomReport call to Context dispatch.
This commit is contained in:
Paul Beckingham
2009-06-11 21:17:30 -04:00
parent edd065d80e
commit 37e08df8ba
4 changed files with 56 additions and 10 deletions

View File

@@ -151,9 +151,12 @@ int Context::run ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Context::dispatch () std::string Context::dispatch ()
{ {
bool gc = true; // TODO Should be false for shadow file updates.
bool gcMod = false; // Change occurred by way of gc. bool gcMod = false; // Change occurred by way of gc.
bool cmdMod = false; // Change occurred by way of command type. bool cmdMod = false; // Change occurred by way of command type.
std::string out; std::string out;
/* /*
// Read-only commands with no side effects. // Read-only commands with no side effects.
if (command == "export") { out = handleExport (); } if (command == "export") { out = handleExport (); }
@@ -192,18 +195,19 @@ std::string Context::dispatch ()
// Command that display IDs and therefore need TDB::gc first. // Command that display IDs and therefore need TDB::gc first.
/* /*
else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); } else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); } // TODO OBSOLETE
else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (); } else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (); }
else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); } else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); } // TODO OBSOLETE
else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); } else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); } // TODO OBSOLETE
else if (cmd.validCustom (command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (command); }
*/ */
else if (cmd.validCustom (cmd.command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); }
// If the command is not recognized, display usage. // If the command is not recognized, display usage.
else { out = shortUsage (); } else { out = shortUsage (); }
// Only update the shadow file if such an update was not suppressed (shadow), // Only update the shadow file if such an update was not suppressed (shadow),
// and if an actual change occurred (gcMod || cmdMod). // and if an actual change occurred (gcMod || cmdMod).
// TODO
// if (shadow && (gcMod || cmdMod)) // if (shadow && (gcMod || cmdMod))
// shadow (); // shadow ();

View File

@@ -282,6 +282,46 @@ void TDB2::upgrade ()
throw std::string ("unimplemented TDB2::upgrade"); throw std::string ("unimplemented TDB2::upgrade");
} }
////////////////////////////////////////////////////////////////////////////////
// Scans the pending tasks for any that are completed or deleted, and if so,
// moves them to the completed.data file. Returns a count of tasks moved.
int TDB2::gc ()
{
int count = 0;
/*
// Read everything from the pending file.
std::vector <T> all;
allPendingT (all);
// A list of the truly pending tasks.
std::vector <T> pending;
std::vector<T>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
{
// Some tasks stay in the pending file.
if (it->getStatus () == T::pending ||
it->getStatus () == T::recurring)
{
pending.push_back (*it);
}
// Others are transferred to the completed file.
else
{
writeCompleted (*it);
++count;
}
}
// Dump all clean tasks into pending. But don't bother unless at least one
// task was transferred.
if (count)
overwritePending (pending);
*/
return count;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FILE* TDB2::openAndLock (const std::string& file) FILE* TDB2::openAndLock (const std::string& file)
{ {

View File

@@ -52,10 +52,12 @@ public:
int load (std::vector <Task>&, Filter&); int load (std::vector <Task>&, Filter&);
int loadPending (std::vector <Task>&, Filter&); int loadPending (std::vector <Task>&, Filter&);
int loadCompleted (std::vector <Task>&, Filter&); int loadCompleted (std::vector <Task>&, Filter&);
void add (Task&);
void update (Task&, Task&); void add (Task&); // Single task add to pending
int commit (); void update (Task&, Task&); // Single task update to pending
void upgrade (); int commit (); // Write out all tasks
void upgrade (); // Convert both files to FF4
int gc (); // Clean up pending
private: private:
FILE* openAndLock (const std::string&); FILE* openAndLock (const std::string&);

View File

@@ -3,11 +3,11 @@ PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
cmd.t config.t cmd.t config.t
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -lncurses LFLAGS = -L/usr/local/lib -lncurses
OBJECTS = ../TDB2.o ../T.o ../Task.o ../parse.o ../text.o ../Date.o ../Table.o \ OBJECTS = ../TDB2.o ../T.o ../Task.o ../valid.o ../text.o ../Date.o ../Table.o \
../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o ../Cmd.o \ ../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o ../Cmd.o \
../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \ ../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \
../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \ ../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \
../report.o ../Grid.o ../color.o ../rules.o ../recur.o ../report.o ../Grid.o ../color.o ../rules.o ../recur.o ../custom.o
all: $(PROJECT) all: $(PROJECT)