X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmiracle%2Fmiracle_local.c;h=c1029a19d828530f712ed605e998370692f58dcc;hb=728c83b4335c25e43f90eb5d4bab5b86107ca21c;hp=51f35f804a27f6c646c73e709fafa857eda8df66;hpb=a748638a86c7023aa12e7ca6e49813821fe804fd;p=melted diff --git a/src/miracle/miracle_local.c b/src/miracle/miracle_local.c index 51f35f8..c1029a1 100644 --- a/src/miracle/miracle_local.c +++ b/src/miracle/miracle_local.c @@ -26,7 +26,11 @@ #include #include #include + +/* Needed for backtrace on linux */ +#ifdef linux #include +#endif /* Valerie header files */ #include @@ -56,6 +60,8 @@ typedef struct static valerie_response miracle_local_connect( miracle_local ); static valerie_response miracle_local_execute( miracle_local, char * ); +static valerie_response miracle_local_push( miracle_local, char *, mlt_service ); +static valerie_response miracle_local_receive( miracle_local, char *, char * ); static void miracle_local_close( miracle_local ); response_codes miracle_help( command_argument arg ); response_codes miracle_run( command_argument arg ); @@ -75,6 +81,8 @@ valerie_parser miracle_parser_init_local( ) parser->connect = (parser_connect)miracle_local_connect; parser->execute = (parser_execute)miracle_local_execute; + parser->push = (parser_push)miracle_local_push; + parser->received = (parser_received)miracle_local_receive; parser->close = (parser_close)miracle_local_close; parser->real = local; @@ -97,7 +105,7 @@ valerie_parser miracle_parser_init_local( ) typedef struct { int code; - char *message; + const char *message; } responses_t; @@ -138,7 +146,7 @@ arguments_types; typedef struct { /* The command string corresponding to this operation (e.g. "play") */ - char *command; + const char *command; /* The function associated with it */ response_codes (*operation) ( command_argument ); /* a boolean to indicate if this is a unit or global command @@ -147,7 +155,7 @@ typedef struct /* What type is the argument (RTTI :-) ATYPE_whatever */ int type; /* online help information */ - char *help; + const char *help; } command_t; @@ -174,6 +182,7 @@ static command_t vocabulary[] = {"INSERT", miracle_insert, 1, ATYPE_STRING, "Insert a clip at the given clip index."}, {"REMOVE", miracle_remove, 1, ATYPE_NONE, "Remove a clip at the given clip index."}, {"CLEAN", miracle_clean, 1, ATYPE_NONE, "Clean a unit by removing all but the currently playing clip."}, + {"WIPE", miracle_wipe, 1, ATYPE_NONE, "Clean a unit by removing everything before the currently playing clip."}, {"CLEAR", miracle_clear, 1, ATYPE_NONE, "Clear a unit by removing all clips."}, {"MOVE", miracle_move, 1, ATYPE_INT, "Move a clip to another clip index."}, {"APND", miracle_append, 1, ATYPE_STRING, "Append a clip specified in absolute filename argument."}, @@ -208,7 +217,7 @@ static char helpstr [] = /** Lookup the response message for a status code. */ -inline char *get_response_msg( int code ) +inline const char *get_response_msg( int code ) { int i = 0; for ( i = 0; responses[ i ].message != NULL && code != responses[ i ].code; i ++ ) ; @@ -291,6 +300,7 @@ void signal_handler( int sig ) static void sigsegv_handler() { +#ifdef linux void *array[ 10 ]; size_t size; char **strings; @@ -309,6 +319,9 @@ static void sigsegv_handler() free( strings ); miracle_log( LOG_CRIT, "\nDone dumping - exiting.\n" ); +#else + miracle_log( LOG_CRIT, "\a\nMiracle experienced a segmentation fault.\n" ); +#endif exit( EXIT_FAILURE ); } @@ -489,14 +502,96 @@ static valerie_response miracle_local_execute( miracle_local local, char *comman return cmd.response; } +static valerie_response miracle_local_receive( miracle_local local, char *command, char *doc ) +{ + command_argument_t cmd; + cmd.parser = local->parser; + cmd.response = valerie_response_init( ); + cmd.tokeniser = valerie_tokeniser_init( ); + cmd.command = command; + cmd.unit = -1; + cmd.argument = NULL; + cmd.root_dir = local->root_dir; + + /* Set the default error */ + miracle_command_set_error( &cmd, RESPONSE_SUCCESS ); + + /* Parse the command */ + if ( valerie_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 ) + { + int index = 0; + int position = 1; + + /* Strip quotes from all tokens */ + for ( index = 0; index < valerie_tokeniser_count( cmd.tokeniser ); index ++ ) + valerie_util_strip( valerie_tokeniser_get_string( cmd.tokeniser, index ), '\"' ); + + cmd.unit = miracle_command_parse_unit( &cmd, position ); + if ( cmd.unit == -1 ) + miracle_command_set_error( &cmd, RESPONSE_MISSING_ARG ); + position ++; + + miracle_receive( &cmd, doc ); + miracle_command_set_error( &cmd, RESPONSE_SUCCESS ); + + free( cmd.argument ); + } + + valerie_tokeniser_close( cmd.tokeniser ); + + return cmd.response; +} + +static valerie_response miracle_local_push( miracle_local local, char *command, mlt_service service ) +{ + command_argument_t cmd; + cmd.parser = local->parser; + cmd.response = valerie_response_init( ); + cmd.tokeniser = valerie_tokeniser_init( ); + cmd.command = command; + cmd.unit = -1; + cmd.argument = NULL; + cmd.root_dir = local->root_dir; + + /* Set the default error */ + miracle_command_set_error( &cmd, RESPONSE_SUCCESS ); + + /* Parse the command */ + if ( valerie_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 ) + { + int index = 0; + int position = 1; + + /* Strip quotes from all tokens */ + for ( index = 0; index < valerie_tokeniser_count( cmd.tokeniser ); index ++ ) + valerie_util_strip( valerie_tokeniser_get_string( cmd.tokeniser, index ), '\"' ); + + cmd.unit = miracle_command_parse_unit( &cmd, position ); + if ( cmd.unit == -1 ) + miracle_command_set_error( &cmd, RESPONSE_MISSING_ARG ); + position ++; + + miracle_push( &cmd, service ); + miracle_command_set_error( &cmd, RESPONSE_SUCCESS ); + + free( cmd.argument ); + } + + valerie_tokeniser_close( cmd.tokeniser ); + + return cmd.response; +} + /** Close the parser. */ static void miracle_local_close( miracle_local local ) { miracle_delete_all_units(); - pthread_kill_other_threads_np(); +#ifdef linux + //pthread_kill_other_threads_np(); miracle_log( LOG_DEBUG, "Clean shutdown." ); - free( local ); + //free( local ); //mlt_factory_close( ); +#endif }