DM上线动态拉起分布式框架SA

Signed-off-by: wuqi0105 <wuqi85@huawei.com>
This commit is contained in:
wuqi0105
2022-04-26 10:17:45 +08:00
parent d06a592f29
commit 648f76cadf
4 changed files with 145 additions and 0 deletions
@@ -0,0 +1,29 @@
/*
* 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 OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H
#define OHOS_DISTRIBUTED_HARDWARE_LOAD_CALLBACK_H
#include "system_ability_load_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
class DistributedHardwareLoadCallback : public SystemAbilityLoadCallbackStub {
public:
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
};
}
}
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
* 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 OHOS_DM_LOAD_FWK_H
#define OHOS_DM_LOAD_FWK_H
#include "distributed_hardware_load_callback.h"
namespace OHOS {
namespace DistributedHardware {
class DmLoadFwk {
public:
int32_t LoadFwk(void);
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_PERMISSION_MANAGER_H
@@ -0,0 +1,35 @@
/*
* 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.
*/
#include "distributed_hardware_load_callback.h"
#include "dm_log.h"
namespace OHOS {
namespace DistributedHardware {
void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess(
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
{
LOGI("load fwk SA success, systemAbilityId:%d, remoteObject result:%s",
systemAbilityId, (remoteObject != nullptr) ? "true":"false");
if (remoteObject == nullptr) {
LOGE("remoteObject is nullptr");
return;
}
}
void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
LOGE("load fwk SA failed, systemAbilityId:%d", systemAbilityId);
}
}
}
+52
View File
@@ -0,0 +1,52 @@
/*
* 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.
*/
#include "dm_loadfwk.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "dm_constants.h"
#include "dm_log.h"
namespace OHOS {
namespace DistributedHardware {
int32_t DmLoadFwk::LoadFwk(void)
{
LOGI("enter DmLoadFwk::LoadFwk");
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
LOGE("failed to get system ability mgr.");
return DM_SERVICE_NOT_READY;
}
const uint32_t nLoadCount = 3;
int32_t ret = DM_OK;
sptr<DistributedHardwareLoadCallback> loadCallback = new DistributedHardwareLoadCallback();
for (size_t i = 0; i < nLoadCount; i++)
{
ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, loadCallback);
if (ret == DM_OK) {
break;
}
}
if (ret != DM_OK) {
LOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d, nLoadCount:%d",
DISTRIBUTED_HARDWARE_SA_ID, ret, nLoadCount);
return ERR_DM_LOAD_FWK_SA_FAIL;
}
LOGI("leave DmLoadFwk::LoadFwk");
return DM_OK;
}
} // namespace DistributedHardware
} // namespace OHOS