2018-01-31 Fred Gleason <fredg@paravelsystems.com>

* Converted rdrepld(8) to use RDApplication.
This commit is contained in:
Fred Gleason 2018-01-31 03:11:17 -05:00
parent 99814a9f00
commit 2103fa72c1
10 changed files with 56 additions and 121 deletions

View File

@ -16615,3 +16615,5 @@
* Converted rdlogmanager(1) to use RDApplication. * Converted rdlogmanager(1) to use RDApplication.
2018-01-31 Fred Gleason <fredg@paravelsystems.com> 2018-01-31 Fred Gleason <fredg@paravelsystems.com>
* Converted rdpanel(1) to use RDApplication. * Converted rdpanel(1) to use RDApplication.
2018-01-31 Fred Gleason <fredg@paravelsystems.com>
* Converted rdrepld(8) to use RDApplication.

View File

@ -29,8 +29,7 @@ moc_%.cpp: %.h
$(MOC) $< -o $@ $(MOC) $< -o $@
bin_PROGRAMS = rdrepld bin_PROGRAMS = rdrepld
dist_rdrepld_SOURCES = globals.h\ dist_rdrepld_SOURCES = rdrepld.cpp rdrepld.h \
rdrepld.cpp rdrepld.h \
replconfig.cpp replconfig.h\ replconfig.cpp replconfig.h\
replfactory.cpp replfactory.h\ replfactory.cpp replfactory.h\
citadelxds.cpp citadelxds.h citadelxds.cpp citadelxds.h

View File

