Initial import of CVS-v2_8_branch

This commit is contained in:
Fred Gleason
2014-08-12 15:13:02 -04:00
commit afd67c7af8
1508 changed files with 405304 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
## automake.am
##
## Automake.am for rivendell/utils/sas_shim
##
## (C) Copyright 2002-2006 Fred Gleason <fredg@paravelsystems.com>
##
## $Id: Makefile.am,v 1.7.8.1 2012/11/29 01:37:38 cvs Exp $
##
## 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.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@
INCLUDES = -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
sbin_PROGRAMS = sas_shim
dist_sas_shim_SOURCES = sas_shim.cpp sas_shim.h
nodist_sas_shim_SOURCES = moc_sas_shim.cpp
sas_shim_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
EXTRA_DIST = rc.sas_shim
CLEANFILES = *~\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
Makefile.in\
moc_*

159
utils/sas_shim/rc.sas_shim Executable file
View File

@@ -0,0 +1,159 @@
#! /bin/sh
#
# Startup script for the sas_shim Daemon
# (C) Copyright 2003-2004 Fred Gleason <fredg@paravelsystems.com>
#
# $Id: rc.sas_shim,v 1.5 2010/07/29 19:32:40 cvs Exp $
#
# 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.
#
### BEGIN INIT INFO
# Provides: sas_shim
# Required-Start: $remote_fs mysql rivendell
# Required-Stop: $remote_fs
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Start the SAS Shim Daemon
### END INIT INFO
. /lib/lsb/init-functions
#
# Package Definitions
#
PACKAGE_BIN=/usr/local/sbin/sas_shim
PACKAGE_CONFIG=/etc/rd.conf
PACKAGE_PID=/var/run/sas_shim.pid
PACKAGE_NAME="SAS Shim Daemon"
# Check for missing binaries
if [ ! -x $PACKAGE_BIN ] ; then
echo "$PACKAGE_BIN not installed"
exit 5
fi
# Check for existence of needed config file and read it
if [ ! -r $PACKAGE_CONFIG ] ; then
echo "Missing $PACKAGE_CONFIG"
exit 6}
fi
case "$1" in
start)
if test ! -f $PACKAGE_PID ; then
$PACKAGE_BIN
sleep 1
else
if test ! -d /proc/`cat $PACKAGE_PID` ; then
$PACKAGE_BIN
sleep 1
fi
fi
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
log_success_msg "Starting $PACKAGE_NAME"
exit 0
else
log_failure_msg "Starting $PACKAGE_NAME"
exit 1
fi
else
log_failure_msg "Starting $PACKAGE_NAME"
exit 1
fi
;;
stop)
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
kill `cat $PACKAGE_PID` 2> /dev/null
sleep 1
fi
fi
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
log_failure_msg "Shutting down $PACKAGE_NAME"
exit 1
else
log_success_msg "Shutting down $PACKAGE_NAME"
exit 0
fi
else
log_success_msg "Shutting down $PACKAGE_NAME"
exit 0
fi
;;
restart)
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
kill `cat $PACKAGE_PID`
sleep 1
fi
fi
$PACKAGE_BIN
sleep 1
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
log_success_msg "Restarting $PACKAGE_NAME"
exit 0
else
log_success_msg "Restarting $PACKAGE_NAME"
exit 1
fi
else
echo "failed."
exit 1
fi
;;
force-reload)
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
kill `cat $PACKAGE_PID`
sleep 1
fi
fi
$PACKAGE_BIN
sleep 1
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
log_success_msg "Reloading $PACKAGE_NAME"
exit 0
else
log_failure_msg "Restarting $PACKAGE_NAME"
exit 1
fi
else
log_failure_msg "Restarting $PACKAGE_NAME"
exit 1
fi
;;
status)
echo -n "Checking for $PACKAGE_NAME..."
if test -f $PACKAGE_PID ; then
if test -d /proc/`cat $PACKAGE_PID` ; then
echo "running."
exit 0
else
echo "stale PID file."
exit 1
fi
else
echo "stopped."
exit 3
fi
;;
esac
# End of rc.sas_shim

232
utils/sas_shim/sas_shim.cpp Normal file
View File

