WIP, Remote Client/Server, switching to id

This commit is contained in:
emeric
2014-05-20 13:01:48 +02:00
parent 0825e77abc
commit df74634014
5 changed files with 1450 additions and 1770 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+35 -31
View File
@@ -13,16 +13,12 @@ message AudioCollectionRequest
message GetGenreList
{
optional string filter_name = 1; // Genre that contains 'filterName' in its name
required BatchParameter batch_parameter = 2;
}
message GetArtistList
{
// Search Filters
optional string filter_name = 1; // Artist that contains 'filterName' in its name
repeated string filter_genre = 2; // Artist that has at least a track of the genre
repeated uint64 genre_id = 2; // Artist that has at least a track of the genre
required BatchParameter batch_parameter = 3;
}
@@ -30,9 +26,8 @@ message AudioCollectionRequest
message GetReleaseList
{
// Search filters
optional string filter_name = 1; // Release that contains 'filterName' in its name
repeated string artist_name = 2; // Release that contains at least a track of this artist
repeated string filter_genre = 3; // Release that has at least a track of the genre
repeated uint64 artist_id = 2; // Release that contains at least a track of this artist
repeated uint64 filter_genre = 3; // Release that has at least a track of the genre
optional bool get_cover = 4; // Request cover art for each release
@@ -43,15 +38,14 @@ message AudioCollectionRequest
{
// Search filters
optional string filter_name = 1; // Track that contains 'filterName' in its name
repeated string release_name = 2; // Track that is part of the release
repeated string artist_name = 3; // Track made by this artist
repeated string filter_genre = 4; // Track that has at least a track of the genre
optional uint32 disc_number = 5; // Track number
optional uint32 track_number = 6; // Disc number
optional bool get_cover = 7; // Request cover art for each track
repeated uint64 artist_id = 2; // Track that belongs to these artists
repeated uint64 release_id = 3; // Track that is part of these releases
repeated uint64 genre_id = 4; // Track that has at least a track of the genre
required BatchParameter batch_parameter = 8;
optional bool get_cover = 5; // Request cover art for each track
required BatchParameter batch_parameter = 6;
}
@@ -94,45 +88,55 @@ message AudioCollectionResponse
repeated Track tracks = 2;
}
message Genre
{
required string name = 1;
}
message CoverArt
{
optional string mime_type = 1;
repeated bytes data = 2;
}
message Genre
{
required uint64 id = 1;
required string name = 2;
}
message Artist
{
required string name = 1;
required uint32 nb_releases = 2;
required uint64 id = 1;
required string name = 2;
required uint32 nb_releases = 3;
}
message Release
{
required string name = 1;
required uint64 id = 1;
required uint32 nb_tracks = 2;
required uint32 duration_secs = 3;
required string name = 2;
optional CoverArt coverArt = 4;
required uint32 nb_tracks = 3;
required uint32 duration_secs = 4;
optional string release_date = 5;
optional CoverArt coverArt = 6;
}
message Track
{
required int64 media_id = 1;
required uint64 id = 1;
optional uint32 disc_number = 2;
optional uint32 track_number = 3;
optional string artist = 4;
optional string release = 5;
optional string artist = 4;
optional string release = 5;
required string name = 6;
required string name = 6;
required uint32 duration_secs = 7;
required uint32 duration_secs = 7;
optional string release_date = 8;
optional string original_release_date = 9;
@@ -70,9 +70,6 @@ AudioCollectionRequestHandler::processGetGenres(const AudioCollectionRequest::Ge
std::cout << "Offset = " << request.batch_parameter().offset() << std::endl;
std::cout << "Size = " << request.batch_parameter().size() << std::endl;
if (request.has_filter_name())
std::cout << "Filter name = " << request.filter_name() << std::endl;
Wt::Dbo::Transaction transaction( _db.getSession() );
Wt::Dbo::collection<Genre::pointer> genres = Genre::getAll( _db.getSession(), request.batch_parameter().offset(), std::max(static_cast<std::size_t>(request.batch_parameter().size()), _maxListGenres) );
@@ -84,6 +81,7 @@ AudioCollectionRequestHandler::processGetGenres(const AudioCollectionRequest::Ge
AudioCollectionResponse_Genre* genre = response.add_genres();
genre->set_name((*it)->getName());
genre->set_id(it->id());
}
return true;
@@ -106,12 +104,9 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
std::cerr << "Warning: batch parameter size too high (" << request.batch_parameter().size() << ")" << std::endl;
if (request.has_filter_name())
std::cout << "Filter name = " << request.filter_name() << std::endl;
for (int id = 0; id < request.filter_genre_size(); ++id)
for (int id = 0; id < request.genre_id_size(); ++id)
{
std::cout << "Filter genre " << id << " = '" << request.filter_genre(id) << "'" << std::endl;
std::cout << "Genre id " << id << " = '" << request.genre_id(id) << "'" << std::endl;
}
@@ -133,6 +128,7 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
artist->set_name((*it)->getName());
artist->set_nb_releases(0); // TODO
artist->set_id(it->id());
}
std::cout << "Getting artists DONE" << std::endl;
+44 -13
View File
@@ -1,4 +1,4 @@
#include <iostream>
#include <stdexcept>
#include <thread>
@@ -12,6 +12,29 @@
#include "TestDatabase.hpp"
struct GenreInfo
{
uint64_t id;
std::string name;
};
std::ostream& operator<<(std::ostream& os, const GenreInfo& info)
{
os << "id = " << info.id << ", name = '" << info.name << "'" << std::endl;
return os;
}
struct ArtistInfo
{
uint64_t id;
std::string name;
};
std::ostream& operator<<(std::ostream& os, const ArtistInfo& info)
{
os << "id = " << info.id << ", name = '" << info.name << "'" << std::endl;
return os;
}
// Ugly class for testing purposes
class TestServer
@@ -54,7 +77,7 @@ class TestClient
_socket.connect(endpoint);
}
void getArtists(std::vector<std::string>& artists)
void getArtists(std::vector<ArtistInfo>& artists)
{
const std::size_t requestedBatchSize = 32;
@@ -67,7 +90,7 @@ class TestClient
}
std::size_t getArtists(std::vector<std::string>& artists, std::size_t offset, std::size_t size)
std::size_t getArtists(std::vector<ArtistInfo>& artists, std::size_t offset, std::size_t size)
{
std::size_t nbArtists = 0;
@@ -98,14 +121,18 @@ class TestClient
if (!response.audio_collection_response().artist_list().artists(i).has_name())
throw std::runtime_error("no artist name!");
artists.push_back( response.audio_collection_response().artist_list().artists(i).name() );
ArtistInfo artist;
artist.id = response.audio_collection_response().artist_list().artists(i).id();
artist.name = response.audio_collection_response().artist_list().artists(i).name();
artists.push_back( artist );
nbArtists++;
}
return nbArtists;
}
void getGenres(std::vector<std::string>& genres)
void getGenres(std::vector<GenreInfo>& genres)
{
const std::size_t requestedBatchSize = 8;
@@ -117,7 +144,7 @@ class TestClient
}
std::size_t getGenres(std::vector<std::string>& genres, std::size_t offset, std::size_t size)
std::size_t getGenres(std::vector<GenreInfo>& genres, std::size_t offset, std::size_t size)
{
std::size_t nbAdded = 0;
@@ -148,7 +175,11 @@ class TestClient
if (!response.audio_collection_response().genre_list().genres(i).has_name())
throw std::runtime_error("no genre name!");
genres.push_back( response.audio_collection_response().genre_list().genres(i).name() );
GenreInfo genre;
genre.id = response.audio_collection_response().genre_list().genres(i).id();
genre.name = response.audio_collection_response().genre_list().genres(i).name();
genres.push_back( genre );
nbAdded++;
}
@@ -262,22 +293,22 @@ int main()
TestClient client( boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 5080));
// Get Artists
std::vector<std::string> artists;
std::vector<ArtistInfo> artists;
client.getArtists(artists);
// Dump artists
std::cout << "Got " << artists.size() << " artists!" << std::endl;
BOOST_FOREACH(const std::string& artist, artists)
std::cout << "Artist: " << artist << std::endl;
BOOST_FOREACH(const ArtistInfo& artist, artists)
std::cout << "Artist: '" << artist << "'" << std::endl;
// Get genres
std::vector<std::string> genres;
std::vector<GenreInfo> genres;
client.getGenres(genres);
// Dum genres
std::cout << "Got " << genres.size() << " genres!" << std::endl;
BOOST_FOREACH(const std::string& genre, genres)
std::cout << "Genre: " << genre << std::endl;
BOOST_FOREACH(const GenreInfo& genre, genres)
std::cout << "Genre: '" << genre << "'" << std::endl;
testServer.stop();