Merge "[Archive] Log refactoring." into tizen_3.0
authorHyunJin Park <hj.na.park@samsung.com>
Wed, 2 Dec 2015 23:27:52 +0000 (08:27 +0900)
committerGerrit Code Review <gerrit@s001>
Wed, 2 Dec 2015 23:27:53 +0000 (08:27 +0900)
12 files changed:
src/bookmark/bookmark_instance.cc
src/common/common.gyp
src/common/logger.h
src/content/content_instance.cc
src/exif/exif_information.cc
src/exif/exif_instance.cc
src/exif/exif_tag_saver.cc
src/exif/get_exif_info.cc
src/exif/jpeg_file.cc
src/humanactivitymonitor/humanactivitymonitor_instance.cc
src/humanactivitymonitor/humanactivitymonitor_manager.cc
src/sound/sound_manager.cc

index adaa001..c17e0f3 100755 (executable)
@@ -90,27 +90,32 @@ PlatformResult BookmarkInstance::BookmarkUrlExists(const char* url,
   int* ids = nullptr;
   char* compare_url = nullptr;
 
-  if (bp_bookmark_adaptor_get_ids_p(&ids,  // ids
-                                    &ids_count,  // count
-                                    -1,  //limit
-                                    0,  // offset
-                                    -1,  //parent
-                                    -1,  //type
-                                    -1,  // is_operator
-                                    -1,  // is_editable
-                                    BP_BOOKMARK_O_DATE_CREATED,  // order_offset
-                                    0  // ordering ASC
-                                    ) < 0) {
-    LoggerE("Failed to obtain bookmarks");
-    return PlatformResult{ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks"};
+  int ntv_ret = bp_bookmark_adaptor_get_ids_p(
+                    &ids,  // ids
+                    &ids_count,  // count
+                    -1,  //limit
+                    0,  // offset
+                    -1,  //parent
+                    -1,  //type
+                    -1,  // is_operator
+                    -1,  // is_editable
+                    BP_BOOKMARK_O_DATE_CREATED,  // order_offset
+                    0  // ordering ASC
+                    );
+  if (ntv_ret < 0) {
+    return LogAndCreateResult(
+                ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks",
+                ("bp_bookmark_adaptor_get_ids_p error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
   }
 
   PlatformResult result{ErrorCode::NO_ERROR};
   bool url_found = false;
   for (int i = 0; (i < ids_count) && result && !url_found; ++i) {
-    if (bp_bookmark_adaptor_get_url(ids[i], &compare_url) < 0) {
-      LoggerE("Failed to obtain URL");
-      result = PlatformResult{ErrorCode::UNKNOWN_ERR, "Failed to obtain URL"};
+    ntv_ret = bp_bookmark_adaptor_get_url(ids[i], &compare_url);
+    if (ntv_ret < 0) {
+      result = LogAndCreateResult(
+                    ErrorCode::UNKNOWN_ERR, "Failed to obtain URL",
+                    ("bp_bookmark_adaptor_get_url error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
     } else {
       url_found = (0 == strcmp(url, compare_url));
       free(compare_url);
@@ -137,30 +142,38 @@ PlatformResult BookmarkInstance::BookmarkTitleExistsInParent(const char* title,
   int* ids = nullptr;
   char* compare_title = nullptr;
 
-  if (bp_bookmark_adaptor_get_ids_p(&ids,  // ids
-                                    &ids_count,  // count
-                                    -1,  //limit
-                                    0,  // offset
-                                    -1,  //parent
-                                    -1,  //type
-                                    -1,  // is_operator
-                                    -1,  // is_editable
-                                    BP_BOOKMARK_O_DATE_CREATED,  // order_offset
-                                    0  // ordering ASC
-                                    ) < 0) {
-    LoggerE("Failed to obtain bookmarks");
-    return PlatformResult{ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks"};
+  int ntv_ret = bp_bookmark_adaptor_get_ids_p(
+                    &ids,  // ids
+                    &ids_count,  // count
+                    -1,  //limit
+                    0,  // offset
+                    -1,  //parent
+                    -1,  //type
+                    -1,  // is_operator
+                    -1,  // is_editable
+                    BP_BOOKMARK_O_DATE_CREATED,  // order_offset
+                    0  // ordering ASC
+                    );
+  if (ntv_ret < 0) {
+    return LogAndCreateResult(
+                ErrorCode::UNKNOWN_ERR, "Failed to obtain bookmarks",
+                ("bp_bookmark_adaptor_get_ids_p error: %d (%s)",
+                    ntv_ret, get_error_message(ntv_ret)));
   }
 
   PlatformResult result{ErrorCode::NO_ERROR};
   bool title_found = false;
   for (int i = 0; (i < ids_count) && result && !title_found; ++i) {
-    if (bp_bookmark_adaptor_get_parent_id(ids[i], &compare_parent) < 0) {
-      LoggerE("Failed to obtain parent ID");
-      result = PlatformResult{ErrorCode::UNKNOWN_ERR, "Failed to obtain parent ID"};
-    } else if (bp_bookmark_adaptor_get_title(ids[i], &compare_title) < 0) {
-      LoggerE("Failed to obtain title");
-      result = PlatformResult{ErrorCode::UNKNOWN_ERR, "Failed to obtain title"};
+    if ((ntv_ret = bp_bookmark_adaptor_get_parent_id(ids[i], &compare_parent)) < 0) {
+      result = LogAndCreateResult(
+                    ErrorCode::UNKNOWN_ERR, "Failed to obtain parent ID",
+                    ("bp_bookmark_adaptor_get_parent_id error: %d (%s)",
+                        ntv_ret, get_error_message(ntv_ret)));
+    } else if ((ntv_ret = bp_bookmark_adaptor_get_title(ids[i], &compare_title)) < 0) {
+      result = LogAndCreateResult(
+                    ErrorCode::UNKNOWN_ERR, "Failed to obtain title",
+                    ("bp_bookmark_adaptor_get_title error: %d (%s)",
+                        ntv_ret, get_error_message(ntv_ret)));
     } else {
       title_found = (parent == compare_parent) && (0 == strcmp(title, compare_title));
       free(compare_title);
@@ -190,6 +203,7 @@ void BookmarkInstance::BookmarkGet(
   ctx.id             = arg.get(kId).get<double>();
 
   if (!bookmark_foreach(ctx, info)) {
+    LoggerE("BookmarkGet error");
     ReportError(o);
     return;
   }
@@ -227,10 +241,10 @@ void BookmarkInstance::BookmarkAdd(
     bool exists = false;
     auto result = BookmarkUrlExists(url.c_str(), &exists);
     if (!result) {
-      ReportError(result, &o);
+      LogAndReportError(result, &o);
       return;
     } else if (exists) {
-      ReportError(PlatformResult{ErrorCode::UNKNOWN_ERR, "Bookmark already exists"}, &o);
+      LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Bookmark already exists"), &o);
       return;
     }
   }
@@ -239,35 +253,51 @@ void BookmarkInstance::BookmarkAdd(
     bool exists = false;
     auto result = BookmarkTitleExistsInParent(title.c_str(), parent, &exists);
     if (!result) {
-      ReportError(result, &o);
+      LogAndReportError(result, &o);
       return;
     } else if (exists) {
-      ReportError(PlatformResult{ErrorCode::UNKNOWN_ERR, "Bookmark already exists"}, &o);
+      LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Bookmark already exists"), &o);
       return;
     }
   }
 
-  if (bp_bookmark_adaptor_create(&saved_id) < 0) {
+  int ntv_ret;
+
+  ntv_ret = bp_bookmark_adaptor_create(&saved_id);
+  if (ntv_ret < 0) {
+    LoggerE("bp_bookmark_adaptor_create error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
-  if (bp_bookmark_adaptor_set_title(saved_id, title.c_str()) < 0) {
+
+  ntv_ret = bp_bookmark_adaptor_set_title(saved_id, title.c_str());
+  if (ntv_ret < 0) {
     bp_bookmark_adaptor_delete(saved_id);
+    LoggerE("bp_bookmark_adaptor_set_title error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
-  if (bp_bookmark_adaptor_set_parent_id(saved_id, parent) < 0) {
+
+  ntv_ret = bp_bookmark_adaptor_set_parent_id(saved_id, parent);
+  if (ntv_ret < 0) {
     bp_bookmark_adaptor_delete(saved_id);
+    LoggerE("bp_bookmark_adaptor_set_parent_id error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
-  if (bp_bookmark_adaptor_set_type(saved_id, type) < 0) {
+
+  ntv_ret = bp_bookmark_adaptor_set_type(saved_id, type);
+  if (ntv_ret < 0) {
     bp_bookmark_adaptor_delete(saved_id);
+    LoggerE("bp_bookmark_adaptor_set_type error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
-  if (bp_bookmark_adaptor_set_url(saved_id, url.c_str()) < 0) {
+
+  ntv_ret = bp_bookmark_adaptor_set_url(saved_id, url.c_str());
+  if (ntv_ret < 0) {
     bp_bookmark_adaptor_delete(saved_id);
+    LoggerE("bp_bookmark_adaptor_set_url error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
@@ -280,7 +310,10 @@ void BookmarkInstance::BookmarkRemove(
   LoggerD("Enter");
   int id = common::stol(
       common::FromJson<std::string>(arg.get<picojson::object>(), kId));
-  if (bp_bookmark_adaptor_delete(id) < 0) {
+
+  int ntv_ret = bp_bookmark_adaptor_delete(id);
+  if (ntv_ret < 0) {
+    LoggerE("bp_bookmark_adaptor_delete error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
@@ -291,7 +324,9 @@ void BookmarkInstance::BookmarkRemoveAll(
     const picojson::value& msg, picojson::object& o) {
 
   LoggerD("Enter");
-  if (bp_bookmark_adaptor_reset() < 0) {
+  int ntv_ret = bp_bookmark_adaptor_reset();
+  if (ntv_ret < 0) {
+    LoggerE("bp_bookmark_adaptor_reset error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
@@ -303,7 +338,9 @@ void BookmarkInstance::BookmarkGetRootId(
 
   LoggerD("Enter");
   int rootId(0);
-  if (bp_bookmark_adaptor_get_root(&rootId) < 0) {
+  int ntv_ret = bp_bookmark_adaptor_get_root(&rootId);
+  if (ntv_ret < 0) {
+    LoggerE("bp_bookmark_adaptor_get_root error: %d (%s)", ntv_ret, get_error_message(ntv_ret));
     ReportError(o);
     return;
   }
index 43567a3..0985f9e 100644 (file)
@@ -2,6 +2,9 @@
   'includes':[
     '../common/common.gypi',
   ],
+  'variables': {
+    'enable_common_debug_logs%': '0',
+  },
   'targets': [
     {
       'target_name': 'tizen_common',
             }],
           ],
         }],
+        ['extension_build_type == "Debug"', {
+          'conditions': [
+            ['enable_common_debug_logs == 0', {
+              # remove TIZEN_DEBUG_ENABLE flag
+              'defines!': ['TIZEN_DEBUG_ENABLE'],
+            }],
+          ],
+        }],
       ],
       'direct_dependent_settings': {
         'libraries' : [
index e80dc4a..1da429d 100644 (file)
@@ -6,6 +6,37 @@
 #define COMMON_LOGGER_H_
 
 #include <dlog.h>
+
+// Tizen 3.0 uses different debug flag (DLOG_DEBUG_ENABLE) which is always
+// enabled, following code allows to disable logs with DLOG_DEBUG priority if
+// TIZEN_DEBUG_ENABLE is not set.
+// This code should be removed when DLOG_DEBUG_ENABLE flag is no longer set
+// by default in dlog.h file.
+#undef LOG_
+#ifdef TIZEN_DEBUG_ENABLE
+#define LOG_(id, prio, tag, fmt, arg...) \
+  ({ do { \
+    __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+  } while (0); })
+#else  // TIZEN_DEBUG_ENABLE
+#define LOG_(id, prio, tag, fmt, arg...) \
+  ({ do { \
+    if ((int)prio != DLOG_DEBUG) { \
+      __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+    } \
+  } while (0); })
+#endif  // TIZEN_DEBUG_ENABLE
+
+#undef SECURE_LOG_
+#ifdef TIZEN_DEBUG_ENABLE
+#define SECURE_LOG_(id, prio, tag, fmt, arg...) \
+  ({ do { \
+    __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+  } while (0); })
+#else  // TIZEN_DEBUG_ENABLE
+#define SECURE_LOG_(id, prio, tag, fmt, arg...) NOP(fmt, ##arg)
+#endif  // TIZEN_DEBUG_ENABLE
+
 #include <string>
 #include <cstring>
 #include <sstream>
index bb2a360..03c4b18 100755 (executable)
@@ -18,7 +18,6 @@
 
 #include <functional>
 #include <string>
-#include <dlog.h>
 #include <glib.h>
 #include <memory>
 #include <media_content.h>
index 927c533..e1541a1 100755 (executable)
@@ -943,8 +943,8 @@ PlatformResult ExifInformation::saveToFile(const std::string& file_path) {
 
     exif_data = exif_data_new();
     if (!exif_data) {
-      LoggerE("Couldn't allocate new ExifData");
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed",
+                                ("Couldn't allocate new ExifData"));
     }
 
     exif_data_set_option(exif_data, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
index 4687020..8be6a26 100755 (executable)
@@ -68,7 +68,7 @@ void ExifInstance::ExifManagerGetExifInfo(const picojson::value& args, picojson:
       if (status)
         ReportSuccess(result, response->get<picojson::object>());
       else
-        ReportError(status, &response->get<picojson::object>());
+        LogAndReportError(status, &response->get<picojson::object>());
   };
 
   auto get_response = [callback_id, this](const std::shared_ptr<JsonValue>& response)->void {
@@ -101,7 +101,7 @@ void ExifInstance::ExifManagerSaveExifInfo(const picojson::value& args,
       if (status)
         ReportSuccess(result, response->get<picojson::object>());
       else
-        ReportError(status, &response->get<picojson::object>());
+        LogAndReportError(status, &response->get<picojson::object>());
   };
 
   auto get_response = [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
@@ -136,30 +136,29 @@ void ExifInstance::ExifManagerGetThumbnail(const picojson::value& args,
       }
 
       if ("jpeg" != ext && "png" != ext && "gif" != ext) {
-        LoggerE("extension: %s is not valid (jpeg/jpg/png/gif is supported)",
-            ext.c_str());
         status = PlatformResult(ErrorCode::INVALID_VALUES_ERR,
             "getThumbnail support only jpeg/jpg/png/gif");
-        ReportError(status, &response->get<picojson::object>());
+        LogAndReportError(status, &response->get<picojson::object>(),
+                          ("extension: %s is not valid (jpeg/jpg/png/gif is supported)", ext.c_str()));
         return;
       }
 
       LoggerD("Get thumbnail from Exif in file: [%s]", file_path.c_str());
       ExifData *exif_data = exif_data_new_from_file(file_path.c_str());
       if (!exif_data) {
-        LoggerE("Error reading from file [%s]", file_path.c_str());
         status = PlatformResult(ErrorCode::UNKNOWN_ERR,
             "Error reading from file");
-        ReportError(status, &response->get<picojson::object>());
+        LogAndReportError(status, &response->get<picojson::object>(),
+                    ("Error reading from file [%s]", file_path.c_str()));
         return;
       }
 
       if (!exif_data->data || !exif_data->size) {
         exif_data_unref(exif_data);
-        LoggerE("File [%s] doesn't contain thumbnail", file_path.c_str());
         status = PlatformResult(ErrorCode::UNKNOWN_ERR,
             "File doesn't contain thumbnail");
-        ReportError(status, &response->get<picojson::object>());
+        LogAndReportError(status, &response->get<picojson::object>(),
+                    ("File [%s] doesn't contain thumbnail", file_path.c_str()));
         return;
       }
 
index fa41aa6..dc49cba 100755 (executable)
@@ -45,8 +45,7 @@ common::PlatformResult ExifTagSaver::saveToExif(long int value, ExifTag tag,
 
   ExifEntry* entry = prepareEntry(exif_data, tag);
   if (!entry) {
-    LoggerE("Exif entry is null");
-    return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
   }
 
   ExifByteOrder order = exif_data_get_byte_order(exif_data);
@@ -72,8 +71,8 @@ common::PlatformResult ExifTagSaver::saveToExif(long int value, ExifTag tag,
       break;
     }
     default: {
-      LoggerE("Error: wrong format: %d \n", entry->format);
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Wrong format");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Wrong format",
+                                    ("Error: wrong format: %d \n", entry->format));
     }
   }
   return common::PlatformResult(common::ErrorCode::NO_ERROR);
@@ -85,8 +84,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const std::string& value, ExifTa
   LoggerD("Entered");
   ExifEntry* entry = prepareEntry(exif_data, tag);
   if (!entry) {
-    LoggerE("Exif entry is null");
-    return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
   }
 
   if (!value.empty()) {
@@ -106,8 +104,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const std::string& value, ExifTa
 
     entry->data = static_cast<unsigned char*>(malloc(entry->size));
     if (entry->data == nullptr) {
-      LoggerE("Function malloc returned nullptr");
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
     }
 
     memcpy(entry->data, value.c_str(), value.length());
@@ -123,8 +120,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const Rational& value, ExifTag t
   LoggerD("Entered");
   ExifEntry* entry = prepareEntry(exif_data, tag);
   if (!entry) {
-    LoggerE("Exif entry is null");
-    return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
   }
   entry->format = EXIF_FORMAT_RATIONAL;
 
@@ -137,8 +133,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const Rational& value, ExifTag t
     entry->size = ExifTypeInfo::RationalSize;
     entry->data = static_cast<unsigned char*>(malloc(entry->size));
     if (entry->data == nullptr) {
-      LoggerE("Function malloc returned nullptr");
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
     }
     memset(entry->data, 0, entry->size);
   }
@@ -159,8 +154,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const Rationals& value, ExifTag
   LoggerD("Entered");
   ExifEntry* entry = prepareEntry(exif_data, tag);
   if (!entry) {
-    LoggerE("Exif entry is null");
-    return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
   }
   ExifByteOrder order = exif_data_get_byte_order(exif_data);
   entry->format = EXIF_FORMAT_RATIONAL;
@@ -175,8 +169,7 @@ common::PlatformResult ExifTagSaver::saveToExif(const Rationals& value, ExifTag
     entry->size = required_size;
     entry->data = static_cast<unsigned char*>(malloc(entry->size));
     if (entry->data == nullptr) {
-      LoggerE("Function malloc returned nullptr");
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
     }
     memset(entry->data, 0, entry->size);
   }
@@ -198,8 +191,7 @@ common::PlatformResult ExifTagSaver::saveToExif(std::vector<long long int>& valu
   LoggerD("Entered");
   ExifEntry* entry = prepareEntry(exif_data, tag);
   if (!entry) {
-    LoggerE("Exif entry is null");
-    return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Exif entry is null");
   }
   const ExifByteOrder order = exif_data_get_byte_order(exif_data);
 
@@ -212,8 +204,8 @@ common::PlatformResult ExifTagSaver::saveToExif(std::vector<long long int>& valu
     case EXIF_FORMAT_SLONG:
       break;
     default:
-      LoggerE("output ExifFormat: %d is not supported!", store_as);
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "ExifFormat is not supported!");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "ExifFormat is not supported!",
+                                    ("output ExifFormat: %d is not supported!", store_as));
   }
   entry->format = store_as;
 
@@ -228,8 +220,7 @@ common::PlatformResult ExifTagSaver::saveToExif(std::vector<long long int>& valu
     entry->size = required_size;
     entry->data = static_cast<unsigned char*>(malloc(entry->size));
     if (entry->data == nullptr) {
-      LoggerE("Function malloc returned nullptr");
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Function malloc returned nullptr");
     }
     memset(entry->data, 0, entry->size);
   }
@@ -275,7 +266,7 @@ common::PlatformResult ExifTagSaver::saveToExif(std::vector<long long int>& valu
       LoggerE("output ExifFormat: %d is not supported!", store_as);
       free(entry->data);
       entry->data = nullptr;
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "ExifFormat is not supported!");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "ExifFormat is not supported!");
     }
   }
 
@@ -423,8 +414,8 @@ common::PlatformResult ExifTagSaver::deduceIfdSection(ExifTag tag, ExifIfd* exif
 
     // Tags in other sections
     default:
-      LoggerE("Unsupported tag: %d", tag);
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Unsupported tag");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Unsupported tag",
+                                        ("Unsupported tag: %d", tag));
   }
 
   return common::PlatformResult(common::ErrorCode::NO_ERROR);
@@ -483,8 +474,8 @@ common::PlatformResult ExifTagSaver::deduceDataFormat(ExifTag tag, ExifFormat* e
 
     // Unsupported tags:
     default:
-      LoggerE("Unsupported tag: %d", tag);
-      return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Unsupported tag");
+      return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Unsupported tag",
+                                    ("Unsupported tag: %d", tag));
   }
 
   return common::PlatformResult(common::ErrorCode::NO_ERROR);
index 5092a5e..07758f6 100755 (executable)
@@ -221,8 +221,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry,
         pair = std::make_pair("isoSpeedRatings", JsonValue(array));
         result_obj->insert(pair);
       } else {
-        LoggerE("iso speed ratings: format or components count is invalid!");
-        return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR,
+        return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR,
             "iso speed ratings: format or components count is invalid!");
       }
       break;
@@ -246,8 +245,7 @@ PlatformResult GetExifInfo::ProcessEntry(ExifEntry* entry,
               exp_time.toString().c_str());
         }
       } else {
-        LoggerE("exposure time: format or components count is invalid!");
-        return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR,
+        return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR,
             "exposure time: format or components count is invalid!");
       }
       break;
@@ -502,9 +500,9 @@ PlatformResult GetExifInfo::LoadFromURI(const std::string& uri,
   const std::string& file_path = ExifUtil::convertUriToPath(uri);
   ExifData* ed = exif_data_new_from_file(file_path.c_str());
   if (!ed) {
-    LoggerE("Error reading exif from file %s", file_path.c_str());
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-            "Error reading exif from file");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+            "Error reading exif from file",
+            ("Error reading exif from file %s", file_path.c_str()));
   }
 
   LoggerD("loadFromURI_into_json exif_data_foreach_content START");
index b8c6f25..65bc4f5 100755 (executable)
@@ -121,8 +121,8 @@ PlatformResult JpegFile::loadFile(const std::string& path, JpegFilePtr* jpg_ptr)
   LoggerD("Entered");
   JpegFile* new_jpg = new (std::nothrow) JpegFile();
   if (!new_jpg) {
-    LoggerE("Couldn't allocate Jpegfile!");
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed",
+                          ("Couldn't allocate Jpegfile!"));
   }
 
   jpg_ptr->reset(new_jpg);
@@ -142,39 +142,38 @@ PlatformResult JpegFile::load(const std::string& path) {
 
   m_in_file = fopen(path.c_str(), "rb");
   if (!m_in_file) {
-    LoggerE("Couldn't open Jpeg file: [%s]", path.c_str());
-    return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not open JPEG file");
+    return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Could not open JPEG file",
+                              ("Couldn't open Jpeg file: [%s]", path.c_str()));
   }
 
   fseek(m_in_file, 0, SEEK_END);
 
   long ftell_val = ftell(m_in_file);
   if (0 > ftell_val) {
-    LoggerE("Input file [%s] access error! [%d]", path.c_str(), errno);
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                          ("Input file [%s] access error! [%d]", path.c_str(), errno));
   }
 
   const std::size_t in_file_size = static_cast<size_t>(ftell_val);
   fseek(m_in_file, 0, SEEK_SET);
   LoggerD("JPEG file: [%s] size:%d", path.c_str(), in_file_size);
   if (0 == in_file_size) {
-    LoggerE("Input file [%s] is empty!", path.c_str());
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                              ("Input file [%s] is empty!", path.c_str()));
   }
 
   m_in_data = new (std::nothrow) unsigned char[in_file_size];
   if (!m_in_data) {
-    LoggerE("Couldn't allocate buffer with size: %d", in_file_size);
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed",
+                              ("Couldn't allocate buffer with size: %d", in_file_size));
   }
 
   m_in_data_size = in_file_size;
 
   const std::size_t read_bytes = fread(m_in_data, 1, m_in_data_size, m_in_file);
   if (read_bytes != m_in_data_size) {
-    LoggerE("Couldn't read all: %d bytes. Read only: %d bytes!", m_in_data_size,
-        read_bytes);
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not read JPEG file");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not read JPEG file",
+                              ("Couldn't read all: %d bytes. Read only: %d bytes!", m_in_data_size, read_bytes));
   }
 
   if (fclose(m_in_file) == EOF) {
@@ -189,19 +188,19 @@ std::string JpegFile::getPartOfFile(const std::size_t offset,
                                     const std::size_t num_bytes_before,
                                     const std::size_t num_bytes_after) {
   LoggerD("Entered");
-  long long int start = static_cast<long long int>(offset) - num_bytes_before;
-  if (start < 0) {
+  auto start = offset - num_bytes_before;
+  if (offset < num_bytes_before) {
     start = 0;
   }
 
-  long long int end = static_cast<long long int>(offset) + num_bytes_after;
-  if (end >= m_in_data_size) {
+  auto end = offset + num_bytes_after;
+  if (end >= m_in_data_size || end < start) {
     end = m_in_data_size - 1;
   }
 
   std::stringstream ss;
   ss << std::setfill('0') << std::setw(2) << std::hex;
-  for (long long int i = start; i <= end; ++i) {
+  for (size_t i = start; i <= end; ++i) {
     ss << static_cast<int>(m_in_data[i]);
   }
   return ss.str();
@@ -245,9 +244,8 @@ common::PlatformResult JpegFile::generateListOfSections() {
     }
 
     if (search_len == search_offset) {
-      LoggerE("offset:%d | Couldn't find marker! RAW DATA:{%s}", offset,
-          getPartOfFile(offset, 0, 10).c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                                ("offset:%d | Couldn't find marker! RAW DATA:{%s}", offset, getPartOfFile(offset, 0, 10).c_str()));
     }
 
     const std::size_t section_offset = offset + search_offset - 1;
@@ -257,9 +255,9 @@ common::PlatformResult JpegFile::generateListOfSections() {
     LoggerD("offset:%d | Moved to section begin", offset);
 
     if (!isJpegMarker(section_begin[1])) {
-      LoggerE("offset:%d | Is not valid marker: 0x%x RAW DATA:{%s}", offset,
-          section_begin[1], getPartOfFile(section_offset, 0, 4).c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                                ("offset:%d | Is not valid marker: 0x%x RAW DATA:{%s}", offset,
+                                  section_begin[1], getPartOfFile(section_offset, 0, 4).c_str()));
     }
 
     const JpegMarker cur_marker = castToJpegMarker(section_begin[1]);
@@ -273,8 +271,8 @@ common::PlatformResult JpegFile::generateListOfSections() {
     {
       JpegFileSection* sec = new (std::nothrow) JpegFileSection();
       if (!sec) {
-        LoggerE("Couldn't allocate JpegFileSection");
-        return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed",
+                              ("Couldn't allocate JpegFileSection"));
       }
 
       section = JpegFileSectionPtr(sec);
@@ -317,18 +315,18 @@ common::PlatformResult JpegFile::generateListOfSections() {
       offset += 2;  // Read data size - 2 bytes
 
       if (total_section_len < 0) {
-        LoggerE("offset:%d tag:0x%x | Error: total_section_len is: %d < 0",
-            offset, cur_marker, total_section_len);
-        return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                                  ("offset:%d tag:0x%x | Error: total_section_len is: %d < 0",
+                                              offset, cur_marker, total_section_len));
       }
 
       if (section_offset + 2 + total_section_len > m_in_data_size) {
-        LoggerE("offset:%d tag:0x%x | Error: current section offset:%d"
-            " + 2 + total_section_len:%d = %d is greater then file size:%d",
-            offset, cur_marker,
-            section_offset, total_section_len,
-            section_offset + total_section_len, m_in_data_size);
-        return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                                  ("offset:%d tag:0x%x | Error: current section offset:%d"
+                                    " + 2 + total_section_len:%d = %d is greater then file size:%d",
+                                    offset, cur_marker,
+                                    section_offset, total_section_len,
+                                    section_offset + total_section_len, m_in_data_size));
       }
 
       if (JPEG_MARKER_APP1 == cur_marker) {
@@ -458,9 +456,9 @@ PlatformResult JpegFile::setNewExifData(ExifData* new_exif_data) {
     {
       JpegFileSection* new_sec = new (std::nothrow) JpegFileSection();
       if (!new_sec) {
-        LoggerE("Couldn't allocate JpegFileSection");
-        return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                "Memory allocation failed");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                "Memory allocation failed",
+                ("Couldn't allocate JpegFileSection"));
       }
       new_sec->type = JPEG_MARKER_APP1;
 
@@ -479,8 +477,8 @@ PlatformResult JpegFile::setNewExifData(ExifData* new_exif_data) {
     }
 
     if (!soi_is_present) {
-      LoggerW("SOI section is missing");
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "JPEG file is invalid",
+                            ("SOI section is missing"));
     }
 
     // Insert new Exif sections just after SOI
@@ -534,21 +532,21 @@ PlatformResult JpegFile::saveToFile(const std::string& out_path) {
 
     FILE* outf = fopen(out_path.c_str(), "wb");
     if (!outf) {
-      LoggerE("Couldn't open output file:"
-          " [%s] - JPEG file will not be restored!", out_path.c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-          "Couldn't open output file");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+          "Couldn't open output file",
+          ("Couldn't open output file:"
+           " [%s] - JPEG file will not be restored!", out_path.c_str()));
     }
 
     std::size_t bytes_wrote = fwrite(m_in_data, 1, m_in_data_size, outf);
     if (bytes_wrote != m_in_data_size) {
       fclose(outf);
 
-      LoggerE("Couldn't restore whole JPEG! "
-          "Only %d of %d bytes have been wrote!",
-          bytes_wrote, m_in_data_size);
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-          "Couldn't restore whole file");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+          "Couldn't restore whole file",
+          ("Couldn't restore whole JPEG! "
+           "Only %d of %d bytes have been wrote!",
+           bytes_wrote, m_in_data_size));
     }
     if (EOF == fclose(outf)) {
       LoggerE("Couldn't close restore output file: [%s]", out_path.c_str());
@@ -565,8 +563,8 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
 
   m_out_file = fopen(out_path.c_str(), "wb");
   if (!m_out_file) {
-    LoggerE("Couldn't open output file: %s", out_path.c_str());
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not write JPEG file");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not write JPEG file",
+                              ("Couldn't open output file: %s", out_path.c_str()));
   }
 
   unsigned char tmp_buf[128];
@@ -602,8 +600,7 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
         unsigned char* tmp = NULL;
         exif_data_save_data(cur->exif_data, &tmp, &exif_output_size);
         if (!tmp || 0 == exif_output_size) {
-          LoggerE("Couldn't generate RAW Exif data!");
-          return PlatformResult(ErrorCode::UNKNOWN_ERR,
+          return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
                   "Could not save Exif in JPEG file");
         }
 
@@ -613,11 +610,11 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
         exif_output_data.reset(tmp);
 
         if (exif_output_size > MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE) {
-          LoggerE("exif_output_size:%d is greater then maximum JPEG section"
-              "data block size: %d", exif_output_size,
-              MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE);
-          return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                  "Exif data is to big to be saved in JPEG file");
+          return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                                    "Exif data is to big to be saved in JPEG file",
+                                    ("exif_output_size:%d is greater then maximum JPEG section"
+                                        "data block size: %d", exif_output_size,
+                                        MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE));
         }
         section_size += exif_output_size;
         write_exif_data = true;
@@ -637,10 +634,10 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
     offset += bytes_wrote;
 
     if (bytes_wrote != bytes_to_write) {
-      LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
-          bytes_wrote);
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-              "Could not write JPEG file");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+              "Could not write JPEG file",
+              ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
+                        bytes_wrote));
     }
 
     if (write_section_data && cur->size > 0) {
@@ -651,10 +648,10 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
       offset += bytes_wrote;
 
       if (bytes_wrote != bytes_to_write) {
-        LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
-            bytes_wrote);
-        return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                "Could not write JPEG file");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                "Could not write JPEG file",
+                ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
+                            bytes_wrote));
       }
     }
 
@@ -668,10 +665,10 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
       offset += bytes_wrote;
 
       if (bytes_wrote != bytes_to_write) {
-        LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
-            bytes_wrote);
-        return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                "Could not write JPEG file");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                "Could not write JPEG file",
+                ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
+                            bytes_wrote));
       }
     }
 
@@ -684,10 +681,10 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
       offset += bytes_wrote;
 
       if (bytes_wrote != bytes_to_write) {
-        LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
-            bytes_wrote);
-        return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                "Could not write JPEG file");
+        return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                "Could not write JPEG file",
+                ("Couldn't wrote %d bytes! Only %d bytes wrote", bytes_to_write,
+                            bytes_wrote));
       }
     }
   }
@@ -698,10 +695,10 @@ PlatformResult JpegFile::saveToFilePriv(const std::string& out_path) {
         m_out_file);
 
     if (bytes_wrote != m_padding_data_size) {
-      LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote",
-          m_padding_data_size, bytes_wrote);
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-              "Could not write JPEG file");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+              "Could not write JPEG file",
+              ("Couldn't wrote %d bytes! Only %d bytes wrote",
+                        m_padding_data_size, bytes_wrote));
     }
   }
 
index 8b0ddf6..511f74a 100755 (executable)
@@ -75,7 +75,7 @@ PlatformResult HumanActivityMonitorInstance::Init() {
 
 #define CHECK_EXIST(args, name, out) \
     if (!args.contains(name)) { \
-      ReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, \
+      LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, \
           name" is required argument"), &out); \
       return; \
     }
@@ -88,8 +88,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerGetHumanActivityDa
 
   PlatformResult result = Init();
   if (!result) {
-    LoggerE("Failed: Init()");
-    ReportError(result, &out);
+    LogAndReportError(result, &out, ("Failed: Init()"));
     return;
   }
 
@@ -106,8 +105,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerGetHumanActivityDa
     if (result) {
       ReportSuccess(data, response_obj);
     } else {
-      LoggerE("Failed: manager_->GetHumanActivityData()");
-      ReportError(result, &response_obj);
+      LogAndReportError(result, &response_obj, ("Failed: manager_->GetHumanActivityData()"));
     }
 
     Instance::PostMessage(this, response.serialize().c_str());
@@ -125,8 +123,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStart(
 
   PlatformResult result = Init();
   if (!result) {
-    LoggerE("Failed: Init()");
-    ReportError(result, &out);
+    LogAndReportError(result, &out, ("Failed: Init()"));
     return;
   }
 
@@ -146,8 +143,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStart(
   if (result) {
     ReportSuccess(out);
   } else {
-    LoggerE("Failed: manager_->SetListener()");
-    ReportError(result, &out);
+    LogAndReportError(result, &out, ("Failed: manager_->SetListener()"));
   }
 }
 
@@ -158,8 +154,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStop(
 
   PlatformResult result = Init();
   if (!result) {
-    LoggerE("Failed: Init()");
-    ReportError(result, &out);
+    LogAndReportError(result, &out, ("Failed: Init()"));
     return;
   }
 
@@ -167,8 +162,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStop(
   if (result) {
     ReportSuccess(out);
   } else {
-    LoggerE("Failed: manager_->UnsetListener()");
-    ReportError(result, &out);
+    LogAndReportError(result, &out, ("Failed: manager_->UnsetListener()"));
   }
 }
 
index b666e09..fefb0e8 100755 (executable)
@@ -47,7 +47,7 @@ PlatformResult HumanActivityMonitorManager::IsSupported(
 
   // check cache first
   if (supported_.count(type)) {
-    return PlatformResult(supported_[type]
+    return LogAndCreateResult(supported_[type]
         ? ErrorCode::NO_ERROR
         : ErrorCode::NOT_SUPPORTED_ERR);
   }
@@ -60,26 +60,26 @@ PlatformResult HumanActivityMonitorManager::IsSupported(
   } else if (type == kActivityTypeWristUp) {
     ret = gesture_is_supported(GESTURE_WRIST_UP, &supported);
     if (ret != SENSOR_ERROR_NONE) {
-      LOGGER(ERROR) << "gesture_is_supported(GESTURE_WRIST_UP), error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "WRIST_UP gesture check failed");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "WRIST_UP gesture check failed",
+                            ("gesture_is_supported(GESTURE_WRIST_UP), error: %d",ret));
     }
   } else if (type == kActivityTypeHrm) {
     ret = sensor_is_supported(SENSOR_HRM, &supported);
     if (ret != SENSOR_ERROR_NONE) {
-      LOGGER(ERROR) << "sensor_is_supported(HRM), error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "HRM sensor check failed");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "HRM sensor check failed",
+                            ("sensor_is_supported(HRM), error: %d",ret));
     }
   } else if (type == kActivityTypeGps) {
     supported = location_manager_is_supported_method(LOCATIONS_METHOD_GPS);
   } else {
-    return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR);
+    return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR);
   }
 
   supported_[type] = supported;
 
-  return PlatformResult(supported_[type]
+  return LogAndCreateResult(supported_[type]
       ? ErrorCode::NO_ERROR
       : ErrorCode::NOT_SUPPORTED_ERR);
 }
@@ -108,7 +108,7 @@ PlatformResult HumanActivityMonitorManager::SetListener(
     return SetGpsListener(callback);
   }
 
-  return PlatformResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
+  return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
 }
 
 PlatformResult HumanActivityMonitorManager::UnsetListener(
@@ -135,7 +135,7 @@ PlatformResult HumanActivityMonitorManager::UnsetListener(
     return UnsetGpsListener();
   }
 
-  return PlatformResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
+  return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
 }
 
 PlatformResult HumanActivityMonitorManager::GetHumanActivityData(
@@ -148,7 +148,7 @@ PlatformResult HumanActivityMonitorManager::GetHumanActivityData(
   }
 
   if (type == kActivityTypeWristUp) {
-    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR);
+    return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR);
   }
 
   if (type == kActivityTypeHrm) {
@@ -159,7 +159,7 @@ PlatformResult HumanActivityMonitorManager::GetHumanActivityData(
     return GetGpsData(data);
   }
 
-  return PlatformResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
+  return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Undefined activity type");
 }
 
 // WRIST_UP
@@ -170,9 +170,9 @@ PlatformResult HumanActivityMonitorManager::SetWristUpListener(
 
   ret = gesture_create(&gesture_handle_);
   if (ret != GESTURE_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to create WRIST_UP handle, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to create WRIST_UP listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to create WRIST_UP listener",
+                          ("Failed to create WRIST_UP handle, error: %d",ret));
   }
 
   ret = gesture_start_recognition(gesture_handle_,
@@ -181,9 +181,9 @@ PlatformResult HumanActivityMonitorManager::SetWristUpListener(
                                   OnWristUpEvent,
                                   this);
   if (ret != GESTURE_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to start WRIST_UP listener, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to start WRIST_UP listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to start WRIST_UP listener",
+                          ("Failed to start WRIST_UP listener, error: %d",ret));
   }
 
   wrist_up_event_callback_ = callback;
@@ -238,16 +238,16 @@ PlatformResult HumanActivityMonitorManager::SetHrmListener(
 
   ret = sensor_get_default_sensor(SENSOR_HRM, &hrm_sensor);
   if (ret != SENSOR_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to get HRM sensor, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to get HRM sensor");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to get HRM sensor",
+                          ("Failed to get HRM sensor, error: %d",ret));
   }
 
   ret = sensor_create_listener(hrm_sensor, &hrm_sensor_listener_);
   if (ret != SENSOR_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to create HRM sensor listener, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to create HRM sensor listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to create HRM sensor listener",
+                          ("Failed to create HRM sensor listener, error: %d",ret));
   }
 
   ret = sensor_listener_set_event_cb(hrm_sensor_listener_,
@@ -255,16 +255,16 @@ PlatformResult HumanActivityMonitorManager::SetHrmListener(
                                      OnHrmSensorEvent,
                                      this);
   if (ret != SENSOR_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to set HRM sensor listener, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to set HRM sensor listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to set HRM sensor listener",
+                          ("Failed to set HRM sensor listener, error: %d",ret));
   }
 
   ret = sensor_listener_start(hrm_sensor_listener_);
   if (ret != SENSOR_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to start HRM sensor listener, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to start HRM sensor listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to start HRM sensor listener",
+                          ("Failed to start HRM sensor listener, error: %d",ret));
   }
 
   hrm_event_callback_ = callback;