@@ -0,0 +1,232 @@
// sas_shim.cpp
//
// An RDCatch event import shim for the SAS64000
//
// (C) Copyright 2002-2004 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: sas_shim.cpp,v 1.8 2010/07/29 19:32:40 cvs Exp $
//
// 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 <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <qapplication.h>
#include <qtimer.h>
#include <rdconf.h>
#include <rd.h>
#include <rdcmd_switch.h>
#include <rddbheartbeat.h>
#include <sas_shim.h>
void SigHandler(int signo)
{
switch(signo) {
case SIGTERM:
unlink("/var/run/sas_shim.pid");
exit(0);
break;
}
}
MainObject::MainObject(QObject *parent,const char *name)
: QObject(parent,name)
{
//
// Read Command Options
//
RDCmdSwitch *cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"sas_shim","\n");
delete cmd;
rd_config=new RDConfig(RD_CONF_FILE);
rd_config->load();
//
// 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);
//
// RIPCD Connection
//
shim_ripc=new RDRipc("");
shim_ripc->connectHost("localhost",RIPCD_TCP_PORT,rd_config->password());
//
// Station Configuration
//
shim_rdstation=new RDStation(rd_config->stationName());
shim_address=shim_rdstation->address();
//
// TTY Device
//
shim_tty=new RDTTYDevice();
shim_tty->setName(rd_config->sasTtyDevice());
if(!shim_tty->open(IO_ReadOnly)) {
fprintf(stderr,"sas_shim: unabled to open tty device\n");
exit(1);
}
shim_tty->setSpeed(9600);
shim_tty->setWordLength(8);
shim_tty->setParity(RDTTYDevice::None);
//
// Poll Timer
//
QTimer *timer=new QTimer(this,"poll_timer");
connect(timer,SIGNAL(timeout()),this,SLOT(readTtyData()));
timer->start(POLL_INTERVAL);
//
// Detach
//
RDDetach(rd_config->logCoreDumpDirectory());
FILE *pidfile=fopen("/var/run/sas_shim.pid","w");
fprintf(pidfile,"%d",getpid());
fclose(pidfile);
::signal(SIGTERM,SigHandler);
}
void MainObject::readTtyData()
{
static char cmd[3];
static int input;
static int output;
static int istate=0;
char buf[256];
int n;
while((n=shim_tty->readBlock(buf,255))>0) {
for(int i=0;i<n;i++) {
switch(istate) {
case 0: // Start of Command
if(buf[i]=='D') {
istate=1;
}
break;
case 1: // Type Identifier
if(buf[i]=='T') {
istate=2;
}
else {
istate=0;
}
break;
case 2: // Crosspoint State Byte
if(buf[i]=='1') {
istate=3;
}
else {
istate=0;
}
break;
case 3: // First Input Digit
if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[0]=buf[i];
istate=4;
}
else {
istate=0;
}
break;
case 4: // Second Input Digit
if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[1]=buf[i];
cmd[2]=0;
sscanf(cmd,"%d",&input);
istate=5;
}
else {
istate=0;
}
break;
case 5: // First Output Digit
if((buf[i]>='0')&&(buf[i]<='9')) {
cmd[0]=buf[i];
istate=6;
}
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;
}
}
}
}
void MainObject::DispatchRml(int input,int output)
{
RDMacro rml;
rml.setCommand(RDMacro::ST);
rml.setRole(RDMacro::Cmd);
rml.setAddress(shim_address);
rml.setEchoRequested(false);
rml.setArgQuantity(3);
rml.setArg(0,rd_config->sasMatrix());
rml.setArg(1,input);
rml.setArg(2,output);
shim_ripc->sendRml(&rml);
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv,false);
new MainObject(NULL,"main");
return a.exec();
}

59
utils/sas_shim/sas_shim.h Normal file
View File

@@ -0,0 +1,59 @@
// sas_shim.h
//
// An RDCatch event import shim for the SAS64000
//
// (C) Copyright 2002-2004 Fred Gleason <fredg@paravelsystems.com>
//
// $Id: sas_shim.h,v 1.6 2010/07/29 19:32:40 cvs Exp $
//
// 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 SAS_SHIM_H
#define SAS_SHIM_H
#include <qobject.h>
#include <qapplication.h>
#include <qsqldatabase.h>
#include <rdttydevice.h>
#include <rdstation.h>
#include <rdripc.h>
#include <rdconfig.h>
#define POLL_INTERVAL 100
class MainObject : public QObject
{
Q_OBJECT
public:
MainObject(QObject *parent=0,const char *name=0);
private slots:
void readTtyData();
private:
void DispatchRml(int input,int output);
QString shim_station;
RDStation *shim_rdstation;
QHostAddress shim_address;
RDRipc *shim_ripc;
QSqlDatabase *shim_db;
RDTTYDevice *shim_tty;
RDConfig *rd_config;
};
#endif