Fix error codes 29/173229/2
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 20 Mar 2018 05:59:00 +0000 (14:59 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Tue, 20 Mar 2018 08:07:06 +0000 (17:07 +0900)
Change-Id: I931d7969bc4fc197b2f573069653e0bc68923b04
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/fdbroker-internal.cc
src/fdbroker-internal.h
src/proxy-internal.cc
src/proxy-internal.h
src/rpc-port.cc
src/stub-internal.cc
src/stub-internal.h

index ce59d327096391f6ac6f177f7dce095e8e7ce47b..850de59d71b5641a0600c9d2c46ac7d1e11216ab 100644 (file)
@@ -477,12 +477,12 @@ int FdBroker::RegisterDbusInterface(const std::string& port_name) {
 int FdBroker::Listen(IEventListener* ev, const std::string& port_name) {
   if (listener_ != nullptr) {
     LOGE("listener_ is not NULL");
-    return -1;
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
   }
 
   if (ev == nullptr) {
     LOGE("ev is NULL");
-    return -1;
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
   }
 
   if (mock_) {
@@ -491,18 +491,18 @@ int FdBroker::Listen(IEventListener* ev, const std::string& port_name) {
     if (ret < 0)
       return ret;
 
-    return 0;
+    return RPC_PORT_ERROR_NONE;
   }
 
   int ret = RegisterDbusInterface(port_name);
 
   if (ret != 0) {
     LOGE("Failed to register dbus interface");
-    return -1;
+    return RPC_PORT_ERROR_IO_ERROR;
   }
 
   listener_ = ev;
-  return 0;
+  return RPC_PORT_ERROR_NONE;
 }
 
 AccessController& FdBroker::GetAccessController() {
index b5fba7990d5b5a86cdd6443d653e2c08cc9150be..d844064c5ba7f9a78b4400ddc89915775512c371 100644 (file)
@@ -27,6 +27,7 @@
 #include <memory>
 
 #include "ac-internal.h"
+#include "rpc-port.h"
 
 namespace rpc_port {
 namespace internal {
index 82fae450625c5d02223cba485cd1e94b9378a45a..adc17ab5e3406adce00146b4e675a91b4d92c9ab 100644 (file)
@@ -139,17 +139,26 @@ void Proxy::OnPortVanished(const std::string& appid,
   LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str());
 }
 
-void Proxy::Connect(const std::string appid, const std::string& port_name,
+int Proxy::Connect(const std::string appid, const std::string& port_name,
                     IEventListener* ev) {
-  if (ev == nullptr || listener_ != nullptr)
-    return;
+  if (ev == nullptr)
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+  if (listener_ != nullptr) {
+    LOGD("Already connected");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
 
   listener_ = ev;
   target_appid_ = appid;
   port_name_ = port_name;
   int r = fd_broker_.Watch(this, appid, port_name);
-  if (r < 0)
+  if (r < 0) {
     listener_ = nullptr;
+    return RPC_PORT_ERROR_IO_ERROR;
+  }
+
+  return RPC_PORT_ERROR_NONE;
 }
 
 }  // namespace internal
index 7c12f9cda32629c6500b2ba5e6ea5c1c1cd1de64..2cad82c49563156c6657331cd5ca97d178c001f2 100644 (file)
@@ -43,7 +43,7 @@ class Proxy : public FdBroker::IEventWatcher {
     virtual void OnReceived(const std::string& endpoint) = 0;
   };
 
-  void Connect(const std::string appid, const std::string& port_name,
+  int Connect(const std::string appid, const std::string& port_name,
                IEventListener* ev);
   std::shared_ptr<Port> GetPort() const {
     return port_;
index e33fd9da6c39bccbf29f0ae126dee8d9a27b7cb4..fa12ddbeb66b1a81d6423816b4a640b8e4cb7a0e 100755 (executable)
@@ -225,13 +225,12 @@ RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char* appid,
   auto p = static_cast<::ProxyExt*>(h);
   std::lock_guard<std::recursive_mutex> lock(p->GetMutex());
 
-  p->Connect(appid, port, p);
-  return 0;
+  return p->Connect(appid, port, p);
 }
 
 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) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::ProxyExt*>(h);
@@ -243,7 +242,7 @@ RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
 
 RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
     rpc_port_proxy_disconnected_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::ProxyExt*>(h);
@@ -255,7 +254,7 @@ RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
 
 RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
     rpc_port_proxy_rejected_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::ProxyExt*>(h);
@@ -267,7 +266,7 @@ RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
 
 RPC_API int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h,
     rpc_port_proxy_received_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::ProxyExt*>(h);
@@ -315,13 +314,12 @@ RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) {
   auto p = static_cast<::StubExt*>(h);
   std::lock_guard<std::recursive_mutex> lock(p->GetMutex());
 
-  p->Listen(p);
-  return 0;
+  return p->Listen(p);
 }
 
 RPC_API int rpc_port_stub_add_privilege(rpc_port_stub_h h,
     const char* privilege) {
-  if (h == nullptr)
+  if (h == nullptr || privilege == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::StubExt*>(h);
@@ -346,7 +344,7 @@ RPC_API int rpc_port_stub_set_trusted(rpc_port_stub_h h,
 
 RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
     rpc_port_stub_connected_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::StubExt*>(h);
@@ -358,7 +356,7 @@ RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
 
 RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
     rpc_port_stub_disconnected_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::StubExt*>(h);
@@ -370,7 +368,7 @@ RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
 
 RPC_API int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h,
     rpc_port_stub_received_event_cb cb, void* user_data) {
-  if (h == nullptr)
+  if (h == nullptr || cb == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   auto p = static_cast<::StubExt*>(h);
index c981ba5ea08e118f4f578236a6ca00840678fbb1..f126bb039697cd5947e5f4a5c169b1e16be025d9 100644 (file)
@@ -42,12 +42,12 @@ Stub::~Stub() {
   LOGD("Stub::~Stub");
 }
 
-void Stub::Listen(IEventListener* ev) {
+int Stub::Listen(IEventListener* ev) {
   if (ev == nullptr)
-    return;
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   listener_ = ev;
-  fd_broker_.Listen(this, port_name_);
+  return fd_broker_.Listen(this, port_name_);
 }
 
 void Stub::AddPrivilege(const std::string& privilege) {
index ab89aa369ffafda5d06722bca2a575a41004c098..ebbce2a304e8e7c72f366703a94fd26d2aff6229 100644 (file)
@@ -46,7 +46,7 @@ class Stub : private FdBroker::IEventListener {
   Stub(const std::string& port_name, bool mock = false);
   virtual ~Stub();
 
-  void Listen(IEventListener* ev);
+  int Listen(IEventListener* ev);
   void AddPrivilege(const std::string& privilege);
   void SetTrusted(const bool trusted);