mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 17:58:29 +00:00
Continuing on Remote library. ListBase and ListSelection queries are now working.
This commit is contained in:
parent
709afc9806
commit
955e7647d4
8
src/3rdparty/include/sigslot/sigslot.h
vendored
8
src/3rdparty/include/sigslot/sigslot.h
vendored
@ -2220,6 +2220,14 @@ namespace sigslot {
|
||||
pclass->signal_connect(this);
|
||||
}
|
||||
|
||||
bool has_connections(){
|
||||
lock_block<mt_policy> lock(this);
|
||||
if(this->m_connected_slots.size()==0){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void emit(arg1_type a1, arg2_type a2, arg3_type a3)
|
||||
{
|
||||
lock_block<mt_policy> lock(this);
|
||||
|
@ -175,7 +175,7 @@ void Library::Remote::ReadThread(){
|
||||
if(currentQuery->RecieveResults(node,this)){
|
||||
currentQuery->status |= Query::Base::Status::Ended;
|
||||
}else{
|
||||
currentQuery->status |= Query::Base::Status::Canceled;
|
||||
currentQuery->status |= Query::Base::Status::Canceled | Query::Base::Status::Ended;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,11 @@ void Library::Remote::WriteThread(){
|
||||
queryNode.Attributes()["options"] = boost::lexical_cast<std::string>(query->options);
|
||||
}
|
||||
|
||||
query->SendQuery(queryNode);
|
||||
if(!query->SendQuery(queryNode)){
|
||||
// Query can not be send, lets cancel it
|
||||
boost::mutex::scoped_lock lock(this->libraryMutex);
|
||||
query->status |= Query::Base::Status::Canceled | Query::Base::Status::Ended;
|
||||
}
|
||||
|
||||
// Check if writer has quit
|
||||
if(writer.Exited()){
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <core/Query/ListBase.h>
|
||||
#include <core/Library/Base.h>
|
||||
#include <core/Common.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace musik::core;
|
||||
|
||||
@ -251,26 +252,31 @@ bool Query::ListBase::SendResults(musik::core::xml::WriterNode &queryNode,Librar
|
||||
|
||||
}
|
||||
|
||||
if(!continueSending){
|
||||
boost::mutex::scoped_lock lock(library->oResultMutex);
|
||||
// Check for trackinfo update
|
||||
musik::core::xml::WriterNode trackInfoNode(queryNode,"trackinfo");
|
||||
trackInfoNode.Content() = boost::lexical_cast<std::string>( trackInfoTracks );
|
||||
trackInfoNode.Content() += ","+boost::lexical_cast<std::string>( trackInfoDuration );
|
||||
trackInfoNode.Content() += ","+boost::lexical_cast<std::string>( trackInfoSize );
|
||||
}else{
|
||||
if(continueSending){
|
||||
if( metadataResultsCopy.empty() && trackResultsCopy.empty() ){
|
||||
// Yield for more results
|
||||
boost::thread::yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(library->oResultMutex);
|
||||
// Check for trackinfo update
|
||||
musik::core::xml::WriterNode trackInfoNode(queryNode,"trackinfo");
|
||||
trackInfoNode.Content() = boost::lexical_cast<std::string>( this->trackInfoTracks );
|
||||
trackInfoNode.Content() += ","+boost::lexical_cast<std::string>( this->trackInfoDuration );
|
||||
trackInfoNode.Content() += ","+boost::lexical_cast<std::string>( this->trackInfoSize );
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Query::ListBase::RecieveResults(musik::core::xml::ParserNode &queryNode,Library::Base *library){
|
||||
while( musik::core::xml::ParserNode node = queryNode.ChildNode() ){
|
||||
|
||||
// Recieve metadata
|
||||
if( node.Name()=="metadata"){
|
||||
|
||||
std::string metakey(node.Attributes()["key"]);
|
||||
@ -310,6 +316,59 @@ bool Query::ListBase::RecieveResults(musik::core::xml::ParserNode &queryNode,Lib
|
||||
|
||||
|
||||
}
|
||||
|
||||
typedef std::vector<std::string> StringVector;
|
||||
|
||||
// Recieve tracks
|
||||
if( node.Name()=="tracklist"){
|
||||
while( musik::core::xml::ParserNode tracksNode = node.ChildNode("tracks") ){
|
||||
tracksNode.WaitForContent();
|
||||
|
||||
StringVector values;
|
||||
boost::algorithm::split(values,tracksNode.Content(),boost::algorithm::is_any_of(","));
|
||||
|
||||
try{ // lexical_cast can throw
|
||||
TrackVector tempTrackResults;
|
||||
tempTrackResults.reserve(101);
|
||||
|
||||
for(StringVector::iterator value=values.begin();value!=values.end();++value){
|
||||
int trackId(boost::lexical_cast<DBINT>(*value));
|
||||
tempTrackResults.push_back(TrackPtr(new Track(trackId)));
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(library->oResultMutex);
|
||||
this->trackResults.insert(this->trackResults.end(),tempTrackResults.begin(),tempTrackResults.end());
|
||||
}
|
||||
|
||||
}
|
||||
catch(...){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Recieve trackinfo
|
||||
if( node.Name()=="trackinfo"){
|
||||
node.WaitForContent();
|
||||
|
||||
StringVector values;
|
||||
boost::algorithm::split(values,node.Content(),boost::algorithm::is_any_of(","));
|
||||
|
||||
if(values.size()>=3){
|
||||
try{
|
||||
boost::mutex::scoped_lock lock(library->oResultMutex);
|
||||
this->trackInfoTracks = boost::lexical_cast<UINT64>( values[0] );
|
||||
this->trackInfoDuration = boost::lexical_cast<UINT64>( values[1] );
|
||||
this->trackInfoSize = boost::lexical_cast<UINT64>( values[2] );
|
||||
}
|
||||
catch(...){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -571,11 +571,12 @@ bool Query::ListSelection::RecieveQuery(musik::core::xml::ParserNode &queryNode)
|
||||
|
||||
while( musik::core::xml::ParserNode node = queryNode.ChildNode() ){
|
||||
if(node.Name()=="selections"){
|
||||
|
||||
std::cout << "<selections>";
|
||||
// Get metakey nodes
|
||||
// Expected tag is likle this:
|
||||
// <selection key="genre">2,5,3</selection>
|
||||
while( musik::core::xml::ParserNode selectionNode = node.ChildNode("selection") ){
|
||||
std::cout << "<selection key=\"" << selectionNode.Attributes()["key"] << "\">";
|
||||
|
||||
// Wait for all content
|
||||
selectionNode.WaitForContent();
|
||||
@ -587,9 +588,13 @@ bool Query::ListSelection::RecieveQuery(musik::core::xml::ParserNode &queryNode)
|
||||
|
||||
for(StringVector::iterator value=values.begin();value!=values.end();++value){
|
||||
this->SelectMetadata(selectionNode.Attributes()["key"].c_str(),boost::lexical_cast<DBINT>(*value));
|
||||
std::cout << "," << *value;
|
||||
}
|
||||
std::cout << "</selection>" << std::endl;
|
||||
|
||||
}
|
||||
std::cout << "</selections>" << std::endl;
|
||||
|
||||
}else if(node.Name()=="listeners"){
|
||||
|
||||
// Wait for all content
|
||||
@ -656,6 +661,16 @@ bool Query::ListSelection::SendQuery(musik::core::xml::WriterNode &queryNode){
|
||||
listenersNode.Content().append(listener->first);
|
||||
}
|
||||
}
|
||||
// Then the track listener
|
||||
if( this->trackEvent.has_connections() ){
|
||||
xml::WriterNode listTracksNode(queryNode,"listtracks");
|
||||
listTracksNode.Content().append("true");
|
||||
}
|
||||
// Then the track listener
|
||||
if( this->trackInfoEvent.has_connections() ){
|
||||
xml::WriterNode listTrackInfoNode(queryNode,"listtrackinfo");
|
||||
listTrackInfoNode.Content().append("true");
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ void Parser::OnElementEndReal(const char *name){
|
||||
if(this->currentNodeLevels.size()>0){
|
||||
if(this->currentNodeLevels.back()->name == name){
|
||||
|
||||
this->currentNodeLevels.back()->status = Node::Status::Ended;
|
||||
this->currentNodeLevels.back()->status |= Node::Status::Ended;
|
||||
this->currentNodeLevels.pop_back();
|
||||
|
||||
this->currentEventType = EventTypes::NodeEnd;
|
||||
|
@ -138,7 +138,7 @@ std::string& ParserNode::Content(){
|
||||
//////////////////////////////////////////
|
||||
void ParserNode::WaitForContent(){
|
||||
if(this->node && this->status==1){
|
||||
while(this->node->status!=Node::Status::Ended){
|
||||
while( !(this->node->status & Node::Status::Ended) ){
|
||||
// Wait for node to be ended
|
||||
this->parser->ContinueParsing();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user