Implement JSONQUEUE daemon command.

This commit is contained in:
Dianne Skoll
2020-02-27 15:18:23 -05:00
parent cbff2a7bf2
commit 281a1a206e
6 changed files with 106 additions and 15 deletions

View File

@@ -582,7 +582,7 @@ proc ConfigureCalFrame { w firstDay numDays } {
proc DoQueue {} {
global DaemonFile
puts $DaemonFile "QUEUE"
puts $DaemonFile "JSONQUEUE"
flush $DaemonFile
}
@@ -2418,18 +2418,19 @@ proc ShowQueue { file } {
grid columnconfigure $w 1 -weight 0
grid rowconfigure $w 0 -weight 1
grid rowconfigure $w 1 -weight 0
set did 0
CenterWindow $w .
while (1) {
# We should only get one line
gets $file line
if {$line == "NOTE endqueue"} {
if {$line == "NOTE ENDJSONQUEUE"} {
break
}
set did 1
$w.t insert end "$line\n"
}
if {!$did} {
$w.t insert end "*** Queue is empty ***\n"
if {[catch {set obj [::json::many-json2dict $line]}]} {
continue;
}
foreach q $obj {
$w.t insert end "$q\n"
}
}
$w.t configure -state disabled
}
@@ -2456,7 +2457,7 @@ proc DaemonReadable { file } {
scan $line "NOTE reminder %s %s %s" time now tag
IssueBackgroundReminder $file $time $now $tag
}
"NOTE queue" {
"NOTE JSONQUEUE" {
ShowQueue $file
}
"NOTE newdate" {

View File

@@ -245,7 +245,7 @@ static void WriteBottomCalLine (void);
static void WriteIntermediateCalLine (void);
static void WriteCalDays (void);
static void PrintJSONString(char const *s)
void PrintJSONString(char const *s)
{
while (*s) {
switch(*s) {
@@ -262,14 +262,14 @@ static void PrintJSONString(char const *s)
}
}
static void PrintJSONKeyPairInt(char const *name, int val)
void PrintJSONKeyPairInt(char const *name, int val)
{
printf("\"");
PrintJSONString(name);
printf("\":%d, ", val);
}
static void PrintJSONKeyPairString(char const *name, char const *val)
void PrintJSONKeyPairString(char const *name, char const *val)
{
/* If value is blank, skip it! */
if (!val || !*val) {
@@ -283,7 +283,7 @@ static void PrintJSONKeyPairString(char const *name, char const *val)
printf("\", ");
}
static void PrintJSONKeyPairDate(char const *name, int jul)
void PrintJSONKeyPairDate(char const *name, int jul)
{
int y, m, d;
if (jul == NO_DATE) {
@@ -297,7 +297,7 @@ static void PrintJSONKeyPairDate(char const *name, int jul)
}
static void PrintJSONKeyPairDateTime(char const *name, int dt)
void PrintJSONKeyPairDateTime(char const *name, int dt)
{
int y, m, d, h, i, k;
if (dt == NO_TIME) {
@@ -315,6 +315,21 @@ static void PrintJSONKeyPairDateTime(char const *name, int dt)
}
void PrintJSONKeyPairTime(char const *name, int t)
{
int h, i;
if (t == NO_TIME) {
/* Skip it! */
return;
}
h = t / 60;
i = t % 60;
printf("\"");
PrintJSONString(name);
printf("\":\"%02d:%02d\", ", h, i);
}
#ifdef REM_USE_WCHAR
static void PutWideChar(wchar_t const wc)
{

View File

@@ -154,3 +154,9 @@ void SaveAllTriggerInfo(Trigger const *t, TimeTrig const *tt, int trigdate, int
void PerIterationInit(void);
char const *Decolorize(int r, int g, int b);
char const *Colorize(int r, int g, int b);
void PrintJSONString(char const *s);
void PrintJSONKeyPairInt(char const *name, int val);
void PrintJSONKeyPairString(char const *name, char const *val);
void PrintJSONKeyPairDate(char const *name, int jul);
void PrintJSONKeyPairDateTime(char const *name, int dt);
void PrintJSONKeyPairTime(char const *name, int t);

View File

@@ -448,6 +448,66 @@ static int CalculateNextTimeUsingSched(QueuedRem *q)
}
}
/* Dump the queue in JSON format */
static void
json_queue(QueuedRem const *q)
{
printf("[");
while(q) {
if (q->tt.nexttime == NO_TIME) {
q = q->next;
continue;
}
printf("{");
switch(q->typ) {
case NO_TYPE: PrintJSONKeyPairString("type", "NO_TYPE "); break;
case MSG_TYPE: PrintJSONKeyPairString("type", "MSG_TYPE "); break;
case RUN_TYPE: PrintJSONKeyPairString("type", "RUN_TYPE "); break;
case CAL_TYPE: PrintJSONKeyPairString("type", "CAL_TYPE "); break;
case SAT_TYPE: PrintJSONKeyPairString("type", "SAT_TYPE "); break;
case PS_TYPE: PrintJSONKeyPairString("type", "PS_TYPE "); break;
case PSF_TYPE: PrintJSONKeyPairString("type", "PSF_TYPE "); break;
case MSF_TYPE: PrintJSONKeyPairString("type", "MSF_TYPE "); break;
case PASSTHRU_TYPE: PrintJSONKeyPairString("type", "PASSTHRU_TYPE "); break;
default: PrintJSONKeyPairString("type", "? "); break;
}
PrintJSONKeyPairInt("rundisabled", q->RunDisabled);
PrintJSONKeyPairInt("ntrig", q->ntrig);
PrintJSONKeyPairTime("ttime", q->tt.ttime);
PrintJSONKeyPairTime("nextttime", q->tt.nexttime);
PrintJSONKeyPairInt("delta", q->tt.delta);
if (q->tt.rep != NO_TIME) {
PrintJSONKeyPairInt("rep", q->tt.rep);
}
if (q->tt.duration != NO_TIME) {
PrintJSONKeyPairInt("duration", q->tt.duration);
}
if (q->passthru[0]) {
PrintJSONKeyPairString("passthru", q->passthru);
}
if (q->sched[0]) {
PrintJSONKeyPairString("sched", q->sched);
}
if (DBufLen(&(q->tags))) {
PrintJSONKeyPairString("tags", DBufValue(&(q->tags)));
}
/* Last one is a special case - no trailing comma */
printf("\"");
PrintJSONString("body");
printf("\":\"");
if (q->text) {
PrintJSONString(q->text);
} else {
PrintJSONString("");
}
printf("\"}");
q = q->next;
}
printf("]\n");
}
/***************************************************************/
/* */
/* DaemonWait */
@@ -532,6 +592,11 @@ static void DaemonWait(unsigned int sleeptime)
}
printf("NOTE endqueue\n");
fflush(stdout);
} else if (!strcmp(cmdLine, "JSONQUEUE\n")) {
printf("NOTE JSONQUEUE\n");
json_queue(QueueHead);
printf("NOTE ENDJSONQUEUE\n");
fflush(stdout);
} else if (!strcmp(cmdLine, "REREAD\n")) {
printf("NOTE reread\n");
fflush(stdout);

View File

@@ -1833,7 +1833,8 @@ coerce("DATETIME", "2020-05-05@12:45") => 2020-05-05@12:45
set x coerce("DATETIME", "2020-05-05@1:45pm")
coerce("DATETIME", "2020-05-05@1:45pm") => 2020-05-05@13:45
# Don't want Remind to queue reminders
EXIT
Test 2

View File

@@ -525,6 +525,9 @@ set x coerce("DATETIME", "2020-05-05@12:45am")
set x coerce("DATETIME", "2020-05-05@12:45")
set x coerce("DATETIME", "2020-05-05@1:45pm")
# Don't want Remind to queue reminders
EXIT
__EOF__
REM This line should not even be seen
And you can put whatever you like here.