2018-02-03 Fred Gleason <fredg@paravelsystems.com>

* Converted sas_shim(8) to use RDApplication.
This commit is contained in:
Fred Gleason 2018-02-02 17:38:23 -05:00
parent 47a792d0aa
commit 79c0e1d825
3 changed files with 100 additions and 117 deletions

View File

@ -16645,3 +16645,5 @@
* Converted rdpurgecasts(1) to use RDApplication. * Converted rdpurgecasts(1) to use RDApplication.
2018-02-03 Fred Gleason <fredg@paravelsystems.com> 2018-02-03 Fred Gleason <fredg@paravelsystems.com>
* Converted rdrender(1) to use RDApplication. * Converted rdrender(1) to use RDApplication.
2018-02-03 Fred Gleason <fredg@paravelsystems.com>
* Converted sas_shim(8) to use RDApplication.

View File

@ -2,7 +2,7 @@
// //
// An RDCatch event import shim for the SAS64000 // An RDCatch event import shim for the SAS64000
// //
// (C) Copyright 2002-2004,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2002-2004,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -26,21 +26,19 @@
#include <qapplication.h> #include <qapplication.h>
#include <qtimer.h> #include <qtimer.h>
#include <rdconf.h>
#include <rd.h> #include <rd.h>
#include <rdcmd_switch.h> #include <rdapplication.h>
#include <rddbheartbeat.h> #include <rdconf.h>
#include <sas_shim.h>
#include "sas_shim.h"
void SigHandler(int signo) void SigHandler(int signo)
{ {
switch(signo) { switch(signo) {
case SIGTERM: case SIGTERM:
unlink("/var/run/sas_shim.pid"); unlink("/var/run/sas_shim.pid");
exit(0); exit(0);
break; break;
} }
} }
@ -48,52 +46,43 @@ void SigHandler(int signo)
MainObject::MainObject(QObject *parent) MainObject::MainObject(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
QString err_msg;
//
// Open the Database
//
rda=new RDApplication("sas_shim","sas_shim",SAS_SHIM_USAGE,this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"sas_shim: %s\n",(const char *)err_msg);
exit(1);
}
// //
// Read Command Options // Read Command Options
// //
RDCmdSwitch *cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"sas_shim","\n"); for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
delete cmd; if(!rda->cmdSwitch()->processed(i)) {
fprintf(stderr,"sas_shim: unknown command option \"%s\"\n",
rd_config=new RDConfig(RD_CONF_FILE); (const char *)rda->cmdSwitch()->key(i));
rd_config->load(); exit(2);
rd_config->setModuleName("sas_shim"); }
//
// Open Database
//
shim_db=QSqlDatabase::addDatabase(rd_config->mysqlDriver());
if(!shim_db) {
fprintf(stderr,"sas_shim: can't open mySQL database\n");
exit(1);
} }
shim_db->setDatabaseName(rd_config->mysqlDbname());
shim_db->setUserName(rd_config->mysqlUsername());
shim_db->setPassword(rd_config->mysqlPassword());
shim_db->setHostName(rd_config->mysqlHostname());
if(!shim_db->open()) {
fprintf(stderr,"sas_shim: unable to connect to mySQL Server");
shim_db->removeDatabase(rd_config->mysqlDbname());
exit(1);
}
new RDDbHeartbeat(rd_config->mysqlHeartbeatInterval(),this);
// //
// Station Configuration // Station Configuration
// //
shim_rdstation=new RDStation(rd_config->stationName()); shim_address=rda->station()->address();
shim_address=shim_rdstation->address();
// //
// RIPCD Connection // RIPCD Connection
// //
shim_ripc=new RDRipc(shim_rdstation,rd_config,this); rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
shim_ripc->connectHost("localhost",RIPCD_TCP_PORT,rd_config->password());
// //
// TTY Device // TTY Device
// //
shim_tty=new RDTTYDevice(); shim_tty=new RDTTYDevice();
shim_tty->setName(rd_config->sasTtyDevice()); shim_tty->setName(rda->config()->sasTtyDevice());
if(!shim_tty->open(IO_ReadOnly)) { if(!shim_tty->open(IO_ReadOnly)) {
fprintf(stderr,"sas_shim: unabled to open tty device\n"); fprintf(stderr,"sas_shim: unabled to open tty device\n");
exit(1); exit(1);
@ -112,7 +101,7 @@ MainObject::MainObject(QObject *parent)
// //
// Detach // Detach
// //
RDDetach(rd_config->logCoreDumpDirectory()); RDDetach(rda->config()->logCoreDumpDirectory());
FILE *pidfile=fopen("/var/run/sas_shim.pid","w"); FILE *pidfile=fopen("/var/run/sas_shim.pid","w");
fprintf(pidfile,"%d",getpid()); fprintf(pidfile,"%d",getpid());
fclose(pidfile); fclose(pidfile);
@ -132,75 +121,74 @@ void MainObject::readTtyData()
while((n=shim_tty->readBlock(buf,255))>0) { while((n=shim_tty->readBlock(buf,255))>0) {
for(int i=0;i<n;i++) { for(int i=0;i<n;i++) {
switch(istate) { switch(istate) {
case 0: // Start of Command case 0: // Start of Command
if(buf[i]=='D') { if(buf[i]=='D') {
istate=1; istate=1;
} }
break; break;
case 1: // Type Identifier case 1: // Type Identifier
if(buf[i]=='T') { if(buf[i]=='T') {
istate=2; istate=2;
} }
else { else {
istate=0; istate=0;
} }
break; break;
case 2: // Crosspoint State Byte case 2: // Crosspoint State Byte
if(buf[i]=='1') { if(buf[i]=='1') {
istate=3; istate=3;
} }
else { else {
istate=0; istate=0;
} }
break; break;
case 3: // First Input Digit case 3: // First Input Digit
if((buf[i]>='0')&&(buf[i]<='9')) { if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[0]=buf[i]; cmd[0]=buf[i];
istate=4; istate=4;
} }
else { else {
istate=0; istate=0;
} }
break; break;
case 4: // Second Input Digit case 4: // Second Input Digit
if((buf[i]>='0')&&(buf[i]<='9')) { if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[1]=buf[i]; cmd[1]=buf[i];
cmd[2]=0; cmd[2]=0;
sscanf(cmd,"%d",&input); sscanf(cmd,"%d",&input);
istate=5; istate=5;
} }
else { else {
istate=0; istate=0;
} }
break; break;
case 5: // First Output Digit case 5: // First Output Digit
if((buf[i]>='0')&&(buf[i]<='9')) { if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[0]=buf[i]; cmd[0]=buf[i];
istate=6; istate=6;
} }
else { else {
istate=0; istate=0;
} }
break; break;
case 6: // Second Output Digit
if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[1]=buf[i];
cmd[2]=0;
sscanf(cmd,"%d",&output);
DispatchRml(input,output);
istate=0;
}
else {
istate=0;
}
break;
case 6: // Second Output Digit
if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[1]=buf[i];
cmd[2]=0;
sscanf(cmd,"%d",&output);
DispatchRml(input,output);
istate=0;
}
else {
istate=0;
}
break;
} }
} }
} }
@ -216,10 +204,10 @@ void MainObject::DispatchRml(int input,int output)
rml.setAddress(shim_address); rml.setAddress(shim_address);
rml.setEchoRequested(false); rml.setEchoRequested(false);
rml.setArgQuantity(3); rml.setArgQuantity(3);
rml.setArg(0,rd_config->sasMatrix()); rml.setArg(0,rda->config()->sasMatrix());
rml.setArg(1,input); rml.setArg(1,input);
rml.setArg(2,output); rml.setArg(2,output);
shim_ripc->sendRml(&rml); rda->ripc()->sendRml(&rml);
} }

