componentify device profile

Signed-off-by: Gymee <yumeijie@huawei.com>
Change-Id: Iafc2719a4d7b4bebded43ca4d1a25c242ef564e2
This commit is contained in:
Gymee 2022-01-04 14:15:44 +08:00
parent 783a145e5c
commit d93c9285fd
14 changed files with 69 additions and 92 deletions

View File

@ -135,7 +135,7 @@ DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId);
```c++
// 定义同步模式和范围
SyncOptions syncOption;
syncOption.SetSyncMode((OHOS::DistributedKv::SyncMode)atoi(mode.c_str()));
syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)atoi(mode.c_str()));
for (const auto& deviceId : deviceIds) {
syncOption.AddDevice(deviceId);
}

View File

@ -135,7 +135,7 @@ DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId);
```c++
// 定义同步模式和范围
SyncOptions syncOption;
syncOption.SetSyncMode((OHOS::DistributedKv::SyncMode)atoi(mode.c_str()));
syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)atoi(mode.c_str()));
for (const auto& deviceId : deviceIds) {
syncOption.AddDevice(deviceId);
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -16,21 +16,19 @@ import("//build/ohos_var.gni")
device_profile_path = "//foundation/deviceprofile/device_profile_core"
device_profile_service = "${device_profile_path}/services/core"
distributed_datamgr_innerkits =
"//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits"
config("distributed_device_profile_client_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${device_profile_path}/common/include",
"${distributed_datamgr_innerkits}/distributeddata/include",
"//third_party/json/include",
]
}
ohos_shared_library("distributed_device_profile_client") {
install_enable = true
sources = [
"${device_profile_path}/common/src/device_profile_utils.cpp",
"${device_profile_service}/src/profile_change_notification.cpp",
@ -44,18 +42,14 @@ ohos_shared_library("distributed_device_profile_client") {
public_configs = [ ":distributed_device_profile_client_config" ]
deps = [
public_deps = [
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//utils/native/base:utils",
]
public_deps = [ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler" ]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
part_name = "device_profile_core"
subsystem_name = "deviceprofile"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -13,33 +13,40 @@
* limitations under the License.
*/
#ifndef OHOS_SYNC_OPERATION_H
#define OHOS_SYNC_OPERATION_H
#ifndef OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H
#define OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H
#include <list>
#include "parcel.h"
#include "types.h"
namespace OHOS {
namespace DeviceProfile {
// must keep same with DistributedKv::SyncMode
enum class SyncMode {
PULL,
PUSH,
PUSH_PULL,
};
class SyncOptions : public Parcelable {
public:
SyncOptions() = default;
~SyncOptions() = default;
const std::list<std::string>& GetDeviceList() const;
DistributedKv::SyncMode GetSyncMode() const;
SyncMode GetSyncMode() const;
void AddDevice(const std::string& deviceId);
void SetSyncMode(DistributedKv::SyncMode mode);
void SetSyncMode(SyncMode mode);
bool Marshalling(Parcel& parcel) const override;
bool Unmarshalling(Parcel& parcel);
private:
DistributedKv::SyncMode syncMode_ {DistributedKv::SyncMode::PUSH};
SyncMode syncMode_ {SyncMode::PUSH};
std::list<std::string> syncDevIds_;
};
} // namespace DeviceProfile
} // namespace OHOS
#endif // OHOS_SYNC_OPERATION_H
#endif // OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H

View File

@ -32,4 +32,4 @@
}
},
"subsystem": "deviceprofile"
}
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -16,8 +16,8 @@ import("//build/ohos_var.gni")
device_profile_path = "//foundation/deviceprofile/device_profile_core"
device_profile_innerkits = "${device_profile_path}/interfaces/innerkits"
distributed_datamgr_innerkits =
"//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits"
device_profile_common_sources =
[ "${device_profile_path}/common/src/device_profile_utils.cpp" ]
config("device_profile_core_config") {
visibility = [ ":*" ]
@ -29,14 +29,10 @@ config("device_profile_core_config") {
"include/subscribemanager",
"${device_profile_path}/common/include",
"${device_profile_innerkits}/core/include",
"${distributed_datamgr_innerkits}/distributeddata/include",
"//third_party/json/include",
]
}
dp_common_sources =
[ "${device_profile_path}/common/src/device_profile_utils.cpp" ]
ohos_shared_library("distributed_device_profile") {
install_enable = true
sources = [
@ -66,25 +62,20 @@ ohos_shared_library("distributed_device_profile") {
"src/subscribemanager/subscriber_death_recipient.cpp",
"src/sync_options.cpp",
]
sources += dp_common_sources
sources += device_profile_common_sources
configs = [ ":device_profile_core_config" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//utils/native/base:utils",
]
external_deps = [
"appexecfwk_standard:libeventhandler",
"distributeddatamgr:distributeddata_inner",
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"startup_l2:syspara",
"utils_base:utils",
]
part_name = "device_profile_core"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -19,6 +19,8 @@
#include <atomic>
#include <shared_mutex>
#include "sync_options.h"
#include "distributed_kv_data_manager.h"
#include "event_handler.h"
#include "kvstore_observer.h"
@ -46,7 +48,7 @@ public:
virtual int32_t PutDeviceProfileBatch(const std::vector<std::string>& keys,
const std::vector<std::string>& values);
virtual int32_t SyncDeviceProfile(const std::vector<std::string>& deviceIdList,
DistributedKv::SyncMode syncMode);
SyncMode syncMode);
virtual int32_t RegisterSyncCallback(const std::shared_ptr<DistributedKv::KvStoreSyncCallback>& sycnCb);
virtual int32_t UnRegisterSyncCallback();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -30,7 +30,7 @@ public:
void Init() override;
int32_t RegisterSyncCallback(const std::shared_ptr<DistributedKv::KvStoreSyncCallback>& sycnCb) override;
int32_t UnRegisterSyncCallback() override;
int32_t SyncDeviceProfile(const std::vector<std::string>& deviceIds, DistributedKv::SyncMode syncMode) override;
int32_t SyncDeviceProfile(const std::vector<std::string>& deviceIds, SyncMode syncMode) override;
void SyncCompleted(const std::map<std::string, DistributedKv::Status>& results) override;
void NotifySyncCompleted(const std::map<std::string, DistributedKv::Status>& results);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -246,14 +246,14 @@ int32_t DeviceProfileStorage::DeleteDeviceProfile(const std::string& key)
}
int32_t DeviceProfileStorage::SyncDeviceProfile(const std::vector<std::string>& deviceIdList,
DistributedKv::SyncMode syncMode)
SyncMode syncMode)
{
HILOGI("called");
std::unique_lock<std::shared_mutex> writeLock(storageLock_);
if (kvStorePtr_ == nullptr) {
return ERR_DP_INVALID_PARAMS;
}
Status status = kvStorePtr_->Sync(deviceIdList, syncMode);
Status status = kvStorePtr_->Sync(deviceIdList, static_cast<DistributedKv::SyncMode>(syncMode));
if (status != Status::SUCCESS) {
HILOGE("sync failed, error = %{public}d", status);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -75,7 +75,7 @@ int32_t OnlineSyncTable::UnRegisterSyncCallback()
}
int32_t OnlineSyncTable::SyncDeviceProfile(const std::vector<std::string>& deviceIds,
DistributedKv::SyncMode syncMode)
SyncMode syncMode)
{
HILOGI("called");
auto syncTask = [this, deviceIds = std::move(deviceIds), syncMode]() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -34,12 +34,12 @@ void SyncOptions::AddDevice(const std::string& deviceId)
syncDevIds_.emplace_back(deviceId);
}
DistributedKv::SyncMode SyncOptions::GetSyncMode() const
SyncMode SyncOptions::GetSyncMode() const
{
return syncMode_;
}
void SyncOptions::SetSyncMode(DistributedKv::SyncMode mode)
void SyncOptions::SetSyncMode(SyncMode mode)
{
syncMode_ = mode;
}
@ -58,7 +58,7 @@ bool SyncOptions::Unmarshalling(Parcel& parcel)
{
int32_t mode = 0;
PARCEL_READ_HELPER_RET(parcel, Int32, mode, false);
syncMode_ = static_cast<DistributedKv::SyncMode>(mode);
syncMode_ = static_cast<DeviceProfile::SyncMode>(mode);
int32_t size = 0;
PARCEL_READ_HELPER_RET(parcel, Int32, size, false);
for (int32_t i = 0; i < size; i++) {

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -26,28 +26,23 @@ device_profile_configs =
device_profile_deps = [
"${device_profile_innerkits}/core:distributed_device_profile_client",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
"//third_party/googletest:gtest_main",
]
device_profile_external_deps = [
"appexecfwk_standard:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"utils_base:utils",
]
device_profile_public_deps = [ "//third_party/googletest:gtest_main" ]
ohos_unittest("profile_crud_test") {
module_out_path = module_output_path
sources = [ "unittest/profile_crud_test.cpp" ]
configs = device_profile_configs
deps = device_profile_deps
if (is_standard_system) {
external_deps = device_profile_external_deps
public_deps = device_profile_public_deps
}
external_deps = device_profile_external_deps
}
ohos_unittest("event_subscribe_test") {
@ -56,10 +51,7 @@ ohos_unittest("event_subscribe_test") {
sources = [ "unittest/event_subscribe_test.cpp" ]
configs = device_profile_configs
deps = device_profile_deps
if (is_standard_system) {
external_deps = device_profile_external_deps
public_deps = device_profile_public_deps
}
external_deps = device_profile_external_deps
}
group("unittest") {

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -15,38 +15,29 @@ import("//build/ohos.gni")
import("//build/ohos_var.gni")
device_profile_path = "//foundation/deviceprofile/device_profile_core"
device_profile_innerkits = "${device_profile_path}/interfaces/innerkits"
device_profile_configs = [
"${device_profile_innerkits}/core:distributed_device_profile_client_config",
]
config("dp_tools_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
ohos_executable("dp") {
install_enable = true
configs = []
configs += device_profile_configs
include_dirs = [
"include",
"//third_party/json/include",
]
configs = [ ":dp_tools_config" ]
sources = [
"${device_profile_path}/tools/dp/src/dp_command.cpp",
"${device_profile_path}/tools/dp/src/main.cpp",
"${device_profile_path}/tools/dp/src/shell_command.cpp",
]
deps = [
"${device_profile_innerkits}/core:distributed_device_profile_client",
"//utils/native/base:utils",
"src/dp_command.cpp",
"src/main.cpp",
"src/shell_command.cpp",
]
deps = [ "${device_profile_path}/interfaces/innerkits/core:distributed_device_profile_client" ]
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"utils_base:utils",
]
part_name = "device_profile_core"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -216,7 +216,7 @@ ErrCode DpShellCommand::SyncCommand()
if (result == ERR_OK) {
SyncOptions syncOption;
syncOption.SetSyncMode((OHOS::DistributedKv::SyncMode)atoi(mode.c_str()));
syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)atoi(mode.c_str()));
for (const auto& deviceId : deviceIds) {
syncOption.AddDevice(deviceId);
}