@@ -278,23 +278,23 @@ PlatformResult HumanActivityMonitorManager::UnsetHrmListener() {
   if (hrm_sensor_listener_) {
     int ret = sensor_listener_stop(hrm_sensor_listener_);
     if (ret != SENSOR_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to stop HRM sensor, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to stop HRM sensor");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to stop HRM sensor",
+                            ("Failed to stop HRM sensor, error: "%d,ret));
     }
 
     ret = sensor_listener_unset_event_cb(hrm_sensor_listener_);
     if (ret != SENSOR_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to unset HRM sensor listener, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to unset HRM sensor listener");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to unset HRM sensor listener",
+                            ("Failed to unset HRM sensor listener, error: %d",ret));
     }
 
     ret = sensor_destroy_listener(hrm_sensor_listener_);
     if (ret != SENSOR_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to destroy HRM sensor listener, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to destroy HRM sensor listener");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to destroy HRM sensor listener",
+                            ("Failed to destroy HRM sensor listener, error: %d",ret));
     }
   }
 
@@ -311,8 +311,7 @@ static PlatformResult ConvertHrmEvent(sensor_event_s* event,
   LOGGER(DEBUG) << "  |- value_count: " << event->value_count;
 
   if (event->value_count < 2) {
-    LOGGER(ERROR) << "To few values of HRM event";
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "To few values of HRM event");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "To few values of HRM event");
   }
 
   LOGGER(DEBUG) << "  |- values[0]: " << event->values[0];
