mirror of
https://github.com/game-stop/veejay.git
synced 2025-12-17 13:20:01 +01:00
show input when verbose is enabled
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* sendVIMS - very simple client for VeeJay
|
/* sendVIMS - very simple client for VeeJay
|
||||||
* (C) 2002-2016 Niels Elburg <nwelburg@gmail.com>
|
* (C) 2002-2016 Niels Elburg <nwelburg@gmail.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 as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -57,501 +57,505 @@ static int is_fifo =0;
|
|||||||
/* add 4xx VIMS series, read back data from blocking socket */
|
/* add 4xx VIMS series, read back data from blocking socket */
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
int vims;
|
int vims;
|
||||||
int hdr; // make header lengths consistent one day ...
|
int hdr; // make header lengths consistent one day ...
|
||||||
}
|
}
|
||||||
vims_replies[] =
|
vims_replies[] =
|
||||||
{
|
{
|
||||||
{ VIMS_VIDEO_INFORMATION,3 },
|
{ VIMS_VIDEO_INFORMATION,3 },
|
||||||
{ VIMS_EFFECT_LIST,6 },
|
{ VIMS_EFFECT_LIST,6 },
|
||||||
{ VIMS_EDITLIST_LIST,6 },
|
{ VIMS_EDITLIST_LIST,6 },
|
||||||
{ VIMS_BUNDLE_LIST,6 },
|
{ VIMS_BUNDLE_LIST,6 },
|
||||||
{ VIMS_STREAM_LIST,5 },
|
{ VIMS_STREAM_LIST,5 },
|
||||||
{ VIMS_SAMPLE_LIST, 8},
|
{ VIMS_SAMPLE_LIST, 8},
|
||||||
{ VIMS_STREAM_GET_V4L,3},
|
{ VIMS_STREAM_GET_V4L,3},
|
||||||
{ VIMS_CHAIN_GET_ENTRY,3},
|
{ VIMS_CHAIN_GET_ENTRY,3},
|
||||||
{ VIMS_VIMS_LIST,5},
|
{ VIMS_VIMS_LIST,5},
|
||||||
{ VIMS_SAMPLE_INFO,8},
|
{ VIMS_SAMPLE_INFO,8},
|
||||||
{ VIMS_SAMPLE_OPTIONS,5},
|
{ VIMS_SAMPLE_OPTIONS,5},
|
||||||
{ VIMS_DEVICE_LIST,6},
|
{ VIMS_DEVICE_LIST,6},
|
||||||
{ VIMS_FONT_LIST,6},
|
{ VIMS_FONT_LIST,6},
|
||||||
{ VIMS_SRT_LIST,6},
|
{ VIMS_SRT_LIST,6},
|
||||||
{ VIMS_SRT_INFO,6},
|
{ VIMS_SRT_INFO,6},
|
||||||
{ VIMS_TRACK_LIST,5},
|
{ VIMS_TRACK_LIST,5},
|
||||||
{ VIMS_SEQUENCE_LIST,6},
|
{ VIMS_SEQUENCE_LIST,6},
|
||||||
{ VIMS_KEYLIST,6},
|
{ VIMS_KEYLIST,6},
|
||||||
{ VIMS_WORKINGDIR,8},
|
{ VIMS_WORKINGDIR,8},
|
||||||
{ VIMS_SAMPLE_STACK,3},
|
{ VIMS_SAMPLE_STACK,3},
|
||||||
{ VIMS_GET_IMAGE,8},
|
{ VIMS_GET_IMAGE,8},
|
||||||
{ VIMS_CHAIN_GET_PARAMETERS,4},
|
{ VIMS_CHAIN_GET_PARAMETERS,4},
|
||||||
{ VIMS_GET_SHM,SHM_ID_LEN },
|
{ VIMS_GET_SHM,SHM_ID_LEN },
|
||||||
{ VIMS_GET_STREAM_ARGS, 3 },
|
{ VIMS_GET_STREAM_ARGS, 3 },
|
||||||
{ VIMS_GET_GENERATORS,5 },
|
{ VIMS_GET_GENERATORS,5 },
|
||||||
{ 0,0 },
|
{ 0,0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static vj_client *sayvims_connect(void)
|
static vj_client *sayvims_connect(void)
|
||||||
{
|
{
|
||||||
vj_client *client = vj_client_alloc( 0,0,0 );
|
vj_client *client = vj_client_alloc( 0,0,0 );
|
||||||
if(!client)
|
if(!client)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(host_name == NULL)
|
if(host_name == NULL)
|
||||||
host_name = strdup( "localhost" );
|
host_name = strdup( "localhost" );
|
||||||
|
|
||||||
if(!vj_client_connect( client, host_name,group_name, port_num ))
|
if(!vj_client_connect( client, host_name,group_name, port_num ))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Unable to connect to %s:%d\n", host_name, port_num );
|
fprintf(stderr,"Unable to connect to %s:%d\n", host_name, port_num );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reconnect(void)
|
static void reconnect(void)
|
||||||
{
|
{
|
||||||
if( sayvims )
|
if( sayvims )
|
||||||
{
|
{
|
||||||
vj_client_close(sayvims);
|
vj_client_close(sayvims);
|
||||||
vj_client_free(sayvims);
|
vj_client_free(sayvims);
|
||||||
}
|
}
|
||||||
|
|
||||||
sayvims = sayvims_connect();
|
sayvims = sayvims_connect();
|
||||||
if( sayvims == NULL )
|
if( sayvims == NULL )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to make a connection with %s:%d\n", host_name, port_num);
|
fprintf(stderr, "Unable to make a connection with %s:%d\n", host_name, port_num);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vjsend( int cmd, unsigned char *buf )
|
static int vjsend( int cmd, unsigned char *buf )
|
||||||
{
|
{
|
||||||
/* bad-check if connection is still up */
|
/* bad-check if connection is still up */
|
||||||
if(!sayvims->mcast) {
|
if(!sayvims->mcast) {
|
||||||
int foobar = vj_client_poll(sayvims, V_CMD );
|
int foobar = vj_client_poll(sayvims, V_CMD );
|
||||||
if( foobar && vj_client_link_can_read(sayvims, V_CMD) )
|
if( foobar && vj_client_link_can_read(sayvims, V_CMD) )
|
||||||
{
|
{
|
||||||
unsigned char dummy[8];
|
unsigned char dummy[8];
|
||||||
/* read one byte will fail if connection is closed */
|
/* read one byte will fail if connection is closed */
|
||||||
/* nb: only vims query messages write something to V_CMD (vims 400-499)*/
|
/* nb: only vims query messages write something to V_CMD (vims 400-499)*/
|
||||||
int res = vj_client_read(sayvims, V_CMD, dummy, 1);
|
int res = vj_client_read(sayvims, V_CMD, dummy, 1);
|
||||||
if( res <= 0 ) {
|
if( res <= 0 ) {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* strip newline */
|
/* strip newline */
|
||||||
size_t index = strcspn( (char*) buf,"\n\r");
|
size_t index = strcspn( (char*) buf,"\n\r");
|
||||||
if (index)
|
if (index)
|
||||||
buf[ index ] = '\0';
|
buf[ index ] = '\0';
|
||||||
|
|
||||||
if( index == 0 )
|
if( index == 0 )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* send buffer */
|
/* send buffer */
|
||||||
int result = vj_client_send( sayvims,cmd, buf);
|
int result = vj_client_send( sayvims,cmd, buf);
|
||||||
if( result <= 0)
|
if( result <= 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to send message '%s'\n", buf );
|
fprintf(stderr, "Unable to send message '%s'\n", buf );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
if(verbose)
|
||||||
|
fprintf(stdout, "%s\n", buf);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vimsReplyLength(int vims_id)
|
static int vimsReplyLength(int vims_id)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; vims_replies[i].vims != 0; i ++ ) {
|
for( i = 0; vims_replies[i].vims != 0; i ++ ) {
|
||||||
if( vims_replies[i].vims == vims_id )
|
if( vims_replies[i].vims == vims_id )
|
||||||
return vims_replies[i].hdr;
|
return vims_replies[i].hdr;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *vimsReply(int expectedLen, int *actualWritten)
|
static unsigned char *vimsReply(int expectedLen, int *actualWritten)
|
||||||
{
|
{
|
||||||
if( expectedLen <= 0 )
|
if( expectedLen <= 0 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int hdrLen = expectedLen + 1;
|
int hdrLen = expectedLen + 1;
|
||||||
char header[hdrLen];
|
char header[hdrLen];
|
||||||
|
|
||||||
memset( header, 0, sizeof(header) );
|
memset( header, 0, sizeof(header) );
|
||||||
|
|
||||||
int result = vj_client_read( sayvims, V_CMD, (unsigned char*) header, expectedLen );
|
int result = vj_client_read( sayvims, V_CMD, (unsigned char*) header, expectedLen );
|
||||||
if( result == -1 )
|
if( result == -1 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int dataLen = 0;
|
int dataLen = 0;
|
||||||
if( sscanf( header, "%d", &dataLen ) != 1 )
|
if( sscanf( header, "%d", &dataLen ) != 1 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unsigned char *data = NULL;
|
unsigned char *data = NULL;
|
||||||
if( result <= 0 || dataLen <= 0 || expectedLen <= 0 )
|
if( result <= 0 || dataLen <= 0 || expectedLen <= 0 )
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
data = (unsigned char*) vj_calloc( sizeof(unsigned char) * (dataLen + 1));
|
data = (unsigned char*) vj_calloc( sizeof(unsigned char) * (dataLen + 1));
|
||||||
*actualWritten = vj_client_read( sayvims, V_CMD, data, dataLen );
|
*actualWritten = vj_client_read( sayvims, V_CMD, data, dataLen );
|
||||||
if( *actualWritten == -1 )
|
if( *actualWritten == -1 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *vimsAnswer(int len)
|
static unsigned char *vimsAnswer(int len)
|
||||||
{
|
{
|
||||||
unsigned char *tmp = (unsigned char*) vj_calloc( sizeof(unsigned char) * (len+1));
|
unsigned char *tmp = (unsigned char*) vj_calloc( sizeof(unsigned char) * (len+1));
|
||||||
int result = vj_client_read( sayvims, V_CMD, tmp, len );
|
int result = vj_client_read( sayvims, V_CMD, tmp, len );
|
||||||
if( result == -1 )
|
if( result == -1 )
|
||||||
{
|
{
|
||||||
free(tmp);
|
free(tmp);
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vimsMustReadReply(char *msg, int *vims_event_id)
|
static int vimsMustReadReply(char *msg, int *vims_event_id)
|
||||||
{
|
{
|
||||||
int mustRead = 0;
|
int mustRead = 0;
|
||||||
int vims_id = 0;
|
int vims_id = 0;
|
||||||
if( sscanf( msg, "%d:", &vims_id ) ) {
|
if( sscanf( msg, "%d:", &vims_id ) ) {
|
||||||
if( vims_id >= 400 && vims_id <= 499 )
|
if( vims_id >= 400 && vims_id <= 499 )
|
||||||
mustRead = 1;
|
mustRead = 1;
|
||||||
}
|
}
|
||||||
*vims_event_id = vims_id;
|
*vims_event_id = vims_id;
|
||||||
|
|
||||||
return mustRead;
|
return mustRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count played frames (delay) */
|
/* count played frames (delay) */
|
||||||
static int vj_flush(int frames) {
|
static int vj_flush(int frames) {
|
||||||
|
|
||||||
char status[512];
|
char status[512];
|
||||||
memset(status,0,sizeof(status));
|
memset(status,0,sizeof(status));
|
||||||
|
|
||||||
while(frames>0) {
|
while(frames>0) {
|
||||||
if( vj_client_poll(sayvims, V_STATUS ))
|
if( vj_client_poll(sayvims, V_STATUS ))
|
||||||
{
|
{
|
||||||
char sta_len[6];
|
char sta_len[6];
|
||||||
memset( sta_len,0,sizeof(sta_len));
|
memset( sta_len,0,sizeof(sta_len));
|
||||||
int nb = vj_client_read( sayvims, V_STATUS, (unsigned char*) sta_len, 5 );
|
int nb = vj_client_read( sayvims, V_STATUS, (unsigned char*) sta_len, 5 );
|
||||||
if( nb <= 0 )
|
if( nb <= 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(sta_len[0] == 'V' )
|
if(sta_len[0] == 'V' )
|
||||||
{
|
{
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
sscanf( sta_len + 1, "%03d", &bytes );
|
sscanf( sta_len + 1, "%03d", &bytes );
|
||||||
if(bytes > 0 )
|
if(bytes > 0 )
|
||||||
{
|
{
|
||||||
memset( status,0, sizeof(status));
|
memset( status,0, sizeof(status));
|
||||||
int n = vj_client_read(sayvims,V_STATUS,(unsigned char*) status,bytes);
|
int n = vj_client_read(sayvims,V_STATUS,(unsigned char*) status,bytes);
|
||||||
if( n )
|
if( n )
|
||||||
{
|
{
|
||||||
if(dump) fprintf(stdout , "%s\n", status );
|
if(dump) fprintf(stdout , "%s\n", status );
|
||||||
frames -- ;
|
frames -- ;
|
||||||
}
|
}
|
||||||
else if(n == -1)
|
else if(n == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading status from Veejay\n");
|
fprintf(stderr, "Error reading status from Veejay\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int processLine(FILE *infile, FILE *outfile, char *tmp, size_t len)
|
static int processLine(FILE *infile, FILE *outfile, char *tmp, size_t len)
|
||||||
{
|
{
|
||||||
int line_len = getline( &tmp, &len, infile );
|
int line_len = getline( &tmp, &len, infile );
|
||||||
|
|
||||||
if( line_len > 0 )
|
if( line_len > 0 )
|
||||||
{
|
{
|
||||||
tmp[line_len] = '\0';
|
tmp[line_len] = '\0';
|
||||||
|
|
||||||
if( strncmp( "quit", tmp,4 ) == 0 )
|
if( strncmp( "quit", tmp,4 ) == 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if( tmp[0] == '+' )
|
if( tmp[0] == '+' )
|
||||||
{
|
{
|
||||||
int wait_frames_ = 1;
|
int wait_frames_ = 1;
|
||||||
if( sscanf( tmp + 1, "%d" , &wait_frames_ ) == 1 ) {
|
if( sscanf( tmp + 1, "%d" , &wait_frames_ ) == 1 ) {
|
||||||
if( vj_flush( wait_frames_ ) == 0)
|
if(verbose)
|
||||||
return 0;
|
fprintf(stdout, "wait %d frames\n", wait_frames_);
|
||||||
}
|
if( vj_flush( wait_frames_ ) == 0)
|
||||||
}
|
return 0;
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
int vims_id = 0;
|
else
|
||||||
int mustRead = vimsMustReadReply( tmp, &vims_id );
|
{
|
||||||
|
int vims_id = 0;
|
||||||
|
int mustRead = vimsMustReadReply( tmp, &vims_id );
|
||||||
|
|
||||||
if( vjsend( V_CMD, (unsigned char*) tmp ) == 0 )
|
if( vjsend( V_CMD, (unsigned char*) tmp ) == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( mustRead )
|
if( mustRead )
|
||||||
{
|
{
|
||||||
if( vims_id == VIMS_GET_SHM )
|
if( vims_id == VIMS_GET_SHM )
|
||||||
{
|
{
|
||||||
unsigned char *data = vimsAnswer( SHM_ID_LEN );
|
unsigned char *data = vimsAnswer( SHM_ID_LEN );
|
||||||
if( data != NULL )
|
if( data != NULL )
|
||||||
{
|
{
|
||||||
if( outfile != NULL )
|
if( outfile != NULL )
|
||||||
fwrite( data, sizeof(unsigned char), SHM_ID_LEN, outfile);
|
fwrite( data, sizeof(unsigned char), SHM_ID_LEN, outfile);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( vims_id == VIMS_GET_IMAGE )
|
else if ( vims_id == VIMS_GET_IMAGE )
|
||||||
{
|
{
|
||||||
int headerLength = vimsReplyLength( vims_id );
|
int headerLength = vimsReplyLength( vims_id );
|
||||||
int dataLength = 0;
|
int dataLength = 0;
|
||||||
unsigned char *data = vimsReply( headerLength, &dataLength);
|
unsigned char *data = vimsReply( headerLength, &dataLength);
|
||||||
char *out = NULL;
|
char *out = NULL;
|
||||||
if( data != NULL )
|
if( data != NULL )
|
||||||
{
|
{
|
||||||
if( outfile == NULL )
|
if( outfile == NULL )
|
||||||
goto skip_img_read;
|
goto skip_img_read;
|
||||||
|
|
||||||
if( base64_encode )
|
if( base64_encode )
|
||||||
{
|
{
|
||||||
#ifdef BASE64_AVUTIL
|
#ifdef BASE64_AVUTIL
|
||||||
int b64len = AV_BASE64_SIZE( dataLength );
|
int b64len = AV_BASE64_SIZE( dataLength );
|
||||||
out = (char*) vj_calloc( sizeof(char) * b64len );
|
out = (char*) vj_calloc( sizeof(char) * b64len );
|
||||||
char *b64str = av_base64_encode( out, b64len, data, dataLength );
|
char *b64str = av_base64_encode( out, b64len, data, dataLength );
|
||||||
if( b64str != NULL ) {
|
if( b64str != NULL ) {
|
||||||
fwrite( b64str, sizeof(char), b64len, outfile);
|
fwrite( b64str, sizeof(char), b64len, outfile);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
fwrite(data,sizeof(char),dataLength,outfile);
|
fwrite(data,sizeof(char),dataLength,outfile);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fwrite( data, sizeof(char), dataLength, outfile);
|
fwrite( data, sizeof(char), dataLength, outfile);
|
||||||
}
|
}
|
||||||
if( out != NULL )
|
if( out != NULL )
|
||||||
free(out);
|
free(out);
|
||||||
skip_img_read:
|
skip_img_read:
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int headerLength = vimsReplyLength( vims_id );
|
int headerLength = vimsReplyLength( vims_id );
|
||||||
int dataLength = 0;
|
int dataLength = 0;
|
||||||
unsigned char *data = vimsReply( headerLength, &dataLength);
|
unsigned char *data = vimsReply( headerLength, &dataLength);
|
||||||
if( data != NULL )
|
if( data != NULL )
|
||||||
{
|
{
|
||||||
if( outfile != NULL )
|
if( outfile != NULL )
|
||||||
fwrite( data, sizeof(unsigned char), dataLength, outfile);
|
fwrite( data, sizeof(unsigned char), dataLength, outfile);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if( outfile )
|
if( outfile )
|
||||||
fflush(outfile);
|
fflush(outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (line_len < 0)
|
else if (line_len < 0)
|
||||||
{
|
{
|
||||||
if( is_fifo )
|
if( is_fifo )
|
||||||
return 0; /* wait for more input */
|
return 0; /* wait for more input */
|
||||||
|
|
||||||
if(errno == 0) /* end of file reached */
|
if(errno == 0) /* end of file reached */
|
||||||
fprintf(stderr, "EOF reached\n");
|
fprintf(stderr, "EOF reached\n");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1; //wait for more input
|
return 1; //wait for more input
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Usage(char *progname)
|
static void Usage(char *progname)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s [options] [messages]\n",progname);
|
fprintf(stderr, "Usage: %s [options] [messages]\n",progname);
|
||||||
fprintf(stderr, "where options are:\n");
|
fprintf(stderr, "where options are:\n");
|
||||||
fprintf(stderr, " -p\t\tVeejay port (3490)\n");
|
fprintf(stderr, " -p\t\tVeejay port (3490)\n");
|
||||||
fprintf(stderr, " -g\t\tVeejay groupname (224.0.0.31)\n");
|
fprintf(stderr, " -g\t\tVeejay groupname (224.0.0.31)\n");
|
||||||
fprintf(stderr, " -h\t\tVeejay hostname (localhost)\n");
|
fprintf(stderr, " -h\t\tVeejay hostname (localhost)\n");
|
||||||
fprintf(stderr, " -m\t\tSend single message\n");
|
fprintf(stderr, " -m\t\tSend single message\n");
|
||||||
fprintf(stderr, " -i\t\tInteractive mode\n");
|
fprintf(stderr, " -i\t\tInteractive mode\n");
|
||||||
fprintf(stderr, " -f file\tRead from (special) file\n");
|
fprintf(stderr, " -f file\tRead from (special) file\n");
|
||||||
fprintf(stderr, " -d\t\tDump status to stdout\n");
|
fprintf(stderr, " -d\t\tDump status to stdout\n");
|
||||||
fprintf(stderr, " -b\t\tBase64 encode binary data\n");
|
fprintf(stderr, " -b\t\tBase64 encode binary data\n");
|
||||||
fprintf(stderr, " -v\t\tVerbose\n");
|
fprintf(stderr, " -v\t\tVerbose\n");
|
||||||
fprintf(stderr, " -?\t\tPrint this help\n");
|
fprintf(stderr, " -?\t\tPrint this help\n");
|
||||||
fprintf(stderr, "\nExit interactive mode by typing 'quit'\n");
|
fprintf(stderr, "\nExit interactive mode by typing 'quit'\n");
|
||||||
fprintf(stderr, "Messages to send to veejay must be wrapped in quotes\n");
|
fprintf(stderr, "Messages to send to veejay must be wrapped in quotes\n");
|
||||||
fprintf(stderr, "VIMS reply messages are only displayed in interactive mode.\n");
|
fprintf(stderr, "VIMS reply messages are only displayed in interactive mode.\n");
|
||||||
fprintf(stderr, "You can send multiple messages by seperating them with a whitespace\n");
|
fprintf(stderr, "You can send multiple messages by seperating them with a whitespace\n");
|
||||||
fprintf(stderr, "Example: %s \"600:;\"\n",progname);
|
fprintf(stderr, "Example: %s \"600:;\"\n",progname);
|
||||||
fprintf(stderr, " (quit veejay)\n");
|
fprintf(stderr, " (quit veejay)\n");
|
||||||
fprintf(stderr, "Example: echo \"%03d:;\" | %s \n", VIMS_QUIT, progname);
|
fprintf(stderr, "Example: echo \"%03d:;\" | %s \n", VIMS_QUIT, progname);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "Example: sayVIMS -h 192.168.100.12 -m \"600:;\"\n");
|
fprintf(stderr, "Example: sayVIMS -h 192.168.100.12 -m \"600:;\"\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "Example: sayVIMS -m \"360:0 0 101 1;\"\n");
|
fprintf(stderr, "Example: sayVIMS -m \"360:0 0 101 1;\"\n");
|
||||||
fprintf(stderr, " (Add effect 'Mirror' to chain entry)\n");
|
fprintf(stderr, " (Add effect 'Mirror' to chain entry)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_option(const char *name, char *value)
|
static int set_option(const char *name, char *value)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if(strcmp(name, "h") == 0 )
|
if(strcmp(name, "h") == 0 )
|
||||||
{
|
{
|
||||||
host_name = strdup(optarg);
|
host_name = strdup(optarg);
|
||||||
if(group_name) err ++;
|
if(group_name) err ++;
|
||||||
}
|
|
||||||
else if(strcmp(name, "g") == 0)
|
|
||||||
{
|
|
||||||
if(host_name) err ++;
|
|
||||||
group_name = strdup( optarg );
|
|
||||||
}
|
|
||||||
else if (strcmp(name, "p") == 0)
|
|
||||||
{
|
|
||||||
port_num = atoi(optarg);
|
|
||||||
}
|
|
||||||
else if (strcmp(name, "i") == 0)
|
|
||||||
{
|
|
||||||
interactive = 1;
|
|
||||||
}
|
|
||||||
else if (strcmp(name, "m") == 0 )
|
|
||||||
{
|
|
||||||
single_msg = 1;
|
|
||||||
msg = strdup( optarg );
|
|
||||||
}
|
}
|
||||||
else if(strcmp(name, "d") == 0)
|
else if(strcmp(name, "g") == 0)
|
||||||
{
|
{
|
||||||
dump = 1;
|
if(host_name) err ++;
|
||||||
}
|
group_name = strdup( optarg );
|
||||||
else if(strcmp(name,"v") == 0 )
|
}
|
||||||
{
|
else if (strcmp(name, "p") == 0)
|
||||||
verbose = 1;
|
{
|
||||||
}
|
port_num = atoi(optarg);
|
||||||
else if(strcmp(name,"b") == 0 )
|
}
|
||||||
{
|
else if (strcmp(name, "i") == 0)
|
||||||
|
{
|
||||||
|
interactive = 1;
|
||||||
|
}
|
||||||
|
else if (strcmp(name, "m") == 0 )
|
||||||
|
{
|
||||||
|
single_msg = 1;
|
||||||
|
msg = strdup( optarg );
|
||||||
|
}
|
||||||
|
else if(strcmp(name, "d") == 0)
|
||||||
|
{
|
||||||
|
dump = 1;
|
||||||
|
}
|
||||||
|
else if(strcmp(name,"v") == 0 )
|
||||||
|
{
|
||||||
|
verbose = 1;
|
||||||
|
}
|
||||||
|
else if(strcmp(name,"b") == 0 )
|
||||||
|
{
|
||||||
#ifdef BASE64_AVUTIL
|
#ifdef BASE64_AVUTIL
|
||||||
base64_encode = 1;
|
base64_encode = 1;
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "compiled without base64 support\n");
|
fprintf(stderr, "compiled without base64 support\n");
|
||||||
err++;
|
err++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if(strcmp(name,"?") == 0)
|
else if(strcmp(name,"?") == 0)
|
||||||
{
|
{
|
||||||
help = 1;
|
help = 1;
|
||||||
}
|
}
|
||||||
else if(strcmp(name,"f") == 0 )
|
else if(strcmp(name,"f") == 0 )
|
||||||
{
|
{
|
||||||
in_file = strdup( optarg );
|
in_file = strdup( optarg );
|
||||||
}
|
}
|
||||||
else err++;
|
else err++;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_work(int stdin_fd, FILE *std_out)
|
static void do_work(int stdin_fd, FILE *std_out)
|
||||||
{
|
{
|
||||||
FILE *instd = stdin;
|
FILE *instd = stdin;
|
||||||
const int len = 1024;
|
const int len = 1024;
|
||||||
if( in_file )
|
if( in_file )
|
||||||
instd = fdopen( stdin_fd, "r" );
|
instd = fdopen( stdin_fd, "r" );
|
||||||
|
|
||||||
char *tmp = (char*) vj_calloc( len );
|
char *tmp = (char*) vj_calloc( len );
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
{
|
{
|
||||||
int result = processLine(instd,std_out, tmp, len);
|
int result = processLine(instd,std_out, tmp, len);
|
||||||
if( result == -1 ) {
|
if( result == -1 ) {
|
||||||
fprintf(stderr, "session ends, bye!\n");
|
fprintf(stderr, "session ends, bye!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memset( tmp, 0, len );
|
memset( tmp, 0, len );
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i = 0;
|
int n = 0;
|
||||||
int n = 0;
|
char option[2];
|
||||||
char option[2];
|
int err = 0;
|
||||||
int err = 0;
|
int std_fd = 0;
|
||||||
int std_fd = 0;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct stat std_stat;
|
struct stat std_stat;
|
||||||
memset( &std_stat, 0, sizeof(std_stat));
|
memset( &std_stat, 0, sizeof(std_stat));
|
||||||
|
|
||||||
veejay_set_debug_level(verbose);
|
veejay_set_debug_level(verbose);
|
||||||
|
|
||||||
// parse commandline parameters
|
// parse commandline parameters
|
||||||
while( ( n = getopt(argc,argv, "h:g:p:f:m:idbv?")) != EOF)
|
while( ( n = getopt(argc,argv, "h:g:p:f:m:idbv?")) != EOF)
|
||||||
{
|
{
|
||||||
sprintf(option,"%c",n);
|
sprintf(option,"%c",n);
|
||||||
err += set_option( option,optarg);
|
err += set_option( option,optarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(help || err || optind > argc)
|
if(help || err || optind > argc)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "veejay sayVIMS %s\n", VERSION );
|
fprintf(stdout, "veejay sayVIMS %s\n", VERSION );
|
||||||
Usage( argv[0] );
|
Usage( argv[0] );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vj_mem_init();
|
vj_mem_init();
|
||||||
|
|
||||||
reconnect();
|
reconnect();
|
||||||
|
|
||||||
if(!sayvims) {
|
if(!sayvims) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( interactive )
|
if( interactive )
|
||||||
{
|
{
|
||||||
fprintf(stdout, "veejay sayVIMS %s\n",VERSION);
|
fprintf(stdout, "veejay sayVIMS %s\n",VERSION);
|
||||||
fprintf(stdout, "\ttype 'quit' or press CTRL-c to exit\n");
|
fprintf(stdout, "\ttype 'quit' or press CTRL-c to exit\n");
|
||||||
fprintf(stdout, "\tsee 'veejay -u' for a list of commands\n");
|
fprintf(stdout, "\tsee 'veejay -u' for a list of commands\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_file)
|
if(in_file)
|
||||||
{
|
{
|
||||||
std_fd = open( in_file, O_RDONLY );
|
std_fd = open( in_file, O_RDONLY );
|
||||||
if(std_fd == -1) {
|
if(std_fd == -1) {
|
||||||
fprintf(stderr, "unable to open file\n");
|
fprintf(stderr, "unable to open file\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( fstat( std_fd, &std_stat ) != 0 ) {
|
if( fstat( std_fd, &std_stat ) != 0 ) {
|
||||||
fprintf(stderr, "unable to stat file: %s\n", strerror(errno));
|
fprintf(stderr, "unable to stat file: %s\n", strerror(errno));
|
||||||
close(std_fd);
|
close(std_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
is_fifo = S_ISFIFO( std_stat.st_mode );
|
is_fifo = S_ISFIFO( std_stat.st_mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(single_msg) /* single message send */
|
if(single_msg) /* single message send */
|
||||||
{
|
{
|
||||||
ret = vjsend( V_CMD, (unsigned char*)msg );
|
ret = vjsend( V_CMD, (unsigned char*)msg );
|
||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do_work( std_fd, ( interactive ? stdout : NULL ) );
|
do_work( std_fd, ( interactive ? stdout : NULL ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vj_client_close(sayvims);
|
vj_client_close(sayvims);
|
||||||
vj_client_free(sayvims);
|
vj_client_free(sayvims);
|
||||||
free(host_name);
|
free(host_name);
|
||||||
|
|
||||||
close(std_fd);
|
close(std_fd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user