Check coding style 20/185620/2
authormk5004.lee <mk5004.lee@samsung.com>
Wed, 1 Aug 2018 07:08:22 +0000 (16:08 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Thu, 2 Aug 2018 01:47:11 +0000 (10:47 +0900)
- parser, watchface-common

Change-Id: I7f3fc6d5661a6aa9e7a291decd0eae45f438de11
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
parser/complication_parser_plugin.cc
parser/complication_parser_plugin_internal.h
parser/complication_parser_plugin_pkgmgr_interface.cc
watchface-common/watchface-util.cc
watchface-common/watchface-util.h
watchface-common/watchface_exception.h

index 4f0a50c..9797867 100644 (file)
@@ -123,7 +123,7 @@ static char* _get_attribute(xmlNode* node, const char* name) {
 
   val = xmlGetProp(node, (const xmlChar*)name);
   if (val) {
-    attr = strdup((char*)val);
+    attr = strdup(reinterpret_cast<char*>(val));
     xmlFree(val);
   }
 
@@ -132,8 +132,10 @@ static char* _get_attribute(xmlNode* node, const char* name) {
 
 static int _get_support_type_tag(xmlNode* node) {
   unsigned int i;
+  unsigned int map_count;
 
-  for (i = 0; i < (sizeof(__type_map) / sizeof(struct support_type_tag_map)); i++) {
+  map_count  = sizeof(__type_map) / sizeof(struct support_type_tag_map);
+  for (i = 0; i < map_count; i++) {
     if (!xmlStrcasecmp(node->name, (const xmlChar*)__type_map[i].name))
       return __type_map[i].tag;
   }
@@ -143,8 +145,10 @@ static int _get_support_type_tag(xmlNode* node) {
 
 static const char* _get_bundle_key(const char* xml_element) {
   unsigned int i;
+  unsigned int map_count;
 
-  for (i = 0; i < (sizeof(__budle_key_map) / sizeof(struct xml_to_bundle_key_map)); i++) {
+  map_count = sizeof(__budle_key_map) / sizeof(struct xml_to_bundle_key_map);
+  for (i = 0; i < map_count; i++) {
     if (strcmp(xml_element, __budle_key_map[i].xml_element) == 0)
       return __budle_key_map[i].bundle_key;
   }
@@ -256,7 +260,7 @@ static int _get_time_value(const char* time_type, const char* time_val,
   }
 
   time_t default_time = mktime(timeinfo);
-  char num_str[32] = {0,};
+  char num_str[32] = {0, };
   snprintf(num_str, sizeof(num_str), "%ld", default_time);
   *default_value = num_str;
   LOGD("%d/%d/%d %d:%d:%d (%s)",
@@ -341,7 +345,7 @@ static int _parse_support_type(xmlNode* node, sqlite3* db, const char* pkgid,
           if (prev_value)
             bundle_del(default_data, TIME_KEY);
         } else {
-          default_value = (char*)tmpdata->children->content;
+          default_value = reinterpret_cast<char*>(tmpdata->children->content);
         }
 
         ret = bundle_add_str(default_data, bundle_key, default_value);
@@ -425,11 +429,13 @@ static int _parse_label(xmlNode* node, sqlite3* db, const char* providerid) {
   sqlite3_bind_text(stmt, idx++, providerid, -1, SQLITE_TRANSIENT);
 
   if (lang)
-    sqlite3_bind_text(stmt, idx++, (char*)lang, -1, SQLITE_TRANSIENT);
+    sqlite3_bind_text(stmt, idx++, reinterpret_cast<char*>(lang), -1,
+                        SQLITE_TRANSIENT);
   else
     sqlite3_bind_text(stmt, idx++, "No Locale", -1, SQLITE_TRANSIENT);
 
-  sqlite3_bind_text(stmt, idx, (char*)node->children->content, -1, SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, idx, reinterpret_cast<char*>(node->children->content),
+                        -1, SQLITE_TRANSIENT);
 
   ret = sqlite3_step(stmt);
   if (ret != SQLITE_DONE) {
@@ -448,7 +454,8 @@ out:
   return ret;
 }
 
-static int _parse_privilege(xmlNode* node, sqlite3* db, const char* providerid) {
+static int _parse_privilege(xmlNode* node, sqlite3* db,
+    const char* providerid) {
   int ret;
   sqlite3_stmt* stmt = NULL;
   xmlNode* tmp;
@@ -470,7 +477,8 @@ static int _parse_privilege(xmlNode* node, sqlite3* db, const char* providerid)
   for (tmp = node->children; tmp; tmp = tmp->next) {
     if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"privilege")) {
       sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 2, (char*)tmp->children->content, -1, SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 2, (char*)tmp->children->content, -1,
+                        SQLITE_TRANSIENT);
 
       ret = sqlite3_step(stmt);
       if (ret != SQLITE_DONE) {
@@ -545,7 +553,7 @@ static int _parse_complication(xmlNode* node, sqlite3* db, const char* pkgid,
         || tmp->children->content == NULL)
         return -1;
 
-      period = atoi((char*)tmp->children->content);
+      period = atoi(reinterpret_cast<char*>(tmp->children->content));
       if (period < 60)
         period = 60;
     } else if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"label")) {
@@ -654,7 +662,8 @@ out:
   return result;
 }
 
-int complication_parser_plugin_parse_manifest(xmlDocPtr doc, const char* pkgid) {
+int complication_parser_plugin_parse_manifest(xmlDocPtr doc,
+    const char* pkgid) {
   xmlNode* root;
   xmlNode* tmp;
 
index 91b5f21..73b001f 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef __WIDGET_PLUGIN_PARSER_INTERNAL_H__
-#define __WIDGET_PLUGIN_PARSER_INTERNAL_H__
+#ifndef PARSER_COMPLICATION_PARSER_PLUGIN_INTERNAL_H_
+#define PARSER_COMPLICATION_PARSER_PLUGIN_INTERNAL_H_
 
 #include <stdbool.h>
 #include <sys/types.h>
@@ -40,4 +40,4 @@ int complication_parser_db_remove_complication(const char* pkgid);
 
 sqlite3* open_db(uid_t uid);
 int check_db(uid_t uid);
-#endif
+#endif  // PARSER_COMPLICATION_PARSER_PLUGIN_INTERNAL_H_
index b4af9bc..7da374d 100644 (file)
@@ -24,7 +24,8 @@ extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char* pkgid) {
   return complication_parser_plugin_init();
 }
 
-extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgid) {
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc,
+    const char* pkgid) {
   if (complication_parser_plugin_parse_manifest(doc, pkgid)) {
     LOGE("parse failed");
     return -1;
@@ -41,7 +42,8 @@ extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char* pkgid) {
   return complication_parser_plugin_init();
 }
 
-extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgid) {
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc,
+    const char* pkgid) {
   if (complication_parser_db_remove_complication(pkgid)) {
     LOGE("remove db fail");
     return -1;
@@ -59,14 +61,17 @@ extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char* pkgid) {
   return complication_parser_plugin_fini();
 }
 
-extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char* pkgid) {
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(
+    const char* pkgid) {
   return complication_parser_plugin_init();
 }
 
-extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgid) {
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc,
+    const char* pkgid) {
   return complication_parser_db_remove_complication(pkgid);
 }
 
-extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char* pkgid) {
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(
+    const char* pkgid) {
   return complication_parser_plugin_fini();
 }
index e01fbf5..15e4eef 100644 (file)
@@ -28,7 +28,6 @@
 #include "watchface-util.h"
 #include "watchface-common.h"
 
-
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
@@ -39,8 +38,9 @@
 #define LOG_TAG "WATCHFACE_COMPLICATION"
 
 namespace watchface_complication {
-  namespace util {
-  static int __cynara_check(const char* client, const char* user, const char* privilege) {
+namespace util {
+  static int __cynara_check(const char* client, const char* user,
+      const char* privilege) {
     int ret, cynara_ret;
     cynara* p_cynara = NULL;
 
@@ -70,8 +70,8 @@ namespace watchface_complication {
   int CheckPrivilege(const char* privilege) {
     int fd;
     int ret;
-    char subject_label[SMACK_LABEL_LEN + 1] = {0,};
-    char uid[10] = {0,};
+    char subject_label[SMACK_LABEL_LEN + 1] = {0, };
+    char uid[10] = {0, };
 
     fd = open("/proc/self/attr/current", O_RDONLY);
     if (fd == -1) {
@@ -84,7 +84,7 @@ namespace watchface_complication {
       LOGE("read [%d] failed!", errno);
       ret = WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
     } else {
-      snprintf(uid, 10, "%d", getuid());
+      snprintf(uid, sizeof(uid), "%d", getuid());
       ret = __cynara_check(subject_label, uid, privilege);
     }
 
@@ -114,7 +114,7 @@ namespace watchface_complication {
       goto out;
     }
 
-    LOGD("app_id(%s), client(%s), user(%s)", sender_appid.c_str(), client, user);
+    LOGD("appid(%s), client(%s), user(%s)", sender_appid.c_str(), client, user);
 
     ret = __cynara_check(client, user, privilege.c_str());
 
@@ -127,7 +127,8 @@ out:
     return ret;
   }
 
-  std::string GetSenderAppid(GDBusConnection* conn, const std::string& sender_name) {
+  std::string GetSenderAppid(GDBusConnection* conn,
+      const std::string& sender_name) {
     int ret = 0;
     char buffer[MAX_PACKAGE_STR_SIZE + 1] = {0, };
     int pid = GetSenderPid(conn, sender_name);
@@ -147,8 +148,10 @@ out:
     GVariant* body;
     int pid = 0;
 
-    msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
-                    "org.freedesktop.DBus", "GetConnectionUnixProcessID");
+    msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
+                          "/org/freedesktop/DBus",
+                          "org.freedesktop.DBus",
+                          "GetConnectionUnixProcessID");
     if (!msg) {
       LOGE("Can't allocate new method call");
       goto out;
@@ -220,5 +223,5 @@ out:
     }
   }
 
-  }    /* namespace util */
-}      /*  namespace watchface_complication */
+}  // namespace util
+}  // namespace watchface_complication
index 1703791..ddee2af 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef WATCHFACE_COMPLICATION_UTIL_H_
-#define WATCHFACE_COMPLICATION_UTIL_H_
+#ifndef WATCHFACE_COMMON_WATCHFACE_UTIL_H_
+#define WATCHFACE_COMMON_WATCHFACE_UTIL_H_
 
 #include <gio/gio.h>
 #include <string>
@@ -30,19 +30,20 @@ enum cynara_result {
 };
 
 namespace watchface_complication {
-  namespace util {
+namespace util {
   int CheckPrivilege(const char* privilege);
   int CheckPrivilege(std::string& privilege,
                                      GDBusConnection *connection,
                                      std::string& sender_name,
                                      std::string& sender_appid);
   int GetSenderPid(GDBusConnection *conn, const std::string& sender_name);
-  std::string GetSenderAppid(GDBusConnection *conn, const std::string& sender_name);
+  std::string GetSenderAppid(GDBusConnection *conn,
+                          const std::string& sender_name);
   bool CheckSender(const char* sender_app_id,
                                 const std::string& sender_name,
                                 GDBusConnection* conn);
   bool CheckComplicationType(int type);
-  }
-}  /* namespace watchface_complication */
+}  // namespace util
+}  // namespace watchface_complication
 
-#endif  /* WATCHFACE_COMPLICATION_DB_MANAGER_H_ */
+#endif  // WATCHFACE_COMMON_WATCHFACE_UTIL_H_
index 420dd9b..7e63eb5 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef WATCHFACE_COMPLICATION_EXCEPTION_H_
-#define WATCHFACE_COMPLICATION_EXCEPTION_H_
+#ifndef WATCHFACE_COMMON_WATCHFACE_EXCEPTION_H_
+#define WATCHFACE_COMMON_WATCHFACE_EXCEPTION_H_
 
 #include <string>
 #include <exception>
 #define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
 
 namespace watchface_complication {
-  class Exception : public std::exception {
-    public:
-      Exception(int error_code, std::string file = __FILE__, int line = __LINE__ ) {
-        _error_code = error_code;
-        _whatMessage = file.substr(file.find_last_of("/") + 1) + ":"
-           + std::to_string(line) + GetErrorString(error_code);
-      }
-      virtual ~Exception() {};
-      virtual const char *what(void) const noexcept {
-        return _whatMessage.c_str();
-      }
-      int GetErrorCode() {
-        return _error_code;
-      }
 
-      private:
-      int _error_code;
-      std::string _whatMessage;
-      std::string GetErrorString(int error_code) {
-        switch (error_code) {
-        case WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY:
-          return ": OUT_OF_MEMORY";
-        case WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER:
-          return ": INVALID_PARAMETER";
-        case WATCHFACE_COMPLICATION_ERROR_IO_ERROR:
-          return ": IO_ERROR";
-        case WATCHFACE_COMPLICATION_ERROR_NO_DATA:
-          return ": NO_DATA";
-        case WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED:
-          return ": PERMISSION_DENIED";
-        case WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED:
-          return ": NOT_SUPPORTED";
-        case WATCHFACE_COMPLICATION_ERROR_DB:
-          return ": DB_ERROR";
-        case WATCHFACE_COMPLICATION_ERROR_DBUS:
-          return ": DBUS_ERROR";
-        case WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY:
-          return ": EDIT_NOT_READY";
-        case WATCHFACE_COMPLICATION_ERROR_EXIST_ID:
-          return ": EXIST_ID";
-        case WATCHFACE_COMPLICATION_ERROR_NOT_EXIST:
-          return ": NOT_EXIST";
-        default :
-          return "";
-      }
+class Exception : public std::exception {
+ public:
+  Exception(int error_code, std::string file = __FILE__, int line = __LINE__ ) {
+    _error_code = error_code;
+    _whatMessage = file.substr(file.find_last_of("/") + 1) + ":"
+        + std::to_string(line) + GetErrorString(error_code);
     }
-  };
-}
+    virtual ~Exception() {}
+    virtual const char *what(void) const noexcept {
+      return _whatMessage.c_str();
+    }
+    int GetErrorCode() {
+      return _error_code;
+    }
+
+ private:
+    int _error_code;
+    std::string _whatMessage;
+    std::string GetErrorString(int error_code) {
+      switch (error_code) {
+      case WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY:
+        return ": OUT_OF_MEMORY";
+      case WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER:
+        return ": INVALID_PARAMETER";
+      case WATCHFACE_COMPLICATION_ERROR_IO_ERROR:
+        return ": IO_ERROR";
+      case WATCHFACE_COMPLICATION_ERROR_NO_DATA:
+        return ": NO_DATA";
+      case WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED:
+        return ": PERMISSION_DENIED";
+      case WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED:
+        return ": NOT_SUPPORTED";
+      case WATCHFACE_COMPLICATION_ERROR_DB:
+        return ": DB_ERROR";
+      case WATCHFACE_COMPLICATION_ERROR_DBUS:
+        return ": DBUS_ERROR";
+      case WATCHFACE_COMPLICATION_ERROR_EDIT_NOT_READY:
+        return ": EDIT_NOT_READY";
+      case WATCHFACE_COMPLICATION_ERROR_EXIST_ID:
+        return ": EXIST_ID";
+      case WATCHFACE_COMPLICATION_ERROR_NOT_EXIST:
+        return ": NOT_EXIST";
+      default :
+        return "";
+    }
+  }
+};
+
+}  // namespace watchface_complication
 
-#endif  /* WATCHFACE_COMPLICATION_DB_MANAGER_H_ */
+#endif  // WATCHFACE_COMMON_WATCHFACE_EXCEPTION_H_