X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fvalerie%2Fconsumer_valerie.c;h=76a8a1c1901bb9024b5df9e9951333b81f6d29ca;hb=bf3264b9e340ba5c11cbf59835a8af3db94e0cc2;hp=781238d5dd2444da1e3195afa4693b50982e99c6;hpb=de477d594bdd9c5d9ee2d3441cd0ccf49ab52feb;p=melted diff --git a/src/modules/valerie/consumer_valerie.c b/src/modules/valerie/consumer_valerie.c index 781238d..76a8a1c 100644 --- a/src/modules/valerie/consumer_valerie.c +++ b/src/modules/valerie/consumer_valerie.c @@ -1,21 +1,21 @@ /* - * consumer_westley.c -- a libxml2 serialiser of mlt service networks + * consumer_valerie.c -- pushes a service via valerie * Copyright (C) 2003-2004 Ushodaya Enterprises Limited - * Author: Dan Dennedy + * Author: Charles Yates * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "consumer_valerie.h" @@ -46,19 +46,19 @@ mlt_consumer consumer_valerie_init( char *arg ) { char *temp = NULL; int port = atoi( strchr( arg, ':' ) + 1 ); - mlt_properties_set( mlt_consumer_properties( this ), "server", arg ); - temp = mlt_properties_get( mlt_consumer_properties( this ), "server" ); + mlt_properties_set( MLT_CONSUMER_PROPERTIES( this ), "server", arg ); + temp = mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "server" ); *( strchr( temp, ':' ) ) = '\0'; - mlt_properties_set_int( mlt_consumer_properties( this ), "port", port ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "port", port ); } else { - mlt_properties_set( mlt_consumer_properties( this ), "server", arg == NULL ? "localhost" : arg ); - mlt_properties_set_int( mlt_consumer_properties( this ), "port", 5250 ); + mlt_properties_set( MLT_CONSUMER_PROPERTIES( this ), "server", arg == NULL ? "localhost" : arg ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "port", 5250 ); } - mlt_properties_set_int( mlt_consumer_properties( this ), "unit", 0 ); - mlt_properties_set( mlt_consumer_properties( this ), "command", "append" ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "unit", 0 ); + mlt_properties_set( MLT_CONSUMER_PROPERTIES( this ), "command", "append" ); // Allow thread to be started/stopped this->start = consumer_start; @@ -78,23 +78,45 @@ mlt_consumer consumer_valerie_init( char *arg ) static int consumer_start( mlt_consumer this ) { // Get the producer service - mlt_service service = mlt_service_producer( mlt_consumer_service( this ) ); + mlt_service service = mlt_service_producer( MLT_CONSUMER_SERVICE( this ) ); // Get the properties object - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Get all the properties now char *server = mlt_properties_get( properties, "server" ); int port = mlt_properties_get_int( properties, "port" ); - char *command = mlt_properties_get( properties, "command" ); + char *cmd = mlt_properties_get( properties, "command" ); int unit = mlt_properties_get_int( properties, "unit" ); char *title = mlt_properties_get( properties, "title" ); + char command[ 2048 ]; // If this is a reuse, then a valerie object will exist valerie connection = mlt_properties_get_data( properties, "connection", NULL ); + // Special case - we can get a doc too... + char *doc = mlt_properties_get( properties, "westley" ); + + // Set the title if provided if ( service != NULL ) { + if ( title != NULL ) + mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", title ); + else if ( mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "title" ) == NULL ) + mlt_properties_set( MLT_SERVICE_PROPERTIES( service ), "title", "Anonymous Submission" ); + title = mlt_properties_get( MLT_SERVICE_PROPERTIES( service ), "title" ); + } + + strcpy( command, cmd == NULL ? "" : cmd ); + if ( strstr( command, "title=" ) == NULL && title != NULL ) + { + strcat( command, " title=\"" ); + strcat( command, title ); + strcat( command, "\"" ); + } + + if ( service != NULL || doc != NULL ) + { // Initiate the connection if required if ( connection == NULL ) { @@ -108,6 +130,7 @@ static int consumer_start( mlt_consumer this ) else { fprintf( stderr, "Unable to connect to the server at %s:%d\n", server, port ); + mlt_properties_set_int( properties, "_error", 1 ); valerie_close( connection ); valerie_parser_close( parser ); connection = NULL; @@ -117,20 +140,26 @@ static int consumer_start( mlt_consumer this ) // If we have connection, push the service over if ( connection != NULL ) { - int error; + if ( doc == NULL ) + { + int error; - // Set the title if provided - if ( title != NULL ) - mlt_properties_set( mlt_service_properties( service ), "title", title ); - else if ( mlt_properties_get( mlt_service_properties( service ), "title" ) == NULL ) - mlt_properties_set( mlt_service_properties( service ), "title", "Anonymous Submission" ); + // Push the service + error = valerie_unit_push( connection, unit, command, service ); - // Push the service - error = valerie_unit_push( connection, unit, command, service ); + // Report error + if ( error != valerie_ok ) + fprintf( stderr, "Push failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + } + else + { + // Push the service + int error = valerie_unit_receive( connection, unit, command, doc ); - // Report error - if ( error != valerie_ok ) - fprintf( stderr, "Push failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + // Report error + if ( error != valerie_ok ) + fprintf( stderr, "Send failed on %s:%d %s u%d (%d)\n", server, port, command, unit, error ); + } } }