Ejemplo n.º 1
0
// ----------------------------------------------------------------------------
//
void TextUI::run()
{
	m_running = true;

	m_text_io.printf( "\n\nSpotify API Test Bench - type ? for command list\n\n" );

    m_player->connect();                   // Try to connect using stored credentials

	while ( m_running ) {
        // See if we need to login
        if ( !m_player->isLoggedIn() && !spotify_login( ) )
           break;

        CString label;
        PlayingInfo playing_info;

        if ( m_player->getPlayingTrack( &playing_info ) ) {
            label.Format( "Now %s: %s", "Playing", m_player->getTrackFullName( playing_info.track_link ) );
            label.AppendFormat( " | length %s remaining %s", track_time(playing_info.track_length), track_time(playing_info.time_remaining) );

            if ( m_player->isTrackPaused() )
                label.Append( " | PAUSED" );

		    m_text_io.printf( "\n%s\n", (LPCSTR)label );
        }

		m_text_io.clear();

		m_text_io.printf( "> ", (LPCSTR)label );

		CString cmd;
		int retcode = m_text_io.getString( cmd );
		m_text_io.printf( "\n" );

        if ( !m_player->isLoggedIn() )
            continue;
		if ( retcode != INPUT_SUCCESS )
			continue;
		m_text_io.tokenize( cmd );
		if ( !m_text_io.nextToken( cmd ) )
			continue;

		cmd.MakeLower();

		HandlerMap::iterator it = function_map.find( cmd );
		if ( it == function_map.end() ) {
			m_text_io.printf( "Unrecognized command '%s' - Type ? for list of commands\n", (LPCTSTR)cmd );
		}
		else if ( !m_running && (*it).second.m_running ) {
			m_text_io.printf( "UI must be running to use '%s'\n", (LPCTSTR)cmd );
		}
		else {
		    (this->*(*it).second.m_funcptr)();
		}
	}
}
Ejemplo n.º 2
0
 /** Looks up proto in the map. Returns NULL if no protocol handler was found. */
 const std::string &lookup(const std::string &proto, HandlerPtr &handlerPtr) const {
     typename HandlerMap::const_iterator iter = mHandlers.find(proto);
     if (iter == mHandlers.end()) {
         SILOG(transfer,error,"No protocol handler registered for "<<proto);
         return proto;
     }
     const std::pair<std::string, HandlerPtr> &protoHandler = (*iter).second;
     handlerPtr = protoHandler.second;
     return protoHandler.first;
 }