common::Instance::PostMessage(cbData->instance, picojson::value(out).serialize().c_str());
}
-// DEPRECATED CALLBACK. contentChangeCallback() is currently in use
-static void changedContentV1Callback(media_content_error_e error, int pid,
- media_content_db_update_item_type_e update_item,
- media_content_db_update_type_e update_type,
- media_content_type_e media_type, char* uuid, char* path,
- char* mime_type, void* user_data) {
- ScopeLogger("File change callback");
-
- if (error != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Media content changed callback error: %d", (int)error);
- return;
- }
-
- if (update_item == MEDIA_ITEM_FILE) {
- if (!uuid) {
- LoggerE("Provided uuid is NULL, ignoring");
- return;
- }
-
- ReplyCallbackData* cbData = static_cast<ReplyCallbackData*>(user_data);
-
- int ret;
- picojson::value result = picojson::value(picojson::object());
- picojson::object& obj = result.get<picojson::object>();
-
- if (update_type == MEDIA_CONTENT_INSERT || update_type == MEDIA_CONTENT_UPDATE) {
- media_info_h media = NULL;
- ret = media_info_get_media_from_db(uuid, &media);
- if (ret == MEDIA_CONTENT_ERROR_NONE && media != NULL) {
- picojson::object o;
-
- ContentToJson(media, o);
- ReportSuccess(picojson::value(o), obj);
-
- if (update_type == MEDIA_CONTENT_INSERT) {
- obj["state"] = picojson::value("oncontentadded");
- } else {
- obj["state"] = picojson::value("oncontentupdated");
- }
-
- media_info_destroy(media);
- }
- } else {
- ReportSuccess(picojson::value(std::string(uuid)), obj);
- obj["state"] = picojson::value("oncontentremoved");
- }
-
- obj["listenerId"] = cbData->args.get("listenerId");
- common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
- } else {
- LoggerD("Media item is not a file, skipping.");
- return;
- }
-}
-
-// DEPRECATED CALLBACK. contentChangeCallback() is currently in use
-static void changedContentV2Callback(media_content_error_e error, int pid,
+static void changedContentCallback(media_content_error_e error, int pid,
media_content_db_update_item_type_e update_item,
media_content_db_update_type_e update_type,
media_content_type_e media_type, char* uuid, char* path,
listener_data_->cbType = ContentManagerErrorCallback;
}
- if (ContentManager::getInstance()
- ->setChangeListener(changedContentV1Callback, static_cast<void*>(listener_data_))
- .IsError()) {
- LogAndReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
- "The callback did not register properly"),
- &out);
- }
-
if (nullptr == noti_handle_) { // To remain consistency with the previous implementation
if (ContentManager::getInstance()
- ->addChangeListener(¬i_handle_, changedContentV2Callback,
+ ->addChangeListener(¬i_handle_, changedContentCallback,
static_cast<void*>(listener_data_))
.IsError()) {
LogAndReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
// CHECK_PRIVILEGE_ACCESS(kPrivilegeContentRead, &out);
CHECK_PRIVILEGE_ACCESS(kPrivilegeContentWrite, &out);
- if (ContentManager::getInstance()->unSetChangeListener().IsError()) {
- LoggerD("unsuccesfull deregistering of callback");
- }
if (ContentManager::getInstance()->removeChangeListener(noti_handle_).IsError()) {
LoggerD("unsuccesfull deregistering of callback");
} else {
}
}
-PlatformResult ContentManager::setChangeListener(media_content_db_update_cb callback,
- void* user_data) {
- ScopeLogger();
-
- int ret = media_content_set_db_updated_cb(callback, user_data);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "registering the listener is failed.",
- ("Failed: registering the listener is failed %d (%s)", ret, get_error_message(ret)));
- }
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult ContentManager::unSetChangeListener() {
- ScopeLogger();
-
- int ret = media_content_unset_db_updated_cb();
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "unregistering the listener is failed.",
- ("Failed: unregistering the listener is failed: %d (%s)", ret, get_error_message(ret)));
- }
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
void ContentManager::createPlaylist(std::string name,
const std::shared_ptr<ReplyCallbackData>& user_data) {
ScopeLogger();