Refactor coding style 59/245259/6
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 6 Oct 2020 06:29:33 +0000 (15:29 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 6 Oct 2020 07:29:06 +0000 (16:29 +0900)
Change-Id: Icfc09b7ca2a7d28abcc8082effcefdedd2d9f130
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
16 files changed:
src/ac-internal.cc
src/ac-internal.hh [moved from src/ac-internal.h with 76% similarity]
src/debug-port-internal.cc
src/debug-port-internal.hh
src/fdbroker-internal.cc
src/fdbroker-internal.hh [moved from src/fdbroker-internal.h with 87% similarity]
src/parcel-internal.cc
src/parcel-internal.hh [moved from src/parcel-internal.h with 82% similarity]
src/port-internal.cc
src/port-internal.hh [moved from src/port-internal.h with 82% similarity]
src/proxy-internal.cc
src/proxy-internal.hh [moved from src/proxy-internal.h with 93% similarity]
src/rpc-port-parcel.cc
src/rpc-port.cc
src/stub-internal.cc
src/stub-internal.hh [moved from src/stub-internal.h with 93% similarity]

index d6c4037..194f9fa 100644 (file)
@@ -24,7 +24,7 @@
 #include <cynara-error.h>
 #include <cynara-creds-gdbus.h>
 
-#include "ac-internal.h"
+#include "ac-internal.hh"
 #include "log-private.hh"
 
 namespace rpc_port {
similarity index 76%
rename from src/ac-internal.h
rename to src/ac-internal.hh
index cb3b674..e870ec3 100644 (file)
@@ -36,26 +36,26 @@ class AccessController {
 
   void AddPrivilege(std::string privilege);
   void SetTrusted(const bool trusted);
-  int Check(GDBusConnection *connection, const char *sender,
+  int Check(GDBusConnection* connection, const char* sender,
             const char* sender_appid);
 
  private:
   class Cynara {
    public:
-     Cynara();
-     ~Cynara();
+    Cynara();
+    ~Cynara();
 
-     int FetchCredsFromDBus(GDBusConnection *connection, const char *sender);
-     int Check(const std::string& privilege) const;
+    int FetchCredsFromDBus(GDBusConnection* connection, const char* sender);
+    int Check(const std::string& privilege) const;
 
    private:
-     std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
-     std::unique_ptr<char, decltype(std::free)*> client_;
-     std::unique_ptr<char, decltype(std::free)*> user_;
+    std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
+    std::unique_ptr<char, decltype(std::free)*> client_;
+    std::unique_ptr<char, decltype(std::free)*> user_;
   };
 
   int SetCache(const std::string& sender);
-  int CheckTrusted(const char *sender_appid);
+  int CheckTrusted(const charsender_appid);
   int CheckPrivilege(const Cynara& c);
 
  private:
index dc1b0ba..4723a87 100644 (file)
 
 #include "debug-port-internal.hh"
 #include "log-private.hh"
-#include "parcel-internal.h"
+#include "parcel-internal.hh"
 
 namespace rpc_port {
 namespace internal {
 
-static const char PATH_RPC_PORT_UTIL_SOCK[] =
-    "/run/aul/daemons/.rpc-port-util-sock";
-static const char RPC_PORT_SIGNAL_PATH[] = "/Org/Tizen/RPC/Port/Signal";
-static const char RPC_PORT_SIGNAL_INTERFACE[] = "org.tizen.rpc.port.signal";
-static const char RPC_PORT_SIGNAL_DEBUG[] = "Debug";
-static const char RPC_PORT_SIGNAL_NEW[] = "New";
+namespace {
+const char PATH_RPC_PORT_UTIL_SOCK[] = "/run/aul/daemons/.rpc-port-util-sock";
+const char RPC_PORT_SIGNAL_PATH[] = "/Org/Tizen/RPC/Port/Signal";
+const char RPC_PORT_SIGNAL_INTERFACE[] = "org.tizen.rpc.port.signal";
+const char RPC_PORT_SIGNAL_DEBUG[] = "Debug";
+const char RPC_PORT_SIGNAL_NEW[] = "New";
+}  // namespace
 
 DebugPort::~DebugPort() {
   if (!disposed_)
@@ -54,22 +55,20 @@ void DebugPort::AddSession(std::string port_name, std::string destination,
     int main_port, int delegate_port) {
   std::lock_guard<std::recursive_mutex> lock(GetMutex());
   sessions_.emplace_back(
-      new DebugPort::Session(
-        port_name, destination, main_port, delegate_port));
+      new DebugPort::Session(std::move(port_name), std::move(destination),
+      main_port, delegate_port));
 }
 
 void DebugPort::RemoveSession(int port) {
   std::lock_guard<std::recursive_mutex> lock(GetMutex());
-  auto iter = sessions_.begin();
-  while (iter != sessions_.end()) {
-    if ((*iter)->GetMainPort() == port ||
-        (*iter)->GetDelegatePort() == port) {
-      _W("Remove session. port(%d)", port);
-      iter = sessions_.erase(iter);
-      break;
-    }
-
-    ++iter;
+  auto iter = std::find_if(sessions_.begin(), sessions_.end(),
+      [port](std::shared_ptr<DebugPort::Session>& sess) -> bool {
+        return sess->GetMainPort() == port || sess->GetDelegatePort() == port;
+      });
+
+  if (iter != sessions_.end()) {
+    _W("Remove session. port(%d)", port);
+    iter = sessions_.erase(iter);
   }
 }
 
index 3fa25e7..8904bba 100644 (file)
@@ -27,8 +27,8 @@
 #include <string>
 #include <thread>
 
-#include "parcel-internal.h"
-#include "port-internal.h"
+#include "parcel-internal.hh"
+#include "port-internal.hh"
 #include "shared-queue-internal.hh"
 
 namespace rpc_port {
index 19450e0..6cc085d 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <algorithm>
 
-#include "fdbroker-internal.h"
+#include "fdbroker-internal.hh"
 #include "log-private.hh"
 
 #define EILLEGALACCESS 127
@@ -189,7 +189,7 @@ FdBroker::FdList::~FdList() {
 }
 
 int FdBroker::FdList::Add(int fd) {
-  GError *err = nullptr;
+  GErrorerr = nullptr;
 
   g_unix_fd_list_append(fd_list_, fd, &err);
   close(fd);
@@ -267,7 +267,7 @@ int FdBroker::Send(const std::string& target_appid,
                    const std::string& port_name,
                    int (*fds)[2]) {
   std::string interface_name = GetInterfaceName(target_appid, port_name);
-  GDBusMessage *msg;
+  GDBusMessagemsg;
   SocketPair main_sock_pair(mock_);
   SocketPair delegate_sock_pair(mock_);
   FdList fd_list;
@@ -510,10 +510,10 @@ void FdBroker::ReceiveMessage(const char* sender_appid,
   free(returned_fds);
 }
 
-void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn,
-    const gchar *sender, const gchar *object_path,
-    const gchar *iface_name, const gchar *method_name,
-    GVariant *parameters, GDBusMethodInvocation *invocation,
+void FdBroker::OnReceiveDbusMethod(GDBusConnectionconn,
+    const gchar* sender, const gchar* object_path,
+    const gchar* iface_name, const gchar* method_name,
+    GVariant* parameters, GDBusMethodInvocation* invocation,
     gpointer user_data) {
   auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
   auto broker = ptr->lock();
@@ -550,7 +550,7 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn,
 
 int FdBroker::GetOwnerId(const std::string& interface_name) {
   int owner_id = 0;
-  GError *error = NULL;
+  GErrorerror = NULL;
 
   GVariant* result = g_dbus_connection_call_sync(
       DBusConnectionManager::GetInst().GetConnection(),
@@ -590,11 +590,11 @@ int FdBroker::GetOwnerId(const std::string& interface_name) {
   return owner_id;
 }
 
-int FdBroker::GetSenderPid(GDBusConnection *connection, const gchar *sender) {
-  GDBusMessage *msg = NULL;
-  GDBusMessage *reply = NULL;
-  GError *err = NULL;
-  GVariant *body;
+int FdBroker::GetSenderPid(GDBusConnection* connection, const gchar* sender) {
+  GDBusMessagemsg = NULL;
+  GDBusMessagereply = NULL;
+  GErrorerr = NULL;
+  GVariantbody;
   int pid = 0;
 
   msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
@@ -729,9 +729,9 @@ AccessController& FdBroker::GetAccessController() {
   return ac_;
 }
 
-void FdBroker::OnNameAppeared(GDBusConnection *connection,
-                              const gchar *name,
-                              const gchar *name_owner,
+void FdBroker::OnNameAppeared(GDBusConnectionconnection,
+                              const gcharname,
+                              const gcharname_owner,
                               gpointer user_data) {
   auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
   auto broker = ptr->lock();
@@ -769,8 +769,8 @@ void FdBroker::OnNameAppeared(GDBusConnection *connection,
   broker->watcher_->OnPortAppeared();
 }
 
-void FdBroker::OnNameVanished(GDBusConnection *connection,
-                              const gchar *name,
+void FdBroker::OnNameVanished(GDBusConnectionconnection,
+                              const gcharname,
                               gpointer user_data) {
   auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
   auto broker = ptr->lock();
similarity index 87%
rename from src/fdbroker-internal.h
rename to src/fdbroker-internal.hh
index 21ce847..bc02d81 100644 (file)
@@ -29,7 +29,7 @@
 #include <thread>
 #include <list>
 
-#include "ac-internal.h"
+#include "ac-internal.hh"
 #include "rpc-port.h"
 
 namespace rpc_port {
@@ -145,26 +145,26 @@ class FdBroker : public std::enable_shared_from_this<FdBroker> {
   };
 
  private:
-  static void OnReceiveDbusMethod(GDBusConnection *conn, const gchar *sender,
-                                  const gchar *object_path,
-                                  const gchar *iface_name,
-                                  const gchar *method_name,
-                                  GVariant *parameters,
-                                  GDBusMethodInvocation *invocation,
+  static void OnReceiveDbusMethod(GDBusConnection* conn, const gchar* sender,
+                                  const gcharobject_path,
+                                  const gchariface_name,
+                                  const gcharmethod_name,
+                                  GVariantparameters,
+                                  GDBusMethodInvocationinvocation,
                                   gpointer user_data);
   int GetOwnerId(const std::string& interface_name);
-  int GetSenderPid(GDBusConnection *connection, const gchar *sender);
+  int GetSenderPid(GDBusConnection* connection, const gchar* sender);
   int RegisterDbusInterface(const std::string& port_name);
   void ReceiveMessage(const char* sender_appid,
                       GDBusMethodInvocation* invocation);
   std::string GetInterfaceName(const std::string& target_appid,
                                const std::string& port_name);
-  static void OnNameAppeared(GDBusConnection *connection,
-                             const gchar *name,
-                             const gchar *name_owner,
+  static void OnNameAppeared(GDBusConnectionconnection,
+                             const gcharname,
+                             const gcharname_owner,
                              gpointer user_data);
-  static void OnNameVanished(GDBusConnection *connection,
-                             const gchar *name,
+  static void OnNameVanished(GDBusConnectionconnection,
+                             const gcharname,
                              gpointer user_data);
   static void OnResultReceived(GObject* source_object,
                                GAsyncResult* res,
index 319b921..0667929 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include <cstring>
 
-#include "parcel-internal.h"
+#include "parcel-internal.hh"
 
 namespace rpc_port {
 
@@ -171,4 +171,24 @@ void Parcel::Reset(const unsigned char* buf, unsigned int size) {
 }
 // LCOV_EXCL_STOP
 
+template<typename T>
+void Parcel::Write(T d) {
+  unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+  std::copy(p, p + sizeof(T), std::back_inserter(data_));
+}
+
+template<typename T>
+T Parcel::Read() {
+  T d = 0;
+  unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+  if (reader_ + sizeof(T) > data_.size())
+    return d;
+  std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
+  reader_ += sizeof(T);
+  return d;
+}
+
+
 }  // namespace rpc_port
similarity index 82%
rename from src/parcel-internal.h
rename to src/parcel-internal.hh
index 991fe17..acf9b6f 100644 (file)
@@ -60,23 +60,10 @@ class Parcel {
 
  private:
   template<typename T>
-  void Write(T d) {
-    unsigned char* p = reinterpret_cast<unsigned char*>(&d);
-
-    std::copy(p, p + sizeof(T), std::back_inserter(data_));
-  }
+  void Write(T d);
 
   template<typename T>
-  T Read() {
-    T d = 0;
-    unsigned char* p = reinterpret_cast<unsigned char*>(&d);
-
-    if (reader_ + sizeof(T) > data_.size())
-      return d;
-    std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
-    reader_ += sizeof(T);
-    return d;
-  }
+  T Read();
 
  private:
   std::vector<unsigned char> data_;
index 8cba7dc..ec798fd 100644 (file)
@@ -29,7 +29,7 @@
 #include <glib-unix.h>
 
 #include "log-private.hh"
-#include "port-internal.h"
+#include "port-internal.hh"
 #include "rpc-port.h"
 
 #define MAX_CNT 100
similarity index 82%
rename from src/port-internal.h
rename to src/port-internal.hh
index 4cab83b..a8cd03a 100644 (file)
@@ -64,25 +64,25 @@ class Port {
   }
 
  private:
-   class DelayMessage {
-    public:
-     DelayMessage(const char* msg, int start_index, int size);
-     ~DelayMessage() = default;
-     void SetIndex(int index);
-     int GetSize();
-     int GetOriginalSize();
-     char* GetMessage();
-
-    private:
-     std::vector<unsigned char> message_;
-     int index_;
-     int size_;
-   };
-
-   enum PortStatus {
-    PORT_STATUS_ERROR_NONE,
-    PORT_STATUS_ERROR_IO_ERROR,
-    PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE
+  class DelayMessage {
+   public:
+    DelayMessage(const char* msg, int start_index, int size);
+    ~DelayMessage() = default;
+    void SetIndex(int index);
+    int GetSize();
+    int GetOriginalSize();
+    char* GetMessage();
+
+   private:
+    std::vector<unsigned char> message_;
+    int index_;
+    int size_;
+  };
+
+  enum PortStatus {
+   PORT_STATUS_ERROR_NONE,
+   PORT_STATUS_ERROR_IO_ERROR,
+   PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE
   };
 
   int PushDelayedMessage(std::shared_ptr<DelayMessage> dm);
index 3e0b7ed..cac8637 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "debug-port-internal.hh"
 #include "log-private.hh"
-#include "proxy-internal.h"
+#include "proxy-internal.hh"
 
 #define EILLEGALACCESS 127
 
@@ -39,7 +39,7 @@ Proxy::~Proxy() {
   _D("Proxy::~Proxy");
 }
 
-gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+gboolean Proxy::OnSocketDisconnected(GIOChannelgio, GIOCondition cond,
                                      gpointer data) {
   Proxy* proxy = static_cast<Proxy*>(data);
   IEventListener* listener = proxy->listener_;
@@ -69,7 +69,7 @@ gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
   return FALSE;
 }
 
-gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond,
+gboolean Proxy::OnDataReceived(GIOChannelgio, GIOCondition cond,
                                gpointer data) {
   Proxy* proxy = static_cast<Proxy*>(data);
   int fd = g_io_channel_unix_get_fd(gio);
similarity index 93%
rename from src/proxy-internal.h
rename to src/proxy-internal.hh
index 5ada809..64a824c 100644 (file)
@@ -24,8 +24,8 @@
 #include <string>
 #include <memory>
 
-#include "fdbroker-internal.h"
-#include "port-internal.h"
+#include "fdbroker-internal.hh"
+#include "port-internal.hh"
 
 namespace rpc_port {
 namespace internal {
@@ -78,9 +78,9 @@ class Proxy : public FdBroker::IEventWatcher {
   };
 
  private:
-  static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+  static gboolean OnSocketDisconnected(GIOChannelgio, GIOCondition cond,
                                        gpointer data);
-  static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
+  static gboolean OnDataReceived(GIOChannelgio, GIOCondition cond,
                                  gpointer data);
   static gboolean DbusNameTimeout(gpointer user_data);
   void OnPortAppeared() override;
index 13b7cc2..c4fa7fb 100644 (file)
@@ -18,8 +18,8 @@
 
 #include "rpc-port-parcel.h"
 
-#include "parcel-internal.h"
-#include "port-internal.h"
+#include "parcel-internal.hh"
+#include "port-internal.hh"
 
 #define MAX_PARCEL_SIZE   (1024 * 1024 * 10)
 
@@ -65,8 +65,8 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h,
   }
 
   Parcel* p = new Parcel(buf, len);
-  delete[] buf;
 
+  delete[] buf;
   *h = p;
 
   return RPC_PORT_ERROR_NONE;
@@ -391,8 +391,8 @@ RPC_API int rpc_port_parcel_reset_reader(rpc_port_parcel_h h) {
 // LCOV_EXCL_STOP
 
 // LCOV_EXCL_START
-RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array,
-    unsigned int *size) {
+RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array,
+    unsigned intsize) {
   if (h == nullptr || !array || !size)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
@@ -412,7 +412,7 @@ RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array,
 // LCOV_EXCL_STOP
 
 // LCOV_EXCL_START
-RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array,
+RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const voidarray,
     unsigned int size) {
   if (h == nullptr || !array || size == 0)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
index 81362f6..451fb83 100644 (file)
 #include <thread>
 
 #include "log-private.hh"
-#include "port-internal.h"
-#include "proxy-internal.h"
+#include "port-internal.hh"
+#include "proxy-internal.hh"
 #include "rpc-port.h"
-#include "stub-internal.h"
+#include "stub-internal.hh"
 
 #undef RPC_API
 #define RPC_API extern "C" __attribute__((visibility("default")))
@@ -303,7 +303,7 @@ RPC_API int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char* appid,
 // LCOV_EXCL_STOP
 
 RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
-    rpc_port_proxy_connected_event_cb cb, void *user_data) {
+    rpc_port_proxy_connected_event_cb cb, voiduser_data) {
   if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
@@ -483,7 +483,7 @@ RPC_API int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h,
 }
 
 RPC_API int rpc_port_stub_get_port(rpc_port_stub_h h,
-    rpc_port_port_type_e type, const char *instance, rpc_port_h* port) {
+    rpc_port_port_type_e type, const charinstance, rpc_port_h* port) {
   if (h == nullptr || port == nullptr || instance == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
index 35ecd09..df41588 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "debug-port-internal.hh"
 #include "log-private.hh"
-#include "stub-internal.h"
+#include "stub-internal.hh"
 
 namespace rpc_port {
 namespace internal {
@@ -88,7 +88,7 @@ void Stub::RemoveAcceptedPorts(std::string instance) {
   }
 }
 
-gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond,
+gboolean Stub::OnDataReceived(GIOChannelgio, GIOCondition cond,
                               gpointer data) {
   Stub* stub = static_cast<Stub*>(data);
   int fd = g_io_channel_unix_get_fd(gio);
@@ -128,7 +128,7 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond,
   return TRUE;
 }
 
-gboolean Stub::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+gboolean Stub::OnSocketDisconnected(GIOChannelgio, GIOCondition cond,
                                     gpointer data) {
   Stub* stub = static_cast<Stub*>(data);
   int fd = g_io_channel_unix_get_fd(gio);
similarity index 93%
rename from src/stub-internal.h
rename to src/stub-internal.hh
index 9063acb..bc562df 100644 (file)
@@ -26,8 +26,8 @@
 #include <memory>
 
 #include "debug-port-internal.hh"
-#include "fdbroker-internal.h"
-#include "port-internal.h"
+#include "fdbroker-internal.hh"
+#include "port-internal.hh"
 
 namespace rpc_port {
 namespace internal {
@@ -76,9 +76,9 @@ class Stub : private FdBroker::IEventListener {
     bool is_delegate_ = false;
   };
 
-  static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
+  static gboolean OnDataReceived(GIOChannelgio, GIOCondition cond,
                                  gpointer data);
-  static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+  static gboolean OnSocketDisconnected(GIOChannelgio, GIOCondition cond,
                                        gpointer data);
 
   void OnFdReceived(const std::string& sender, int fds[2]) override;