未验证 提交 fbc3beb2 编写于 作者: O openharmony_ci 提交者: Gitee

!85 Remove dbinder's dependency on samgr

Merge pull request !85 from liubb_0516/master
......@@ -56,7 +56,6 @@ ohos_shared_library("libdbinder") {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
subsystem_name = "communication"
part_name = "ipc"
......
......@@ -24,9 +24,10 @@
#include <list>
#include <thread>
#include "dbinder_service_stub.h"
#include "ipc_object_proxy.h"
#include "ipc_object_stub.h"
#include "dbinder_service_stub.h"
#include "rpc_system_ability_callback.h"
namespace OHOS {
class DBinderRemoteListener;
......@@ -100,7 +101,7 @@ public:
virtual ~DBinderService();
public:
static sptr<DBinderService> GetInstance();
bool StartDBinderService();
bool StartDBinderService(std::shared_ptr<RpcSystemAbilityCallback> &callbackImpl);
sptr<DBinderServiceStub> MakeRemoteBinder(const std::u16string &serviceName,
const std::string &deviceID, binder_uintptr_t binderObject, uint64_t pid = 0);
bool RegisterRemoteProxy(std::u16string serviceName, sptr<IRemoteObject> binderObject);
......@@ -194,6 +195,8 @@ private:
std::map<IPCObjectProxy *, std::string> busNameObject_;
static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001;
static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff;
std::shared_ptr<RpcSystemAbilityCallback> dbinderCallback_;
};
} // namespace OHOS
#endif // OHOS_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACES_RPC_SERVICES_CALLBACK_H
#define INTERFACES_RPC_SERVICES_CALLBACK_H
#include "iremote_object.h"
namespace OHOS {
class RpcSystemAbilityCallback {
public:
virtual sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) = 0;
RpcSystemAbilityCallback() = default;
virtual ~RpcSystemAbilityCallback() = default;
};
} // namespace OHOS
#endif // INTERFACES_RPC_SERVICES_CALLBACK_H
\ No newline at end of file
......@@ -21,14 +21,12 @@
#include <arpa/inet.h>
#include "securec.h"
#include "string_ex.h"
#include "iservice_registry.h"
#include "ipc_skeleton.h"
#include "ipc_thread_skeleton.h"
#include "dbinder_log.h"
#include "dbinder_service_stub.h"
#include "dbinder_remote_listener.h"
#include "if_system_ability_manager.h"
#include "dbinder_error_code.h"
#include "softbus_bus_center.h"
#include "dbinder_sa_death_recipient.h"
......@@ -58,6 +56,7 @@ DBinderService::~DBinderService()
noticeProxy_.clear();
deathRecipients_.clear();
busNameObject_.clear();
dbinderCallback_ = nullptr;
DBINDER_LOGI("dbinder service died");
}
......@@ -74,7 +73,7 @@ std::string DBinderService::GetLocalDeviceID()
return networkId;
}
bool DBinderService::StartDBinderService()
bool DBinderService::StartDBinderService(std::shared_ptr<RpcSystemAbilityCallback> &callbackImpl)
{
if (mainThreadCreated_) {
return true;
......@@ -85,6 +84,7 @@ bool DBinderService::StartDBinderService()
return false;
}
mainThreadCreated_ = true;
dbinderCallback_ = callbackImpl;
return true;
}
......@@ -372,21 +372,18 @@ sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject
DBINDER_LOGI("already have proxy");
return proxy;
}
if (dbinderCallback_ == nullptr) {
DBINDER_LOGE("samgr not initialized get remote sa callback");
return nullptr;
}
/* proxy is null, attempt to get a new proxy */
std::u16string serviceName = GetRegisterService(binderObject);
if (serviceName.empty() && !CheckSystemAbilityId(systemAbilityId)) {
DBINDER_LOGE("service is not registered in this device, saId:%{public}d", systemAbilityId);
return nullptr;
}
auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (manager == nullptr) {
DBINDER_LOGE("when new proxy, find samgr fail!");
return nullptr;
}
int digitalName = !serviceName.empty() ? std::atoi(Str16ToStr8(serviceName).c_str()) : systemAbilityId;
proxy = manager->GetSystemAbility(digitalName);
int32_t digitalName = !serviceName.empty() ? std::atoi(Str16ToStr8(serviceName).c_str()) : systemAbilityId;
proxy = dbinderCallback_->GetSystemAbilityFromRemote(digitalName);
if (proxy != nullptr) {
/* When the stub object dies, you need to delete the corresponding busName information */
IPCObjectProxy *saProxy = reinterpret_cast<IPCObjectProxy *>(proxy.GetRefPtr());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册