}
]);
- throw 'Not implemented';
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback,
+ native_.getErrorObject(result));
+ } else {
+ var thumb = native_.getResultObject(result);
+ args.successCallback(thumb.src);
+ }
+ };
+
+ native_.call('Exif_getThumbnail', {'uri': args.uri}, callback);
};
// this function passes ExifInformation_exposureProgram_attribute test:
#include <string>
#include <sstream>
+#include "common/platform_exception.h"
#include "common/task-queue.h"
#include "common/logger.h"
void ExifInstance::saveExifInfo(const picojson::value& args,
picojson::object& out) {
+ LoggerD("Entered");
const std::string& uri = args.get("uri").get<std::string>();
const double callback_id = args.get("callbackId").get<double>();
void ExifInstance::getThumbnail(const picojson::value& args,
picojson::object& out) {
- LoggerE("getThumbnail is not implemented (c++)");
+ LoggerD("Entered");
+ const std::string& uri = args.get("uri").get<std::string>();
+
+ const double callback_id = args.get("callbackId").get<double>();
+ auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
+ try {
+ const std::string file_path = ExifUtil::convertUriToPath(uri);
+ ExifData* exif_data = nullptr;
+ JsonValue result = JsonValue(JsonObject());;
+ JsonObject& result_obj = result.get<JsonObject>();
+
+ std::string ext = file_path.substr(file_path.find_last_of(".") + 1);
+ std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
+
+ if ("jpg" == ext) {
+ ext = "jpeg";
+ }
+
+ if ("jpeg" == ext || "png" == ext || "gif" == ext) {
+ LoggerD("Get thumbnail from Exif in file: [%s]", file_path.c_str());
+
+ exif_data = exif_data_new_from_file(file_path.c_str());
+ if (!exif_data) {
+ throw common::UnknownException("File can not be loaded");
+ }
+
+ if (exif_data->data && exif_data->size) {
+ gchar* ch_uri = g_base64_encode(exif_data->data, exif_data->size);
+ std::string base64 = "data:image/"+ext+";base64," + ch_uri;
+
+ exif_data_unref(exif_data);
+
+ std::pair<std::string, std::string> pair;
+ pair = std::make_pair("src", base64);
+ result_obj.insert(pair);
+ } else {
+ exif_data_unref(exif_data);
+ LoggerE("File [%s] doesn't contain thumbnail", file_path.c_str());
+ throw common::InvalidValuesException("File doesn't contain"
+ " thumbnail");
+ }
+ } else {
+ LoggerE("extension: %s is not valid (jpeg/jpg/png/gif is supported)",
+ ext.c_str());
+ throw common::NotSupportedException("getThumbnail support only"
+ " jpeg/jpg/png/gif");
+ }
+
+ ReportSuccess(result, response->get<picojson::object>());
+ } catch (const common::PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
+ };
+
+ auto get_response =
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback is %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
+
+ common::TaskQueue::GetInstance().Queue<JsonValue>(
+ get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
} // namespace exif