Beispiel #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)();
		}
	}
}
 /** 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;
 }
static bool invokeHandler (QVariant &t, const HandlerMap &handlers, int type, const QVariantList &stack) {
	using namespace Nuria;
	auto it = handlers.constFind (type);
	
	if (it != handlers.constEnd ()) {
		Callback cb (*it);
		QVariant result = cb (stack, t);
		
		if (result.isValid ()) {
			t = result;
			return true;
		}
		
	}
	
	// 
	return false;
}
Beispiel #4
0
			/**
			 * The method registers the handler.
			 */
			inline void registerHandlers(const HandlerMap& map)
			{
				this->handlers.insert(map.begin(),map.end());
			}
 /** Removes a registered protocol handler. */
 void removeHandler(const std::string &proto) {
     mHandlers.remove(proto);
 }
Beispiel #6
0
// ----------------------------------------------------------------------------
//
void TextUI::help() {
	for ( HandlerMap::iterator it=function_map.begin(); it != function_map.end(); it++ ) {
		m_text_io.printf( "%-4s - %s\n", (LPCTSTR)(*it).first, (*it).second.m_desc );
	}
}
 void call() 
 {
     m_.call(0, this, 10);
     m_.call(1, this, 20);
 }
Beispiel #8
0
//=========================================================================
scx::Condition Host::connect_request(MessageStream* message,
                                     Request& request,
                                     Response& response)
{
  HandlerMap* h = 0;

  const scx::Uri& uri = request.get_uri();
  const std::string& uripath = scx::Uri::decode(uri.get_path());

  // Check valid path
  if (!check_path(uripath)) {
    response.set_status(http::Status::Forbidden);
    return scx::Close;
  }
  
  // Check http authorization
  if (!check_auth(request,response)) {
    response.set_status(http::Status::Unauthorized);
    return scx::Close;
  }
  
  scx::FilePath path = m_docroot + uripath;
  request.set_path(path);
  
  std::string pathinfo;
  h = lookup_path_map(uripath,pathinfo);
  if (h) {
    // Path mapped module
    request.set_path_info(pathinfo);
  } else {
    // Normal file mapping
    scx::FileStat stat(path);
    if (!stat.exists()) {
      response.set_status(http::Status::NotFound);
      return scx::Close;
    } else if (stat.is_dir()) {
      h = lookup_extn_map(".");
    } else {
      h = lookup_extn_map(uripath);
    }
  }

  check_session(request,response);

  scx::Log log("http.hosts");
  log.attach("id", m_id);
  log.attach("message", request.get_id());
  log.attach("handler", h ? h->get_type() : "NONE");
  log.attach("session", request.get_session() ?
             request.get_session()->get_id() : "NONE");
  log.submit("Handling message");
  
  // Check we have a handler
  if (h == 0) {
    LOG("No handler found for request");
    response.set_status(http::Status::ServiceUnavailable);
    return scx::Close;
  }

  // Invoke the handler
  return h->handle_message(message);
}