rsked/vlcplayer.cc
/// Takes apart the status response into state, volume and resource
///  'stopped' : PlayerState::Stopped
///  'playing' : PlayerState::Playing
///  'paused'  : PlayerState::Paused
/// Returns true if a normal status response is parsed, othewise false.
///
/// * May throw std::runtime_error in VERY rare circumstances
///


May throw std::runtime_error in VERY rare circumstances
May throw std :: runtime_error in VERY rare circumstances
static bool
parse_status( const std::string &sresp1, PlayerState &pstate,
                   unsigned &obsvol, std::string &resource)
{
   std::string::const_iterator start, end;
   start = sresp1.begin();
   end = sresp1.end();
   boost::match_results<std::string::const_iterator> what;
   boost::match_flag_type flags = boost::match_default;
   bool parsedp {false};
   while(regex_search(start, end, what, Status_regex, flags))
   {
       std::string skey(what[1].first, what[1].second);
       std::string sval(what[2].first, what[2].second);
       parsedp = true;
       if (skey == "audio volume") {
           try {
               obsvol = static_cast<unsigned>( std::stoul(sval) );
           } catch(...) {
               LOG_WARNING(Lgr) << "Vlc reports odd volume: " << sval;
           }
       }
       else if (skey == "status") {
           if ("stopped" == sval) { pstate = PlayerState::Stopped; }
           else if ("playing" == sval) { pstate = PlayerState::Playing; }
           else if ("paused" == sval) { pstate = PlayerState::Paused; }
           else {
               LOG_ERROR(Lgr) << "VLC unexpected status: '" << sval << "'";
               pstate=PlayerState::Broken;
           }
       }
       else if (skey == "new input") {
           resource = sval;   
       }
       start = what[0].second;  
       flags |= boost::match_prev_avail;
       flags |= boost::match_not_bob;
   }
   return parsedp;
}
static bool parse_status ( const std :: string & sresp1 , PlayerState & pstate , unsigned & obsvol , std :: string & resource ) { std :: string :: const_iterator start , end ; start = sresp1 . begin ( ) ; end = sresp1 . end ( ) ; boost :: match_results < std :: string :: const_iterator > what ; boost :: match_flag_type flags = boost :: match_default ; bool parsedp { false } ; while ( regex_search ( start , end , what , Status_regex , flags ) ) { std :: string skey ( what [ 1 ] . first , what [ 1 ] . second ) ; std :: string sval ( what [ 2 ] . first , what [ 2 ] . second ) ; parsedp = true ; if ( skey == " " ) { try { obsvol = static_cast < unsigned > ( std :: stoul ( sval ) ) ; } catch ( ... ) { LOG_WARNING ( Lgr ) << " " << sval ; } } else if ( skey == " " ) { if ( " " == sval ) { pstate = PlayerState :: Stopped ; } else if ( " " == sval ) { pstate = PlayerState :: Playing ; } else if ( " " == sval ) { pstate = PlayerState :: Paused ; } else { LOG_ERROR ( Lgr ) << " " << sval << " " ; pstate = PlayerState :: Broken ; } } else if ( skey == " " ) { resource = sval ; } start = what [ 0 ] . second ; flags |= boost :: match_prev_avail ; flags |= boost :: match_not_bob ; } return parsedp ; }
Takes apart the status response into state, volume and resource
'stopped' : PlayerState::Stopped
'playing' : PlayerState::Playing
'paused'  : PlayerState::Paused
Returns true if a normal status response is parsed, othewise false.
Takes apart the status response into state volume and resource ' stopped ' : PlayerState :: Stopped ' playing ' : PlayerState :: Playing ' paused ' : PlayerState :: Paused Returns true if a normal status response is parsed othewise false .
// can throw std::invalid_argument // TODO: maybe trim any file:// prefix? // move to the next sexpr