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_) {
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() {
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
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);
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);
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);
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);
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);
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);
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);
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);