From 63947813daadce893f3a0c4bcadd262ed5d69b24 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 6 Jul 2017 11:01:53 -0400 Subject: [PATCH] 2017-07-06 Fred Gleason * Refactored catch connector code in RDCatch(1) to support an arbitrary number of hosts. * Removed RD_MAX_STATIONS from 'lib/rd.h'. --- ChangeLog | 4 ++ lib/rd.h | 5 -- rdcatch/rdcatch.cpp | 108 ++++++++++++++++++++++++-------------------- rdcatch/rdcatch.h | 23 +++++++--- 4 files changed, 80 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7204b65e..a8cbd8af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15885,3 +15885,7 @@ * Added a new icon set created by Josh Edelstein. 2017-06-28 Fred Gleason * Incremented the package version to 2.16.0int05. +2017-07-06 Fred Gleason + * Refactored catch connector code in RDCatch(1) to support an + arbitrary number of hosts. + * Removed RD_MAX_STATIONS from 'lib/rd.h'. diff --git a/lib/rd.h b/lib/rd.h index b524b623..aaec2e1a 100644 --- a/lib/rd.h +++ b/lib/rd.h @@ -122,11 +122,6 @@ */ #define MAX_GPIO_PINS 32768 -/* - * Max number of possible workstations - */ -#define RD_MAX_STATIONS 64 - /* * Max number of possible audio adapters */ diff --git a/rdcatch/rdcatch.cpp b/rdcatch/rdcatch.cpp index 89abaf6a..6b6a46a6 100644 --- a/rdcatch/rdcatch.cpp +++ b/rdcatch/rdcatch.cpp @@ -93,6 +93,27 @@ RDSystem *catch_system=NULL; #include "../icons/upload.xpm" #include "../icons/rdcatch-22x22.xpm" +CatchConnector::CatchConnector(RDCatchConnect *conn,const QString &station_name) +{ + catch_connect=conn; + catch_station_name=station_name; +} + + +RDCatchConnect *CatchConnector::connector() const +{ + return catch_connect; +} + + +QString CatchConnector::stationName() +{ + return catch_station_name; +} + + + + MainWidget::MainWidget(QWidget *parent) :QWidget(parent) { @@ -268,58 +289,50 @@ MainWidget::MainWidget(QWidget *parent) RDSqlQuery *q= new RDSqlQuery("select NAME,IPV4_ADDRESS from STATIONS\ where NAME!=\"DEFAULT\""); - catch_station_count=0; while(q->next()) { - catch_connect[catch_station_count].connect= - new RDCatchConnect(catch_station_count,this); - catch_connect[catch_station_count].station= - q->value(0).toString().lower(); - connect(catch_connect[catch_station_count].connect, + catch_connect.push_back(new CatchConnector(new RDCatchConnect(catch_connect.size(),this),q->value(0).toString().lower())); + connect(catch_connect.back()->connector(), SIGNAL(statusChanged(int,unsigned,RDDeck::Status,int,const QString &)), this, SLOT(statusChangedData(int,unsigned,RDDeck::Status,int,const QString &))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(monitorChanged(int,unsigned,bool)), this,SLOT(monitorChangedData(int,unsigned,bool))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(connected(int,bool)), this,SLOT(connectedData(int,bool))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(meterLevel(int,int,int,int)), this,SLOT(meterLevelData(int,int,int,int))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(eventUpdated(int)), this,SLOT(eventUpdatedData(int))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(eventPurged(int)), this,SLOT(eventPurgedData(int))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(deckEventSent(int,int,int)), this,SLOT(deckEventSentData(int,int,int))); - connect(catch_connect[catch_station_count].connect, + connect(catch_connect.back()->connector(), SIGNAL(heartbeatFailed(int)), this,SLOT(heartbeatFailedData(int))); - catch_connect[catch_station_count].connect-> + catch_connect.back()->connector()-> connectHost(q->value(1).toString(),RDCATCHD_TCP_PORT, catch_config->password()); - catch_station_count++; - sql=QString().sprintf("select CHANNEL,MON_PORT_NUMBER from DECKS \ where (CARD_NUMBER!=-1)&&(PORT_NUMBER!=-1)&&(CHANNEL>0)&&(STATION_NAME=\"%s\") \ order by CHANNEL",(const char *)q->value(0).toString().lower()); q1=new RDSqlQuery(sql); while(q1->next()) { - catch_connect[catch_station_count-1]. - chan.push_back(q1->value(0).toUInt()); - catch_connect[catch_station_count-1]. - mon_id.push_back(catch_monitor.size()); + catch_connect.back()->chan.push_back(q1->value(0).toUInt()); + catch_connect.back()->mon_id.push_back(catch_monitor.size()); catch_monitor.push_back(new CatchMonitor()); catch_monitor.back()->setDeckMon(new DeckMon(q->value(0).toString(), q1->value(0).toUInt(), catch_monitor_vbox)); - catch_monitor.back()->setSerialNumber(catch_station_count-1); + catch_monitor.back()->setSerialNumber(catch_connect.size()-1); catch_monitor.back()->setChannelNumber(q1->value(0).toUInt()); catch_monitor_vbox->addWidget(catch_monitor.back()->deckMon()); @@ -620,7 +633,7 @@ void MainWidget::resizeData() void MainWidget::connectedData(int serial,bool state) { if(state) { - catch_connect[serial].connect->enableMetering(true); + catch_connect[serial]->connector()->enableMetering(true); } } @@ -705,7 +718,7 @@ void MainWidget::addData() } catch_recordings_list->setSelected(item,true); catch_recordings_list->ensureItemVisible(item); - catch_connect[conn].connect->addEvent(n); + catch_connect[conn]->connector()->addEvent(n); nextEventData(); break; @@ -769,8 +782,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete recording; @@ -785,8 +798,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete playout; @@ -801,8 +814,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete event; @@ -817,8 +830,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete switch_event; @@ -833,8 +846,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete download; @@ -849,8 +862,8 @@ void MainWidget::editData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[old_conn].connect->removeEvent(id); - catch_connect[new_conn].connect->addEvent(id); + catch_connect[old_conn]->connector()->removeEvent(id); + catch_connect[new_conn]->connector()->addEvent(id); nextEventData(); } delete upload; @@ -895,7 +908,7 @@ void MainWidget::deleteData() fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[conn].connect->removeEvent(item->text(28).toInt()); + catch_connect[conn]->connector()->removeEvent(item->text(28).toInt()); sql=QString().sprintf("delete from RECORDINGS where ID=%s", (const char *)item->text(28)); q=new RDSqlQuery(sql); @@ -1168,9 +1181,9 @@ void MainWidget::meterLevelData(int serial,int deck,int l_r,int level) { DeckMon *monitor; - for(unsigned i=0;ideckMon(); + for(unsigned i=0;ichan.size();i++) { + if(catch_connect[serial]->chan[i]==(unsigned)deck) { + monitor=catch_monitor[catch_connect[serial]->mon_id[i]]->deckMon(); if(l_r==0) { monitor->setLeftMeter(level); } @@ -1185,14 +1198,14 @@ void MainWidget::meterLevelData(int serial,int deck,int l_r,int level) void MainWidget::abortData(int id) { - catch_connect[catch_monitor[id]->serialNumber()].connect-> + catch_connect[catch_monitor[id]->serialNumber()]->connector()-> stop(catch_monitor[id]->channelNumber()); } void MainWidget::monitorData(int id) { - catch_connect[catch_monitor[id]->serialNumber()].connect-> + catch_connect[catch_monitor[id]->serialNumber()]->connector()-> toggleMonitor(catch_monitor[id]->channelNumber()); } @@ -1262,7 +1275,7 @@ void MainWidget::heartbeatFailedData(int id) str=QString(tr("Control connection timed out to host")); QString msg=QString().sprintf("%s '%s'!",(const char *)str, - (const char *)catch_connect[id].station); + (const char *)catch_connect[id]->stationName()); QMessageBox::warning(this,"RDCatch",msg); } @@ -1592,7 +1605,7 @@ void MainWidget::ProcessNewRecords(std::vector *adds) fprintf(stderr,"rdcatch: invalid connection index!\n"); return; } - catch_connect[conn].connect->addEvent(adds->at(i)); + catch_connect[conn]->connector()->addEvent(adds->at(i)); } nextEventData(); } @@ -2533,14 +2546,13 @@ int MainWidget::GetMonitor(int serial,int chan) int MainWidget::GetConnection(QString station,unsigned chan) { - for(int i=0;istationName()==station.lower()) { if(chan==0) { return i; } - for(unsigned j=0;jchan.size();j++) { + if(catch_connect[i]->chan[j]==chan) { return i; } } diff --git a/rdcatch/rdcatch.h b/rdcatch/rdcatch.h index 4a04e10d..920bb3f0 100644 --- a/rdcatch/rdcatch.h +++ b/rdcatch/rdcatch.h @@ -57,6 +57,21 @@ #define RDCATCH_MAX_VISIBLE_MONITORS 8 #define RDCATCH_USAGE "[--offline-host-warnings=yes|no]\n" +class CatchConnector +{ + public: + CatchConnector(RDCatchConnect *conn,const QString &station_name); + RDCatchConnect *connector() const; + QString stationName(); + std::vector chan; + std::vector mon_id; + + private: + RDCatchConnect *catch_connect; + QString catch_station_name; +}; + + class MainWidget : public QWidget { Q_OBJECT @@ -128,13 +143,7 @@ class MainWidget : public QWidget std::vector catch_monitor; QScrollView *catch_monitor_view; VBox *catch_monitor_vbox; - struct { - RDCatchConnect *connect; - QString station; - std::vector chan; - std::vector mon_id; - } catch_connect[RD_MAX_STATIONS]; - int catch_station_count; + std::vector catch_connect; QSqlDatabase *catch_db; int catch_audition_stream; int catch_play_handle;