diff --git a/ChangeLog b/ChangeLog index 5d443079..3137ff89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18364,3 +18364,6 @@ 2019-01-10 Fred Gleason * Fixed a bug in 'pypad_xds.py' that threw an exception when processing a PAD update originated from a null log. +2019-01-10 Fred Gleason + * Refactored dropbox instance management to use multicast + notifications. diff --git a/docs/apis/catchd.xml b/docs/apis/catchd.xml index fc376855..5f8322e8 100644 --- a/docs/apis/catchd.xml +++ b/docs/apis/catchd.xml @@ -464,17 +464,6 @@ - - Restart Dropbox Instances - - Restart all rdimport1 - instances for running dropboxes. - - - RX! - - - Input Monitor State diff --git a/lib/rdnotification.cpp b/lib/rdnotification.cpp index 055aa275..f5e0be08 100644 --- a/lib/rdnotification.cpp +++ b/lib/rdnotification.cpp @@ -107,6 +107,10 @@ bool RDNotification::read(const QString &str) notify_id=QVariant(args[3].toUInt()); break; + case RDNotification::DropboxType: + notify_id=QVariant(args[3]); + break; + case RDNotification::NullType: case RDNotification::LastType: break; @@ -150,6 +154,10 @@ QString RDNotification::write() const ret+=QString().sprintf("%u",notify_id.toUInt()); break; + case RDNotification::DropboxType: + ret+=notify_id.toString(); + break; + case RDNotification::NullType: case RDNotification::LastType: break; @@ -175,6 +183,10 @@ QString RDNotification::typeString(RDNotification::Type type) ret="PYPAD"; break; + case RDNotification::DropboxType: + ret="DROPBOX"; + break; + case RDNotification::NullType: case RDNotification::LastType: break; diff --git a/lib/rdnotification.h b/lib/rdnotification.h index 4331117d..3b63c633 100644 --- a/lib/rdnotification.h +++ b/lib/rdnotification.h @@ -27,7 +27,8 @@ class RDNotification { public: - enum Type {NullType=0,CartType=1,LogType=2,PypadType=3,LastType=4}; + enum Type {NullType=0,CartType=1,LogType=2,PypadType=3,DropboxType=4, + LastType=5}; enum Action {NoAction=0,AddAction=1,DeleteAction=2,ModifyAction=3, LastAction=4}; RDNotification(Type type,Action action,const QVariant &id); diff --git a/rdadmin/edit_dropbox.cpp b/rdadmin/edit_dropbox.cpp index 726de550..8f7643a4 100644 --- a/rdadmin/edit_dropbox.cpp +++ b/rdadmin/edit_dropbox.cpp @@ -657,13 +657,13 @@ void EditDropbox::okData() q=new RDSqlQuery(sql); delete q; } - done(0); + done(true); } void EditDropbox::cancelData() { - done(-1); + done(false); } diff --git a/rdadmin/list_dropboxes.cpp b/rdadmin/list_dropboxes.cpp index 2f263404..e3eaf9dc 100644 --- a/rdadmin/list_dropboxes.cpp +++ b/rdadmin/list_dropboxes.cpp @@ -29,8 +29,10 @@ #include #include +#include #include #include +#include #include "edit_dropbox.h" #include "list_dropboxes.h" @@ -152,7 +154,14 @@ void ListDropboxes::addData() int id=box->id(); delete box; EditDropbox *edit_dropbox=new EditDropbox(id,this); - if(edit_dropbox->exec()<0) { + if(edit_dropbox->exec()) { + RDNotification *notify=new RDNotification(RDNotification::DropboxType, + RDNotification::AddAction, + list_stationname); + rda->ripc()->sendNotification(*notify); + delete notify; + } + else { QString sql=QString().sprintf("delete from DROPBOXES where ID=%d",id); RDSqlQuery *q=new RDSqlQuery(sql); delete q; @@ -175,7 +184,13 @@ void ListDropboxes::editData() return; } EditDropbox *edit_dropbox=new EditDropbox(item->id(),this); - edit_dropbox->exec(); + if(edit_dropbox->exec()) { + RDNotification *notify=new RDNotification(RDNotification::DropboxType, + RDNotification::ModifyAction, + list_stationname); + rda->ripc()->sendNotification(*notify); + delete notify; + } delete edit_dropbox; RefreshItem(item); } @@ -197,6 +212,13 @@ void ListDropboxes::deleteData() sql=QString().sprintf("delete from DROPBOXES where ID=%d",item->id()); q=new RDSqlQuery(sql); delete q; + + RDNotification *notify=new RDNotification(RDNotification::DropboxType, + RDNotification::DeleteAction, + list_stationname); + rda->ripc()->sendNotification(*notify); + delete notify; + delete item; } diff --git a/rdcatchd/rdcatchd.cpp b/rdcatchd/rdcatchd.cpp index e8a51d10..358e80f9 100644 --- a/rdcatchd/rdcatchd.cpp +++ b/rdcatchd/rdcatchd.cpp @@ -1817,13 +1817,6 @@ void MainObject::DispatchCommand(ServerConnection *conn) LoadHeartbeat(); } - if(cmds.at(0)=="RX") { // Signal rdservice(8) to Restart Dropbox Instances - pid_t pid=RDGetPid(QString(RD_PID_DIR)+"/rdservice.pid"); - if(pid>0) { - kill(pid,SIGUSR1); - } - } - if((cmds.at(0)=="MN")&&(cmds.size()==3)) { // Monitor State chan=cmds.at(1).toInt(&ok); if(!ok) { diff --git a/ripcd/Makefile.am b/ripcd/Makefile.am index 02b7ceb7..4626e323 100644 --- a/ripcd/Makefile.am +++ b/ripcd/Makefile.am @@ -59,6 +59,7 @@ dist_ripcd_SOURCES = acu1p.cpp acu1p.h\ local_audio.cpp local_audio.h\ local_gpio.cpp local_gpio.h\ local_macros.cpp\ + local_notifications.cpp\ loaddrivers.cpp\ modbus.cpp modbus.h\ modemlines.cpp modemlines.h\ diff --git a/ripcd/local_notifications.cpp b/ripcd/local_notifications.cpp new file mode 100644 index 00000000..1c0e0244 --- /dev/null +++ b/ripcd/local_notifications.cpp @@ -0,0 +1,38 @@ +// local_notifications.cpp +// +// Process local notifications for ripcd(8) +// +// (C) Copyright 2002-2019 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. +// + +#include + +#include +#include + +#include "ripcd.h" + +void MainObject::RunLocalNotifications(RDNotification *notify) +{ + if((notify->type()==RDNotification::DropboxType)&& + (notify->id().toString()==rda->config()->stationName())) { + pid_t pid=RDGetPid(QString(RD_PID_DIR)+"/rdservice.pid"); + if(pid>0) { + kill(pid,SIGUSR1); + } + } +} + diff --git a/ripcd/ripcd.cpp b/ripcd/ripcd.cpp index 7fd3d6c1..64193c9e 100644 --- a/ripcd/ripcd.cpp +++ b/ripcd/ripcd.cpp @@ -229,13 +229,18 @@ void MainObject::notificationReceivedData(const QString &msg, const QHostAddress &addr) { RDNotification *notify=new RDNotification(); + + syslog(LOG_NOTICE,"recv: %s\n",(const char *)msg.toUtf8()); + if(!notify->read(msg)) { LogLine(RDConfig::LogWarning, "Invalid notification received from "+addr.toString()); delete notify; return; } + RunLocalNotifications(notify); BroadcastCommand("ON "+msg+"!"); + delete notify; } @@ -512,6 +517,7 @@ bool MainObject::DispatchCommand(RipcdConnection *conn) delete notify; return true; } + RunLocalNotifications(notify); BroadcastCommand("ON "+msg+"!",conn->id()); ripcd_notification_mcaster-> send(msg,rda->system()->notificationAddress(),RD_NOTIFICATION_PORT); diff --git a/ripcd/ripcd.h b/ripcd/ripcd.h index 9816dc82..04e1692c 100644 --- a/ripcd/ripcd.h +++ b/ripcd/ripcd.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -90,6 +91,7 @@ class MainObject : public QObject void ReadRmlSocket(QUdpSocket *sock,RDMacro::Role role,bool echo); QString StripPoint(QString); void LoadLocalMacros(); + void RunLocalNotifications(RDNotification *notify); void RunLocalMacros(RDMacro *rml); void LoadGpiTable(); void SendGpi(int ch,int matrix);