static void *mvcp_remote_status_thread( void *arg ) { mvcp_remote remote = arg; char temp[ 10240 ]; int length = 0; int offset = 0; mvcp_tokeniser tokeniser = mvcp_tokeniser_init( ); mvcp_notifier notifier = mvcp_parser_get_notifier( remote->parser ); mvcp_status_t status; int index = 0; mvcp_socket_write_data( remote->status, "STATUS\r\n", 8 ); temp[ 0 ] = '\0'; while ( !remote->terminated && ( length = mvcp_socket_read_data( remote->status, temp + offset, sizeof( temp ) - 1 ) ) >= 0 ) { if ( length < 0 ) break; temp[ length ] = '\0'; if ( strchr( temp, '\n' ) == NULL ) { offset = length; continue; } offset = 0; mvcp_tokeniser_parse_new( tokeniser, temp, "\n" ); for ( index = 0; index < mvcp_tokeniser_count( tokeniser ); index ++ ) { char *line = mvcp_tokeniser_get_string( tokeniser, index ); if ( line[ strlen( line ) - 1 ] == '\r' ) { mvcp_util_chomp( line ); mvcp_status_parse( &status, line ); mvcp_notifier_put( notifier, &status ); } else { strcpy( temp, line ); offset = strlen( temp ); } } } mvcp_notifier_disconnected( notifier ); mvcp_tokeniser_close( tokeniser ); remote->terminated = 1; return NULL; }
void mvcp_status_parse( mvcp_status status, char *text ) { mvcp_tokeniser tokeniser = mvcp_tokeniser_init( ); if ( mvcp_tokeniser_parse_new( tokeniser, text, " " ) == 17 ) { status->unit = atoi( mvcp_tokeniser_get_string( tokeniser, 0 ) ); strncpy( status->clip, mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser, 2 ), '\"' ), sizeof( status->clip ) ); status->position = atol( mvcp_tokeniser_get_string( tokeniser, 3 ) ); status->speed = atoi( mvcp_tokeniser_get_string( tokeniser, 4 ) ); status->fps = atof( mvcp_tokeniser_get_string( tokeniser, 5 ) ); status->in = atol( mvcp_tokeniser_get_string( tokeniser, 6 ) ); status->out = atol( mvcp_tokeniser_get_string( tokeniser, 7 ) ); status->length = atol( mvcp_tokeniser_get_string( tokeniser, 8 ) ); strncpy( status->tail_clip, mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser, 9 ), '\"' ), sizeof( status->tail_clip ) ); status->tail_position = atol( mvcp_tokeniser_get_string( tokeniser, 10 ) ); status->tail_in = atol( mvcp_tokeniser_get_string( tokeniser, 11 ) ); status->tail_out = atol( mvcp_tokeniser_get_string( tokeniser, 12 ) ); status->tail_length = atol( mvcp_tokeniser_get_string( tokeniser, 13 ) ); status->seek_flag = atoi( mvcp_tokeniser_get_string( tokeniser, 14 ) ); status->generation = atoi( mvcp_tokeniser_get_string( tokeniser, 15 ) ); status->clip_index = atoi( mvcp_tokeniser_get_string( tokeniser, 16 ) ); if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "unknown" ) ) status->status = unit_unknown; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "undefined" ) ) status->status = unit_undefined; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "offline" ) ) status->status = unit_offline; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "not_loaded" ) ) status->status = unit_not_loaded; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "stopped" ) ) status->status = unit_stopped; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "paused" ) ) status->status = unit_paused; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "playing" ) ) status->status = unit_playing; else if ( !strcmp( mvcp_tokeniser_get_string( tokeniser, 1 ), "disconnected" ) ) status->status = unit_disconnected; } else { memset( status, 0, sizeof( mvcp_status_t ) ); fprintf( stderr, "Status thread changed?\n" ); } mvcp_tokeniser_close( tokeniser ); }
static mvcp_response melted_local_push( melted_local local, char *command, mlt_service service ) { command_argument_t cmd; cmd.parser = local->parser; cmd.response = mvcp_response_init( ); cmd.tokeniser = mvcp_tokeniser_init( ); cmd.command = command; cmd.unit = -1; cmd.argument = NULL; cmd.root_dir = local->root_dir; /* Set the default error */ melted_command_set_error( &cmd, RESPONSE_SUCCESS ); /* Parse the command */ if ( mvcp_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 ) { int index = 0; int position = 1; /* Strip quotes from all tokens */ for ( index = 0; index < mvcp_tokeniser_count( cmd.tokeniser ); index ++ ) mvcp_util_strip( mvcp_tokeniser_get_string( cmd.tokeniser, index ), '\"' ); cmd.unit = melted_command_parse_unit( &cmd, position ); if ( cmd.unit == -1 ) melted_command_set_error( &cmd, RESPONSE_MISSING_ARG ); position ++; melted_push( &cmd, service ); melted_command_set_error( &cmd, RESPONSE_SUCCESS ); free( cmd.argument ); } mvcp_tokeniser_close( cmd.tokeniser ); return cmd.response; }
static mvcp_response melted_local_execute( melted_local local, char *command ) { command_argument_t cmd; cmd.parser = local->parser; cmd.response = mvcp_response_init( ); cmd.tokeniser = mvcp_tokeniser_init( ); cmd.command = command; cmd.unit = -1; cmd.argument = NULL; cmd.root_dir = local->root_dir; /* Set the default error */ melted_command_set_error( &cmd, RESPONSE_UNKNOWN_COMMAND ); /* Parse the command */ if ( mvcp_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 ) { int index = 0; char *value = mvcp_tokeniser_get_string( cmd.tokeniser, 0 ); int found = 0; /* Strip quotes from all tokens */ for ( index = 0; index < mvcp_tokeniser_count( cmd.tokeniser ); index ++ ) mvcp_util_strip( mvcp_tokeniser_get_string( cmd.tokeniser, index ), '\"' ); /* Search the vocabulary array for value */ for ( index = 1; !found && vocabulary[ index ].command != NULL; index ++ ) if ( ( found = !strcasecmp( vocabulary[ index ].command, value ) ) ) break; /* If we found something, the handle the args and call the handler. */ if ( found ) { int position = 1; melted_command_set_error( &cmd, RESPONSE_SUCCESS ); if ( vocabulary[ index ].is_unit ) { cmd.unit = melted_command_parse_unit( &cmd, position ); if ( cmd.unit == -1 ) melted_command_set_error( &cmd, RESPONSE_MISSING_ARG ); position ++; } if ( melted_command_get_error( &cmd ) == RESPONSE_SUCCESS ) { cmd.argument = melted_command_parse_argument( &cmd, position, vocabulary[ index ].type, command ); if ( cmd.argument == NULL && vocabulary[ index ].type != ATYPE_NONE ) melted_command_set_error( &cmd, RESPONSE_MISSING_ARG ); position ++; } if ( melted_command_get_error( &cmd ) == RESPONSE_SUCCESS ) { response_codes error = vocabulary[ index ].operation( &cmd ); melted_command_set_error( &cmd, error ); } free( cmd.argument ); } } mvcp_tokeniser_close( cmd.tokeniser ); return cmd.response; }