From 89999e6bef45129e548434a05fa0eddfd0c65de8 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Fri, 14 Apr 2023 18:09:52 +0800 Subject: [PATCH] update Signed-off-by: zuojiangjiang --- .../cloud/cloud_event.cpp} | 25 +-- .../framework/cloud/cloud_info.cpp | 10 + .../framework/cloud/schema_meta.cpp | 10 + .../include/cloud/cloud_event.h} | 27 +-- .../framework/include/cloud/cloud_info.h | 6 +- .../framework/include/cloud/schema_meta.h | 3 +- .../framework/include/eventcenter/event.h | 2 +- .../service/cloud/cloud_service_impl.cpp | 203 ++++++++++++++---- .../service/cloud/cloud_service_impl.h | 19 +- .../service/cloud/cloud_service_stub.cpp | 25 +++ .../service/cloud/cloud_service_stub.h | 2 + .../service/rdb/rdb_service_impl.cpp | 99 +-------- .../service/rdb/rdb_service_impl.h | 8 - .../service/rdb/rdb_service_stub.cpp | 27 --- .../service/rdb/rdb_service_stub.h | 8 +- .../cloud_data/include/cloud_service_proxy.h | 4 +- .../cloud_data/include/cloud_types_util.h | 30 +++ .../cloud_data/src/cloud_service_proxy.cpp | 23 ++ .../cloud_data/src/cloud_types_util.cpp | 30 +++ .../native/rdb/include/rdb_service_proxy.h | 4 - .../native/rdb/include/rdb_types_util.h | 5 - .../native/rdb/src/rdb_service_proxy.cpp | 24 --- .../native/rdb/src/rdb_types_util.cpp | 10 - .../cloud_data/include/cloud_service.h | 11 + .../inner_api/rdb/include/rdb_service.h | 6 - 25 files changed, 350 insertions(+), 271 deletions(-) rename datamgr_service/services/distributeddataservice/{service/rdb/rdb_event.cpp => framework/cloud/cloud_event.cpp} (48%) rename datamgr_service/services/distributeddataservice/{service/rdb/rdb_event.h => framework/include/cloud/cloud_event.h} (54%) create mode 100644 relational_store/frameworks/native/cloud_data/include/cloud_types_util.h create mode 100644 relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_event.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp similarity index 48% rename from datamgr_service/services/distributeddataservice/service/rdb/rdb_event.cpp rename to datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp index a80cca18..66e58e6d 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_event.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -13,32 +13,21 @@ * limitations under the License. */ -#include "rdb_event.h" +#include "cloud/cloud_event.h" -namespace OHOS::DistributedRdb { -RdbEvent::RdbEvent(int32_t evtId, int32_t user, const std::string &bundleName, const std::string &storeName) - : DistributedData::Event(evtId), user_(user), bundleName_(std::move(bundleName)), storeName_(std::move(storeName)) +namespace OHOS::DistributedData { +CloudEvent::CloudEvent(int32_t evtId, int32_t user) + : Event(evtId), user_(user) { } -int32_t RdbEvent::GetUser() const +int32_t CloudEvent::GetUser() const { return user_; } -std::string RdbEvent::GetBundleName() const +bool CloudEvent::Equals(const Event &event) const { - return bundleName_; -} - -std::string RdbEvent::GetStoreName() const -{ - return storeName_; -} - -bool RdbEvent::Equals(const DistributedData::Event &event) const -{ - auto &evt = static_cast(event); - return (user_ == evt.user_) && (bundleName_ == evt.bundleName_) && (storeName_ == evt.storeName_); + return false; } } \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp index 1cca4c4f..c0b0ccc8 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -98,6 +98,16 @@ void CloudInfo::DelApp(const std::string &appId) } } +CloudInfo::AppInfo &CloudInfo::GetApp(const std::string &appId) +{ + for (auto &app : apps) { + if (app.appId == appId) { + return app; + } + } + return appNil_; +} + std::string CloudInfo::GetPrefix(const std::initializer_list &fields) { return GetKey(INFO_PREFIX, fields).append(Constant::KEY_SEPARATOR); diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/schema_meta.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/schema_meta.cpp index 8fe8f41b..5b773512 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/schema_meta.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/schema_meta.cpp @@ -74,4 +74,14 @@ bool SchemaMeta::Field::Unmarshal(const Serializable::json &node) GetValue(node, GET_NAME(nullable), nullable); return true; } + +SchemaMeta::Database SchemaMeta::GetDataBase(const std::string &storeId) +{ + for (const auto &database : databases) { + if (database.name == storeId) { + return database; + } + } + return {}; +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_event.h b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h similarity index 54% rename from datamgr_service/services/distributeddataservice/service/rdb/rdb_event.h rename to datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h index d3d83c33..2ef233a7 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_event.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -13,34 +13,27 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_RDB_RDB_EVENT_H -#define OHOS_DISTRIBUTED_DATA_SERVICES_RDB_RDB_EVENT_H +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H #include #include "eventcenter/event.h" -namespace OHOS::DistributedRdb { -class RdbEvent : public DistributedData::Event { +namespace OHOS::DistributedData { +class CloudEvent : public Event { public: enum : int32_t { - RDB_FEATURE_INIT = EVT_RDB, - RDB_CREATE, - RDB_BUTT + CLOUD_RDB_FEATURE_INIT = EVT_CLOUD, + CLOUD_BUTT }; - RdbEvent(int32_t evtId, int32_t user, const std::string &bundleName, const std::string &storeName); - ~RdbEvent() = default; + CloudEvent(int32_t evtId, int32_t user); + ~CloudEvent() = default; int32_t GetUser() const; - std::string GetBundleName() const; - std::string GetStoreName() const; bool Equals(const DistributedData::Event &event) const override; private: int32_t user_; - int32_t schemaVersion_; - std::string bundleName_; - std::string storeName_; - std::string cloudId_; }; -} // namespace OHOS::DistributedRdb -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_RDB_RDB_EVENT_H +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H diff --git a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h index 89b09e86..db56c3bd 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -21,8 +21,8 @@ class API_EXPORT CloudInfo final : public Serializable { public: struct API_EXPORT AppInfo final : public Serializable { static constexpr uint32_t CURRENT_VERSION = 0x04000001; - std::string bundleName; - std::string appId; + std::string bundleName = ""; + std::string appId = ""; uint64_t version = CURRENT_VERSION; bool cloudSwitch = false; @@ -41,6 +41,7 @@ public: bool IsValid() const; bool IsExist(const std::string &appId) const; void DelApp(const std::string &appId); + AppInfo &GetApp(const std::string &appId); static std::string GetPrefix(const std::initializer_list &field); bool Marshal(json &node) const override; @@ -51,6 +52,7 @@ private: static constexpr const char *SCHEMA_PREFIX = "CLOUD_SCHEMA"; static std::string GetKey(const std::string &prefix, const std::initializer_list &fields); + AppInfo appNil_ {}; }; } #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H diff --git a/datamgr_service/services/distributeddataservice/framework/include/cloud/schema_meta.h b/datamgr_service/services/distributeddataservice/framework/include/cloud/schema_meta.h index d2fd0701..dd7cb32d 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/cloud/schema_meta.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/schema_meta.h @@ -36,7 +36,7 @@ public: }; struct API_EXPORT Database final : public Serializable { - std::string name; + std::string name = ""; std::vector tables; bool Marshal(json &node) const override; @@ -47,6 +47,7 @@ public: bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; + Database GetDataBase(const std::string &storeId); }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H diff --git a/datamgr_service/services/distributeddataservice/framework/include/eventcenter/event.h b/datamgr_service/services/distributeddataservice/framework/include/eventcenter/event.h index 5ee3a433..27bf9df2 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/eventcenter/event.h +++ b/datamgr_service/services/distributeddataservice/framework/include/eventcenter/event.h @@ -28,7 +28,7 @@ public: EVT_INITED, EVT_UPDATE, EVT_CUSTOM = 0x1000, - EVT_RDB = 0x2000 + EVT_CLOUD = 0x2000 }; API_EXPORT Event(int32_t evtId); API_EXPORT Event(Event &&) noexcept = delete; diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 983ca503..a035ab95 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -20,6 +20,7 @@ #include "account/account_delegate.h" #include "checker/checker_manager.h" #include "cloud_syncer.h" +#include "cloud/cloud_event.h" #include "cloud/cloud_server.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" @@ -27,7 +28,6 @@ #include "utils/anonymous.h" #include "log_print.h" #include "metadata/meta_data_manager.h" -#include "rdb_event.h" namespace OHOS::CloudData { using namespace DistributedData; @@ -47,20 +47,16 @@ CloudServiceImpl::Factory::~Factory() {} CloudServiceImpl::CloudServiceImpl() { - EventCenter::GetInstance().Subscribe(RdbEvent::RDB_FEATURE_INIT, [this](const Event &event) { - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGI("no cloud server"); - return; - } - auto &rdbEvent = static_cast(event); - auto cloudInfo = instance->GetServerInfo(rdbEvent.GetUser()); - if (!cloudInfo.IsValid()) { - ZLOGI("accountId empty"); + EventCenter::GetInstance().Subscribe(CloudEvent::CLOUD_RDB_FEATURE_INIT, [this](const Event &event) { + auto &rdbEvent = static_cast(event); + CloudInfo cloudInfo; + cloudInfo.user = rdbEvent.GetUser(); + if (GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", rdbEvent.GetUser()); return; } UpdateCloudInfo(cloudInfo); - UpdateSchema(cloudInfo); + AddSchema(cloudInfo); }); } @@ -68,18 +64,14 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map lg(mutex_); CloudInfo cloudInfo; - if (GetCloudInfo(id, cloudInfo) != SUCCESS) { + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = true; for (const auto &item : switches) { std::string appId = GetAppId(item.first); - for (auto &app : cloudInfo.apps) { - if (app.appId == appId) { - app.cloudSwitch = item.second; - break; - } - } + cloudInfo.GetApp(appId).cloudSwitch = item.second; } if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; @@ -91,7 +83,8 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) { std::lock_guard lg(mutex_); CloudInfo cloudInfo; - if (GetCloudInfo(id, cloudInfo) != SUCCESS) { + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = false; @@ -105,22 +98,17 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri { std::lock_guard lg(mutex_); CloudInfo cloudInfo; - if (GetCloudInfo(id, cloudInfo) != SUCCESS) { + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } - bool exist = false; std::string appId = GetAppId(bundleName); - for (auto &app : cloudInfo.apps) { - if (app.appId == appId) { - app.cloudSwitch = appSwitch; - exist = true; - break; - } - } - if (!exist) { + auto &app = cloudInfo.GetApp(appId); + if (app.appId.empty()) { ZLOGE("bundleName:%{public}s", bundleName.c_str()); return INVALID_ARGUMENT; } + app.cloudSwitch = appSwitch; if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } @@ -137,10 +125,91 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str return 0; } -int32_t CloudServiceImpl::GetCloudInfo(const std::string &id, CloudInfo &cloudInfo) +int32_t CloudServiceImpl::Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) { + if (!CheckAccess(storeInfo.bundleName)) { + ZLOGE("permission denied"); + return ERROR; + } + auto tokenId = IPCSkeleton::GetCallingTokenID(); + CloudInfo cloudInfo; + cloudInfo.id = id; + cloudInfo.user = AccountDelegate::GetInstance()->GetUserByToken(tokenId);; + if (ConfigCloudInfo(storeInfo, cloudInfo) != SUCCESS) { + return ERROR; + } + UpdateSchema(cloudInfo, storeInfo, storeInfo.version); + if (GetStoreSchema(cloudInfo, storeInfo, schema) != SUCCESS) { + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo &cloudInfo) +{ + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); + return ERROR; + } + auto appId = GetAppId(storeInfo.bundleName); + if (!cloudInfo.IsExist(appId)) { + CloudInfo::AppInfo appInfo; + appInfo.bundleName = storeInfo.bundleName; + appInfo.appId = appId; + cloudInfo.apps.emplace_back(appInfo); + } + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + return SUCCESS; +} + +int32_t CloudServiceImpl::GetStoreSchema( + const CloudInfo &cloudInfo, const StoreInfo &storeInfo, std::string &schema) +{ + auto appId = GetAppId(storeInfo.bundleName); + if (!cloudInfo.IsExist(appId)) { + ZLOGE("no exist bundleName:%{public}s", storeInfo.bundleName.c_str()); + return ERROR; + } + SchemaMeta schemaMeta; + auto keys = cloudInfo.GetSchemaKey(); + if (!MetaDataManager::GetInstance().LoadMeta(keys[storeInfo.bundleName], schemaMeta, true)) { + ZLOGE("schema empty bundleName:%{public}s", storeInfo.bundleName.c_str()); + return ERROR; + } + auto database = schemaMeta.GetDataBase(storeInfo.storeId); + if (database.name.empty()) { + ZLOGE("storeId:%{public}s", storeInfo.storeId.c_str()); + return ERROR; + } + schema = Serializable::Marshall(database); + return SUCCESS; +} + +int32_t CloudServiceImpl::ClearConfig(const std::string &id, const StoreInfo &storeInfo) +{ + if (!CheckAccess(storeInfo.bundleName)) { + ZLOGE("permission denied"); + return ERROR; + } + + CloudInfo cloudInfo; cloudInfo.id = id; - uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); + if (GetCloudInfo(cloudInfo) != SUCCESS) { + ZLOGE("id:%{public}s", Anonymous::Change(cloudInfo.id).c_str()); + return ERROR; + } + auto appId = GetAppId(storeInfo.bundleName); + if (cloudInfo.IsExist(appId)) { + auto keys = cloudInfo.GetSchemaKey(); + MetaDataManager::GetInstance().DelMeta(keys[storeInfo.bundleName], true); + cloudInfo.DelApp(appId); + } + return SUCCESS; +} + +int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) +{ + auto tokenId = IPCSkeleton::GetCallingTokenID(); cloudInfo.user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { ZLOGE("invalid argument id:%{public}s, user:%{public}d", @@ -150,6 +219,19 @@ int32_t CloudServiceImpl::GetCloudInfo(const std::string &id, CloudInfo &cloudIn return SUCCESS; } +int32_t CloudServiceImpl::GetServerInfo(CloudInfo &cloudInfo) +{ + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return SERVER_UNAVAILABLE; + } + cloudInfo = instance->GetServerInfo(cloudInfo.user); + if (!cloudInfo.IsValid()) { + return ERROR; + } + return SUCCESS; +} + std::string CloudServiceImpl::GetAppId(const std::string &bundleName) { CheckerManager::StoreInfo storeInfo; @@ -159,7 +241,16 @@ std::string CloudServiceImpl::GetAppId(const std::string &bundleName) return CheckerManager::GetInstance().GetAppId(storeInfo); } -void CloudServiceImpl::UpdateCloudInfo(DistributedData::CloudInfo &cloudInfo) +bool CloudServiceImpl::CheckAccess(const std::string &bundleName) +{ + CheckerManager::StoreInfo storeInfo; + storeInfo.uid = IPCSkeleton::GetCallingUid(); + storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); + storeInfo.bundleName = bundleName; + return CheckerManager::GetInstance().IsValid(storeInfo); +} + +void CloudServiceImpl::UpdateCloudInfo(CloudInfo &cloudInfo) { CloudInfo oldInfo; if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), oldInfo, true)) { @@ -172,7 +263,7 @@ void CloudServiceImpl::UpdateCloudInfo(DistributedData::CloudInfo &cloudInfo) MetaDataManager::GetInstance().SaveMeta(oldInfo.GetKey(), oldInfo, true); } -void CloudServiceImpl::UpdateSchema(DistributedData::CloudInfo &cloudInfo) +void CloudServiceImpl::AddSchema(CloudInfo &cloudInfo) { auto keys = cloudInfo.GetSchemaKey(); for (const auto &key : keys) { @@ -180,13 +271,45 @@ void CloudServiceImpl::UpdateSchema(DistributedData::CloudInfo &cloudInfo) if (MetaDataManager::GetInstance().LoadMeta(key.second, schemaMeta, true)) { continue; } - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("no cloud server"); - return; + if (GetAppSchema(cloudInfo.user, key.first, schemaMeta) != SUCCESS) { + continue; } - schemaMeta = instance->GetAppSchema(cloudInfo.user, key.first); MetaDataManager::GetInstance().SaveMeta(key.second, schemaMeta, true); } } -} \ No newline at end of file + +int32_t CloudServiceImpl::GetAppSchema( + int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta) +{ + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return SERVER_UNAVAILABLE; + } + schemaMeta = instance->GetAppSchema(user, bundleName); + return SUCCESS; +} + +void CloudServiceImpl::UpdateSchema(CloudInfo &cloudInfo, const StoreInfo &storeInfo, int32_t version) +{ + auto keys = cloudInfo.GetSchemaKey(); + SchemaMeta schemaMeta; + if (!MetaDataManager::GetInstance().LoadMeta(keys[storeInfo.bundleName], schemaMeta, true)) { + AddSchema(cloudInfo); + return; + } + if (version <= schemaMeta.version) { + ZLOGI("input ver:%{public}d, meta ver:%{public}d", version, schemaMeta.version); + return; + } + SchemaMeta serverMeta; + if (GetAppSchema(cloudInfo.user, storeInfo.bundleName, serverMeta) != SUCCESS) { + ZLOGI("get schema meta fail"); + return; + } + if (serverMeta.version != version) { + ZLOGI("input ver:%{public}d, server ver:%{public}d", version, serverMeta.version); + return; + } + MetaDataManager::GetInstance().SaveMeta(keys[storeInfo.bundleName], serverMeta, true); +} +} // OHOS::CloudData \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h index d2dec093..afb98b0c 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -19,6 +19,7 @@ #include #include "cloud_service_stub.h" #include "cloud/cloud_info.h" +#include "cloud/schema_meta.h" namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { @@ -30,6 +31,9 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; + int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) override; + int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) override; + private: class Factory { public: @@ -40,10 +44,19 @@ private: }; static Factory factory_; - void UpdateCloudInfo(DistributedData::CloudInfo &cloudInfo); - void UpdateSchema(DistributedData::CloudInfo &cloudInfo); - int32_t GetCloudInfo(const std::string &id, DistributedData::CloudInfo &cloudInfo); + using CloudInfo = DistributedData::CloudInfo; + using SchemaMeta = DistributedData::SchemaMeta; + + void UpdateCloudInfo(CloudInfo &cloudInfo); + void AddSchema(CloudInfo &cloudInfo); + void UpdateSchema(CloudInfo &cloudInfo, const StoreInfo &storeInfo, int32_t version); + int32_t ConfigCloudInfo(const StoreInfo &storeInfo, CloudInfo &cloudInfo); + int32_t GetStoreSchema(const CloudInfo &cloudInfo, const StoreInfo &storeInfo, std::string &schema); + int32_t GetCloudInfo(CloudInfo &cloudInfo); + int32_t GetServerInfo(CloudInfo &cloudInfo); + int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); std::string GetAppId(const std::string &bundleName); + bool CheckAccess(const std::string &bundleName); std::mutex mutex_; }; } // namespace OHOS::DistributedData diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 2ccf869e..ae472364 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -27,6 +27,8 @@ const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { &CloudServiceStub::OnChangeAppSwitch, &CloudServiceStub::OnClean, &CloudServiceStub::OnNotifyDataChange, + &CloudServiceStub::OnConfig, + &CloudServiceStub::OnClearConfig, }; int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) @@ -101,4 +103,27 @@ int32_t CloudServiceStub::OnNotifyDataChange(const std::string &id, MessageParce auto result = NotifyDataChange(id, bundleName); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; } + +int32_t CloudServiceStub::OnConfig(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + StoreInfo storeInfo; + if (!ITypesUtil::Unmarshal(data, storeInfo)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + std::string schema; + auto result = Config(id, storeInfo, schema); + return ITypesUtil::Marshal(reply, result, schema) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnClearConfig(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + StoreInfo storeInfo; + if (!ITypesUtil::Unmarshal(data, storeInfo)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + auto result = ClearConfig(id, storeInfo); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} } // namespace OHOS::CloudData diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h index 4175015d..f1f3cd62 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_stub.h @@ -31,6 +31,8 @@ private: int32_t OnChangeAppSwitch(const std::string &id, MessageParcel &data, MessageParcel &reply); int32_t OnClean(const std::string &id, MessageParcel &data, MessageParcel &reply); int32_t OnNotifyDataChange(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnConfig(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnClearConfig(const std::string &id, MessageParcel &data, MessageParcel &reply); static const Handler HANDLERS[TRANS_BUTT]; }; } // namespace OHOS::CloudData diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 35a9fbf1..a0a29d01 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -17,7 +17,7 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "checker/checker_manager.h" -#include "cloud/cloud_server.h" +#include "cloud/cloud_event.h" #include "communicator/device_manager_adapter.h" #include "crypto_manager.h" #include "eventcenter/event_center.h" @@ -26,7 +26,6 @@ #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permission/permission_validator.h" -#include "rdb_event.h" #include "rdb_notifier_proxy.h" #include "types_export.h" #include "utils/anonymous.h" @@ -390,100 +389,6 @@ int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::stri return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); } -int32_t RdbServiceImpl::CloudConfig(const CloudParam ¶m, std::string &schema) -{ - if (!CheckAccess({.bundleName_ = param.bundleName, .storeName_ = param.storeName})) { - ZLOGE("permission error"); - return RDB_ERROR; - } - auto tokenId = IPCSkeleton::GetCallingTokenID(); - auto user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); - if (ConfigCloudInfo(param, user) != RDB_OK) { - return RDB_ERROR; - } - auto createEvt = std::make_unique( - RdbEvent::RDB_CREATE, user, param.bundleName, RdbSyncer::RemoveSuffix(param.storeName)); - EventCenter::GetInstance().PostEvent(std::move(createEvt)); - if (GetSchema(param, user, schema) != RDB_OK) { - return RDB_ERROR; - } - return RDB_OK; -} - -int32_t RdbServiceImpl::GetSchema(const CloudParam ¶m, int32_t user, std::string &schema) -{ - CloudInfo cloudInfo; - cloudInfo.id = param.cloudId; - cloudInfo.user = user; - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { - ZLOGE("cloudId:%{public}s, user:%{public}d", param.cloudId.c_str(), user); - return RDB_ERROR; - } - auto appId = GetAppId(param.bundleName); - if (!cloudInfo.IsExist(appId)) { - ZLOGE("bundleName:%{public}s", param.bundleName.c_str()); - return RDB_ERROR; - } - SchemaMeta schemaMeta; - auto keys = cloudInfo.GetSchemaKey(); - if (!MetaDataManager::GetInstance().LoadMeta(keys[param.bundleName], schemaMeta, true)) { - ZLOGE("schema empty, bundleName:%{public}s", param.bundleName.c_str()); - return RDB_ERROR; - } - schema = Serializable::Marshall(schemaMeta); - return RDB_OK; -} - -int32_t RdbServiceImpl::ConfigCloudInfo(const CloudParam ¶m, int32_t user) -{ - CloudInfo cloudInfo; - cloudInfo.id = param.cloudId; - cloudInfo.user = user; - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - return RDB_ERROR; - } - cloudInfo = instance->GetServerInfo(user); - if (!cloudInfo.IsValid()) { - return RDB_ERROR; - } - } - auto appId = GetAppId(param.bundleName); - if (!cloudInfo.IsExist(appId)) { - CloudInfo::AppInfo appInfo; - appInfo.bundleName = param.bundleName; - appInfo.appId = appId; - cloudInfo.apps.emplace_back(appInfo); - } - MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); - return RDB_OK; -} - -int32_t RdbServiceImpl::ClearCloudConfig(const CloudParam ¶m) -{ - if (!CheckAccess({.bundleName_ = param.bundleName, .storeName_ = param.storeName})) { - ZLOGE("permission error"); - return RDB_ERROR; - } - auto tokenId = IPCSkeleton::GetCallingTokenID(); - CloudInfo cloudInfo; - cloudInfo.user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); - cloudInfo.id = param.cloudId; - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { - ZLOGE("invalid argument id:%{public}s, user:%{public}d", - Anonymous::Change(cloudInfo.id).c_str(), cloudInfo.user); - return RDB_ERROR; - } - auto appId = GetAppId(param.bundleName); - if (cloudInfo.IsExist(appId)) { - auto keys = cloudInfo.GetSchemaKey(); - MetaDataManager::GetInstance().DelMeta(keys[param.bundleName], true); - cloudInfo.DelApp(appId); - } - return RDB_OK; -} - std::string RdbServiceImpl::GetAppId(const std::string &bundleName) { CheckerManager::StoreInfo storeInfo; @@ -553,7 +458,7 @@ int32_t RdbServiceImpl::OnInitialize() { auto tokenId = IPCSkeleton::GetCallingTokenID(); auto user = AccountDelegate::GetInstance()->GetUserByToken(tokenId); - auto initEvt = std::make_unique(RdbEvent::RDB_FEATURE_INIT, user, "", ""); + auto initEvt = std::make_unique(CloudEvent::CLOUD_RDB_FEATURE_INIT, user); EventCenter::GetInstance().PostEvent(std::move(initEvt)); return RDB_OK; } diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h index 64792d8d..0961337a 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -69,10 +69,6 @@ protected: int32_t DoUnSubscribe(const RdbSyncerParam& param) override; - int32_t CloudConfig(const CloudParam ¶m, std::string &schema) override; - - int32_t ClearCloudConfig(const CloudParam ¶m) override; - private: std::string GenIdentifier(const RdbSyncerParam& param); @@ -84,10 +80,6 @@ private: void OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult& result); - int32_t ConfigCloudInfo(const CloudParam ¶m, int32_t user); - - int32_t GetSchema(const CloudParam ¶m, int32_t user, std::string &schema); - std::string GetAppId(const std::string &bundleName); class DeathRecipientImpl : public IRemoteObject::DeathRecipient { diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index de06ccf8..137a0598 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -186,31 +186,4 @@ int32_t RdbServiceStub::OnRemoteDoDestroyTable(MessageParcel &data, MessageParce int32_t status = DestroyRDBTable(param); return ITypesUtil::Marshal(reply, status) ? RDB_OK : RDB_ERROR; } - -int32_t RdbServiceStub::OnRemoteDoCloudConfig(MessageParcel& data, MessageParcel& reply) -{ - CloudParam param; - if (!ITypesUtil::Unmarshal(data, param)) { - ZLOGE("read from message parcel failed"); - reply.WriteInt32(RDB_ERROR); - return RDB_OK; - } - - std::string schema; - int32_t status = CloudConfig(param, schema); - return ITypesUtil::Marshal(reply, status, schema) ? RDB_OK : RDB_ERROR; -} - -int32_t RdbServiceStub::OnRemoteDoClearCloudConfig(MessageParcel& data, MessageParcel& reply) -{ - CloudParam param; - if (!ITypesUtil::Unmarshal(data, param)) { - ZLOGE("read from message parcel failed"); - reply.WriteInt32(RDB_ERROR); - return RDB_OK; - } - - int32_t status = ClearCloudConfig(param); - return ITypesUtil::Marshal(reply, status) ? RDB_OK : RDB_ERROR; -} } // namespace OHOS::DistributedRdb diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h index 49599de2..901a7d6e 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -68,10 +68,6 @@ private: int32_t OnRemoteDoDestroyTable(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteDoCloudConfig(MessageParcel& data, MessageParcel& reply); - - int32_t OnRemoteDoClearCloudConfig(MessageParcel& data, MessageParcel& reply); - using RequestHandle = int (RdbServiceStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandle HANDLERS[RDB_SERVICE_CMD_MAX] = { [RDB_SERVICE_CMD_OBTAIN_TABLE] = &RdbServiceStub::OnRemoteObtainDistributedTableName, @@ -83,9 +79,7 @@ private: [RDB_SERVICE_CMD_UNSUBSCRIBE] = &RdbServiceStub::OnRemoteDoUnSubscribe, [RDB_SERVICE_CMD_REMOTE_QUERY] = &RdbServiceStub::OnRemoteDoRemoteQuery, [RDB_SERVICE_CREATE_RDB_TABLE] = &RdbServiceStub::OnRemoteDoCreateTable, - [RDB_SERVICE_DESTROY_RDB_TABLE] = &RdbServiceStub::OnRemoteDoDestroyTable, - [RDB_SERVICE_CLOUD_CONFIG] = &RdbServiceStub::OnRemoteDoCloudConfig, - [RDB_SERVICE_CLEAR_CLOUD_CONFIG] = &RdbServiceStub::OnRemoteDoClearCloudConfig + [RDB_SERVICE_DESTROY_RDB_TABLE] = &RdbServiceStub::OnRemoteDoDestroyTable }; }; } // namespace OHOS::DistributedRdb diff --git a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h index 8ece3de8..a45f62a3 100644 --- a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h +++ b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h @@ -17,7 +17,7 @@ #define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_PROXY_H #include "icloud_service.h" -#include "iremote_object.h"" +#include "iremote_object.h" #include "iremote_proxy.h" namespace OHOS::CloudData { @@ -30,6 +30,8 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; + int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) override; + int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) override; private: sptr remote_; diff --git a/relational_store/frameworks/native/cloud_data/include/cloud_types_util.h b/relational_store/frameworks/native/cloud_data/include/cloud_types_util.h new file mode 100644 index 00000000..8dbd969d --- /dev/null +++ b/relational_store/frameworks/native/cloud_data/include/cloud_types_util.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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_DATA_CLOUD_CLOUD_TYPES_UTIL_H +#define OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H + +#include "cloud_service.h" +#include "itypes_util.h" +#include "rdb_visibility.h" + +namespace OHOS::ITypesUtil { +using StoreInfo = CloudData::CloudService::StoreInfo; +template<> +RDB_API_EXPORT bool Marshalling(const StoreInfo &input, MessageParcel &data); +template<> +RDB_API_EXPORT bool Unmarshalling(StoreInfo &output, MessageParcel &data); +} // namespace OHOS::ITypesUtil +#endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_TYPES_UTIL_H diff --git a/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp b/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp index fd295595..833cb5a3 100644 --- a/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp +++ b/relational_store/frameworks/native/cloud_data/src/cloud_service_proxy.cpp @@ -102,4 +102,27 @@ int32_t CloudServiceProxy::NotifyDataChange(const std::string &id, const std::st } return static_cast(status); } + +int32_t CloudServiceProxy::Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) +{ + MessageParcel reply; + int32_t status = IPC_SEND(TRANS_CONFIG, reply, id, storeInfo); + if (status != SUCCESS) { + ZLOGE("status:0x%{public}x id:%{public}.6s bundleName:%{public}s, storeId:%{public}s", + status, id.c_str(), storeInfo.bundleName.c_str(), storeInfo.storeId.c_str()); + } + ITypesUtil::Unmarshal(reply, schema); + return static_cast(status); +} + +int32_t CloudServiceProxy::ClearConfig(const std::string &id, const StoreInfo &storeInfo) +{ + MessageParcel reply; + int32_t status = IPC_SEND(TRANS_CLEAR_CONFIG, reply, id, storeInfo); + if (status != SUCCESS) { + ZLOGE("status:0x%{public}x id:%{public}.6s bundleName:%{public}s, storeId:%{public}s", + status, id.c_str(), storeInfo.bundleName.c_str(), storeInfo.storeId.c_str()); + } + return static_cast(status); +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp b/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp new file mode 100644 index 00000000..d127971f --- /dev/null +++ b/relational_store/frameworks/native/cloud_data/src/cloud_types_util.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 "cloud_types_util.h" + +namespace OHOS::ITypesUtil { +template<> +bool Marshalling(const StoreInfo &input, MessageParcel &data) +{ + return ITypesUtil::Marshal(data, input.bundleName, input.storeId, input.version); +} +template<> +bool Unmarshalling(StoreInfo &output, MessageParcel &data) +{ + return ITypesUtil::Unmarshal(data, output.bundleName, output.storeId, output.version); +} +} // namespace OHOS::ITypesUtil + \ No newline at end of file diff --git a/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h b/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h index 333616f0..b7166e23 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h +++ b/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h @@ -67,10 +67,6 @@ protected: int32_t DoUnSubscribe(const RdbSyncerParam& param) override; - int32_t CloudConfig(const CloudParam& param, std::string &schema) override; - - int32_t ClearCloudConfig(const CloudParam& param) override; - private: uint32_t GetSeqNum(); diff --git a/relational_store/frameworks/native/rdb/include/rdb_types_util.h b/relational_store/frameworks/native/rdb/include/rdb_types_util.h index ca589d37..71dcf135 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_types_util.h +++ b/relational_store/frameworks/native/rdb/include/rdb_types_util.h @@ -21,7 +21,6 @@ #include "values_bucket.h" #include "rdb_visibility.h" namespace OHOS::ITypesUtil { -using CloudParam = DistributedRdb::CloudParam; using SyncerParam = DistributedRdb::RdbSyncerParam; using SyncOption = DistributedRdb::SyncOption; using RdbPredicates = DistributedRdb::RdbPredicates; @@ -57,9 +56,5 @@ template<> bool Marshalling(const Asset &input, MessageParcel &data); template<> bool Unmarshalling(Asset &output, MessageParcel &data); -template<> -bool Marshalling(const CloudParam &input, MessageParcel &data); -template<> -bool Unmarshalling(CloudParam &output, MessageParcel &data); } #endif // DISTRIBUTED_RDB_RDB_TYPES_UTIL_H diff --git a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp index a8f00b9d..760709ad 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp @@ -282,30 +282,6 @@ int32_t RdbServiceProxy::DoUnSubscribe(const RdbSyncerParam ¶m) return status; } -int32_t RdbServiceProxy::CloudConfig(const CloudParam ¶m, std::string &schema) -{ - MessageParcel reply; - int32_t status = IPC_SEND(RDB_SERVICE_CLOUD_CONFIG, reply, param); - if (status != RDB_OK) { - ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, cloudId:%{public}.6s", - status, param.bundleName.c_str(), param.storeName.c_str(), param.cloudId.c_str()); - return status; - } - ITypesUtil::Unmarshal(reply, schema); - return RDB_OK; -} - -int32_t RdbServiceProxy::ClearCloudConfig(const CloudParam ¶m) -{ - MessageParcel reply; - int32_t status = IPC_SEND(RDB_SERVICE_CLEAR_CLOUD_CONFIG, reply, param); - if (status != RDB_OK) { - ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, cloudId:%{public}.6s", - status, param.bundleName.c_str(), param.storeName.c_str(), param.cloudId.c_str()); - } - return status; -} - int32_t RdbServiceProxy::RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet) { diff --git a/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp b/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp index d7ed7c9e..a45c56c2 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp @@ -98,14 +98,4 @@ bool ITypesUtil::Unmarshalling(Asset &output, MessageParcel &data) { return ITypesUtil::Unmarshal(data, output.version, output.name, output.size, output.modifyTime, output.uri); } -template<> -bool Marshalling(const CloudParam &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, input.bundleName, input.storeName, input.cloudId, input.schemaVerion); -} -template<> -bool Unmarshalling(CloudParam &output, MessageParcel &data) -{ - return ITypesUtil::Unmarshal(data, output.bundleName, output.storeName, output.cloudId, output.schemaVerion); } -} \ No newline at end of file diff --git a/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h b/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h index c7016761..e1645330 100644 --- a/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h +++ b/relational_store/interfaces/inner_api/cloud_data/include/cloud_service.h @@ -29,6 +29,8 @@ public: TRANS_CHANGE_APP_SWITCH, TRANS_CLEAN, TRANS_NOTIFY_DATA_CHANGE, + TRANS_CONFIG, + TRANS_CLEAR_CONFIG, TRANS_BUTT, }; enum Action : int32_t @@ -49,10 +51,17 @@ public: SUCCESS = 0, ERROR, INVALID_ARGUMENT, + SERVER_UNAVAILABLE, IPC_ERROR, IPC_PARCEL_ERROR }; + struct StoreInfo { + std::string bundleName; + std::string storeId; + int32_t version; + }; + static constexpr const char *SERVICE_NAME = "cloud"; virtual ~CloudService() = default; virtual int32_t EnableCloud(const std::string &id, const std::map &switches) = 0; @@ -60,6 +69,8 @@ public: virtual int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) = 0; virtual int32_t Clean(const std::string &id, const std::map &actions) = 0; virtual int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) = 0; + virtual int32_t Config(const std::string &id, const StoreInfo &storeInfo, std::string &schema) = 0; + virtual int32_t ClearConfig(const std::string &id, const StoreInfo &storeInfo) = 0; }; } // namespace OHOS::CloudData #endif // OHOS_DISTRIBUTED_DATA_CLOUD_CLOUD_SERVICE_H diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_service.h b/relational_store/interfaces/inner_api/rdb/include/rdb_service.h index bffb1ac3..a72ebf72 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_service.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_service.h @@ -37,8 +37,6 @@ public: RDB_SERVICE_CMD_REMOTE_QUERY, RDB_SERVICE_CREATE_RDB_TABLE, RDB_SERVICE_DESTROY_RDB_TABLE, - RDB_SERVICE_CLOUD_CONFIG, - RDB_SERVICE_CLEAR_CLOUD_CONFIG, RDB_SERVICE_CMD_MAX }; virtual std::string ObtainDistributedTableName(const std::string &device, const std::string &table) = 0; @@ -73,10 +71,6 @@ protected: virtual int32_t DoSubscribe(const RdbSyncerParam ¶m) = 0; virtual int32_t DoUnSubscribe(const RdbSyncerParam ¶m) = 0; - - virtual int32_t CloudConfig(const CloudParam ¶m, std::string &schema) = 0; - - virtual int32_t ClearCloudConfig(const CloudParam ¶m) = 0; }; } } // namespace OHOS::DistributedRdb -- Gitee