View File

@ -2,7 +2,7 @@
// //
// An RDCatch event import shim for the SAS64000 // An RDCatch event import shim for the SAS64000
// //
// (C) Copyright 2002-2004,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2002-2004,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -21,16 +21,13 @@
#ifndef SAS_SHIM_H #ifndef SAS_SHIM_H
#define SAS_SHIM_H #define SAS_SHIM_H
#include <qobject.h>
#include <qapplication.h> #include <qapplication.h>
#include <qsqldatabase.h> #include <qhostaddress.h>
#include <qobject.h>
#include <rdttydevice.h> #include <rdttydevice.h>
#include <rdstation.h> #define SAS_SHIM_USAGE "\n"
#include <rdripc.h>
#include <rdconfig.h>
#define POLL_INTERVAL 100 #define POLL_INTERVAL 100
class MainObject : public QObject class MainObject : public QObject
@ -45,13 +42,9 @@ class MainObject : public QObject
private: private:
void DispatchRml(int input,int output); void DispatchRml(int input,int output);
QString shim_station; QString shim_station;
RDStation *shim_rdstation;
QHostAddress shim_address; QHostAddress shim_address;
RDRipc *shim_ripc;
QSqlDatabase *shim_db;
RDTTYDevice *shim_tty; RDTTYDevice *shim_tty;
RDConfig *rd_config;
}; };
#endif #endif // SAS_SHIM_H