@@ -358,7 +357,7 @@ void HumanActivityMonitorManager::OnHrmSensorEvent(
 PlatformResult HumanActivityMonitorManager::GetHrmData(picojson::value* data) {
   LoggerD("Enter");
   if (!hrm_sensor_listener_) {
-    return PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR);
+    return LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR);
   }
 
   int ret;
@@ -366,9 +365,9 @@ PlatformResult HumanActivityMonitorManager::GetHrmData(picojson::value* data) {
   sensor_event_s event;
   ret = sensor_listener_read_data(hrm_sensor_listener_, &event);
   if (ret != SENSOR_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to get HRM sensor data, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to get HRM sensor data");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to get HRM sensor data",
+                          ("Failed to get HRM sensor data, error: %d",ret));
   }
 
   *data = picojson::value(picojson::object());
@@ -389,9 +388,9 @@ PlatformResult HumanActivityMonitorManager::SetGpsListener(
 
   ret = location_manager_create(LOCATIONS_METHOD_GPS, &location_handle_);
   if (ret != LOCATIONS_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to create location manager, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to create location manager");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to create location manager",
+                          ("Failed to create location manager, error: %d",ret));
   }
 
   ret = location_manager_set_location_batch_cb(location_handle_,
@@ -400,16 +399,16 @@ PlatformResult HumanActivityMonitorManager::SetGpsListener(
                                                120, // batch_period
                                                this);
   if (ret != LOCATIONS_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to set location listener, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to set location listener");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to set location listener",
+                          ("Failed to set location listener, error: %d",ret));
   }
 
   ret = location_manager_start_batch(location_handle_);
   if (ret != LOCATIONS_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to start location manager, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                          "Failed to start location manager");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                          "Failed to start location manager",
