2018-05-18 Fred Gleason <fredg@paravelsystems.com>

* Renamed rdvairplay(1) to rdvairplayd(8).
This commit is contained in:
Fred Gleason
2018-05-18 11:46:33 +00:00
parent a6f55c9853
commit 4d4a726329
11 changed files with 34 additions and 45 deletions

49
rdvairplayd/Makefile.am Normal file
View File

@@ -0,0 +1,49 @@
## Makefile.am
##
## Makefile for rdvairplayd(8)
##
## (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.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@ -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
sbin_PROGRAMS = rdvairplayd
dist_rdvairplayd_SOURCES = local_macros.cpp\
rdvairplayd.cpp rdvairplayd.h
nodist_rdvairplayd_SOURCES = moc_rdvairplayd.cpp
rdvairplayd_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
CLEANFILES = *~\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
Makefile.in\
moc_*

View File

@@ -0,0 +1,563 @@
// local_macros.cpp
//
// Local RML Macros for rdvairplayd(8)
//
// (C) Copyright 2002-2004,2016-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 <stdio.h>
#include <rdapplication.h>
#include <rddb.h>
#include <rdescape_string.h>
#include <rdmacro.h>
#include "rdvairplayd.h"
void MainObject::rmlReceivedData(RDMacro *rml)
{
QString logname;
int fade;
RDLogLine *logline=NULL;
int index=-1;
bool all_logs=false;
int start;
int end;
int next_line;
if(rml->role()!=RDMacro::Cmd) {
return;
}
switch(rml->command()) {
case RDMacro::LL: // Load Log
if((rml->argQuantity()<1)||(rml->argQuantity()>3)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->argQuantity()==1) { // Clear Log
air_logs[index]->clear();
rda->log(RDConfig::LogInfo,QString().sprintf("unloaded log machine %d",
rml->arg(0).toInt()));
}
else { // Load Log
logname=rml->arg(1).toString();
if(!RDLog::exists(logname)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
air_logs[index]->setLogName(RDLog::tableName(logname));
air_logs[index]->load();
rda->log(RDConfig::LogInfo,"loaded log \""+logname+"\" into log machine"+
QString().sprintf(" %d",rml->arg(0).toInt()));
}
if(rml->argQuantity()==3) { // Start Log
if(rml->arg(2).toInt()<air_logs[index]->size()) {
if(rml->arg(2).toInt()>=0) { // Unconditional start
air_logs[index]->play(rml->arg(2).toInt(),RDLogLine::StartMacro);
rda->log(RDConfig::LogInfo,QString().
sprintf("started log machine %d at line %d",
rml->arg(0).toInt(),rml->arg(2).toInt()));
}
if(rml->arg(2).toInt()==-2) { // Start if trans type allows
// Find first non-running event
bool found=false;
for(int i=0;i<air_logs[index]->size();i++) {
if((logline=air_logs[index]->logLine(i))!=NULL) {
if(logline->status()==RDLogLine::Scheduled) {
found=true;
i=air_logs[index]->size();
}
}
}
if(found) {
switch(logline->transType()) {
case RDLogLine::Play:
case RDLogLine::Segue:
air_logs[index]->play(0,RDLogLine::StartMacro);
rda->log(RDConfig::LogInfo,QString().
sprintf("started log machine %d at line 0",
rml->arg(0).toInt()));
break;
case RDLogLine::Stop:
case RDLogLine::NoTrans:
break;
}
}
}
}
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::AL: // Append Log
if(rml->argQuantity()!=2) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
logname=rml->arg(1).toString();
if(!RDLog::exists(logname)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
air_logs[index]->append(logname);
rda->log(RDConfig::LogInfo,QString("appended log \"")+logname+
QString().sprintf("\" into log machine %d",rml->arg(0).toInt()));
break;
case RDMacro::MN: // Make Next
if(rml->argQuantity()!=2) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((rml->arg(1).toInt()<0)||
(rml->arg(1).toInt()>=air_logs[index]->size())) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
air_logs[index]->makeNext(rml->arg(1).toInt());
rda->log(RDConfig::LogInfo,
QString().sprintf("made line %d next in log machine %d",
rml->arg(1).toInt(),rml->arg(0).toInt()));
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::PL: // Start
if(rml->argQuantity()!=2) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((rml->arg(1).toInt()<0)||
(rml->arg(1).toInt()>=air_logs[index]->size())) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(!air_logs[index]->running()) {
if(!air_logs[index]->play(rml->arg(1).toInt(),RDLogLine::StartMacro)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
}
rda->log(RDConfig::LogInfo,QString().
sprintf("started log machine %d at line %d",
rml->arg(0).toInt(),rml->arg(1).toInt()));
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::PM: // Set Mode
if((rml->argQuantity()!=1)&&(rml->argQuantity()!=2)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->argQuantity()==2) {
if((index=LogMachineIndex(rml->arg(1).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
}
start=0;
end=RD_RDVAIRPLAY_LOG_QUAN;
if(index>=0) {
start=index;
end=index+1;
}
switch((RDAirPlayConf::OpMode)rml->arg(0).toInt()) {
case RDAirPlayConf::LiveAssist:
for(int i=start;i<end;i++) {
SetLiveAssistMode(i);
}
break;
case RDAirPlayConf::Manual:
for(int i=start;i<end;i++) {
SetManualMode(i);
}
break;
case RDAirPlayConf::Auto:
for(int i=start;i<end;i++) {
SetAutoMode(i);
}
break;
default:
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
return;
}
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::PN: // Start Next
if((rml->argQuantity()<1)||(rml->argQuantity()>3)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->argQuantity()>=2) {
if((rml->arg(1).toInt()<1)||(rml->arg(1).toInt()>2)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->argQuantity()==3) {
if((rml->arg(2).toInt()<0)||(rml->arg(2).toInt()>1)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
}
}
next_line=air_logs[index]->nextLine();
if(air_logs[index]->nextLine()>=0) {
if(rml->argQuantity()==1) {
air_logs[index]->
play(air_logs[index]->nextLine(),RDLogLine::StartMacro);
}
else {
if(rml->argQuantity()==2) {
air_logs[index]->play(air_logs[index]->nextLine(),
RDLogLine::StartMacro,rml->arg(1).toInt()-1);
}
else {
air_logs[index]->
play(air_logs[index]->nextLine(),RDLogLine::StartMacro,
rml->arg(1).toInt()-1,rml->arg(2).toInt());
}
}
rda->log(RDConfig::LogInfo,QString().
sprintf("started log machine %d at line %d",
rml->arg(0).toInt(),next_line));
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::PS: // Stop
if((rml->argQuantity()<1)||(rml->argQuantity()>3)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
index=LogMachineIndex(rml->arg(0).toInt(),&all_logs);
if((index<0)&(!all_logs)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
fade=0;
if(rml->argQuantity()>1) {
fade=rml->arg(1).toInt();
}
if(all_logs) {
for(int i=0;i<RD_RDVAIRPLAY_LOG_QUAN;i++) {
air_logs[i]->stop(true,0,fade);
}
rda->log(RDConfig::LogInfo,"stopped all logs");
}
else {
if(rml->argQuantity()==3) {
air_logs[index]->stop(false,rml->arg(2).toInt(),fade);
}
else {
air_logs[index]->stop(true,0,fade);
}
rda->log(RDConfig::LogInfo,QString().sprintf("stopped log machine %d",
rml->arg(0).toInt()));
break;
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::MD: // Duck Machine
if(rml->argQuantity()<3 || rml->argQuantity()>4) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
index=LogMachineIndex(rml->arg(0).toInt(),&all_logs);
if((index<0)&&(!all_logs)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(all_logs) {
for(int i=0;i<RD_RDVAIRPLAY_LOG_QUAN;i++) {
air_logs[i]->duckVolume(rml->arg(1).toInt()*100,rml->arg(2).toInt());
}
rda->log(RDConfig::LogInfo,QString().
sprintf("set volumne of all log machines to %d dBFS",
rml->arg(1).toInt()));
}
else {
if(rml->argQuantity()==3) {
air_logs[index]->
duckVolume(rml->arg(1).toInt()*100,rml->arg(2).toInt());
}
else {
air_logs[index]->duckVolume(rml->arg(1).toInt()*100,
rml->arg(2).toInt(),rml->arg(3).toInt());
}
rda->log(RDConfig::LogInfo,QString().
sprintf("set volumne of log machine %d to %d dBFS",
rml->arg(0).toInt(),
rml->arg(1).toInt()));
break;
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::PX: // Add Next
if(rml->argQuantity()!=2) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
index=LogMachineIndex(rml->arg(0).toInt());
if((index<0)||(rml->arg(1).toUInt()>999999)) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
next_line=air_logs[index]->nextLine();
if(air_logs[index]->nextLine()>=0) {
air_logs[index]->insert(air_logs[index]->nextLine(),
rml->arg(1).toUInt(),RDLogLine::Play);
rda->log(RDConfig::LogInfo,QString().
sprintf("inserted cart %06u at line %d on log machine %d",
rml->arg(1).toUInt(),next_line,rml->arg(0).toInt()));
}
else {
air_logs[index]->insert(air_logs[index]->size(),
rml->arg(1).toUInt(),RDLogLine::Play);
air_logs[index]->makeNext(air_logs[index]->size()-1);
rda->log(RDConfig::LogInfo,QString().
sprintf("inserted cart %06u at line %d on log machine %d",
rml->arg(1).toUInt(),air_logs[index]->size()-1,
rml->arg(0).toInt()));
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::RL: // Refresh Log
if(rml->argQuantity()!=1) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(0).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(!air_logs[index]->refresh()) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
else {
rda->log(RDConfig::LogInfo,QString().sprintf("refreshed log machine %d",
rml->arg(0).toInt()));
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
case RDMacro::SN: // Set default Now & Next Cart
if(rml->argQuantity()!=3) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((rml->arg(0).toString().lower()!="now")&&
(rml->arg(0).toString().lower()!="next")) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if((index=LogMachineIndex(rml->arg(1).toInt()))<0) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->arg(2).toUInt()>999999) {
if(rml->echoRequested()) {
rml->acknowledge(false);
rda->ripc()->sendRml(rml);
}
return;
}
if(rml->arg(0).toString().lower()=="now") {
air_logs[index]->setNowCart(rml->arg(2).toUInt());
rda->log(RDConfig::LogInfo,QString().
sprintf("set default \"now\" cart to %06u on log machine %d",
rml->arg(2).toUInt(),rml->arg(1).toInt()));
}
else {
air_logs[index]->setNextCart(rml->arg(2).toUInt());
rda->log(RDConfig::LogInfo,QString().
sprintf("set default \"next\" cart to %06u on log machine %d",
rml->arg(2).toUInt(),rml->arg(1).toInt()));
}
if(rml->echoRequested()) {
rml->acknowledge(true);
rda->ripc()->sendRml(rml);
}
break;
default:
break;
}
}
int MainObject::LogMachineIndex(int log_mach,bool *all) const
{
if((log_mach<=RD_RDVAIRPLAY_LOG_BASE)||
(log_mach>RD_RDVAIRPLAY_LOG_BASE+RD_RDVAIRPLAY_LOG_QUAN)) {
return -1;
}
if(all!=NULL) {
*all=log_mach-RD_RDVAIRPLAY_LOG_BASE==0;
}
return log_mach-RD_RDVAIRPLAY_LOG_BASE-1;
}

385
rdvairplayd/rdvairplayd.cpp Normal file
View File

@@ -0,0 +1,385 @@
// rdvairplayd.cpp
//
// Headless log player
//
// (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 <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <qapplication.h>
#include <rdapplication.h>
#include <rdcheck_daemons.h>
#include <rdconf.h>
#include <rddatedecode.h>
#include <rddbheartbeat.h>
#include <rdescape_string.h>
#include <rdmixer.h>
#include <rdweb.h>
#include "rdvairplayd.h"
bool global_exiting=false;
void SigHandler(int signo)
{
switch(signo) {
case SIGINT:
case SIGTERM:
global_exiting=true;
break;
}
}
MainObject::MainObject(QObject *parent)
:QObject(parent)
{
QString err_msg;
//
// Ensure that system daemons are running
//
RDInitializeDaemons();
//
// Startup DateTime
//
air_startup_datetime=QDateTime::currentDateTime();
//
// Open the Database
//
rda=new RDApplication("rdvairplayd","rdvairplayd",RDVAIRPLAYD_USAGE,this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"rdvairplayd: %s\n",(const char *)err_msg);
exit(1);
}
air_previous_exit_code=rda->airplayConf()->virtualExitCode();
rda->airplayConf()->setVirtualExitCode(RDAirPlayConf::ExitDirty);
//
// Read Command Options
//
for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
if(!rda->cmdSwitch()->processed(i)) {
fprintf(stderr,"rdvairplayd: unknown command option \"%s\"\n",
(const char *)rda->cmdSwitch()->key(i));
exit(2);
}
}
//
// CAE Connection
//
rda->cae()->connectHost();
//
// Set Audio Assignments
//
// air_segue_length=rda->airplayConf()->segueLength()+1;
RDSetMixerPorts(rda->config()->stationName(),rda->cae());
//
// RIPC Connection
//
connect(rda->ripc(),SIGNAL(connected(bool)),
this,SLOT(ripcConnectedData(bool)));
connect(rda,SIGNAL(userChanged()),this,SLOT(userData()));
connect(rda->ripc(),SIGNAL(rmlReceived(RDMacro *)),
this,SLOT(rmlReceivedData(RDMacro *)));
// connect(rda->ripc(),SIGNAL(gpiStateChanged(int,int,bool)),
// this,SLOT(gpiStateChangedData(int,int,bool)));
rda->ripc()->
connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
//
// Macro Player
//
air_event_player=new RDEventPlayer(rda->ripc(),this);
//
// UDP Transmission Socket
//
air_nownext_socket=new QSocketDevice(QSocketDevice::Datagram);
//
// Log Machines
//
QSignalMapper *reload_mapper=new QSignalMapper(this);
connect(reload_mapper,SIGNAL(mapped(int)),this,SLOT(logReloadedData(int)));
QSignalMapper *rename_mapper=new QSignalMapper(this);
QString default_svcname=rda->airplayConf()->defaultSvc();
for(int i=0;i<RD_RDVAIRPLAY_LOG_QUAN;i++) {
air_logs[i]=new RDLogPlay(i+RD_RDVAIRPLAY_LOG_BASE,air_event_player,
air_nownext_socket,"",&air_plugin_hosts);
air_logs[i]->setDefaultServiceName(default_svcname);
//
// FIXME: Add the ability to specify default carts for vLogs!
//
air_logs[i]->setNowCart(rda->airplayConf()->logNowCart(i));
air_logs[i]->setNextCart(rda->airplayConf()->logNextCart(i));
reload_mapper->setMapping(air_logs[i],i);
connect(air_logs[i],SIGNAL(reloaded()),reload_mapper,SLOT(map()));
rename_mapper->setMapping(air_logs[i],i);
connect(air_logs[i],SIGNAL(renamed()),rename_mapper,SLOT(map()));
// connect(air_logs[i],SIGNAL(refreshStatusChanged(bool)),
// this,SLOT(refreshStatusChangedData(bool)));
// connect(air_logs[i],SIGNAL(channelStarted(int,int,int,int)),
// this,SLOT(logChannelStartedData(int,int,int,int)));
// connect(air_logs[i],SIGNAL(channelStopped(int,int,int,int)),
// this,SLOT(logChannelStoppedData(int,int,int,int)));
int cards[2]={0,0};
cards[0]=rda->airplayConf()->virtualCard(i+RD_RDVAIRPLAY_LOG_BASE);
cards[1]=rda->airplayConf()->virtualCard(i+RD_RDVAIRPLAY_LOG_BASE);
int ports[2]={0,0};
ports[0]=rda->airplayConf()->virtualPort(i+RD_RDVAIRPLAY_LOG_BASE);
ports[1]=rda->airplayConf()->virtualPort(i+RD_RDVAIRPLAY_LOG_BASE);
QString start_rml[2]={"",""};
start_rml[0]=rda->airplayConf()->virtualStartRml(i+RD_RDVAIRPLAY_LOG_BASE);
start_rml[1]=rda->airplayConf()->virtualStartRml(i+RD_RDVAIRPLAY_LOG_BASE);
QString stop_rml[2]={"",""};
stop_rml[0]=rda->airplayConf()->virtualStopRml(i+RD_RDVAIRPLAY_LOG_BASE);
stop_rml[1]=rda->airplayConf()->virtualStopRml(i+RD_RDVAIRPLAY_LOG_BASE);
air_logs[i]->setChannels(cards,ports,start_rml,stop_rml);
air_logs[i]->
setOpMode(rda->airplayConf()->opMode(i+RD_RDVAIRPLAY_LOG_BASE));
}
// connect(air_logs[0],SIGNAL(transportChanged()),
// this,SLOT(transportChangedData()));
//
// Load Plugins
//
QString sql;
RDSqlQuery *q;
sql=QString("select ")+
"PLUGIN_PATH,"+
"PLUGIN_ARG "+
"from NOWNEXT_PLUGINS where "+
"(STATION_NAME=\""+RDEscapeString(rda->config()->stationName())+"\")&&"+
"(LOG_MACHINE=0)";
q=new RDSqlQuery(sql);
while(q->next()) {
air_plugin_hosts.
push_back(new RDRLMHost(q->value(0).toString(),q->value(1).toString(),
air_nownext_socket,this));
rda->log(RDConfig::LogInfo,QString().
sprintf("Loading RLM \"%s\"",
(const char *)q->value(0).toString()));
if(!air_plugin_hosts.back()->load()) {
rda->log(RDConfig::LogWarning,QString().
sprintf("Failed to load RLM \"%s\"",
(const char *)q->value(0).toString()));
}
}
delete q;
//
// Exit Timer
//
air_exit_timer=new QTimer(this);
connect(air_exit_timer, SIGNAL(timeout()),this,SLOT(exitData()));
air_exit_timer->start(100);
::signal(SIGINT,SigHandler);
::signal(SIGTERM,SigHandler);
}
void MainObject::ripcConnectedData(bool state)
{
QHostAddress addr;
QString sql;
RDSqlQuery *q;
RDMacro rml;
rml.setRole(RDMacro::Cmd);
addr.setAddress("127.0.0.1");
rml.setAddress(addr);
rml.setEchoRequested(false);
//
// Get Onair Flag State
//
rda->ripc()->sendOnairFlag();
//
// Load Initial Logs
//
for(unsigned i=0;i<RD_RDVAIRPLAY_LOG_QUAN;i++) {
int mach=i+RD_RDVAIRPLAY_LOG_BASE;
switch(rda->airplayConf()->startMode(mach)) {
case RDAirPlayConf::StartEmpty:
break;
case RDAirPlayConf::StartPrevious:
air_start_lognames[i]=RDDateTimeDecode(rda->airplayConf()->currentLog(mach),
air_startup_datetime,rda->station(),rda->config());
if(!air_start_lognames[i].isEmpty()) {
if(air_previous_exit_code==RDAirPlayConf::ExitDirty) {
if((air_start_lines[i]=rda->airplayConf()->logCurrentLine(mach))>=0) {
air_start_starts[i]=rda->airplayConf()->autoRestart(mach)&&
rda->airplayConf()->logRunning(mach);
}
}
else {
air_start_lines[i]=0;
air_start_starts[i]=false;
}
}
break;
case RDAirPlayConf::StartSpecified:
air_start_lognames[i]=RDDateTimeDecode(rda->airplayConf()->logName(mach),
air_startup_datetime,rda->station(),
rda->config());
if(!air_start_lognames[i].isEmpty()) {
if(air_previous_exit_code==RDAirPlayConf::ExitDirty) {
if(air_start_lognames[i]==rda->airplayConf()->currentLog(mach)) {
if((air_start_lines[i]=rda->airplayConf()->logCurrentLine(mach))>=0) {
air_start_starts[i]=rda->airplayConf()->autoRestart(mach)&&
rda->airplayConf()->logRunning(mach);
}
else {
air_start_lines[i]=0;
air_start_starts[i]=false;
}
}
}
}
break;
}
if(!air_start_lognames[i].isEmpty()) {
sql=QString("select NAME from LOGS where ")+
"NAME=\""+RDEscapeString(air_start_lognames[i])+"\"";
q=new RDSqlQuery(sql);
if(q->first()) {
rml.setCommand(RDMacro::LL); // Load Log
rml.setArgQuantity(2);
rml.setArg(0,mach+1);
rml.setArg(1,air_start_lognames[i]);
rda->ripc()->sendRml(&rml);
}
else {
rda->log(RDConfig::LogWarning,QString().sprintf("vlog %d: ",mach+1)+
"log \""+air_start_lognames[i]+"\" doesn't exist");
}
delete q;
}
}
}
void MainObject::userData()
{
// printf("User connected!\n");
}
void MainObject::logReloadedData(int log)
{
QHostAddress addr;
int mach=log+RD_RDVAIRPLAY_LOG_BASE;
//
// Load Initial Log
//
if(air_start_lognames[log].isEmpty()) {
return;
}
RDMacro rml;
rml.setRole(RDMacro::Cmd);
addr.setAddress("127.0.0.1");
rml.setAddress(addr);
rml.setEchoRequested(false);
if(air_start_lines[log]<air_logs[log]->size()) {
rml.setCommand(RDMacro::MN); // Make Next
rml.setArgQuantity(2);
rml.setArg(0,mach+1);
rml.setArg(1,air_start_lines[log]);
rda->ripc()->sendRml(&rml);
if(air_start_starts[log]) {
rml.setCommand(RDMacro::PN); // Start Next
rml.setArgQuantity(1);
rml.setArg(0,mach+1);
rda->ripc()->sendRml(&rml);
}
}
else {
rda->log(RDConfig::LogWarning,QString().sprintf("vlog %d: ",mach+1)+
QString().sprintf("line %d doesn't exist ",air_start_lines[log])+
"in log \""+air_start_lognames[log]+"\"");
}
air_start_lognames[log]="";
}
void MainObject::exitData()
{
if(global_exiting) {
for(unsigned i=0;i<air_plugin_hosts.size();i++) {
air_plugin_hosts[i]->unload();
}
for(int i=0;i<RD_RDVAIRPLAY_LOG_QUAN;i++) {
delete air_logs[i];
}
rda->airplayConf()->setVirtualExitCode(RDAirPlayConf::ExitClean);
rda->log(RDConfig::LogInfo,"exiting");
exit(0);
}
}
void MainObject::SetAutoMode(int index)
{
air_logs[index]->setOpMode(RDAirPlayConf::Auto);
rda->log(RDConfig::LogInfo,
QString().sprintf("log machine %d mode set to AUTOMATIC",
index+RD_RDVAIRPLAY_LOG_BASE+1));
}
void MainObject::SetLiveAssistMode(int index)
{
air_logs[index]->setOpMode(RDAirPlayConf::LiveAssist);
rda->log(RDConfig::LogInfo,
QString().sprintf("log machine %d mode set to LIVE ASSIST",
index+RD_RDVAIRPLAY_LOG_BASE+1));
}
void MainObject::SetManualMode(int index)
{
air_logs[index]->setOpMode(RDAirPlayConf::Manual);
rda->log(RDConfig::LogInfo,
QString().sprintf("log machine %d mode set to MANUAL",
index+RD_RDVAIRPLAY_LOG_BASE+1));
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new MainObject();
return a.exec();
}

66
rdvairplayd/rdvairplayd.h Normal file
View File

@@ -0,0 +1,66 @@
// rdvairplayd.h
//
// Headless log player
//
// (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 RDVAIRPLAYD_H
#define RDVAIRPLAYD_H
#include <qobject.h>
#include <qsocketdevice.h>
#include <rdevent_player.h>
#include <rd.h>
#include <rdlogplay.h>
#include <rdmacro.h>
#include <rdrlmhost.h>
#define RDVAIRPLAYD_USAGE "[options]\n"
class MainObject : public QObject
{
Q_OBJECT;
public:
MainObject(QObject *parent=0);
private slots:
void ripcConnectedData(bool state);
void userData();
void rmlReceivedData(RDMacro*);
void logReloadedData(int log);
void exitData();
private:
void SetAutoMode(int index);
void SetLiveAssistMode(int index);
void SetManualMode(int index);
int LogMachineIndex(int log_mach,bool *all=NULL) const;
RDLogPlay *air_logs[RD_RDVAIRPLAY_LOG_QUAN];
QString air_start_lognames[RD_RDVAIRPLAY_LOG_QUAN];
int air_start_lines[RD_RDVAIRPLAY_LOG_QUAN];
bool air_start_starts[RD_RDVAIRPLAY_LOG_QUAN];
std::vector<RDRLMHost *> air_plugin_hosts;
RDEventPlayer *air_event_player;
QSocketDevice *air_nownext_socket;
QDateTime air_startup_datetime;
RDAirPlayConf::ExitCode air_previous_exit_code;
QTimer *air_exit_timer;
};
#endif // RDVAIRPLAYD_H