2021-09-23 Fred Gleason <fredg@paravelsystems.com>

* 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 <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-09-23 14:44:16 -04:00
parent 34dc526c66
commit eb27824e8a
14 changed files with 240 additions and 35 deletions

View File

@ -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 <fredg@paravelsystems.com>
* Removed the 'STATIONS.TIME_STAMP' field from the database.
* Incremented the database version to 357.
* Removed the 'RDStation::isOnline()' method.

View File

@ -255,6 +255,19 @@
</tbody>
</tgroup>
</table>
<sect3 xml:id="sect.object_types.station_presence.notes">
<title>Notes</title>
<para>
Upon reception of a <userinput>STATION_PRESENCE</userinput>
notification with an action of <userinput>ADD</userinput>,
a receiving host should reply via unicast UDP with their own
<userinput>STATION_PRESENCE</userinput> with an action of
<userinput>MODIFY</userinput> to the originating IP address,
such replies to be randomly delayed by 10 - 20 seconds after
reception of the <userinput>ADD</userinput> notification.
</para>
</sect3>
</sect2>
</sect1>

View File

@ -24,7 +24,7 @@
/*
* Current Database Version
*/
#define RD_VERSION_DATABASE 356
#define RD_VERSION_DATABASE 357
#endif // DBVERSION_H

View File

@ -21,6 +21,7 @@
#ifndef RDNOTIFICATION_H
#define RDNOTIFICATION_H
#include <QHostAddress>
#include <QString>
#include <QVariant>

View File

@ -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;

View File

@ -2,7 +2,7 @@
//
// Abstract a Rivendell Workstation
//
// (C) Copyright 2002-2004,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 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
@ -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;

View File

@ -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\

79
ripcd/presence.cpp Normal file
View File

@ -0,0 +1,79 @@
// presence.cpp
//
// Presence data for a Rivendell station
//
// (C) Copyright 2021 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 <rdapplication.h>
#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;
}

53
ripcd/presence.h Normal file
View File

@ -0,0 +1,53 @@
// presence.h
//
// Presence data for a Rivendell station
//
// (C) Copyright 2021 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 PRESENCE_H
#define PRESENCE_H
#include <QHostAddress>
#include <QObject>
#include <QString>
#include <QTimer>
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

View File

@ -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);

View File

@ -23,14 +23,13 @@
#include <sys/types.h>
#include <vector>
#include <qobject.h>
#include <qstring.h>
#include <qsignalmapper.h>
#include <qtcpserver.h>
#include <qtimer.h>
#include <qudpsocket.h>
#include <QMap>
#include <QObject>
#include <QString>
#include <QSignalMapper>
#include <QTcpServer>
#include <QTimer>
#include <QUdpSocket>
#ifdef JACK
#include <jack/jack.h>
@ -46,9 +45,10 @@
#include <rdmulticaster.h>
#include <rdtty.h>
#include <ripcd_connection.h>
#include <globals.h>
#include <switcher.h>
#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<QString,Presence *> ripcd_presences;
#ifdef JACK
jack_client_t *ripcd_jack_client;
QTimer *ripcd_start_jack_timer;

View File

@ -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_schema<cur_schema)) {
sql=QString("alter table `STATIONS` ")+
"add column `TIME_STAMP` datetime after `DESCRIPTION`";
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
WriteSchemaVersion(--cur_schema);
}
//
// Revert 356
//

View File

@ -160,7 +160,7 @@ void MainObject::InitializeSchemaMap() {
global_version_map["3.4"]=317;
global_version_map["3.5"]=346;
global_version_map["3.6"]=347;
global_version_map["4.0"]=356;
global_version_map["4.0"]=357;
}

View File

@ -10967,6 +10967,12 @@ bool MainObject::UpdateSchema(int cur_schema,int set_schema,QString *err_msg)
WriteSchemaVersion(++cur_schema);
}
if((cur_schema<357)&&(set_schema>cur_schema)) {
DropColumn("STATIONS","TIME_STAMP");
WriteSchemaVersion(++cur_schema);
}
// NEW SCHEMA UPDATES GO HERE...