+                          ("Failed to start location manager, error: %d",ret));
   }
 
   gps_event_callback_ = callback;
@@ -423,23 +422,23 @@ PlatformResult HumanActivityMonitorManager::UnsetGpsListener() {
   if (location_handle_) {
     int ret = location_manager_stop_batch(location_handle_);
     if (ret != LOCATIONS_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to stop location manager, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to stop location manager");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to stop location manager",
+                            ("Failed to stop location manager, error: %d",ret));
     }
 
     ret = location_manager_unset_location_batch_cb(location_handle_);
     if (ret != LOCATIONS_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to unset location listener, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to unset location listener");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to unset location listener",
+                            ("Failed to unset location listener, error: %d",ret));
     }
 
     ret = location_manager_destroy(location_handle_);
     if (ret != LOCATIONS_ERROR_NONE) {
-      LOGGER(ERROR) << "Failed to destroy location manager, error: " << ret;
-      return PlatformResult(ErrorCode::UNKNOWN_ERR,
-                            "Failed to destroy location manager");
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                            "Failed to destroy location manager",
+                            ("Failed to destroy location manager, error: %d",ret));
     }
   }
 
@@ -503,7 +502,7 @@ void HumanActivityMonitorManager::OnGpsEvent(int num_of_location,
 PlatformResult HumanActivityMonitorManager::GetGpsData(picojson::value* data) {
   LoggerD("Enter");
   if (!location_handle_) {
-    return PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR);
+    return LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR);
   }
 
   int ret;
@@ -516,8 +515,8 @@ PlatformResult HumanActivityMonitorManager::GetGpsData(picojson::value* data) {
                                       &level, &horizontal, &vertical,
                                       &timestamp);
   if (ret != LOCATIONS_ERROR_NONE) {
-    LOGGER(ERROR) << "Failed to get location, error: " << ret;
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get location");
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to get location",
+                              ("Failed to get location, error: %d",ret));
   }
 
   *data = picojson::value(picojson::array());
index 4bc7e0d..42443c6 100644 (file)
@@ -191,7 +191,7 @@ PlatformResult SoundManager::GetMaxVolume(sound_type_e type, int* max_volume) {
 
 double SoundManager::ConvertToSystemVolume(int max_volume, int volume) {
   LoggerD("Enter");
-  return round(static_cast<double>(volume) * 10 / max_volume) / 10;
+  return round(static_cast<double>(volume) * 100 / max_volume) / 100;
 }
 
 void SoundManager::VolumeChangeCallback(sound_type_e type, unsigned int value) {