Commit b85135e3 authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Cloudbrowser: added synchronization to cerr logging.

parent 557ad8db
......@@ -40,12 +40,16 @@ void DownloadFileCallback::receivedData(const char* data, uint32_t length) {
}
void DownloadFileCallback::done() {
{
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[OK] Finished download.\n";
}
file_.close();
emit window_->downloadProgressChanged(0, 0);
std::cerr << "[OK] Finished download.\n";
}
void DownloadFileCallback::error(const std::string& desc) {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[FAIL] Download: " << desc << "\n";
emit window_->downloadProgressChanged(0, 0);
}
......@@ -60,7 +64,10 @@ UploadFileCallback::UploadFileCallback(Window* window, QUrl url)
std::ios_base::in | std::ios_base::binary) {}
void UploadFileCallback::reset() {
std::cerr << "[DIAG] Starting transmission\n";
{
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[DIAG] Starting transmission\n";
}
file_.seekg(std::ios::beg);
}
......@@ -70,11 +77,13 @@ uint32_t UploadFileCallback::putData(char* data, uint32_t maxlength) {
}
void UploadFileCallback::done() {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[OK] Successfuly uploaded\n";
emit window_->uploadProgressChanged(0, 0);
}
void UploadFileCallback::error(const std::string& description) {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[FAIL] Upload: " << description << "\n";
emit window_->uploadProgressChanged(0, 0);
}
......@@ -87,6 +96,7 @@ CloudProviderCallback::CloudProviderCallback(Window* w) : window_(w) {}
ICloudProvider::ICallback::Status CloudProviderCallback::userConsentRequired(
const ICloudProvider& p) {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[DIAG] User consent required: " << p.authorizeLibraryUrl()
<< "\n";
emit window_->openBrowser(p.authorizeLibraryUrl().c_str());
......@@ -106,6 +116,7 @@ void CloudProviderCallback::declined(const ICloudProvider&) {
void CloudProviderCallback::error(const ICloudProvider&,
const std::string& desc) {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[FAIL] Authorize " << desc.c_str() << "\n";
emit window_->closeBrowser();
}
......@@ -119,6 +130,7 @@ void ListDirectoryCallback::receivedItem(IItem::Pointer item) {
void ListDirectoryCallback::done(const std::vector<IItem::Pointer>&) {}
void ListDirectoryCallback::error(const std::string& str) {
std::unique_lock<std::mutex> lock(window_->stream_mutex());
std::cerr << "[FAIL] ListDirectory: " << str << "\n";
emit window_->closeBrowser();
}
......@@ -138,6 +150,7 @@ void DownloadThumbnailCallback::done() {
}
void DownloadThumbnailCallback::error(const std::string& error) {
std::unique_lock<std::mutex> lock(item_->window_->stream_mutex());
std::cerr << "[FAIL] Thumbnail: " << error << "\n";
}
......
......@@ -92,8 +92,11 @@ void Window::initializeCloud(QString name) {
cloud_provider_ = ICloudStorage::create()->provider(name.toStdString());
else
cloud_provider_ = make_unique<MockProvider>();
std::cerr << "[DIAG] Trying to authorize with "
<< settings.value(name).toString().toStdString() << std::endl;
{
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Trying to authorize with "
<< settings.value(name).toString().toStdString() << std::endl;
}
ICloudProvider::Hints hints =
fromQMap(settings.value(name + "_hints").toMap());
cloud_provider_->initialize(settings.value(name).toString().toStdString(),
......@@ -118,6 +121,7 @@ void Window::changeCurrentDirectory(int directory_id) {
}
void Window::onSuccessfullyAuthorized() {
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[OK] Successfully authorized "
<< cloud_provider_->name().c_str() << "\n";
}
......@@ -133,7 +137,10 @@ void Window::onPlayFile(QString filename) {
}
void Window::onPlayFileFromUrl(QString url) {
std::cerr << "[DIAG] Playing url " << url.toStdString() << "\n";
{
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Playing url " << url.toStdString() << "\n";
}
VLC::Media media(vlc_instance_, url.toStdString(), VLC::Media::FromLocation);
media_player_.setMedia(media);
media_player_.play();
......@@ -222,13 +229,22 @@ void Window::play(int item_id) {
}
void Window::stop() {
std::cerr << "[DIAG] Trying to stop player\n";
{
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Trying to stop player\n";
}
media_player_.stop();
std::cerr << "[DIAG] Stopped\n";
{
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Stopped\n";
}
}
void Window::uploadFile(QString path) {
std::cerr << "[DIAG] Uploading file " << path.toStdString() << "\n";
{
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Uploading file " << path.toStdString() << "\n";
}
QUrl url = path;
upload_request_ = cloud_provider_->uploadFileAsync(
current_directory_, url.fileName().toStdString(),
......@@ -241,6 +257,8 @@ void Window::downloadFile(int item_id, QUrl path) {
i->item(),
make_unique<DownloadFileCallback>(this, path.toLocalFile().toStdString() +
"/" + i->item()->filename()));
std::unique_lock<std::mutex> lock(stream_mutex());
std::cerr << "[DIAG] Downloading file " << path.toLocalFile().toStdString()
<< "\n";
}
......@@ -296,10 +314,7 @@ bool ImageProvider::hasImage(QString id) {
int DirectoryModel::rowCount(const QModelIndex&) const { return list_.size(); }
QVariant DirectoryModel::data(const QModelIndex& id, int) const {
if (static_cast<uint32_t>(id.row()) >= list_.size()) {
std::cerr << "[FAIL] QML requests nonexistent object.\n";
return QVariant();
}
if (static_cast<uint32_t>(id.row()) >= list_.size()) return QVariant();
auto model = list_[id.row()].get();
model->fetchThumbnail();
......
......@@ -68,6 +68,7 @@ class ItemModel : public QObject {
private:
friend class Window;
friend class DownloadThumbnailCallback;
QString thumbnail_;
IItem::Pointer item_;
......@@ -113,6 +114,8 @@ class Window : public QQuickView {
void onPlayFile(QString filename);
void onPlayFileFromUrl(QString url);
std::mutex& stream_mutex() const { return stream_mutex_; }
signals:
void openBrowser(QString url);
void closeBrowser();
......@@ -155,6 +158,7 @@ class Window : public QQuickView {
VLC::MediaPlayer media_player_;
std::future<void> clear_directory_;
DirectoryModel directory_model_;
mutable std::mutex stream_mutex_;
Q_OBJECT
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment