Completed first version of vx info server and workstation utility.

Removed the stupid program PVSget.
This commit is contained in:
Jim Kowalkowski
1995-09-07 21:25:59 +00:00
parent 818bc0d475
commit 43ef20b90c
6 changed files with 291 additions and 207 deletions
+2 -1
View File
@@ -28,8 +28,9 @@
#define BS_Error 1
#define BS_Close 2
#define BS_Ping 3
#define BS_Done 4
#define BS_LAST_VERB 3
#define BS_LAST_VERB 4
#define BS_RETRY_COUNT 3
/* protocol states */
+8 -8
View File
@@ -11,27 +11,24 @@ LEXOPT = -L
SRCS.c = ../dbVarSub.c dbLoadTemplate_lex.c dbLoadTemplate.c \
dbLoadRecords_lex.c dbLoadRecords.c \
../BSlib.c ../PVSvx.c ../PVSserver.c ../PVSget.c
../BSlib.c ../PVSserver.c
VAR_OBJS = dbVarSub.o dbLoadTemplate.o dbLoadRecords.o
OBJS = $(VAR_OBJS) BSlib.o PVSvx.o PVSserver.o PVSget.o
OBJS = $(VAR_OBJS) BSlib.o PVSserver.o
PROD = subtool dbLoadTemplate
TARGETS = PVSvx PVSserver PVSget
TARGETS = PVSserver rdbls
include $(EPICS)/config/RULES.Unix
dbLoadTemplate.o: dbLoadTemplate_lex.c
dbLoadRecords.o: dbLoadRecords_lex.c
PVSvx: PVSvx.o BSlib.o
$(LINK.c) $(ARCH_DEP_LDLIBS) $(LDFLAGS) -o $@ $^
PVSserver: PVSserver.o BSlib.o
$(LINK.c) $(ARCH_DEP_LDLIBS) $(LDFLAGS) -o $@ $^
PVSget: PVSget.o BSlib.o
$(LINK.c) $(ARCH_DEP_LDLIBS) $(LDFLAGS) -o $@ $^
rdbls.o: ../PVSserver.c
$(COMPILE.c) $(CFLAGS) -DRDBLS -o $@ $<
subtool.o: dbLoadTemplate.c dbLoadTemplate_lex.c
$(COMPILE.c) $(CFLAGS) -DSUB_TOOL -o $@ $<
@@ -39,6 +36,9 @@ subtool.o: dbLoadTemplate.c dbLoadTemplate_lex.c
subtool: subtool.o dbVarSub.o
$(LINK.c) $(CFLAGS) -DSUB_TOOL -o $@ $^ -s
rdbls: rdbls.o BSlib.o
$(LINK.c) $(ARCH_DEP_LDLIBS) $(LDFLAGS) -DRDBLS -o $@ $^ -s
dbLoadTemplate: $(VAR_OBJS)
$(LINK.c) -o $@ $^ $(LDLIBS) -lDb
+16 -3
View File
@@ -11,8 +11,21 @@
#define PVS_TCP_PORT 50299
#define PVS_UDP_CPORT 50300
#define PVS_Request (BS_LAST_VERB+1)
#define PVS_Data (BS_LAST_VERB+2)
#define PVS_Alive (BS_LAST_VERB+3)
#define PVS_Data (BS_LAST_VERB+1)
#define PVS_Alive (BS_LAST_VERB+2)
#define PVS_RecList (BS_LAST_VERB+3)
#define PVS_AppList (BS_LAST_VERB+4)
#define PVS_RecDump (BS_LAST_VERB+5)
#define PVS_LAST_VERB PVS_RecDump
struct pvs_info_packet
{
unsigned short cmd;
char text[90];
};
typedef struct pvs_info_packet PVS_INFO_PACKET;
#define PVS_SET_CMD(pvs_info,command) (pvs_info)->cmd=htons(command)
#endif
-88
View File
@@ -1,88 +0,0 @@
/* only runable on work station now */
#include "PVS.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc,char** argv)
{
BS* bs;
int verb,size,done,len,i;
char* buffer;
BSDATA info;
if(argc<2)
{
printf("Enter IOC name on command line\n");
return -1;
}
done=0;
buffer=(char*)malloc(PVS_TRANSFER_SIZE);
if(BSsetAddressPort(&info,argv[1],PVS_TCP_PORT)<0)
{
printf("Failed to locate IOC host name\n");
return -1;
}
if((bs=BSipOpenData(&info))==NULL)
{
printf("open of socket to IOC failed\n");
}
else
{
while(done==0)
{
printf("Begin----------\n");
/* read messages until close received */
if(BSreceiveHeader(bs,&verb,&size)<0)
{
printf("receive failed from socket\n");
done=-1;
}
else
{
switch(verb)
{
case PVS_Data: /* read a block of names */
printf("got PVS_Data msg, size=%d\n",size);
if((len=BSreceiveData(bs,buffer,size))<0)
{
printf("receive data failed\n");
}
else
{
for(i=0;i<len;i++)
{
if(buffer[i]!=' ')
putchar(buffer[i]);
else
putchar('\n');
}
}
putchar('\n');
break;
case BS_Close: /* transfers complete */
printf("got BS_Close\n");
BSsendHeader(bs,BS_Ok,0);
done=-1;
break;
default:
printf("unknown message type received from remote\n");
if(size>0) done=-1;
break;
}
}
}
printf("Closing connection\n");
BSfreeBS(bs);
}
free(buffer);
}
+110 -42
View File
@@ -18,8 +18,54 @@ typedef struct PVSnode PVSNODE;
static PVSNODE* ioc_list = (PVSNODE*)NULL;
static int read_pvs(BSDATA* info);
static int read_pvs(BSDATA* info,int serv,char* sname);
#ifndef PVS_SERVER_PROG
#ifdef RDBLS
int main(int argc,char** argv)
{
BSDATA info;
int rc;
if(argc<2)
{
fprintf(stderr,"usage: %s IOC-ip-address\n",argv[0]);
return -1;
}
BSsetAddress(&info,argv[1]);
rc=read_pvs(&info,PVS_RecList,(char*)NULL);
if(rc<0) fprintf(stderr,"read of data failed horribly\n");
return 0;
}
#else
int main(int argc,char** argv)
{
BSDATA info;
int serv;
int rc;
if(argc<4)
{
fprintf(stderr,"usage: %s IOC-name server-number [server-name]\n",
argv[0]);
return -1;
}
serv=atoi(argv[2]);
BSsetAddress(&info,argv[1]);
if(serv>PVS_LAST_VERB)
rc=read_pvs(&info,serv,argv[3]);
else
rc=read_pvs(&info,serv,(char*)NULL);
if(rc<0) fprintf(stderr,"read of data failed horribly\n");
return 0;
}
#endif
#else
int main(int argc,char** argv)
{
int soc,mlen;
@@ -115,7 +161,7 @@ int main(int argc,char** argv)
close(soc);
BSserverClearSignals();
sleep(1);
return read_pvs(&info);
return read_pvs(&info,PVS_RecList,NULL);
default: /* parent */
break;
}
@@ -126,11 +172,12 @@ int main(int argc,char** argv)
close(soc);
return 0;
}
#endif
static int read_pvs(BSDATA* info)
static int read_pvs(BSDATA* info,int serv,char* sname)
{
BS* bs;
int verb,size,done,len,i,port;
int verb,size,done,len,i,port,rsize;
char* buffer;
char ip_from[40];
FILE* fd;
@@ -146,68 +193,89 @@ static int read_pvs(BSDATA* info)
unlink(ip_from);
}
buffer=(char*)malloc(PVS_TRANSFER_SIZE+2);
done=0;
BSsetPort(info,PVS_TCP_PORT);
if((bs=BSipOpenData(info))==NULL)
{
fprintf(stderr,"Open of socket to IOC failed\n");
return -1;
}
if(serv>PVS_LAST_VERB)
rsize=strlen(sname)+1;
else
rsize=0;
if(BSsendHeader(bs,serv,rsize)<0)
{
if((fd=fopen(ip_from,"w"))==(FILE*)NULL)
fprintf(stderr,"Command send failed\n");
return -1;
}
if(rsize>0)
{
if(BSsendData(bs,sname,rsize)<0)
{
fprintf(stderr,"Open of name file failed\n");
fprintf(stderr,"send of command name failed\n");
return -1;
}
}
#ifdef PVS_SERVER_PROG
if((fd=fopen(ip_from,"w"))==(FILE*)NULL)
{
fprintf(stderr,"Open of name file failed\n");
return -1;
}
#else
fd=stdout;
#endif
buffer=(char*)malloc(PVS_TRANSFER_SIZE+2);
while(done==0)
{
if(BSreceiveHeader(bs,&verb,&size)<0)
{
fprintf(stderr,"Receive header failed\n");
done=-1;
}
else
{
while(done==0)
switch(verb)
{
/* read messages until close received */
if(BSreceiveHeader(bs,&verb,&size)<0)
case PVS_Data: /* read a block of names */
if((len=BSreceiveData(bs,buffer,size))<0)
{
fprintf(stderr,"Receive header failed\n");
done=-1;
fprintf(stderr,"Receive data failed\n");
}
else
{
switch(verb)
for(i=0;i<len;i++)
{
case PVS_Data: /* read a block of names */
if((len=BSreceiveData(bs,buffer,size))<0)
{
fprintf(stderr,"Receive data failed\n");
}
else
{
for(i=0;i<len;i++)
{
if(buffer[i]==' ') buffer[i]='\n';
}
buffer[len]='\n';
buffer[len+1]='\0';
fputs(buffer,fd);
}
break;
case BS_Close: /* transfers complete */
if(BSsendHeader(bs,BS_Ok,0)<0)
{
fprintf(stderr,"ACK Header send failed\n");
}
done=-1;
break;
default:
if(size>0) done=-1;
break;
if(buffer[i]==' ') buffer[i]='\n';
}
buffer[len]='\n';
buffer[len+1]='\0';
fputs(buffer,fd);
}
break;
case BS_Done: /* transfers complete */
BSclose(bs);
done=-1;
break;
default:
if(size>0) done=-1;
break;
}
fclose(fd);
}
BSfreeBS(bs);
}
#ifdef PVS_SERVER_PROG
fclose(fd);
#endif
free(buffer);
return 0;
}
+155 -65
View File
@@ -1,4 +1,6 @@
/* This file not really set up to run under Unix yet, just under vxWorks. */
#include "PVS.h"
#include <string.h>
@@ -8,6 +10,9 @@
#include <vxWorks.h>
#include <iv.h>
#include <taskLib.h>
#include <sysSymTbl.h>
#include <sysLib.h>
#include <symLib.h>
#include <dbStaticLib.h>
extern struct dbBase *pdbBase;
@@ -20,6 +25,14 @@ extern struct dbBase *pdbBase;
static void PVSserver(int want_annouce,char* name);
static int PVSannouce(int want_annouce,char* name);
static void handle_requests(BS* bs);
static void handle_reclist(BS* bs);
static void handle_applist(BS* bs);
static void handle_recdump(BS* bs);
void PVS_test_server(BS* bs);
static char* names = (char*)NULL;
static char* buffer = (char*)NULL;
#ifdef vxWorks
int PVSstart(int want_annouce, char* name)
@@ -51,12 +64,8 @@ int main(int argc,char** argv)
}
#endif
#ifdef vxWorks
taskSpawn("PVS",150,VX_FP_TASK|VX_STDIO,5000,
(FUNCPTR)PVSserver,want_annouce,(int)name,0,0,0,0,0,0,0,0);
#else
PVSserver(want_annouce,name);
#endif
return 0;
}
@@ -64,7 +73,7 @@ int main(int argc,char** argv)
static int PVSannouce(int want_annouce,char* name)
{
int soc,mlen;
unsigned short buf,in_buf;
PVS_INFO_PACKET buf,in_buf;
BSDATA info,in_info;
if(want_annouce==0 && name)
@@ -81,7 +90,7 @@ static int PVSannouce(int want_annouce,char* name)
return -1;
}
buf=htons(PVS_Alive);
PVS_SET_CMD(&buf,PVS_Alive);
mlen=BStransUDP(soc,&info,&buf,sizeof(buf),&in_buf,sizeof(in_buf));
/* check for errors */
@@ -106,20 +115,14 @@ static void PVSserver(int want_annouce,char* name)
{
fd_set fds,rfds;
int tsoc,usoc,nsoc,len,s;
unsigned short buf;
unsigned long names_len,nl;
struct sockaddr stemp;
int stemp_len;
char* names;
char* n;
PVS_INFO_PACKET buf;
BSDATA info;
BS* bs;
long rc;
#ifdef vxWorks
DBENTRY db;
#endif
bs=(BS*)NULL;
buffer=(char*)malloc(100); /* just make the buffer */
names=(char*)malloc(PVS_TRANSFER_SIZE);
if((tsoc=BSopenListenerTCP(PVS_TCP_PORT))<0)
@@ -152,7 +155,6 @@ static void PVSserver(int want_annouce,char* name)
{
if(FD_ISSET(tsoc,&rfds))
{
/* only requests for PVs will come in here for now */
/* handle the request here - single threaded server */
stemp_len=sizeof(stemp);
@@ -161,56 +163,8 @@ static void PVSserver(int want_annouce,char* name)
else
{
bs=BSmakeBS(nsoc);
#ifdef vxWorks
dbInitEntry(pdbBase,&db);
names_len=0;
for(rc=dbFirstRecdes(&db);rc==0;rc=dbNextRecdes(&db))
{
for(rc=dbFirstRecord(&db);rc==0;rc=dbNextRecord(&db))
{
/* collect the names util we excede the max */
n=dbGetRecordName(&db);
s=strlen(n);
if((names_len+s)>PVS_TRANSFER_SIZE)
{
names[names_len++]='\0';
if(BSsendHeader(bs,PVS_Data,names_len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,names,names_len)<0)
printf("PVSserver: data send failed\n");
}
names_len=0;
}
memcpy(&names[names_len],n,s);
names_len+=s;
names[names_len++]=' ';
}
}
if(names_len>0)
{
names[names_len++]='\0';
if(BSsendHeader(bs,PVS_Data,names_len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,names,names_len)<0)
printf("PVSserver: data send failed\n");
}
}
#else
strcpy(names,"jim Kowalkowski");
names_len=strlen("jim kowalkowski")+1;
if(BSsendHeader(bs,PVS_Data,names_len)<0)
printf("BSsendHeader failed\n");
else
{
if(BSsendData(bs,names,names_len)<0)
printf("BSsendData failed\n");
}
#endif
BSclose(bs);
handle_requests(bs);
BSfreeBS(bs);
}
}
if(FD_ISSET(usoc,&rfds))
@@ -229,4 +183,140 @@ static void PVSserver(int want_annouce,char* name)
}
}
static void handle_reclist(BS* bs)
{
DBENTRY db;
long rc;
char* n;
unsigned long names_len;
int s;
dbInitEntry(pdbBase,&db);
names_len=0;
for(rc=dbFirstRecdes(&db);rc==0;rc=dbNextRecdes(&db))
{
for(rc=dbFirstRecord(&db);rc==0;rc=dbNextRecord(&db))
{
/* collect the names util we excede the max */
n=dbGetRecordName(&db);
s=strlen(n);
if((names_len+s)>PVS_TRANSFER_SIZE)
{
names[names_len++]='\0';
if(BSsendHeader(bs,PVS_Data,names_len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,names,names_len)<0)
printf("PVSserver: data send failed\n");
}
names_len=0;
}
memcpy(&names[names_len],n,s);
names_len+=s;
names[names_len++]=' ';
}
}
if(names_len>0)
{
names[names_len++]='\0';
if(BSsendHeader(bs,PVS_Data,names_len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,names,names_len)<0)
printf("PVSserver: data send failed\n");
}
}
BSsendHeader(bs,BS_Done,0);
}
static void handle_requests(BS* bs)
{
int verb,size,notdone,len;
void (*func)(BS*);
SYM_TYPE stype;
notdone=1;
while(notdone)
{
/* at this point I should be getting a command */
if(BSreceiveHeader(bs,&verb,&size)<0)
{
printf("PVSserver: receive header failed\n");
notdone=0;
}
else
{
switch(verb)
{
case PVS_RecList: handle_reclist(bs); break;
case PVS_AppList: handle_applist(bs); break;
case PVS_RecDump: handle_recdump(bs); break;
case BS_Close:
BSsendHeader(bs,BS_Ok,0);
notdone=0;
break;
case PVS_Data: break;
case PVS_Alive: break;
case BS_Ok: break;
case BS_Error: break;
case BS_Ping: break;
case BS_Done: break;
default:
/* custom service */
if(size>0)
{
/* this should be the name of the service */
/* look up the symbol name in buffer and call as
subroutine, passing it the BS */
len=BSreceiveData(bs,&buffer[1],size);
switch(len)
{
case 0: /* timeout */ notdone=0; break;
case -1: /* error */ notdone=0; break;
default:
buffer[0]='_';
if(strncmp(buffer,"_PVS",4)==0)
{
if(symFindByName(sysSymTbl,buffer,
(char**)&func,&stype)==ERROR)
func=(void (*)(BS*))NULL;
if(func)
func(bs);
else
BSsendHeader(bs,BS_Done,0);
}
else
BSsendHeader(bs,BS_Done,0);
}
}
else
printf("PVSserver: unknown command received\n");
}
}
}
}
void PVS_test_server(BS* bs)
{
printf("PVS_test_server invoked\n");
BSsendHeader(bs,BS_Done,0);
}
void handle_applist(BS* bs)
{
printf("AppList server invoked\n");
BSsendHeader(bs,BS_Done,0);
}
void handle_recdump(BS* bs)
{
printf("RecDump server invoked\n");
BSsendHeader(bs,BS_Done,0);
}