2018-03-25 Fred Gleason <fredg@paravelsystems.com>

* Added support for notifications to rdlogmanager(1).
This commit is contained in:
Fred Gleason 2018-03-25 15:47:30 -04:00
parent aa2fad829c
commit 5d0e1786a2
8 changed files with 311 additions and 164 deletions

View File

@ -16743,3 +16743,5 @@
2018-03-25 Fred Gleason <fredg@paravelsystems.com>
* Fixed typos in 'docs/apis/Makefile.am' that broke the
'make dist' target.
2018-03-25 Fred Gleason <fredg@paravelsystems.com>
* Added support for notifications to rdlogmanager(1).

View File

@ -62,6 +62,7 @@ dist_rdlogmanager_SOURCES = add_clock.cpp add_clock.h\
list_events.cpp list_events.h\
list_grids.cpp list_grids.h\
list_svcs.cpp list_svcs.h\
logobject.cpp logobject.h\
pick_report_dates.cpp pick_report_dates.h\
rdlogmanager.cpp rdlogmanager.h\
rename_item.cpp rename_item.h\
@ -87,6 +88,7 @@ nodist_rdlogmanager_SOURCES = moc_add_clock.cpp\
moc_list_events.cpp\
moc_list_grids.cpp\
moc_list_svcs.cpp\
moc_logobject.cpp\
moc_pick_report_dates.cpp\
moc_rdlogmanager.cpp\
moc_rename_item.cpp\

View File

@ -35,156 +35,6 @@
#include <rdlogmanager.h>
#include <globals.h>
int RunLogOperation(int argc,char *argv[],const QString &svcname,
int start_offset,bool protect_existing,bool gen_log,
bool merge_mus,bool merge_tfc)
{
QString sql;
RDSqlQuery *q;
QString report;
QString unused_report;
QString svcname_table=svcname;
svcname_table.replace(" ","_");
QString err_msg;
QApplication a(argc,argv,false);
//
// Open the Database
rda=new RDApplication("RDLogManager","rdlogmanager",RDLOGMANAGER_USAGE);
if(!rda->open(&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(1);
}
//
// Some Basic Structures
//
RDSvc *svc=new RDSvc(svcname,rda->station(),rda->config());
if(!svc->exists()) {
fprintf(stderr,"rdlogmanager: no such service\n");
return 256;
}
QDate start_date=QDate::currentDate().addDays(1+start_offset);
QString logname=
RDDateDecode(svc->nameTemplate(),start_date,rda->station(),rda->config(),
svc->name());
RDLog *log=new RDLog(logname);
//
// Generate Log
//
if(gen_log) {
if(protect_existing&&log->exists()) {
fprintf(stderr,"log \"%s\" already exists\n",
(const char *)log->name().utf8());
exit(256);
}
log->removeTracks(rda->station(),rda->user(),rda->config());
srand(QTime::currentTime().msec());
sql=RDCreateStackTableSql(svcname_table,rda->config());
q=new RDSqlQuery(sql);
if(!q->isActive()) {
fprintf(stderr,"SQL: %s\n",(const char *)sql);
fprintf(stderr,"SQL Error: %s\n",
(const char *)q->lastError().databaseText());
}
delete q;
if(!svc->generateLog(start_date,
RDDateDecode(svc->nameTemplate(),start_date,
rda->station(),rda->config(),svc->name()),
RDDateDecode(svc->nameTemplate(),start_date.addDays(1),
rda->station(),rda->config(),svc->name()),
&unused_report,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
return 256;
}
log->updateTracks();
//
// Generate Exception Report
//
RDLogEvent *event=
new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
event->load();
if((event->validate(&report,start_date)!=0)||
(!unused_report.isEmpty())) {
printf("%s\n\n%s",(const char*)report,(const char*)unused_report);
}
delete event;
}
//
// Merge Music
//
if(merge_mus) {
if(!log->exists()) {
fprintf(stderr,"rdlogmanager: log does not exist\n");
return 256;
}
if(protect_existing&&
(log->linkState(RDLog::SourceMusic)==RDLog::LinkDone)) {
fprintf(stderr,"rdlogmanager: music for log \"%s\" is already imported\n",
(const char *)log->name().utf8());
return 256;
}
report="";
log->removeTracks(rda->station(),rda->user(),rda->config());
if(!svc->clearLogLinks(RDSvc::Traffic,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
return 256;
}
if(!svc->clearLogLinks(RDSvc::Music,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
return 256;
}
if(svc->linkLog(RDSvc::Music,start_date,logname,&report,rda->user(),&err_msg)) {
printf("%s\n",(const char*)report);
}
else {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
}
//
// Merge Traffic
//
if(merge_tfc) {
if(!log->exists()) {
fprintf(stderr,"rdlogmanager: log does not exist\n");
return 256;
}
if(protect_existing&&
(log->linkState(RDLog::SourceTraffic)==RDLog::LinkDone)) {
fprintf(stderr,
"rdlogmanager: traffic for log \"%s\" is already imported\n",
(const char *)log->name().utf8());
return 256;
}
report="";
if(!svc->clearLogLinks(RDSvc::Traffic,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
return 256;
}
if(svc->linkLog(RDSvc::Traffic,start_date,logname,&report,rda->user(),
&err_msg)) {
printf("%s\n",(const char*)report);
}
else {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
}
}
//
// Clean Up
//
delete log;
delete svc;
return 0;
}
int RunReportOperation(int argc,char *argv[],const QString &rptname,
bool protect_existing,int start_offset,int end_offset)
{

View File

@ -338,6 +338,7 @@ void GenerateLog::createData()
}
}
}
SendNotification(RDNotification::DeleteAction,log->name());
log->removeTracks(rda->station(),rda->user(),rda->config());
//
@ -376,6 +377,7 @@ void GenerateLog::createData()
return;
}
log->updateTracks();
SendNotification(RDNotification::AddAction,log->name());
delete log;
delete svc;
@ -465,6 +467,7 @@ void GenerateLog::musicData()
delete svc;
return;
}
SendNotification(RDNotification::ModifyAction,log->name());
delete log;
delete svc;
if(!report.isEmpty()) {
@ -515,6 +518,7 @@ void GenerateLog::trafficData()
delete svc;
return;
}
SendNotification(RDNotification::ModifyAction,log->name());
delete log;
delete svc;
if(!report.isEmpty()) {
@ -641,3 +645,13 @@ void GenerateLog::UpdateControls()
delete svc;
fileScanData();
}
void GenerateLog::SendNotification(RDNotification::Action action,
const QString &logname)
{
RDNotification *notify=new RDNotification(RDNotification::LogType,
action,QVariant(logname));
rda->ripc()->sendNotification(*notify);
delete notify;
}

View File

@ -21,14 +21,15 @@
#ifndef GENERATE_LOG_H
#define GENERATE_LOG_H
#include <qdialog.h>
#include <qsqldatabase.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qdatetimeedit.h>
#include <qcombobox.h>
#include <qprogressdialog.h>
#include <qdatetimeedit.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qpixmap.h>
#include <qprogressdialog.h>
#include <qpushbutton.h>
#include <rdnotification.h>
#define GENERATE_LOG_FILESCAN_INTERVAL 5000
@ -55,6 +56,7 @@ class GenerateLog : public QDialog
private:
void UpdateControls();
void SendNotification(RDNotification::Action action,const QString &logname);
QLabel *gen_service_label;
QComboBox *gen_service_box;
QLabel *gen_date_label;

218
rdlogmanager/logobject.cpp Normal file
View File

@ -0,0 +1,218 @@
// logobject.cpp
//
// Generate/merge logs from the command line.
//
// (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <stdlib.h>
#include <qapplication.h>
#include <rdapplication.h>
#include <rdcreate_log.h>
#include <rddatedecode.h>
#include <rdlog.h>
#include <rdsvc.h>
#include "logobject.h"
LogObject::LogObject(const QString &svcname,int start_offset,
bool protect_existing,bool gen_log,bool merge_mus,
bool merge_tfc,QObject *parent)
: QObject(parent)
{
QString err_msg;
log_service_name=svcname;
log_start_offset=start_offset;
log_protect_existing=protect_existing;
log_generate_log=gen_log;
log_merge_music=merge_mus;
log_merge_traffic=merge_tfc;
//
// Open the Database
//
rda=new RDApplication("RDLogManager","rdlogmanager","");
if(!rda->open(&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(1);
}
connect(rda,SIGNAL(userChanged()),this,SLOT(userData()));
rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,
rda->config()->password());
}
void LogObject::userData()
{
QString err_msg;
QString sql;
RDSqlQuery *q;
QString report;
QString unused_report;
QString svcname_table=log_service_name;
svcname_table.replace(" ","_");
if(rda->user()->createLog()) {
//
// Some Basic Structures
//
RDSvc *svc=new RDSvc(log_service_name,rda->station(),rda->config());
if(!svc->exists()) {
fprintf(stderr,"rdlogmanager: no such service\n");
exit(256);
}
QDate start_date=QDate::currentDate().addDays(1+log_start_offset);
QString logname=
RDDateDecode(svc->nameTemplate(),start_date,rda->station(),rda->config(),
svc->name());
RDLog *log=new RDLog(logname);
//
// Generate Log
//
if(log_generate_log) {
if(log_protect_existing&&log->exists()) {
fprintf(stderr,"log \"%s\" already exists\n",
(const char *)log->name().utf8());
exit(256);
}
SendNotification(RDNotification::DeleteAction,log->name());
log->removeTracks(rda->station(),rda->user(),rda->config());
srand(QTime::currentTime().msec());
sql=RDCreateStackTableSql(svcname_table,rda->config());
q=new RDSqlQuery(sql);
if(!q->isActive()) {
fprintf(stderr,"SQL: %s\n",(const char *)sql);
fprintf(stderr,"SQL Error: %s\n",
(const char *)q->lastError().databaseText());
}
delete q;
if(!svc->generateLog(start_date,
RDDateDecode(svc->nameTemplate(),start_date,
rda->station(),rda->config(),svc->name()),
RDDateDecode(svc->nameTemplate(),start_date.addDays(1),
rda->station(),rda->config(),svc->name()),
&unused_report,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
log->updateTracks();
SendNotification(RDNotification::AddAction,log->name());
//
// Generate Exception Report
//
RDLogEvent *event=
new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
event->load();
if((event->validate(&report,start_date)!=0)||
(!unused_report.isEmpty())) {
printf("%s\n\n%s",(const char*)report,(const char*)unused_report);
}
delete event;
}
//
// Merge Music
//
if(log_merge_music) {
if(!log->exists()) {
fprintf(stderr,"rdlogmanager: log does not exist\n");
exit(256);
}
if(log_protect_existing&&
(log->linkState(RDLog::SourceMusic)==RDLog::LinkDone)) {
fprintf(stderr,
"rdlogmanager: music for log \"%s\" is already imported\n",
(const char *)log->name().utf8());
exit(256);
}
report="";
log->removeTracks(rda->station(),rda->user(),rda->config());
if(!svc->clearLogLinks(RDSvc::Traffic,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
if(!svc->clearLogLinks(RDSvc::Music,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
if(svc->linkLog(RDSvc::Music,start_date,logname,&report,rda->user(),
&err_msg)) {
printf("%s\n",(const char*)report);
}
else {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
SendNotification(RDNotification::ModifyAction,log->name());
}
//
// Merge Traffic
//
if(log_merge_traffic) {
if(!log->exists()) {
fprintf(stderr,"rdlogmanager: log does not exist\n");
exit(256);
}
if(log_protect_existing&&
(log->linkState(RDLog::SourceTraffic)==RDLog::LinkDone)) {
fprintf(stderr,
"rdlogmanager: traffic for log \"%s\" is already imported\n",
(const char *)log->name().utf8());
exit(256);
}
report="";
if(!svc->clearLogLinks(RDSvc::Traffic,logname,rda->user(),&err_msg)) {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
exit(256);
}
if(svc->linkLog(RDSvc::Traffic,start_date,logname,&report,rda->user(),
&err_msg)) {
printf("%s\n",(const char*)report);
}
else {
fprintf(stderr,"rdlogmanager: %s\n",(const char *)err_msg);
}
SendNotification(RDNotification::ModifyAction,log->name());
}
//
// Clean Up
//
delete log;
delete svc;
exit(0);
}
fprintf(stderr,"rdlogmanager: insufficient permissions\n");
exit(1);
}
void LogObject::SendNotification(RDNotification::Action action,
const QString &logname)
{
RDNotification *notify=new RDNotification(RDNotification::LogType,
action,QVariant(logname));
rda->ripc()->sendNotification(*notify);
qApp->processEvents();
delete notify;
}

49
rdlogmanager/logobject.h Normal file
View File

@ -0,0 +1,49 @@
// logobject.h
//
// The Log Manager Utility for Rivendell.
//
// (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef LOGOBJECT_H
#define LOGOBJECT_H
#include <qobject.h>
#include <rdnotification.h>
class LogObject : public QObject
{
Q_OBJECT
public:
LogObject(const QString &svcname,int start_offset,bool protect_existing,
bool gen_log,bool merge_mus,bool merge_tfc,QObject *parent=0);
private slots:
void userData();
private:
void SendNotification(RDNotification::Action action,const QString &logname);
QString log_service_name;
int log_start_offset;
bool log_protect_existing;
bool log_generate_log;
bool log_merge_music;
bool log_merge_traffic;
};
#endif // LOG_OBJECT_H

View File

@ -58,6 +58,7 @@
#include "list_grids.h"
#include "list_svcs.h"
#include "rdlogmanager.h"
#include "logobject.h"
//
// Icons
@ -377,12 +378,16 @@ int main(int argc,char *argv[])
for(unsigned i=0;i<cmd->keys();i++) {
if (cmd->key(i)=="-P") {
cmd_protect_existing = true;
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-g") {
printf("generate\n");
cmd_generate = true;
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-m") {
cmd_merge_music = true;
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-t") {
cmd_merge_traffic = true;
@ -391,8 +396,8 @@ int main(int argc,char *argv[])
if(cmd->key(i)=="--skip-db-check") {
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-s") {
if (i+1<cmd->keys()) {
if(cmd->key(i)=="-s") {
if((i+1)<cmd->keys()) {
i++;
cmd_service = cmd->key(i);
}
@ -400,9 +405,10 @@ int main(int argc,char *argv[])
fprintf(stderr,"rdlogmanager: missing argument to \"-s\"\n");
exit(2);
}
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-r") {
if (i+1<cmd->keys()) {
if(cmd->key(i)=="-r") {
if(i+1<cmd->keys()) {
i++;
cmd_report = cmd->key(i);
}
@ -410,6 +416,7 @@ int main(int argc,char *argv[])
fprintf(stderr,"rdlogmanager: missing argument to \"-r\"\n");
exit(2);
}
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-d") {
if (i+1<cmd->keys()) {
@ -420,6 +427,7 @@ int main(int argc,char *argv[])
fprintf(stderr,"rdlogmanager: missing argument to \"-d\"\n");
exit(2);
}
cmd->setProcessed(i,true);
}
if (cmd->key(i)=="-e") {
if (i+1<cmd->keys()) {
@ -430,6 +438,7 @@ int main(int argc,char *argv[])
fprintf(stderr,"rdlogmanager: missing argument to \"-e\"\n");
exit(2);
}
cmd->setProcessed(i,true);
}
if(!cmd->processed(i)) {
fprintf(stderr,"rdlogmanager: unknown command option \"%s\"\n",
@ -446,10 +455,11 @@ int main(int argc,char *argv[])
}
if(cmd_generate||cmd_merge_traffic||cmd_merge_music) {
return RunLogOperation(argc,argv,cmd_service,cmd_start_offset,
cmd_protect_existing,cmd_generate,
cmd_merge_music,cmd_merge_traffic);
}
QApplication a(argc,argv,false);
new LogObject(cmd_service,cmd_start_offset,cmd_protect_existing,
cmd_generate,cmd_merge_music,cmd_merge_traffic);
return a.exec();
}
if(!cmd_report.isEmpty()) {
return RunReportOperation(argc,argv,cmd_report,cmd_protect_existing,
cmd_start_offset,cmd_end_offset);