From eb27824e8a3b944d741f8254aa0354b89593d794 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 23 Sep 2021 14:44:16 -0400 Subject: [PATCH] 2021-09-23 Fred Gleason * Removed the 'STATIONS.TIME_STAMP' field from the database. * Incremented the database version to 357. * Removed the 'RDStation::isOnline()' method. Signed-off-by: Fred Gleason --- ChangeLog | 4 ++ docs/apis/notification.xml | 13 ++++++ lib/dbversion.h | 2 +- lib/rdnotification.h | 1 + lib/rdstation.cpp | 19 -------- lib/rdstation.h | 3 +- ripcd/Makefile.am | 2 + ripcd/presence.cpp | 79 ++++++++++++++++++++++++++++++++++ ripcd/presence.h | 53 +++++++++++++++++++++++ ripcd/ripcd.cpp | 49 +++++++++++++++++++++ ripcd/ripcd.h | 26 +++++------ utils/rddbmgr/revertschema.cpp | 16 +++++++ utils/rddbmgr/schemamap.cpp | 2 +- utils/rddbmgr/updateschema.cpp | 6 +++ 14 files changed, 240 insertions(+), 35 deletions(-) create mode 100644 ripcd/presence.cpp create mode 100644 ripcd/presence.h diff --git a/ChangeLog b/ChangeLog index 15367d3b..8804d905 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22456,3 +22456,7 @@ system. * Added code to ripcd(8) to provide system presence information. * Removed vestigal exit monitor code from rdcatchd(8). +2021-09-23 Fred Gleason + * Removed the 'STATIONS.TIME_STAMP' field from the database. + * Incremented the database version to 357. + * Removed the 'RDStation::isOnline()' method. diff --git a/docs/apis/notification.xml b/docs/apis/notification.xml index 4a02900e..c8336325 100644 --- a/docs/apis/notification.xml +++ b/docs/apis/notification.xml @@ -255,6 +255,19 @@ + + + Notes + + Upon reception of a STATION_PRESENCE + notification with an action of ADD, + a receiving host should reply via unicast UDP with their own + STATION_PRESENCE with an action of + MODIFY to the originating IP address, + such replies to be randomly delayed by 10 - 20 seconds after + reception of the ADD notification. + + diff --git a/lib/dbversion.h b/lib/dbversion.h index 42858f05..7a940eab 100644 --- a/lib/dbversion.h +++ b/lib/dbversion.h @@ -24,7 +24,7 @@ /* * Current Database Version */ -#define RD_VERSION_DATABASE 356 +#define RD_VERSION_DATABASE 357 #endif // DBVERSION_H diff --git a/lib/rdnotification.h b/lib/rdnotification.h index 0368d966..7fb934ec 100644 --- a/lib/rdnotification.h +++ b/lib/rdnotification.h @@ -21,6 +21,7 @@ #ifndef RDNOTIFICATION_H #define RDNOTIFICATION_H +#include #include #include diff --git a/lib/rdstation.cpp b/lib/rdstation.cpp index 9cdfc0bb..245de506 100644 --- a/lib/rdstation.cpp +++ b/lib/rdstation.cpp @@ -45,25 +45,6 @@ bool RDStation::exists() const } -bool RDStation::isOnline() const -{ - bool ret=false; - - QString sql=QString("select ")+ - "`TIME_STAMP` "+ // 00 - "from `STATIONS where "+ - "`NAME`='"+RDEscapeString(station_name)+"'"; - RDSqlQuery *q=new RDSqlQuery(sql); - if(q->first()) { - ret=(!q->value(0).isNull())&& - (q->value(0).toDateTime().addSecs(30)>QDateTime::currentDateTime()); - } - delete q; - - return ret; -} - - QString RDStation::name() const { return station_name; diff --git a/lib/rdstation.h b/lib/rdstation.h index e7afb7c5..539af111 100644 --- a/lib/rdstation.h +++ b/lib/rdstation.h @@ -2,7 +2,7 @@ // // Abstract a Rivendell Workstation // -// (C) Copyright 2002-2004,2016 Fred Gleason +// (C) Copyright 2002-2021 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 @@ -37,7 +37,6 @@ class RDStation ~RDStation(); QString name() const; bool exists() const; - bool isOnline() const; QString shortName() const; void setShortName(const QString &str) const; QString description() const; diff --git a/ripcd/Makefile.am b/ripcd/Makefile.am index 6c2bcff4..21e14be4 100644 --- a/ripcd/Makefile.am +++ b/ripcd/Makefile.am @@ -65,6 +65,7 @@ dist_ripcd_SOURCES = acu1p.cpp acu1p.h\ modbus.cpp modbus.h\ modemlines.cpp modemlines.h\ quartz1.cpp quartz1.h\ + presence.cpp presence.h\ ripcd.cpp ripcd.h globals.h\ ripcd_connection.cpp ripcd_connection.h\ rossnkscp.cpp rossnkscp.h\ @@ -113,6 +114,7 @@ nodist_ripcd_SOURCES = moc_am16.cpp\ moc_local_gpio.cpp\ moc_modbus.cpp\ moc_modemlines.cpp\ + moc_presence.cpp\ moc_quartz1.cpp\ moc_ripcd.cpp\ moc_rossnkscp.cpp\ diff --git a/ripcd/presence.cpp b/ripcd/presence.cpp new file mode 100644 index 00000000..951e9b3c --- /dev/null +++ b/ripcd/presence.cpp @@ -0,0 +1,79 @@ +// presence.cpp +// +// Presence data for a Rivendell station +// +// (C) Copyright 2021 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 "presence.h" + +Presence::Presence(const QString &name,QObject *parent) + : QObject(parent) +{ + d_name=name.toLower(); + rda->syslog(LOG_DEBUG,"adding presence record for \"%s\"", + name.toUtf8().constData()); +} + + +Presence::~Presence() +{ + rda->syslog(LOG_DEBUG,"removing presence record for \"%s\"", + d_name.toUtf8().constData()); + if(d_timer!=NULL) { + delete d_timer; + } +} + + +QString Presence::name() const +{ + return d_name; +} + + +QHostAddress Presence::hostAddress() const +{ + return d_host_address; +} + + +void Presence::setHostAddress(const QHostAddress &addr) +{ + d_host_address=addr; +} + + +void Presence::updateLocalId() +{ + if(d_timer!=NULL) { + delete d_timer; + } + d_timer=new QTimer(this); + d_timer->setSingleShot(true); + connect(d_timer,SIGNAL(timeout()),this,SLOT(timeoutData())); + d_timer->start(10000+(long long)random*10000/RAND_MAX); +} + + +void Presence::timeoutData() +{ + emit sendLocalId(d_name); + d_timer->deleteLater(); + d_timer=NULL; +} diff --git a/ripcd/presence.h b/ripcd/presence.h new file mode 100644 index 00000000..01abbe7b --- /dev/null +++ b/ripcd/presence.h @@ -0,0 +1,53 @@ +// presence.h +// +// Presence data for a Rivendell station +// +// (C) Copyright 2021 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 PRESENCE_H +#define PRESENCE_H + +#include +#include +#include +#include + +class Presence : public QObject +{ + Q_OBJECT + public: + Presence(const QString &name,QObject *parent=0); + ~Presence(); + QString name() const; + QHostAddress hostAddress() const; + void setHostAddress(const QHostAddress &addr); + void updateLocalId(); + + signals: + void sendLocalId(const QString &name); + + private slots: + void timeoutData(); + + private: + QString d_name; + QHostAddress d_host_address; + QTimer *d_timer; +}; + + +#endif // PRESENCE_H diff --git a/ripcd/ripcd.cpp b/ripcd/ripcd.cpp index efc812b1..60181d18 100644 --- a/ripcd/ripcd.cpp +++ b/ripcd/ripcd.cpp @@ -202,10 +202,15 @@ MainObject::MainObject(QObject *parent) // // Presence // + /* ripcd_presence_timer=new QTimer(this); connect(ripcd_presence_timer,SIGNAL(timeout()),this,SLOT(presenceData())); presenceData(); ripcd_presence_timer->start(15000); + */ + Presence *pres=new Presence(rda->station()->name()); + pres->setHostAddress(rda->station()->address()); + ripcd_presences[pres->name()]=pres; RDNotification *notify= new RDNotification(RDNotification::StationPresenceType, RDNotification::AddAction,rda->station()->name()); @@ -252,6 +257,7 @@ void MainObject::newConnectionData() void MainObject::notificationReceivedData(const QString &msg, const QHostAddress &addr) { + Presence *pres=NULL; RDNotification *notify=new RDNotification(); if(!notify->read(msg)) { @@ -260,6 +266,34 @@ void MainObject::notificationReceivedData(const QString &msg, delete notify; return; } + + // + // Update presence database + // + if(notify->type()==RDNotification::StationPresenceType) { + if((notify->action()==RDNotification::AddAction)|| + (notify->action()==RDNotification::ModifyAction)) { + if((pres=ripcd_presences.value(notify->id().toString()))==NULL) { + pres=new Presence(notify->id().toString(),this); + connect(pres,SIGNAL(sendLocalId(const QString &)), + this,SLOT(sendLocalIdData(const QString &))); + ripcd_presences[pres->name()]=pres; + } + pres->setHostAddress(addr); + if(notify->action()==RDNotification::AddAction) { + pres->updateLocalId(); + } + // Notify stack!! + } + if(notify->action()==RDNotification::DeleteAction) { + if((pres=ripcd_presences.value(notify->id().toString()))!=NULL) { + // Notify stack! + delete pres; + ripcd_presences.remove(notify->id().toString()); + } + } + } + RunLocalNotifications(notify); BroadcastCommand("ON "+msg+"!"); @@ -501,6 +535,21 @@ void MainObject::presenceData() } +void MainObject::sendLocalIdData(const QString &name) +{ + Presence *pres=ripcd_presences.value(name); + + if(pres!=NULL) { + RDNotification *notify= + new RDNotification(RDNotification::StationPresenceType, + RDNotification::ModifyAction,name); + ripcd_notification_mcaster-> + send(notify->write(),pres->hostAddress(),RD_NOTIFICATION_PORT); + delete notify; + } +} + + void MainObject::SetUser(QString username) { rda->station()->setUserName(username); diff --git a/ripcd/ripcd.h b/ripcd/ripcd.h index 066dace0..7a334fde 100644 --- a/ripcd/ripcd.h +++ b/ripcd/ripcd.h @@ -23,14 +23,13 @@ #include -#include - -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #ifdef JACK #include @@ -46,9 +45,10 @@ #include #include -#include -#include -#include +#include "globals.h" +#include "presence.h" +#include "ripcd_connection.h" +#include "switcher.h" // // Global RIPCD Definitions @@ -84,7 +84,8 @@ class MainObject : public QObject void garbageData(); void startJackData(); void presenceData(); - + void sendLocalIdData(const QString &name); + private: void SetUser(QString username); void ExecCart(int cartnum); @@ -137,6 +138,7 @@ class MainObject : public QObject unsigned ripc_macro_cart[RD_MAX_MACRO_TIMERS]; RDMulticaster *ripcd_notification_mcaster; QTimer *ripcd_garbage_timer; + QMap ripcd_presences; #ifdef JACK jack_client_t *ripcd_jack_client; QTimer *ripcd_start_jack_timer; diff --git a/utils/rddbmgr/revertschema.cpp b/utils/rddbmgr/revertschema.cpp index 1591f93d..7a1e5fe5 100644 --- a/utils/rddbmgr/revertschema.cpp +++ b/utils/rddbmgr/revertschema.cpp @@ -41,6 +41,22 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg) // NEW SCHEMA REVERSIONS GO HERE... + + + + // + // Revert 357 + // + if((cur_schema==357)&&(set_schemacur_schema)) { + DropColumn("STATIONS","TIME_STAMP"); + + WriteSchemaVersion(++cur_schema); + } + // NEW SCHEMA UPDATES GO HERE...