WIP, Remote Client/Server, fist working genre list!

This commit is contained in:
emeric
2014-05-18 23:34:34 +02:00
parent 3b7813a581
commit 0825e77abc
8 changed files with 289 additions and 123 deletions
+1
View File
@@ -99,6 +99,7 @@ class Genre
// Find utility // Find utility
static pointer getByName(Wt::Dbo::Session& session, const std::string& name); static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session); static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size);
// Create utility // Create utility
static pointer create(Wt::Dbo::Session& session, const std::string& name); static pointer create(Wt::Dbo::Session& session, const std::string& name);
+5
View File
@@ -39,3 +39,8 @@ Genre::create(Wt::Dbo::Session& session, const std::string& name)
return session.add(new Genre(name)); return session.add(new Genre(name));
} }
Wt::Dbo::collection<Genre::pointer>
Genre::getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size)
{
return session.find<Genre>().offset(offset).limit(size);
}
+92 -79
View File
@@ -118,7 +118,7 @@ void protobuf_AssignDesc_collection_2eproto() {
AudioCollectionRequest_GetGenreList_descriptor_ = AudioCollectionRequest_descriptor_->nested_type(1); AudioCollectionRequest_GetGenreList_descriptor_ = AudioCollectionRequest_descriptor_->nested_type(1);
static const int AudioCollectionRequest_GetGenreList_offsets_[2] = { static const int AudioCollectionRequest_GetGenreList_offsets_[2] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AudioCollectionRequest_GetGenreList, filter_name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AudioCollectionRequest_GetGenreList, filter_name_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AudioCollectionRequest_GetGenreList, preferred_batch_size_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AudioCollectionRequest_GetGenreList, batch_parameter_),
}; };
AudioCollectionRequest_GetGenreList_reflection_ = AudioCollectionRequest_GetGenreList_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection( new ::google::protobuf::internal::GeneratedMessageReflection(
@@ -453,7 +453,7 @@ void protobuf_AddDesc_collection_2eproto() {
::Remote::protobuf_AddDesc_common_2eproto(); ::Remote::protobuf_AddDesc_common_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile( ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\020collection.proto\022\006Remote\032\014common.proto" "\n\020collection.proto\022\006Remote\032\014common.proto"
"\"\313\010\n\026AudioCollectionRequest\0221\n\004type\030\001 \002(" "\"\365\010\n\026AudioCollectionRequest\0221\n\004type\030\001 \002("
"\0162#.Remote.AudioCollectionRequest.Type\022\?" "\0162#.Remote.AudioCollectionRequest.Type\022\?"
"\n\nget_genres\030\002 \001(\0132+.Remote.AudioCollect" "\n\nget_genres\030\002 \001(\0132+.Remote.AudioCollect"
"ionRequest.GetGenreList\022A\n\013get_artists\030\003" "ionRequest.GetGenreList\022A\n\013get_artists\030\003"
@@ -462,56 +462,57 @@ void protobuf_AddDesc_collection_2eproto() {
"e.AudioCollectionRequest.GetReleaseList\022" "e.AudioCollectionRequest.GetReleaseList\022"
"\?\n\nget_tracks\030\005 \001(\0132+.Remote.AudioCollec" "\?\n\nget_tracks\030\005 \001(\0132+.Remote.AudioCollec"
"tionRequest.GetTrackList\032.\n\016BatchParamet" "tionRequest.GetTrackList\032.\n\016BatchParamet"
"er\022\016\n\006offset\030\001 \002(\r\022\014\n\004size\030\002 \002(\r\032A\n\014GetG" "er\022\016\n\006offset\030\001 \002(\r\022\014\n\004size\030\002 \002(\r\032k\n\014GetG"
"enreList\022\023\n\013filter_name\030\001 \001(\t\022\034\n\024preferr" "enreList\022\023\n\013filter_name\030\001 \001(\t\022F\n\017batch_p"
"ed_batch_size\030\002 \001(\r\032\202\001\n\rGetArtistList\022\023\n" "arameter\030\002 \002(\0132-.Remote.AudioCollectionR"
"\013filter_name\030\001 \001(\t\022\024\n\014filter_genre\030\002 \003(\t" "equest.BatchParameter\032\202\001\n\rGetArtistList\022"
"\022F\n\017batch_parameter\030\003 \002(\0132-.Remote.Audio" "\023\n\013filter_name\030\001 \001(\t\022\024\n\014filter_genre\030\002 \003"
"CollectionRequest.BatchParameter\032\253\001\n\016Get" "(\t\022F\n\017batch_parameter\030\003 \002(\0132-.Remote.Aud"
"ReleaseList\022\023\n\013filter_name\030\001 \001(\t\022\023\n\013arti" "ioCollectionRequest.BatchParameter\032\253\001\n\016G"
"st_name\030\002 \003(\t\022\024\n\014filter_genre\030\003 \003(\t\022\021\n\tg" "etReleaseList\022\023\n\013filter_name\030\001 \001(\t\022\023\n\013ar"
"et_cover\030\004 \001(\010\022F\n\017batch_parameter\030\005 \002(\0132" "tist_name\030\002 \003(\t\022\024\n\014filter_genre\030\003 \003(\t\022\021\n"
"-.Remote.AudioCollectionRequest.BatchPar" "\tget_cover\030\004 \001(\010\022F\n\017batch_parameter\030\005 \002("
"ameter\032\352\001\n\014GetTrackList\022\023\n\013filter_name\030\001" "\0132-.Remote.AudioCollectionRequest.BatchP"
" \001(\t\022\024\n\014release_name\030\002 \003(\t\022\023\n\013artist_nam" "arameter\032\352\001\n\014GetTrackList\022\023\n\013filter_name"
"e\030\003 \003(\t\022\024\n\014filter_genre\030\004 \003(\t\022\023\n\013disc_nu" "\030\001 \001(\t\022\024\n\014release_name\030\002 \003(\t\022\023\n\013artist_n"
"mber\030\005 \001(\r\022\024\n\014track_number\030\006 \001(\r\022\021\n\tget_" "ame\030\003 \003(\t\022\024\n\014filter_genre\030\004 \003(\t\022\023\n\013disc_"
"cover\030\007 \001(\010\022F\n\017batch_parameter\030\010 \002(\0132-.R" "number\030\005 \001(\r\022\024\n\014track_number\030\006 \001(\r\022\021\n\tge"
"emote.AudioCollectionRequest.BatchParame" "t_cover\030\007 \001(\010\022F\n\017batch_parameter\030\010 \002(\0132-"
"ter\"a\n\004Type\022\024\n\020TypeGetGenreList\020\000\022\025\n\021Typ" ".Remote.AudioCollectionRequest.BatchPara"
"eGetArtistList\020\001\022\026\n\022TypeGetReleaseList\020\002" "meter\"a\n\004Type\022\024\n\020TypeGetGenreList\020\001\022\025\n\021T"
"\022\024\n\020TypeGetTrackList\020\003\"\300\t\n\027AudioCollecti" "ypeGetArtistList\020\002\022\026\n\022TypeGetReleaseList"
"onResponse\0222\n\004type\030\001 \001(\0162$.Remote.AudioC" "\020\003\022\024\n\020TypeGetTrackList\020\004\"\300\t\n\027AudioCollec"
"ollectionResponse.Type\022\034\n\005error\030\002 \001(\0132\r." "tionResponse\0222\n\004type\030\001 \001(\0162$.Remote.Audi"
"Remote.Error\022=\n\ngenre_list\030\003 \001(\0132).Remot" "oCollectionResponse.Type\022\034\n\005error\030\002 \001(\0132"
"e.AudioCollectionResponse.GenreList\022\?\n\013a" "\r.Remote.Error\022=\n\ngenre_list\030\003 \001(\0132).Rem"
"rtist_list\030\004 \001(\0132*.Remote.AudioCollectio" "ote.AudioCollectionResponse.GenreList\022\?\n"
"nResponse.ArtistList\022A\n\014release_list\030\005 \001" "\013artist_list\030\004 \001(\0132*.Remote.AudioCollect"
"(\0132+.Remote.AudioCollectionResponse.Rele" "ionResponse.ArtistList\022A\n\014release_list\030\005"
"aseList\022=\n\ntrack_list\030\006 \001(\0132).Remote.Aud" " \001(\0132+.Remote.AudioCollectionResponse.Re"
"ioCollectionResponse.TrackList\032B\n\tGenreL" "leaseList\022=\n\ntrack_list\030\006 \001(\0132).Remote.A"
"ist\0225\n\006genres\030\002 \003(\0132%.Remote.AudioCollec" "udioCollectionResponse.TrackList\032B\n\tGenr"
"tionResponse.Genre\032E\n\nArtistList\0227\n\007arti" "eList\0225\n\006genres\030\002 \003(\0132%.Remote.AudioColl"
"sts\030\002 \003(\0132&.Remote.AudioCollectionRespon" "ectionResponse.Genre\032E\n\nArtistList\0227\n\007ar"
"se.Artist\032H\n\013ReleaseList\0229\n\010releases\030\002 \003" "tists\030\002 \003(\0132&.Remote.AudioCollectionResp"
"(\0132\'.Remote.AudioCollectionResponse.Rele" "onse.Artist\032H\n\013ReleaseList\0229\n\010releases\030\002"
"ase\032B\n\tTrackList\0225\n\006tracks\030\002 \003(\0132%.Remot" " \003(\0132\'.Remote.AudioCollectionResponse.Re"
"e.AudioCollectionResponse.Track\032\025\n\005Genre" "lease\032B\n\tTrackList\0225\n\006tracks\030\002 \003(\0132%.Rem"
"\022\014\n\004name\030\001 \002(\t\032+\n\010CoverArt\022\021\n\tmime_type\030" "ote.AudioCollectionResponse.Track\032\025\n\005Gen"
"\001 \001(\t\022\014\n\004data\030\002 \003(\014\032+\n\006Artist\022\014\n\004name\030\001 " "re\022\014\n\004name\030\001 \002(\t\032+\n\010CoverArt\022\021\n\tmime_typ"
"\002(\t\022\023\n\013nb_releases\030\002 \002(\r\032}\n\007Release\022\014\n\004n" "e\030\001 \001(\t\022\014\n\004data\030\002 \003(\014\032+\n\006Artist\022\014\n\004name\030"
"ame\030\001 \002(\t\022\021\n\tnb_tracks\030\002 \002(\r\022\025\n\rduration" "\001 \002(\t\022\023\n\013nb_releases\030\002 \002(\r\032}\n\007Release\022\014\n"
"_secs\030\003 \002(\r\022:\n\010coverArt\030\004 \001(\0132(.Remote.A" "\004name\030\001 \002(\t\022\021\n\tnb_tracks\030\002 \002(\r\022\025\n\rdurati"
"udioCollectionResponse.CoverArt\032\341\001\n\005Trac" "on_secs\030\003 \002(\r\022:\n\010coverArt\030\004 \001(\0132(.Remote"
"k\022\020\n\010media_id\030\001 \002(\003\022\023\n\013disc_number\030\002 \001(\r" ".AudioCollectionResponse.CoverArt\032\341\001\n\005Tr"
"\022\024\n\014track_number\030\003 \001(\r\022\016\n\006artist\030\004 \001(\t\022\017" "ack\022\020\n\010media_id\030\001 \002(\003\022\023\n\013disc_number\030\002 \001"
"\n\007release\030\005 \001(\t\022\014\n\004name\030\006 \002(\t\022\025\n\rduratio" "(\r\022\024\n\014track_number\030\003 \001(\r\022\016\n\006artist\030\004 \001(\t"
"n_secs\030\007 \002(\r\022\024\n\014release_date\030\010 \001(\t\022\035\n\025or" "\022\017\n\007release\030\005 \001(\t\022\014\n\004name\030\006 \002(\t\022\025\n\rdurat"
"iginal_release_date\030\t \001(\t\022\016\n\006genres\030\n \003(" "ion_secs\030\007 \002(\r\022\024\n\014release_date\030\010 \001(\t\022\035\n\025"
"\t\022\020\n\010coverArt\030\013 \001(\014\"d\n\004Type\022\r\n\tTypeError" "original_release_date\030\t \001(\t\022\016\n\006genres\030\n "
"\020\001\022\021\n\rTypeGenreList\020\002\022\022\n\016TypeArtistList\020" "\003(\t\022\020\n\010coverArt\030\013 \001(\014\"d\n\004Type\022\r\n\tTypeErr"
"\003\022\023\n\017TypeReleaseList\020\004\022\021\n\rTypeTrackList\020" "or\020\001\022\021\n\rTypeGenreList\020\002\022\022\n\016TypeArtistLis"
"\005", 2361); "t\020\003\022\023\n\017TypeReleaseList\020\004\022\021\n\rTypeTrackLis"
"t\020\005", 2403);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"collection.proto", &protobuf_RegisterTypes); "collection.proto", &protobuf_RegisterTypes);
AudioCollectionRequest::default_instance_ = new AudioCollectionRequest(); AudioCollectionRequest::default_instance_ = new AudioCollectionRequest();
@@ -564,10 +565,10 @@ const ::google::protobuf::EnumDescriptor* AudioCollectionRequest_Type_descriptor
} }
bool AudioCollectionRequest_Type_IsValid(int value) { bool AudioCollectionRequest_Type_IsValid(int value) {
switch(value) { switch(value) {
case 0:
case 1: case 1:
case 2: case 2:
case 3: case 3:
case 4:
return true; return true;
default: default:
return false; return false;
@@ -834,7 +835,7 @@ void AudioCollectionRequest_BatchParameter::Swap(AudioCollectionRequest_BatchPar
#ifndef _MSC_VER #ifndef _MSC_VER
const int AudioCollectionRequest_GetGenreList::kFilterNameFieldNumber; const int AudioCollectionRequest_GetGenreList::kFilterNameFieldNumber;
const int AudioCollectionRequest_GetGenreList::kPreferredBatchSizeFieldNumber; const int AudioCollectionRequest_GetGenreList::kBatchParameterFieldNumber;
#endif // !_MSC_VER #endif // !_MSC_VER
AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList() AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList()
@@ -843,6 +844,7 @@ AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList()
} }
void AudioCollectionRequest_GetGenreList::InitAsDefaultInstance() { void AudioCollectionRequest_GetGenreList::InitAsDefaultInstance() {
batch_parameter_ = const_cast< ::Remote::AudioCollectionRequest_BatchParameter*>(&::Remote::AudioCollectionRequest_BatchParameter::default_instance());
} }
AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList(const AudioCollectionRequest_GetGenreList& from) AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList(const AudioCollectionRequest_GetGenreList& from)
@@ -854,7 +856,7 @@ AudioCollectionRequest_GetGenreList::AudioCollectionRequest_GetGenreList(const A
void AudioCollectionRequest_GetGenreList::SharedCtor() { void AudioCollectionRequest_GetGenreList::SharedCtor() {
_cached_size_ = 0; _cached_size_ = 0;
filter_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); filter_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
preferred_batch_size_ = 0u; batch_parameter_ = NULL;
::memset(_has_bits_, 0, sizeof(_has_bits_)); ::memset(_has_bits_, 0, sizeof(_has_bits_));
} }
@@ -867,6 +869,7 @@ void AudioCollectionRequest_GetGenreList::SharedDtor() {
delete filter_name_; delete filter_name_;
} }
if (this != default_instance_) { if (this != default_instance_) {
delete batch_parameter_;
} }
} }
@@ -898,7 +901,9 @@ void AudioCollectionRequest_GetGenreList::Clear() {
filter_name_->clear(); filter_name_->clear();
} }
} }
preferred_batch_size_ = 0u; if (has_batch_parameter()) {
if (batch_parameter_ != NULL) batch_parameter_->::Remote::AudioCollectionRequest_BatchParameter::Clear();
}
} }
::memset(_has_bits_, 0, sizeof(_has_bits_)); ::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear(); mutable_unknown_fields()->Clear();
@@ -922,19 +927,17 @@ bool AudioCollectionRequest_GetGenreList::MergePartialFromCodedStream(
} else { } else {
goto handle_uninterpreted; goto handle_uninterpreted;
} }
if (input->ExpectTag(16)) goto parse_preferred_batch_size; if (input->ExpectTag(18)) goto parse_batch_parameter;
break; break;
} }
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
case 2: { case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_preferred_batch_size: parse_batch_parameter:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>( input, mutable_batch_parameter()));
input, &preferred_batch_size_)));
set_has_preferred_batch_size();
} else { } else {
goto handle_uninterpreted; goto handle_uninterpreted;
} }
@@ -969,9 +972,10 @@ void AudioCollectionRequest_GetGenreList::SerializeWithCachedSizes(
1, this->filter_name(), output); 1, this->filter_name(), output);
} }
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
if (has_preferred_batch_size()) { if (has_batch_parameter()) {
::google::protobuf::internal::WireFormatLite::WriteUInt32(2, this->preferred_batch_size(), output); ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
2, this->batch_parameter(), output);
} }
if (!unknown_fields().empty()) { if (!unknown_fields().empty()) {
@@ -992,9 +996,11 @@ void AudioCollectionRequest_GetGenreList::SerializeWithCachedSizes(
1, this->filter_name(), target); 1, this->filter_name(), target);
} }
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
if (has_preferred_batch_size()) { if (has_batch_parameter()) {
target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(2, this->preferred_batch_size(), target); target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
2, this->batch_parameter(), target);
} }
if (!unknown_fields().empty()) { if (!unknown_fields().empty()) {
@@ -1015,11 +1021,11 @@ int AudioCollectionRequest_GetGenreList::ByteSize() const {
this->filter_name()); this->filter_name());
} }
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
if (has_preferred_batch_size()) { if (has_batch_parameter()) {
total_size += 1 + total_size += 1 +
::google::protobuf::internal::WireFormatLite::UInt32Size( ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
this->preferred_batch_size()); this->batch_parameter());
} }
} }
@@ -1052,8 +1058,8 @@ void AudioCollectionRequest_GetGenreList::MergeFrom(const AudioCollectionRequest
if (from.has_filter_name()) { if (from.has_filter_name()) {
set_filter_name(from.filter_name()); set_filter_name(from.filter_name());
} }
if (from.has_preferred_batch_size()) { if (from.has_batch_parameter()) {
set_preferred_batch_size(from.preferred_batch_size()); mutable_batch_parameter()->::Remote::AudioCollectionRequest_BatchParameter::MergeFrom(from.batch_parameter());
} }
} }
mutable_unknown_fields()->MergeFrom(from.unknown_fields()); mutable_unknown_fields()->MergeFrom(from.unknown_fields());
@@ -1072,14 +1078,18 @@ void AudioCollectionRequest_GetGenreList::CopyFrom(const AudioCollectionRequest_
} }
bool AudioCollectionRequest_GetGenreList::IsInitialized() const { bool AudioCollectionRequest_GetGenreList::IsInitialized() const {
if ((_has_bits_[0] & 0x00000002) != 0x00000002) return false;
if (has_batch_parameter()) {
if (!this->batch_parameter().IsInitialized()) return false;
}
return true; return true;
} }
void AudioCollectionRequest_GetGenreList::Swap(AudioCollectionRequest_GetGenreList* other) { void AudioCollectionRequest_GetGenreList::Swap(AudioCollectionRequest_GetGenreList* other) {
if (other != this) { if (other != this) {
std::swap(filter_name_, other->filter_name_); std::swap(filter_name_, other->filter_name_);
std::swap(preferred_batch_size_, other->preferred_batch_size_); std::swap(batch_parameter_, other->batch_parameter_);
std::swap(_has_bits_[0], other->_has_bits_[0]); std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_); _unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_); std::swap(_cached_size_, other->_cached_size_);
@@ -2391,7 +2401,7 @@ AudioCollectionRequest::AudioCollectionRequest(const AudioCollectionRequest& fro
void AudioCollectionRequest::SharedCtor() { void AudioCollectionRequest::SharedCtor() {
_cached_size_ = 0; _cached_size_ = 0;
type_ = 0; type_ = 1;
get_genres_ = NULL; get_genres_ = NULL;
get_artists_ = NULL; get_artists_ = NULL;
get_releases_ = NULL; get_releases_ = NULL;
@@ -2435,7 +2445,7 @@ AudioCollectionRequest* AudioCollectionRequest::New() const {
void AudioCollectionRequest::Clear() { void AudioCollectionRequest::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
type_ = 0; type_ = 1;
if (has_get_genres()) { if (has_get_genres()) {
if (get_genres_ != NULL) get_genres_->::Remote::AudioCollectionRequest_GetGenreList::Clear(); if (get_genres_ != NULL) get_genres_->::Remote::AudioCollectionRequest_GetGenreList::Clear();
} }
@@ -2731,6 +2741,9 @@ void AudioCollectionRequest::CopyFrom(const AudioCollectionRequest& from) {
bool AudioCollectionRequest::IsInitialized() const { bool AudioCollectionRequest::IsInitialized() const {
if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false; if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false;
if (has_get_genres()) {
if (!this->get_genres().IsInitialized()) return false;
}
if (has_get_artists()) { if (has_get_artists()) {
if (!this->get_artists().IsInitialized()) return false; if (!this->get_artists().IsInitialized()) return false;
} }
+44 -26
View File
@@ -53,10 +53,10 @@ class AudioCollectionResponse_Release;
class AudioCollectionResponse_Track; class AudioCollectionResponse_Track;
enum AudioCollectionRequest_Type { enum AudioCollectionRequest_Type {
AudioCollectionRequest_Type_TypeGetGenreList = 0, AudioCollectionRequest_Type_TypeGetGenreList = 1,
AudioCollectionRequest_Type_TypeGetArtistList = 1, AudioCollectionRequest_Type_TypeGetArtistList = 2,
AudioCollectionRequest_Type_TypeGetReleaseList = 2, AudioCollectionRequest_Type_TypeGetReleaseList = 3,
AudioCollectionRequest_Type_TypeGetTrackList = 3 AudioCollectionRequest_Type_TypeGetTrackList = 4
}; };
bool AudioCollectionRequest_Type_IsValid(int value); bool AudioCollectionRequest_Type_IsValid(int value);
const AudioCollectionRequest_Type AudioCollectionRequest_Type_Type_MIN = AudioCollectionRequest_Type_TypeGetGenreList; const AudioCollectionRequest_Type AudioCollectionRequest_Type_Type_MIN = AudioCollectionRequest_Type_TypeGetGenreList;
@@ -255,24 +255,26 @@ class AudioCollectionRequest_GetGenreList : public ::google::protobuf::Message {
inline ::std::string* release_filter_name(); inline ::std::string* release_filter_name();
inline void set_allocated_filter_name(::std::string* filter_name); inline void set_allocated_filter_name(::std::string* filter_name);
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
inline bool has_preferred_batch_size() const; inline bool has_batch_parameter() const;
inline void clear_preferred_batch_size(); inline void clear_batch_parameter();
static const int kPreferredBatchSizeFieldNumber = 2; static const int kBatchParameterFieldNumber = 2;
inline ::google::protobuf::uint32 preferred_batch_size() const; inline const ::Remote::AudioCollectionRequest_BatchParameter& batch_parameter() const;
inline void set_preferred_batch_size(::google::protobuf::uint32 value); inline ::Remote::AudioCollectionRequest_BatchParameter* mutable_batch_parameter();
inline ::Remote::AudioCollectionRequest_BatchParameter* release_batch_parameter();
inline void set_allocated_batch_parameter(::Remote::AudioCollectionRequest_BatchParameter* batch_parameter);
// @@protoc_insertion_point(class_scope:Remote.AudioCollectionRequest.GetGenreList) // @@protoc_insertion_point(class_scope:Remote.AudioCollectionRequest.GetGenreList)
private: private:
inline void set_has_filter_name(); inline void set_has_filter_name();
inline void clear_has_filter_name(); inline void clear_has_filter_name();
inline void set_has_preferred_batch_size(); inline void set_has_batch_parameter();
inline void clear_has_preferred_batch_size(); inline void clear_has_batch_parameter();
::google::protobuf::UnknownFieldSet _unknown_fields_; ::google::protobuf::UnknownFieldSet _unknown_fields_;
::std::string* filter_name_; ::std::string* filter_name_;
::google::protobuf::uint32 preferred_batch_size_; ::Remote::AudioCollectionRequest_BatchParameter* batch_parameter_;
mutable int _cached_size_; mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
@@ -2155,26 +2157,42 @@ inline void AudioCollectionRequest_GetGenreList::set_allocated_filter_name(::std
} }
} }
// optional uint32 preferred_batch_size = 2; // required .Remote.AudioCollectionRequest.BatchParameter batch_parameter = 2;
inline bool AudioCollectionRequest_GetGenreList::has_preferred_batch_size() const { inline bool AudioCollectionRequest_GetGenreList::has_batch_parameter() const {
return (_has_bits_[0] & 0x00000002u) != 0; return (_has_bits_[0] & 0x00000002u) != 0;
} }
inline void AudioCollectionRequest_GetGenreList::set_has_preferred_batch_size() { inline void AudioCollectionRequest_GetGenreList::set_has_batch_parameter() {
_has_bits_[0] |= 0x00000002u; _has_bits_[0] |= 0x00000002u;
} }
inline void AudioCollectionRequest_GetGenreList::clear_has_preferred_batch_size() { inline void AudioCollectionRequest_GetGenreList::clear_has_batch_parameter() {
_has_bits_[0] &= ~0x00000002u; _has_bits_[0] &= ~0x00000002u;
} }
inline void AudioCollectionRequest_GetGenreList::clear_preferred_batch_size() { inline void AudioCollectionRequest_GetGenreList::clear_batch_parameter() {
preferred_batch_size_ = 0u; if (batch_parameter_ != NULL) batch_parameter_->::Remote::AudioCollectionRequest_BatchParameter::Clear();
clear_has_preferred_batch_size(); clear_has_batch_parameter();
} }
inline ::google::protobuf::uint32 AudioCollectionRequest_GetGenreList::preferred_batch_size() const { inline const ::Remote::AudioCollectionRequest_BatchParameter& AudioCollectionRequest_GetGenreList::batch_parameter() const {
return preferred_batch_size_; return batch_parameter_ != NULL ? *batch_parameter_ : *default_instance_->batch_parameter_;
} }
inline void AudioCollectionRequest_GetGenreList::set_preferred_batch_size(::google::protobuf::uint32 value) { inline ::Remote::AudioCollectionRequest_BatchParameter* AudioCollectionRequest_GetGenreList::mutable_batch_parameter() {
set_has_preferred_batch_size(); set_has_batch_parameter();
preferred_batch_size_ = value; if (batch_parameter_ == NULL) batch_parameter_ = new ::Remote::AudioCollectionRequest_BatchParameter;
return batch_parameter_;
}
inline ::Remote::AudioCollectionRequest_BatchParameter* AudioCollectionRequest_GetGenreList::release_batch_parameter() {
clear_has_batch_parameter();
::Remote::AudioCollectionRequest_BatchParameter* temp = batch_parameter_;
batch_parameter_ = NULL;
return temp;
}
inline void AudioCollectionRequest_GetGenreList::set_allocated_batch_parameter(::Remote::AudioCollectionRequest_BatchParameter* batch_parameter) {
delete batch_parameter_;
batch_parameter_ = batch_parameter;
if (batch_parameter) {
set_has_batch_parameter();
} else {
clear_has_batch_parameter();
}
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@@ -2880,7 +2898,7 @@ inline void AudioCollectionRequest::clear_has_type() {
_has_bits_[0] &= ~0x00000001u; _has_bits_[0] &= ~0x00000001u;
} }
inline void AudioCollectionRequest::clear_type() { inline void AudioCollectionRequest::clear_type() {
type_ = 0; type_ = 1;
clear_has_type(); clear_has_type();
} }
inline ::Remote::AudioCollectionRequest_Type AudioCollectionRequest::type() const { inline ::Remote::AudioCollectionRequest_Type AudioCollectionRequest::type() const {
+5 -5
View File
@@ -15,7 +15,7 @@ message AudioCollectionRequest
{ {
optional string filter_name = 1; // Genre that contains 'filterName' in its name optional string filter_name = 1; // Genre that contains 'filterName' in its name
optional uint32 preferred_batch_size = 2; required BatchParameter batch_parameter = 2;
} }
message GetArtistList message GetArtistList
@@ -57,10 +57,10 @@ message AudioCollectionRequest
enum Type enum Type
{ {
TypeGetGenreList = 0; TypeGetGenreList = 1;
TypeGetArtistList = 1; TypeGetArtistList = 2;
TypeGetReleaseList = 2; TypeGetReleaseList = 3;
TypeGetTrackList = 3; TypeGetTrackList = 4;
} }
required Type type = 1; required Type type = 1;
+52 -10
View File
@@ -1,3 +1,5 @@
#include <algorithm> // std::max
#include "AudioCollectionRequestHandler.hpp" #include "AudioCollectionRequestHandler.hpp"
#include "database/AudioTypes.hpp" #include "database/AudioTypes.hpp"
@@ -18,6 +20,17 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
switch (request.type()) switch (request.type())
{ {
case AudioCollectionRequest_Type_TypeGetGenreList:
if (request.has_get_genres())
{
res = processGetGenres(request.get_genres(), *response.mutable_genre_list());
if (res)
response.set_type(AudioCollectionResponse_Type_TypeArtistList);
}
else
std::cerr << "Bad AudioCollectionRequest_Type_TypeGetGenreList" << std::endl;
break;
case AudioCollectionRequest_Type_TypeGetArtistList: case AudioCollectionRequest_Type_TypeGetArtistList:
if (request.has_get_artists()) if (request.has_get_artists())
{ {
@@ -27,7 +40,7 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
} }
else else
std::cerr << "Bad AudioCollectionRequest_Type_TypeGetArtistList: message!" << std::endl; std::cerr << "Bad AudioCollectionRequest_Type_TypeGetArtistList" << std::endl;
break; break;
case AudioCollectionRequest_Type_TypeGetReleaseList: case AudioCollectionRequest_Type_TypeGetReleaseList:
@@ -43,6 +56,39 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
return res; return res;
} }
bool
AudioCollectionRequestHandler::processGetGenres(const AudioCollectionRequest::GetGenreList& request, AudioCollectionResponse::GenreList& response)
{
// sanity checks
if (!request.has_batch_parameter())
{
std::cerr << "No batch parameters found!" << std::endl;
return false;
}
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) );
typedef Wt::Dbo::collection< Genre::pointer > Genres;
for (Genres::iterator it = genres.begin(); it != genres.end(); ++it)
{
AudioCollectionResponse_Genre* genre = response.add_genres();
genre->set_name((*it)->getName());
}
return true;
}
bool bool
AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::GetArtistList& request, AudioCollectionResponse::ArtistList& response) AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::GetArtistList& request, AudioCollectionResponse::ArtistList& response)
{ {
@@ -54,15 +100,11 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
return false; return false;
} }
if (!request.batch_parameter().has_size()
|| !request.batch_parameter().has_offset())
{
std::cerr << "Missing batch parameter details" << std::endl;
return false;
}
std::cout << "Offset = " << request.batch_parameter().offset() << std::endl; std::cout << "Offset = " << request.batch_parameter().offset() << std::endl;
std::cout << "Size = " << request.batch_parameter().size() << std::endl; std::cout << "Size = " << request.batch_parameter().size() << std::endl;
if (request.batch_parameter().size() > _maxListArtists)
std::cerr << "Warning: batch parameter size too high (" << request.batch_parameter().size() << ")" << std::endl;
if (request.has_filter_name()) if (request.has_filter_name())
std::cout << "Filter name = " << request.filter_name() << std::endl; std::cout << "Filter name = " << request.filter_name() << std::endl;
@@ -79,7 +121,7 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
Wt::Dbo::Transaction transaction( _db.getSession() ); Wt::Dbo::Transaction transaction( _db.getSession() );
Wt::Dbo::collection<Artist::pointer> artists = Artist::getAll( _db.getSession(), request.batch_parameter().offset(), request.batch_parameter().size() ); Wt::Dbo::collection<Artist::pointer> artists = Artist::getAll( _db.getSession(), request.batch_parameter().offset(), std::max(static_cast<std::size_t>(request.batch_parameter().size()), _maxListArtists) );
std::cout << "size = " << artists.size() << std::endl; std::cout << "size = " << artists.size() << std::endl;
@@ -90,7 +132,7 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
AudioCollectionResponse_Artist* artist = response.add_artists(); AudioCollectionResponse_Artist* artist = response.add_artists();
artist->set_name((*it)->getName()); artist->set_name((*it)->getName());
artist->set_nb_releases(0); // TODO artist->set_nb_releases(0); // TODO
} }
std::cout << "Getting artists DONE" << std::endl; std::cout << "Getting artists DONE" << std::endl;
@@ -18,9 +18,14 @@ class AudioCollectionRequestHandler
private: private:
bool processGetArtists(const AudioCollectionRequest::GetArtistList& request, AudioCollectionResponse::ArtistList& response); bool processGetArtists(const AudioCollectionRequest::GetArtistList& request, AudioCollectionResponse::ArtistList& response);
bool processGetGenres(const AudioCollectionRequest::GetGenreList& request, AudioCollectionResponse::GenreList& response);
DatabaseHandler& _db; DatabaseHandler& _db;
static const std::size_t _maxListArtists = 128;
static const std::size_t _maxListGenres = 128;
static const std::size_t _maxListReleases = 128;
static const std::size_t _maxListTracks = 32;
}; };
} // namespace Remote } // namespace Remote
+85 -3
View File
@@ -4,6 +4,7 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/foreach.hpp>
#include "remote/server/Server.hpp" #include "remote/server/Server.hpp"
#include "remote/messages/Header.hpp" #include "remote/messages/Header.hpp"
@@ -55,14 +56,29 @@ class TestClient
void getArtists(std::vector<std::string>& artists) void getArtists(std::vector<std::string>& artists)
{ {
const std::size_t requestedBatchSize = 32;
std::size_t offset = 0;
std::size_t res = 0;
while ((res = getArtists(artists, offset, requestedBatchSize) ) > 0)
offset += res;
}
std::size_t getArtists(std::vector<std::string>& artists, std::size_t offset, std::size_t size)
{
std::size_t nbArtists = 0;
// Send request // Send request
Remote::ClientMessage request; Remote::ClientMessage request;
request.set_type( Remote::ClientMessage_Type_AudioCollectionRequest ); request.set_type( Remote::ClientMessage_Type_AudioCollectionRequest );
request.mutable_audio_collection_request()->set_type( Remote::AudioCollectionRequest_Type_TypeGetArtistList); request.mutable_audio_collection_request()->set_type( Remote::AudioCollectionRequest_Type_TypeGetArtistList);
request.mutable_audio_collection_request()->mutable_get_artists()->mutable_batch_parameter()->set_size(64); request.mutable_audio_collection_request()->mutable_get_artists()->mutable_batch_parameter()->set_size(size);
request.mutable_audio_collection_request()->mutable_get_artists()->mutable_batch_parameter()->set_offset(0); request.mutable_audio_collection_request()->mutable_get_artists()->mutable_batch_parameter()->set_offset(offset);
sendMsg(request); sendMsg(request);
@@ -83,10 +99,62 @@ class TestClient
throw std::runtime_error("no artist name!"); throw std::runtime_error("no artist name!");
artists.push_back( response.audio_collection_response().artist_list().artists(i).name() ); artists.push_back( response.audio_collection_response().artist_list().artists(i).name() );
nbArtists++;
} }
return nbArtists;
}
void getGenres(std::vector<std::string>& genres)
{
const std::size_t requestedBatchSize = 8;
std::size_t offset = 0;
std::size_t res = 0;
while ((res = getGenres(genres, offset, requestedBatchSize) ) > 0)
offset += res;
} }
std::size_t getGenres(std::vector<std::string>& genres, std::size_t offset, std::size_t size)
{
std::size_t nbAdded = 0;
// Send request
Remote::ClientMessage request;
request.set_type( Remote::ClientMessage_Type_AudioCollectionRequest );
request.mutable_audio_collection_request()->set_type( Remote::AudioCollectionRequest_Type_TypeGetGenreList);
request.mutable_audio_collection_request()->mutable_get_genres()->mutable_batch_parameter()->set_size(size);
request.mutable_audio_collection_request()->mutable_get_genres()->mutable_batch_parameter()->set_offset(offset);
sendMsg(request);
// Receive responses
Remote::ServerMessage response;
recvMsg(response);
// Process message
if (!response.has_audio_collection_response())
throw std::runtime_error("not an audio_collection_response!");
if (!response.audio_collection_response().has_genre_list())
throw std::runtime_error("not an genre_list!");
for (int i = 0; i < response.audio_collection_response().genre_list().genres_size(); ++i)
{
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() );
nbAdded++;
}
return nbAdded;
}
private: private:
@@ -193,10 +261,24 @@ int main()
// connect to loopback // connect to loopback
TestClient client( boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 5080)); TestClient client( boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 5080));
// TODO get some data // Get Artists
std::vector<std::string> artists; std::vector<std::string> artists;
client.getArtists(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;
// Get genres
std::vector<std::string> 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;
testServer.stop(); testServer.stop();
} }