예제 #1
0
 // add a single result
 void add_result( ri_ptr rip )
 {
     if (!m_cancelled) {
         boost::mutex::scoped_lock lock(m_mut);
         if (rip->score() == 1.0) {
             m_solved = true;
         }
         m_results.push_back(rip);
         // fire callbacks:
         BOOST_FOREACH(rq_callback_t & cb, m_callbacks) {
             cb(id(), rip);
         }
예제 #2
0
 bool sorter(const ri_ptr & lhs, const ri_ptr & rhs)
 {
     // if equal scores, prefer item with higher preference
     // usually this indicates network reliability or user-configured preference
     if( lhs->score() == rhs->score() )
     {
         return lhs->preference() > rhs->preference();
     }
     return lhs->score() > rhs->score();
 }
예제 #3
0
파일: lan.cpp 프로젝트: dsingleton/playdar
// fired when a new result is available for a running query:
void
lan::send_response( query_uid qid, 
                        ri_ptr rip,
                        boost::asio::ip::udp::endpoint sep )
{
    //cout << "lan responding for " << qid << " to: " 
    //     << sep.address().to_string() 
    //     << " score: " << rip->score()
    //     << endl;
    using namespace json_spirit;
    Object response;
    response.push_back( Pair("_msgtype", "result") );
    response.push_back( Pair("qid", qid) );
    Object result = rip->get_json();
    response.push_back( Pair("result", result) );
    ostringstream ss;
    write_formatted( response, ss );
    async_send(&sep, ss.str());
}
예제 #4
0
    void add_result(ri_ptr rip) 
    { 
        //cout << "RQ.add_result: "<< pip->score() <<"\t"
        //     << pip->artist() << " - " << pip->track() << endl;
        {
            boost::mutex::scoped_lock lock(m_mut);
            m_results.push_back(rip); 
        }
        // decide if this result "solves" the query:
        // for now just assume score of 1 means solved.
        if(rip->score() == 1.0) 
        {
//            cout << "SOLVED " << id() << endl;   
            m_solved = true;
        }
        // fire callbacks:
        BOOST_FOREACH(rq_callback_t & cb, m_callbacks)
        {
            cb(id(), rip);
        }