#include "common/picojson.h"
#include "common/platform_result.h"
#include "common/task-queue.h"
+#include "common/virtual_fs.h"
#include "content/content_manager.h"
namespace extension {
using common::tools::ReportSuccess;
using common::tools::ReportError;
-ContentInstance::ContentInstance() {
+ContentInstance::ContentInstance() : noti_handle_(nullptr) {
using std::placeholders::_1;
using std::placeholders::_2;
ContentInstance::~ContentInstance() {
LoggerD("entered");
+ if (noti_handle_) {
+ media_content_unset_db_updated_cb_v2(noti_handle_);
+ noti_handle_ = nullptr;
+ }
}
static gboolean CompletedCallback(const std::shared_ptr<ReplyCallbackData>& user_data) {
}
case ContentManagerScanfileCallback: {
std::string contentURI = user_data->args.get("contentURI").get<std::string>();
- int res = ContentManager::getInstance()->scanFile(contentURI);
+ std::string real_path = common::VirtualFs::GetInstance().GetRealPath(contentURI);
+ int res = ContentManager::getInstance()->scanFile(real_path);
if (res != MEDIA_CONTENT_ERROR_NONE) {
LOGGER(ERROR) << "Scan file failed, error: " << res;
common::PlatformResult err(common::ErrorCode::UNKNOWN_ERR, "Scan file failed.");
}
} else {
ReportSuccess(picojson::value(std::string(uuid)), obj);
- obj["state"] = picojson::value("oncontendirremoved");
+ obj["state"] = picojson::value("oncontentdirremoved");
}
} else {
LOGGER(DEBUG) << "Media item is not a file and not directory, skipping.";
cbData->cbType = ContentManagerErrorCallback;
}
- if (ContentManager::getInstance()->setChangeListener(changedContentCallback, static_cast<void*>(cbData)).IsError()) {
+ if (ContentManager::getInstance()->setChangeListener(¬i_handle_,
+ changedContentCallback,
+ static_cast<void*>(cbData)).IsError()) {
ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "The callback did not register properly"), &out);
}
}
void ContentInstance::ContentManagerUnsetchangelistener(const picojson::value& args, picojson::object& out) {
LoggerD("entered");
- if (ContentManager::getInstance()->unSetChangeListener().IsError()) {
+ if (ContentManager::getInstance()->unSetChangeListener(¬i_handle_).IsError()) {
LoggerD("unsuccesfull deregistering of callback");
}
}
#ifndef CONTENT_CONTENT_INSTANCE_H_
#define CONTENT_CONTENT_INSTANCE_H_
+#include <media_content_internal.h>
#include "common/extension.h"
namespace extension {
void PlaylistGetThumbnailUri(const picojson::value& args, picojson::object& out);
void PlaylistSetThumbnailUri(const picojson::value& args, picojson::object& out);
void PlaylistGetNumberOfTracks(const picojson::value& args, picojson::object& out);
+
+ media_content_noti_h noti_handle_;
};
typedef struct _ReplyCallbackData {
#include "common/converter.h"
#include "common/logger.h"
#include "common/scope_exit.h"
+#include "common/virtual_fs.h"
#include "content/content_filter.h"
using namespace std;
PlatformResult ContentManager::scanDirectory(media_scan_completed_cb callback, ReplyCallbackData* cbData) {
LoggerD("Enter");
const std::string& contentDirURI = cbData->args.get("contentDirURI").get<std::string>();
+ std::string real_path = common::VirtualFs::GetInstance().GetRealPath(contentDirURI);
const bool recursive = cbData->args.get("recursive").get<bool>();
- int ret = media_content_scan_folder(contentDirURI.c_str(), recursive, callback, (void*) cbData);
+ int ret = media_content_scan_folder(real_path.c_str(), recursive, callback, (void*) cbData);
+
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Scan folder failed in platform: %d", ret);
if (MEDIA_CONTENT_ERROR_INVALID_PARAMETER == ret) {
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ContentManager::setChangeListener(media_content_db_update_cb callback, void *user_data) {
+PlatformResult ContentManager::setChangeListener(media_content_noti_h* noti_handle,
+ media_content_db_update_cb callback,
+ void *user_data) {
LoggerD("Enter");
+
int ret = media_content_set_db_updated_cb(callback, user_data);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: registering the listener is failed");
return PlatformResult(ErrorCode::UNKNOWN_ERR, ("registering the listener is failed."));
}
+
+ ret = media_content_set_db_updated_cb_v2(noti_handle, callback, user_data);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerE("Failed: registering the listener of cb_v2 is failed");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, ("registering the listener is failed."));
+ }
+
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ContentManager::unSetChangeListener() {
+PlatformResult ContentManager::unSetChangeListener(media_content_noti_h* noti_handle) {
LoggerD("Enter");
+
int ret = media_content_unset_db_updated_cb();
if(ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: unregistering the listener is failed");
return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
}
+
+ ret = media_content_unset_db_updated_cb_v2(*noti_handle);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerE("Failed: unregistering the listener of cb_v2 is failed");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
+ }
+ *noti_handle = nullptr;
+
return PlatformResult(ErrorCode::NO_ERROR);
}
int scanFile(std::string& uri);
common::PlatformResult scanDirectory(media_scan_completed_cb callback, ReplyCallbackData* cbData);
common::PlatformResult cancelScanDirectory(const std::string& content_dir_uri);
- common::PlatformResult setChangeListener(media_content_db_update_cb callback, void *user_data);
- common::PlatformResult unSetChangeListener();
+ common::PlatformResult setChangeListener(media_content_noti_h* noti_handler,
+ media_content_db_update_cb callback,
+ void *user_data);
+ common::PlatformResult unSetChangeListener(media_content_noti_h* noti_handler);
//Lyrics
int getLyrics(const picojson::value& args,picojson::object& result);