@ -2,7 +2,7 @@
// //
// Replicator implementation for the Citadel XDS Portal // Replicator implementation for the Citadel XDS Portal
// //
// (C) Copyright 2010,2016-2017 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -26,6 +26,7 @@
#include <qfileinfo.h> #include <qfileinfo.h>
#include <qdatetime.h> #include <qdatetime.h>
#include <rdapplication.h>
#include <rdaudioconvert.h> #include <rdaudioconvert.h>
#include <rdcart.h> #include <rdcart.h>
#include <rdcut.h> #include <rdcut.h>
@ -37,7 +38,7 @@
#include <rdtempdirectory.h> #include <rdtempdirectory.h>
#include <rdupload.h> #include <rdupload.h>
#include <citadelxds.h> #include "citadelxds.h"
#define RD_MAX_CART_NUMBER 999999 #define RD_MAX_CART_NUMBER 999999
@ -86,10 +87,10 @@ void CitadelXds::CheckIsciXreference()
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
QFileInfo *fi=new QFileInfo(rdsystem->isciXreferencePath()); QFileInfo *fi=new QFileInfo(rda->system()->isciXreferencePath());
if(fi->exists()) { if(fi->exists()) {
if(fi->lastModified()>xds_isci_datetime) { if(fi->lastModified()>xds_isci_datetime) {
if(LoadIsciXreference(rdsystem->isciXreferencePath())) { if(LoadIsciXreference(rda->system()->isciXreferencePath())) {
sql="update VERSION set LAST_ISCI_XREFERENCE=now()"; sql="update VERSION set LAST_ISCI_XREFERENCE=now()";
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
delete q; delete q;
@ -99,9 +100,9 @@ void CitadelXds::CheckIsciXreference()
} }
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogErr, rda->config()->log("rdrepld",RDConfig::LogErr,
QString().sprintf("unable to load ISCI cross reference file \"%s\"", QString().sprintf("unable to load ISCI cross reference file \"%s\"",
(const char *)rdsystem->isciXreferencePath())); (const char *)rda->system()->isciXreferencePath()));
} }
delete fi; delete fi;
} }
@ -121,9 +122,9 @@ bool CitadelXds::LoadIsciXreference(const QString &filename)
unsigned linenum=3; unsigned linenum=3;
if((f=fopen(filename,"r"))==NULL) { if((f=fopen(filename,"r"))==NULL) {
rdconfig->log("rdrepld",RDConfig::LogErr, rda->config()->log("rdrepld",RDConfig::LogErr,
QString().sprintf("unable to load ISCI cross reference file \"%s\" [%s]", QString().sprintf("unable to load ISCI cross reference file \"%s\" [%s]",
(const char *)rdsystem->isciXreferencePath(), (const char *)rda->system()->isciXreferencePath(),
strerror(errno))); strerror(errno)));
return false; return false;
} }
@ -172,31 +173,31 @@ bool CitadelXds::LoadIsciXreference(const QString &filename)
delete q; delete q;
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). rda->config()->log("rdrepld",RDConfig::LogWarning,QString().
sprintf("invalid date in line %d of \"%s\"", sprintf("invalid date in line %d of \"%s\"",
linenum,(const char *)filename)); linenum,(const char *)filename));
} }
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). rda->config()->log("rdrepld",RDConfig::LogWarning,QString().
sprintf("invalid FILENAME field \"%s\" in line %d of \"%s\"", sprintf("invalid FILENAME field \"%s\" in line %d of \"%s\"",
(const char *)fields[8],linenum,(const char *)filename)); (const char *)fields[8],linenum,(const char *)filename));
} }
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). rda->config()->log("rdrepld",RDConfig::LogWarning,QString().
sprintf("invalid date in line %d of \"%s\"", sprintf("invalid date in line %d of \"%s\"",
linenum,(const char *)filename)); linenum,(const char *)filename));
} }
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogDebug,QString(). rda->config()->log("rdrepld",RDConfig::LogDebug,QString().
sprintf("missing/invalid cart number in line %d of \"%s\"", sprintf("missing/invalid cart number in line %d of \"%s\"",
linenum,(const char *)filename)); linenum,(const char *)filename));
} }
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). rda->config()->log("rdrepld",RDConfig::LogWarning,QString().
sprintf("line %d malformed in \"%s\"", sprintf("line %d malformed in \"%s\"",
linenum,(const char *)filename)); linenum,(const char *)filename));
} }
@ -206,9 +207,9 @@ bool CitadelXds::LoadIsciXreference(const QString &filename)
// //
// Clean Up // Clean Up
// //
rdconfig->log("rdrepld",RDConfig::LogInfo, rda->config()->log("rdrepld",RDConfig::LogInfo,
QString().sprintf("loaded ISCI cross reference file \"%s\"", QString().sprintf("loaded ISCI cross reference file \"%s\"",
(const char *)rdsystem->isciXreferencePath())); (const char *)rda->system()->isciXreferencePath()));
fclose(f); fclose(f);
return true; return true;
} }
@ -347,7 +348,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename)
} }
RDSettings *settings=new RDSettings(); RDSettings *settings=new RDSettings();
QString tempfile=RDTempDirectory::basePath()+"/"+filename; QString tempfile=RDTempDirectory::basePath()+"/"+filename;
RDAudioConvert *conv=new RDAudioConvert(rdconfig->stationName()); RDAudioConvert *conv=new RDAudioConvert(rda->config()->stationName());
conv->setSourceFile(RDCut::pathName(cutname)); conv->setSourceFile(RDCut::pathName(cutname));
conv->setDestinationFile(tempfile); conv->setDestinationFile(tempfile);
conv->setRange(cut->startPoint(),cut->endPoint()); conv->setRange(cut->startPoint(),cut->endPoint());
@ -366,7 +367,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename)
break; break;
default: default:
rdconfig->log("rdrepld",RDConfig::LogErr, rda->config()->log("rdrepld",RDConfig::LogErr,
QString().sprintf("CitadelXds: audio conversion failed: %s, cutname: %s", QString().sprintf("CitadelXds: audio conversion failed: %s, cutname: %s",
(const char *)RDAudioConvert::errorText(conv_err), (const char *)RDAudioConvert::errorText(conv_err),
(const char *)cutname)); (const char *)cutname));
@ -380,17 +381,17 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename)
// //
// Upload File // Upload File
// //
RDUpload *upload=new RDUpload(rdconfig); RDUpload *upload=new RDUpload(rda->config());
upload->setSourceFile(tempfile); upload->setSourceFile(tempfile);
upload->setDestinationUrl(config()->url()+"/"+filename); upload->setDestinationUrl(config()->url()+"/"+filename);
switch(upload_err=upload->runUpload(config()->urlUsername(), switch(upload_err=upload->runUpload(config()->urlUsername(),
config()->urlPassword(), config()->urlPassword(),
rdconfig->logXloadDebugData())) { rda->config()->logXloadDebugData())) {
case RDUpload::ErrorOk: case RDUpload::ErrorOk:
break; break;
default: default:
rdconfig->log("rdrepld",RDConfig::LogErr, rda->config()->log("rdrepld",RDConfig::LogErr,
QString().sprintf("CitadelXds: audio upload failed: %s", QString().sprintf("CitadelXds: audio upload failed: %s",
(const char *)RDUpload::errorText(upload_err))); (const char *)RDUpload::errorText(upload_err)));
unlink(tempfile); unlink(tempfile);
@ -399,7 +400,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename)
} }
unlink(tempfile); unlink(tempfile);
delete upload; delete upload;
rdconfig->log("rdrepld",RDConfig::LogInfo, rda->config()->log("rdrepld",RDConfig::LogInfo,
QString().sprintf("CitadelXds: uploaded cut %s to %s/%s", QString().sprintf("CitadelXds: uploaded cut %s to %s/%s",
(const char *)cutname, (const char *)cutname,
(const char *)config()->url(), (const char *)config()->url(),
@ -433,23 +434,23 @@ void CitadelXds::PurgeCuts()
path+="/"; path+="/";
} }
QUrl url(path+q->value(1).toString()); QUrl url(path+q->value(1).toString());
conv=new RDDelete(rdconfig); conv=new RDDelete(rda->config());
conv->setTargetUrl(url); conv->setTargetUrl(url);
if((conv_err=conv->runDelete(config()->urlUsername(), if((conv_err=conv->runDelete(config()->urlUsername(),
config()->urlPassword(), config()->urlPassword(),
rdconfig->logXloadDebugData()))== rda->config()->logXloadDebugData()))==
RDDelete::ErrorOk) { RDDelete::ErrorOk) {
sql=QString().sprintf("delete from REPL_CART_STATE where ID=%d", sql=QString().sprintf("delete from REPL_CART_STATE where ID=%d",
q->value(0).toInt()); q->value(0).toInt());
q2=new RDSqlQuery(sql); q2=new RDSqlQuery(sql);
delete q2; delete q2;
rdconfig->log("rdrepld",RDConfig::LogInfo, rda->config()->log("rdrepld",RDConfig::LogInfo,
QString().sprintf("purged \"%s\" for replicator \"%s\"", QString().sprintf("purged \"%s\" for replicator \"%s\"",
(const char *)url.toString(), (const char *)url.toString(),
(const char *)config()->name())); (const char *)config()->name()));
} }
else { else {
rdconfig->log("rdrepld",RDConfig::LogErr, rda->config()->log("rdrepld",RDConfig::LogErr,
QString().sprintf("unable to delete \"%s\" for replicator \"%s\" [%s]", QString().sprintf("unable to delete \"%s\" for replicator \"%s\" [%s]",
(const char *)url.toString(), (const char *)url.toString(),
(const char *)config()->name(), (const char *)config()->name(),

View File

@ -21,7 +21,6 @@
#ifndef CITADELXDS_H #ifndef CITADELXDS_H
#define CITADELXDS_H #define CITADELXDS_H
#include "globals.h"
#include "replfactory.h" #include "replfactory.h"
class CitadelXds : public ReplFactory class CitadelXds : public ReplFactory

View File

@ -1,31 +0,0 @@
// globals.h
//
// The Rivendell Replicator Daemon Global Definitions
//
// (C) Copyright 2010,2016 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 GLOBALS_H
#define GLOBALS_H
#include <rdconfig.h>
#include <rdsystem.h>
extern RDConfig *rdconfig;
extern RDSystem *rdsystem;
#endif // GLOBALS_H

View File

@ -2,7 +2,7 @@
// //
// The Rivendell Replicator Daemon // The Rivendell Replicator Daemon
// //
// (C) Copyright 2010,2016-2017 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -25,6 +25,7 @@
#include <qapplication.h> #include <qapplication.h>
#include <dbversion.h> #include <dbversion.h>
#include <rdapplication.h>
#include <rdcart.h> #include <rdcart.h>
#include <rdconf.h> #include <rdconf.h>
#include <rdcmd_switch.h> #include <rdcmd_switch.h>
@ -32,12 +33,8 @@
#include <rdescape_string.h> #include <rdescape_string.h>
#include <rdtempdirectory.h> #include <rdtempdirectory.h>
#include <globals.h> #include "citadelxds.h"
#include <citadelxds.h> #include "rdrepld.h"
#include <rdrepld.h>
RDConfig *rdconfig;
RDSystem *rdsystem;
void SigHandler(int signum) void SigHandler(int signum)
{ {
@ -64,15 +61,7 @@ void SigHandler(int signum)
MainObject::MainObject(QObject *parent) MainObject::MainObject(QObject *parent)
:QObject(parent) :QObject(parent)
{ {
bool skip_db_check=false; QString err_msg;
unsigned schema=0;
//
// Load the config
//
rdconfig=new RDConfig();
rdconfig->load();
rdconfig->setModuleName("rdrepld");
// //
// Read Command Options // Read Command Options
@ -81,7 +70,6 @@ MainObject::MainObject(QObject *parent)
new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdrepld",RDREPLD_USAGE); new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdrepld",RDREPLD_USAGE);
for(unsigned i=0;i<cmd->keys();i++) { for(unsigned i=0;i<cmd->keys();i++) {
if(cmd->key(i)=="--skip-db-check") { if(cmd->key(i)=="--skip-db-check") {
skip_db_check=true;
} }
} }
@ -93,6 +81,12 @@ MainObject::MainObject(QObject *parent)
exit(1); exit(1);
} }
rda=new RDApplication("rdrepld",this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"rdrepld: %s\n",(const char *)err_msg);
exit(1);
}
// //
// Initialize Data Structures // Initialize Data Structures
// //
@ -103,39 +97,15 @@ MainObject::MainObject(QObject *parent)
// //
repl_temp_dir=RDTempDirectory::basePath(); repl_temp_dir=RDTempDirectory::basePath();
// connect(RDDbStatus(),
// Open Database SIGNAL(logText(RDConfig::LogPriority,const QString &)),
// this,SLOT(log(RDConfig::LogPriority,const QString &)));
QString err (tr("ERROR rdrepld aborting - "));
repl_db=RDInitDb(&schema,&err);
if(!repl_db) {
printf(err.ascii());
exit(1);
}
if((schema!=RD_VERSION_DATABASE)&&(!skip_db_check)) {
fprintf(stderr,"rdrepld: database version mismatch, should be %u, is %u\n",
RD_VERSION_DATABASE,schema);
exit(256);
}
connect (RDDbStatus(),SIGNAL(logText(RDConfig::LogPriority,const QString &)),
this,SLOT(log(RDConfig::LogPriority,const QString &)));
//
// System Configuration
//
rdsystem=new RDSystem();
//
// Station Configuration
//
repl_station=new RDStation(rdconfig->stationName());
// //
// Detach // Detach
// //
if(qApp->argc()==1) { if(qApp->argc()==1) {
RDDetach(rdconfig->logCoreDumpDirectory()); RDDetach(rda->config()->logCoreDumpDirectory());
} }
else { else {
debug=true; debug=true;
@ -156,7 +126,7 @@ MainObject::MainObject(QObject *parent)
connect(repl_loop_timer,SIGNAL(timeout()),this,SLOT(mainLoop())); connect(repl_loop_timer,SIGNAL(timeout()),this,SLOT(mainLoop()));
repl_loop_timer->start(RD_RDREPL_SCAN_INTERVAL,true); repl_loop_timer->start(RD_RDREPL_SCAN_INTERVAL,true);
rdconfig->log("rdrepld",RDConfig::LogNotice,"started"); rda->config()->log("rdrepld",RDConfig::LogNotice,"started");
} }
@ -171,7 +141,7 @@ void MainObject::mainLoop()
void MainObject::log(RDConfig::LogPriority prio,const QString &msg) void MainObject::log(RDConfig::LogPriority prio,const QString &msg)
{ {
rdconfig->log("rdrepld",prio,msg); rda->config()->log("rdrepld",prio,msg);
} }
@ -254,7 +224,7 @@ void MainObject::LoadReplicators()
BITRATE,QUALITY,URL,URL_USERNAME,URL_PASSWORD,\ BITRATE,QUALITY,URL,URL_USERNAME,URL_PASSWORD,\
ENABLE_METADATA,NORMALIZATION_LEVEL from \ ENABLE_METADATA,NORMALIZATION_LEVEL from \
REPLICATORS where STATION_NAME=\"%s\"", REPLICATORS where STATION_NAME=\"%s\"",
(const char *)RDEscapeString(rdconfig->stationName())); (const char *)RDEscapeString(rda->config()->stationName()));
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
while(q->next()) { while(q->next()) {
config=new ReplConfig(); config=new ReplConfig();

View File

@ -2,7 +2,7 @@
// //
// The Rivendell Replicator Daemon // The Rivendell Replicator Daemon
// //
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -26,12 +26,10 @@
#include <qobject.h> #include <qobject.h>
#include <qtimer.h> #include <qtimer.h>
#include <rdcheck_daemons.h>
#include <rdsystem.h>
#include <rdstation.h>
#include <rdconfig.h> #include <rdconfig.h>
#include <rdcheck_daemons.h>
#include <replfactory.h> #include "replfactory.h"
#define RDREPLD_USAGE "[-d][--event-id=<id>]\n\nOptions:\n\n-d\n Set 'debug' mode, causing rdrepld(8) to stay in the foreground\n and print debugging info on standard output.\n\n" #define RDREPLD_USAGE "[-d][--event-id=<id>]\n\nOptions:\n\n-d\n Set 'debug' mode, causing rdrepld(8) to stay in the foreground\n and print debugging info on standard output.\n\n"
#define RD_RDREPLD_PID "rdrepl.pid" #define RD_RDREPLD_PID "rdrepl.pid"
@ -53,8 +51,6 @@ class MainObject : public QObject
void FreeReplicators(); void FreeReplicators();
QTimer *repl_loop_timer; QTimer *repl_loop_timer;
QString repl_temp_dir; QString repl_temp_dir;
RDStation *repl_station;
QSqlDatabase *repl_db;
std::vector<ReplFactory *> repl_replicators; std::vector<ReplFactory *> repl_replicators;
bool debug; bool debug;
}; };

View File

@ -2,7 +2,7 @@
// //
// A container class for a Rivendell replication configuration // A container class for a Rivendell replication configuration
// //
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -20,7 +20,7 @@
#include <rd.h> #include <rd.h>
#include <replconfig.h> #include "replconfig.h"
ReplConfig::ReplConfig() ReplConfig::ReplConfig()
{ {

View File

@ -2,7 +2,7 @@
// //
// Virtual base class for replicator methods // Virtual base class for replicator methods
// //
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -18,7 +18,7 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <replfactory.h> #include "replfactory.h"
ReplFactory::ReplFactory(ReplConfig *config) ReplFactory::ReplFactory(ReplConfig *config)
{ {

View File

@ -2,7 +2,7 @@
// //
// Virtual base class for replicator methods // Virtual base class for replicator methods
// //
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2010,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -21,8 +21,7 @@
#ifndef REPLFACTORY_H #ifndef REPLFACTORY_H
#define REPLFACTORY_H #define REPLFACTORY_H
#include <globals.h> #include "replconfig.h"
#include <replconfig.h>
class ReplFactory class ReplFactory
{ {