~xavi-garcia-mena/mediascanner2/ms-dbus-wal

« back to all changes in this revision

Viewing changes to src/mediascanner/MediaStore.cc

  • Committer: Xavi Garcia
  • Date: 2015-02-16 13:40:56 UTC
  • Revision ID: xavi.garcia.mena@canonical.com-20150216134056-8aqd3zm0un60pca5
Erased final _ for member variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
    // http://sqlite.com/faq.html#q6
56
56
    std::mutex dbMutex;
57
57
 
58
 
    OpenType access_;
 
58
    OpenType access_mode;
59
59
 
60
 
    std::unique_ptr<mediascanner::dbus::ServiceStub> media_store_dbus_;
 
60
    std::unique_ptr<mediascanner::dbus::ServiceStub> media_store_dbus;
61
61
 
62
62
    MediaStorePrivate(OpenType access);
63
63
    void insert(const MediaFile &m) const;
433
433
    delete p;
434
434
}
435
435
 
436
 
MediaStorePrivate::MediaStorePrivate(OpenType access) : db(nullptr), access_(access), media_store_dbus_(nullptr) {
437
 
    if(access_ != MS_READ_WRITE) {
438
 
        media_store_dbus_.reset(new dbus::ServiceStub());
 
436
MediaStorePrivate::MediaStorePrivate(OpenType access) : db(nullptr), access_mode(access), media_store_dbus(nullptr) {
 
437
    if(access_mode != MS_READ_WRITE) {
 
438
        media_store_dbus.reset(new dbus::ServiceStub());
439
439
    }
440
440
}
441
441
 
442
442
size_t MediaStorePrivate::size() const {
443
 
    if(access_ != MS_READ_WRITE) {
 
443
    if(access_mode != MS_READ_WRITE) {
444
444
        throw runtime_error("MediaStorePrivate::size() is not available in read only mode");
445
445
    }
446
446
    Statement count(db, "SELECT COUNT(*) FROM media");
449
449
}
450
450
 
451
451
void MediaStorePrivate::insert(const MediaFile &m) const {
452
 
    if(access_ != MS_READ_WRITE) {
 
452
    if(access_mode != MS_READ_WRITE) {
453
453
        throw runtime_error("MediaStorePrivate::insert() is not available in read only mode");
454
454
    }
455
455
    Statement query(db, "INSERT OR REPLACE INTO media (filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, width, height, latitude, longitude, has_thumbnail, type)  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
487
487
}
488
488
 
489
489
void MediaStorePrivate::remove(const string &fname) const {
490
 
    if(access_ != MS_READ_WRITE) {
 
490
    if(access_mode != MS_READ_WRITE) {
491
491
        throw runtime_error("MediaStorePrivate::remove() is not available in read only mode");
492
492
    }
493
493
    Statement del(db, "DELETE FROM media WHERE filename = ?");
496
496
}
497
497
 
498
498
void MediaStorePrivate::insert_broken_file(const std::string &fname, const std::string &etag) const {
499
 
    if(access_ != MS_READ_WRITE) {
 
499
    if(access_mode != MS_READ_WRITE) {
500
500
        throw runtime_error("MediaStorePrivate::insert_broken_file() is not available in read only mode");
501
501
    }
502
502
    Statement del(db, "INSERT OR REPLACE INTO broken_files (filename, etag) VALUES (?, ?)");
506
506
}
507
507
 
508
508
void MediaStorePrivate::remove_broken_file(const std::string &fname) const {
509
 
    if(access_ != MS_READ_WRITE) {
 
509
    if(access_mode != MS_READ_WRITE) {
510
510
        throw runtime_error("MediaStorePrivate::remove_broken_file() is not available in read only mode");
511
511
    }
512
512
    Statement del(db, "DELETE FROM broken_files WHERE filename = ?");
515
515
}
516
516
 
517
517
bool MediaStorePrivate::is_broken_file(const std::string &fname, const std::string &etag) const {
518
 
    if(access_ != MS_READ_WRITE) {
 
518
    if(access_mode != MS_READ_WRITE) {
519
519
        throw runtime_error("MediaStorePrivate::is_broken_file() is not available in read only mode");
520
520
    }
521
521
    Statement query(db, "SELECT * FROM broken_files WHERE filename = ? AND etag = ?");
554
554
}
555
555
 
556
556
MediaFile MediaStorePrivate::lookup(const std::string &filename) const {
557
 
    if(access_ != MS_READ_WRITE) {
558
 
        return media_store_dbus_->lookup(filename);
 
557
    if(access_mode != MS_READ_WRITE) {
 
558
        return media_store_dbus->lookup(filename);
559
559
    }
560
560
    Statement query(db, R"(
561
561
SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, width, height, latitude, longitude, has_thumbnail, type
570
570
}
571
571
 
572
572
vector<MediaFile> MediaStorePrivate::query(const std::string &core_term, MediaType type, const Filter &filter) const {
573
 
    if(access_ != MS_READ_WRITE) {
574
 
        return media_store_dbus_->query(core_term, type, filter);
 
573
    if(access_mode != MS_READ_WRITE) {
 
574
        return media_store_dbus->query(core_term, type, filter);
575
575
    }
576
576
    string qs(R"(
577
577
SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, width, height, latitude, longitude, has_thumbnail, type
642
642
}
643
643
 
644
644
vector<Album> MediaStorePrivate::queryAlbums(const std::string &core_term, const Filter &filter) const {
645
 
    if(access_ != MS_READ_WRITE) {
646
 
        return media_store_dbus_->queryAlbums(core_term, filter);
 
645
    if(access_mode != MS_READ_WRITE) {
 
646
        return media_store_dbus->queryAlbums(core_term, filter);
647
647
    }
648
648
    string qs(R"(
649
649
SELECT album, album_artist, first(date) as date, first(genre) as genre, first(filename) as filename, first(has_thumbnail) as has_thumbnail FROM media
680
680
}
681
681
 
682
682
vector<string> MediaStorePrivate::queryArtists(const string &q, const Filter &filter) const {
683
 
    if(access_ != MS_READ_WRITE) {
684
 
        return media_store_dbus_->queryArtists(q, filter);
 
683
    if(access_mode != MS_READ_WRITE) {
 
684
        return media_store_dbus->queryArtists(q, filter);
685
685
    }
686
686
    string qs(R"(
687
687
SELECT artist FROM media
722
722
}
723
723
 
724
724
vector<MediaFile> MediaStorePrivate::getAlbumSongs(const Album& album) const {
725
 
    if(access_ != MS_READ_WRITE) {
726
 
        return media_store_dbus_->getAlbumSongs(album);
 
725
    if(access_mode != MS_READ_WRITE) {
 
726
        return media_store_dbus->getAlbumSongs(album);
727
727
    }
728
728
    Statement query(db, R"(
729
729
SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, width, height, latitude, longitude, type FROM media
737
737
}
738
738
 
739
739
std::string MediaStorePrivate::getETag(const std::string &filename) const {
740
 
    if(access_ != MS_READ_WRITE) {
741
 
        return media_store_dbus_->getETag(filename);
 
740
    if(access_mode != MS_READ_WRITE) {
 
741
        return media_store_dbus->getETag(filename);
742
742
    }
743
743
    Statement query(db, R"(
744
744
SELECT etag FROM media WHERE filename = ?
752
752
}
753
753
 
754
754
std::vector<MediaFile> MediaStorePrivate::listSongs(const Filter &filter) const {
755
 
    if(access_ != MS_READ_WRITE) {
756
 
        return media_store_dbus_->listSongs(filter);
 
755
    if(access_mode != MS_READ_WRITE) {
 
756
        return media_store_dbus->listSongs(filter);
757
757
    }
758
758
    std::string qs(R"(
759
759
SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, width, height, latitude, longitude, has_thumbnail, type
798
798
}
799
799
 
800
800
std::vector<Album> MediaStorePrivate::listAlbums(const Filter &filter) const {
801
 
    if(access_ != MS_READ_WRITE) {
802
 
        return media_store_dbus_->listAlbums(filter);
 
801
    if(access_mode != MS_READ_WRITE) {
 
802
        return media_store_dbus->listAlbums(filter);
803
803
    }
804
804
    std::string qs(R"(
805
805
SELECT album, album_artist, first(date) as date, first(genre) as genre, first(filename) as filename, first(has_thumbnail) as has_thumbnail FROM media
838
838
}
839
839
 
840
840
vector<std::string> MediaStorePrivate::listArtists(const Filter &filter) const {
841
 
    if(access_ != MS_READ_WRITE) {
842
 
        return media_store_dbus_->listArtists(filter);
 
841
    if(access_mode != MS_READ_WRITE) {
 
842
        return media_store_dbus->listArtists(filter);
843
843
    }
844
844
    string qs(R"(
845
845
SELECT artist FROM media
870
870
}
871
871
 
872
872
vector<std::string> MediaStorePrivate::listAlbumArtists(const Filter &filter) const {
873
 
    if(access_ != MS_READ_WRITE) {
874
 
        return media_store_dbus_->listAlbumArtists(filter);
 
873
    if(access_mode != MS_READ_WRITE) {
 
874
        return media_store_dbus->listAlbumArtists(filter);
875
875
    }
876
876
    string qs(R"(
877
877
SELECT album_artist FROM media
902
902
}
903
903
 
904
904
vector<std::string> MediaStorePrivate::listGenres(const Filter &filter) const {
905
 
    if(access_ != MS_READ_WRITE) {
906
 
        return media_store_dbus_->listGenres(filter);
 
905
    if(access_mode != MS_READ_WRITE) {
 
906
        return media_store_dbus->listGenres(filter);
907
907
    }
908
908
    Statement query(db, R"(
909
909
SELECT genre FROM media
924
924
}
925
925
 
926
926
void MediaStorePrivate::pruneDeleted() {
927
 
    if(access_ != MS_READ_WRITE) {
 
927
    if(access_mode != MS_READ_WRITE) {
928
928
        throw runtime_error("MediaStorePrivate::pruneDeleted() is not available in read only mode");
929
929
    }
930
930
    std::map<std::string, bool> path_cache;
946
946
}
947
947
 
948
948
void MediaStorePrivate::archiveItems(const std::string &prefix) {
949
 
    if(access_ != MS_READ_WRITE) {
 
949
    if(access_mode != MS_READ_WRITE) {
950
950
        throw runtime_error("MediaStorePrivate::archiveItems() is not available in read only mode");
951
951
    }
952
952
    const char *templ = R"(BEGIN TRANSACTION;
966
966
}
967
967
 
968
968
void MediaStorePrivate::restoreItems(const std::string &prefix) {
969
 
    if(access_ != MS_READ_WRITE) {
 
969
    if(access_mode != MS_READ_WRITE) {
970
970
        throw runtime_error("MediaStorePrivate::restoreItems() is not available in read only mode");
971
971
    }
972
972
    const char *templ = R"(BEGIN TRANSACTION;