char* path,
char* mime_type,
void* user_data) {
- LoggerD("Enter");
-
- ReplyCallbackData* cbData = static_cast<ReplyCallbackData*>(user_data);
-
- if (!uuid) {
- LOGGER(ERROR) << "Provided uuid is NULL, ignoring";
- return;
- }
+ LoggerD("Entered file change callback");
if (error != MEDIA_CONTENT_ERROR_NONE) {
LOGGER(ERROR) << "Media content changed callback error: " << error;
return;
}
- int ret;
- picojson::value result = picojson::value(picojson::object());
- picojson::object& obj = result.get<picojson::object>();
-
if (update_item == MEDIA_ITEM_FILE) {
+ if (!uuid) {
+ LOGGER(ERROR) << "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);
ReportSuccess(picojson::value(std::string(uuid)), obj);
obj["state"] = picojson::value("oncontentremoved");
}
- } else if (update_item == MEDIA_ITEM_DIRECTORY) {
+
+ obj["listenerId"] = cbData->args.get("listenerId");
+ common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
+ } else {
+ LOGGER(DEBUG) << "Media item is not a file, skipping.";
+ return;
+ }
+}
+
+static void changedContentV2Callback(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) {
+ LoggerD("Entered directory change callback");
+
+ if (error != MEDIA_CONTENT_ERROR_NONE) {
+ LOGGER(ERROR) << "Media content changed v2 callback error: " << error;
+ return;
+ }
+
+ if (update_item == MEDIA_ITEM_DIRECTORY) {
+ if (!uuid) {
+ LOGGER(ERROR) << "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_folder_h folder = NULL;
ret = media_folder_get_folder_from_db(uuid, &folder);
ReportSuccess(picojson::value(std::string(uuid)), obj);
obj["state"] = picojson::value("oncontentdirremoved");
}
+
+ obj["listenerId"] = cbData->args.get("listenerId");
+ common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
} else {
- LOGGER(DEBUG) << "Media item is not a file and not directory, skipping.";
+ LOGGER(DEBUG) << "Media item is not directory, skipping.";
return;
}
-
- obj["listenerId"] = cbData->args.get("listenerId");
- common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
}
-
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) {\
ReportError(common::PlatformResult(common::ErrorCode::TYPE_MISMATCH_ERR, (name" is required argument")), &out);\
listener_data_->cbType = ContentManagerErrorCallback;
}
- if (ContentManager::getInstance()->setChangeListener(¬i_handle_,
- changedContentCallback,
+ if (ContentManager::getInstance()->setChangeListener(changedContentCallback,
+ static_cast<void*>(listener_data_)).IsError()) {
+ ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "The callback did not register properly"), &out);
+ }
+ if (ContentManager::getInstance()->setV2ChangeListener(¬i_handle_,
+ changedContentV2Callback,
static_cast<void*>(listener_data_)).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(¬i_handle_).IsError()) {
+ if (ContentManager::getInstance()->unSetChangeListener().IsError()) {
+ LoggerD("unsuccesfull deregistering of callback");
+ }
+ if (ContentManager::getInstance()->unSetV2ChangeListener(¬i_handle_).IsError()) {
LoggerD("unsuccesfull deregistering of callback");
}
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ContentManager::setChangeListener(media_content_noti_h* noti_handle,
- media_content_db_update_cb callback,
+PlatformResult ContentManager::setChangeListener(media_content_db_update_cb callback,
void *user_data) {
LoggerD("Enter");
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(media_content_noti_h* noti_handle) {
+PlatformResult ContentManager::unSetChangeListener() {
LoggerD("Enter");
int ret = media_content_unset_db_updated_cb();
LoggerE("Failed: unregistering the listener is failed");
return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
}
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ContentManager::setV2ChangeListener(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_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."));
+ }
- ret = media_content_unset_db_updated_cb_v2(*noti_handle);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ContentManager::unSetV2ChangeListener(media_content_noti_h* noti_handle) {
+ LoggerD("Enter");
+
+ int 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."));
return PlatformResult(ErrorCode::NO_ERROR);
}
+
void ContentManager::createPlaylist(std::string name,
const std::shared_ptr<ReplyCallbackData>& user_data) {
LoggerD("Enter");