diff --git a/ChangeLog b/ChangeLog index 655b668c..6eedb007 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16615,3 +16615,5 @@ * Converted rdlogmanager(1) to use RDApplication. 2018-01-31 Fred Gleason * Converted rdpanel(1) to use RDApplication. +2018-01-31 Fred Gleason + * Converted rdrepld(8) to use RDApplication. diff --git a/rdrepld/Makefile.am b/rdrepld/Makefile.am index 8af7f088..377b81c5 100644 --- a/rdrepld/Makefile.am +++ b/rdrepld/Makefile.am @@ -29,8 +29,7 @@ moc_%.cpp: %.h $(MOC) $< -o $@ bin_PROGRAMS = rdrepld -dist_rdrepld_SOURCES = globals.h\ - rdrepld.cpp rdrepld.h \ +dist_rdrepld_SOURCES = rdrepld.cpp rdrepld.h \ replconfig.cpp replconfig.h\ replfactory.cpp replfactory.h\ citadelxds.cpp citadelxds.h diff --git a/rdrepld/citadelxds.cpp b/rdrepld/citadelxds.cpp index 8078123c..68e2d2b7 100644 --- a/rdrepld/citadelxds.cpp +++ b/rdrepld/citadelxds.cpp @@ -2,7 +2,7 @@ // // Replicator implementation for the Citadel XDS Portal // -// (C) Copyright 2010,2016-2017 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,7 @@ #include #include -#include +#include "citadelxds.h" #define RD_MAX_CART_NUMBER 999999 @@ -86,10 +87,10 @@ void CitadelXds::CheckIsciXreference() QString sql; RDSqlQuery *q; - QFileInfo *fi=new QFileInfo(rdsystem->isciXreferencePath()); + QFileInfo *fi=new QFileInfo(rda->system()->isciXreferencePath()); if(fi->exists()) { if(fi->lastModified()>xds_isci_datetime) { - if(LoadIsciXreference(rdsystem->isciXreferencePath())) { + if(LoadIsciXreference(rda->system()->isciXreferencePath())) { sql="update VERSION set LAST_ISCI_XREFERENCE=now()"; q=new RDSqlQuery(sql); delete q; @@ -99,9 +100,9 @@ void CitadelXds::CheckIsciXreference() } } else { - rdconfig->log("rdrepld",RDConfig::LogErr, + rda->config()->log("rdrepld",RDConfig::LogErr, QString().sprintf("unable to load ISCI cross reference file \"%s\"", - (const char *)rdsystem->isciXreferencePath())); + (const char *)rda->system()->isciXreferencePath())); } delete fi; } @@ -121,9 +122,9 @@ bool CitadelXds::LoadIsciXreference(const QString &filename) unsigned linenum=3; 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]", - (const char *)rdsystem->isciXreferencePath(), + (const char *)rda->system()->isciXreferencePath(), strerror(errno))); return false; } @@ -172,31 +173,31 @@ bool CitadelXds::LoadIsciXreference(const QString &filename) delete q; } else { - rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). + rda->config()->log("rdrepld",RDConfig::LogWarning,QString(). sprintf("invalid date in line %d of \"%s\"", linenum,(const char *)filename)); } } else { - rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). + rda->config()->log("rdrepld",RDConfig::LogWarning,QString(). sprintf("invalid FILENAME field \"%s\" in line %d of \"%s\"", (const char *)fields[8],linenum,(const char *)filename)); } } else { - rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). + rda->config()->log("rdrepld",RDConfig::LogWarning,QString(). sprintf("invalid date in line %d of \"%s\"", linenum,(const char *)filename)); } } else { - rdconfig->log("rdrepld",RDConfig::LogDebug,QString(). + rda->config()->log("rdrepld",RDConfig::LogDebug,QString(). sprintf("missing/invalid cart number in line %d of \"%s\"", linenum,(const char *)filename)); } } else { - rdconfig->log("rdrepld",RDConfig::LogWarning,QString(). + rda->config()->log("rdrepld",RDConfig::LogWarning,QString(). sprintf("line %d malformed in \"%s\"", linenum,(const char *)filename)); } @@ -206,9 +207,9 @@ bool CitadelXds::LoadIsciXreference(const QString &filename) // // Clean Up // - rdconfig->log("rdrepld",RDConfig::LogInfo, + rda->config()->log("rdrepld",RDConfig::LogInfo, QString().sprintf("loaded ISCI cross reference file \"%s\"", - (const char *)rdsystem->isciXreferencePath())); + (const char *)rda->system()->isciXreferencePath())); fclose(f); return true; } @@ -347,7 +348,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename) } RDSettings *settings=new RDSettings(); QString tempfile=RDTempDirectory::basePath()+"/"+filename; - RDAudioConvert *conv=new RDAudioConvert(rdconfig->stationName()); + RDAudioConvert *conv=new RDAudioConvert(rda->config()->stationName()); conv->setSourceFile(RDCut::pathName(cutname)); conv->setDestinationFile(tempfile); conv->setRange(cut->startPoint(),cut->endPoint()); @@ -366,7 +367,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename) break; default: - rdconfig->log("rdrepld",RDConfig::LogErr, + rda->config()->log("rdrepld",RDConfig::LogErr, QString().sprintf("CitadelXds: audio conversion failed: %s, cutname: %s", (const char *)RDAudioConvert::errorText(conv_err), (const char *)cutname)); @@ -380,17 +381,17 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename) // // Upload File // - RDUpload *upload=new RDUpload(rdconfig); + RDUpload *upload=new RDUpload(rda->config()); upload->setSourceFile(tempfile); upload->setDestinationUrl(config()->url()+"/"+filename); switch(upload_err=upload->runUpload(config()->urlUsername(), config()->urlPassword(), - rdconfig->logXloadDebugData())) { + rda->config()->logXloadDebugData())) { case RDUpload::ErrorOk: break; default: - rdconfig->log("rdrepld",RDConfig::LogErr, + rda->config()->log("rdrepld",RDConfig::LogErr, QString().sprintf("CitadelXds: audio upload failed: %s", (const char *)RDUpload::errorText(upload_err))); unlink(tempfile); @@ -399,7 +400,7 @@ bool CitadelXds::PostCut(const QString &cutname,const QString &filename) } unlink(tempfile); delete upload; - rdconfig->log("rdrepld",RDConfig::LogInfo, + rda->config()->log("rdrepld",RDConfig::LogInfo, QString().sprintf("CitadelXds: uploaded cut %s to %s/%s", (const char *)cutname, (const char *)config()->url(), @@ -433,23 +434,23 @@ void CitadelXds::PurgeCuts() path+="/"; } QUrl url(path+q->value(1).toString()); - conv=new RDDelete(rdconfig); + conv=new RDDelete(rda->config()); conv->setTargetUrl(url); if((conv_err=conv->runDelete(config()->urlUsername(), config()->urlPassword(), - rdconfig->logXloadDebugData()))== + rda->config()->logXloadDebugData()))== RDDelete::ErrorOk) { sql=QString().sprintf("delete from REPL_CART_STATE where ID=%d", q->value(0).toInt()); q2=new RDSqlQuery(sql); delete q2; - rdconfig->log("rdrepld",RDConfig::LogInfo, + rda->config()->log("rdrepld",RDConfig::LogInfo, QString().sprintf("purged \"%s\" for replicator \"%s\"", (const char *)url.toString(), (const char *)config()->name())); } else { - rdconfig->log("rdrepld",RDConfig::LogErr, + rda->config()->log("rdrepld",RDConfig::LogErr, QString().sprintf("unable to delete \"%s\" for replicator \"%s\" [%s]", (const char *)url.toString(), (const char *)config()->name(), diff --git a/rdrepld/citadelxds.h b/rdrepld/citadelxds.h index ae51ab58..1dfe9a3f 100644 --- a/rdrepld/citadelxds.h +++ b/rdrepld/citadelxds.h @@ -21,7 +21,6 @@ #ifndef CITADELXDS_H #define CITADELXDS_H -#include "globals.h" #include "replfactory.h" class CitadelXds : public ReplFactory diff --git a/rdrepld/globals.h b/rdrepld/globals.h deleted file mode 100644 index 1fdfe31d..00000000 --- a/rdrepld/globals.h +++ /dev/null @@ -1,31 +0,0 @@ -// globals.h -// -// The Rivendell Replicator Daemon Global Definitions -// -// (C) Copyright 2010,2016 Fred Gleason -// -// 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 -#include - -extern RDConfig *rdconfig; -extern RDSystem *rdsystem; - - -#endif // GLOBALS_H diff --git a/rdrepld/rdrepld.cpp b/rdrepld/rdrepld.cpp index e16062bd..86c072cd 100644 --- a/rdrepld/rdrepld.cpp +++ b/rdrepld/rdrepld.cpp @@ -2,7 +2,7 @@ // // The Rivendell Replicator Daemon // -// (C) Copyright 2010,2016-2017 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -32,12 +33,8 @@ #include #include -#include -#include -#include - -RDConfig *rdconfig; -RDSystem *rdsystem; +#include "citadelxds.h" +#include "rdrepld.h" void SigHandler(int signum) { @@ -64,15 +61,7 @@ void SigHandler(int signum) MainObject::MainObject(QObject *parent) :QObject(parent) { - bool skip_db_check=false; - unsigned schema=0; - - // - // Load the config - // - rdconfig=new RDConfig(); - rdconfig->load(); - rdconfig->setModuleName("rdrepld"); + QString err_msg; // // Read Command Options @@ -81,7 +70,6 @@ MainObject::MainObject(QObject *parent) new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdrepld",RDREPLD_USAGE); for(unsigned i=0;ikeys();i++) { if(cmd->key(i)=="--skip-db-check") { - skip_db_check=true; } } @@ -93,6 +81,12 @@ MainObject::MainObject(QObject *parent) 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 // @@ -103,39 +97,15 @@ MainObject::MainObject(QObject *parent) // repl_temp_dir=RDTempDirectory::basePath(); - // - // Open Database - // - 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()); + connect(RDDbStatus(), + SIGNAL(logText(RDConfig::LogPriority,const QString &)), + this,SLOT(log(RDConfig::LogPriority,const QString &))); // // Detach // if(qApp->argc()==1) { - RDDetach(rdconfig->logCoreDumpDirectory()); + RDDetach(rda->config()->logCoreDumpDirectory()); } else { debug=true; @@ -156,7 +126,7 @@ MainObject::MainObject(QObject *parent) connect(repl_loop_timer,SIGNAL(timeout()),this,SLOT(mainLoop())); 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) { - 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,\ ENABLE_METADATA,NORMALIZATION_LEVEL from \ REPLICATORS where STATION_NAME=\"%s\"", - (const char *)RDEscapeString(rdconfig->stationName())); + (const char *)RDEscapeString(rda->config()->stationName())); q=new RDSqlQuery(sql); while(q->next()) { config=new ReplConfig(); diff --git a/rdrepld/rdrepld.h b/rdrepld/rdrepld.h index da993298..be4881bc 100644 --- a/rdrepld/rdrepld.h +++ b/rdrepld/rdrepld.h @@ -2,7 +2,7 @@ // // The Rivendell Replicator Daemon // -// (C) Copyright 2010,2016 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -26,12 +26,10 @@ #include #include -#include -#include -#include #include +#include -#include +#include "replfactory.h" #define RDREPLD_USAGE "[-d][--event-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" @@ -53,8 +51,6 @@ class MainObject : public QObject void FreeReplicators(); QTimer *repl_loop_timer; QString repl_temp_dir; - RDStation *repl_station; - QSqlDatabase *repl_db; std::vector repl_replicators; bool debug; }; diff --git a/rdrepld/replconfig.cpp b/rdrepld/replconfig.cpp index e79603e1..432a7c95 100644 --- a/rdrepld/replconfig.cpp +++ b/rdrepld/replconfig.cpp @@ -2,7 +2,7 @@ // // A container class for a Rivendell replication configuration // -// (C) Copyright 2010,2016 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -20,7 +20,7 @@ #include -#include +#include "replconfig.h" ReplConfig::ReplConfig() { diff --git a/rdrepld/replfactory.cpp b/rdrepld/replfactory.cpp index 3ea27b00..a9542a15 100644 --- a/rdrepld/replfactory.cpp +++ b/rdrepld/replfactory.cpp @@ -2,7 +2,7 @@ // // Virtual base class for replicator methods // -// (C) Copyright 2010,2016 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -18,7 +18,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include +#include "replfactory.h" ReplFactory::ReplFactory(ReplConfig *config) { diff --git a/rdrepld/replfactory.h b/rdrepld/replfactory.h index 98346d7d..3d130859 100644 --- a/rdrepld/replfactory.h +++ b/rdrepld/replfactory.h @@ -2,7 +2,7 @@ // // Virtual base class for replicator methods // -// (C) Copyright 2010,2016 Fred Gleason +// (C) Copyright 2010,2016-2018 Fred Gleason // // 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 @@ -21,8 +21,7 @@ #ifndef REPLFACTORY_H #define REPLFACTORY_H -#include -#include +#include "replconfig.h" class ReplFactory {