/* * 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_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H #define OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H #include "basic_rust_types.h" #include "cloud_db_impl.h" #include "cloud/asset_loader.h" #include "cloud/cloud_db.h" #include "cloud/cloud_server.h" #include "cloud/subscription.h" namespace OHOS::CloudData { using DBMeta = DistributedData::SchemaMeta::Database; using DBAssetLoader = DistributedData::AssetLoader; using DBCloudDB = DistributedData::CloudDB; using DBCloudInfo = DistributedData::CloudInfo; using DBSchemaMeta = DistributedData::SchemaMeta; using DBTable = DistributedData::Table; using DBField = DistributedData::Field; using DBSub = DistributedData::Subscription; using DBRelation = DBSub::Relation; using DBErr = DistributedData::GeneralError; class CloudServerImpl : public DistributedData::CloudServer { public: DBCloudInfo GetServerInfo(int32_t userId, bool needSpaceInfo) override; std::pair GetAppSchema(int32_t userId, const std::string &bundleName) override; int32_t Subscribe(int32_t userId, const std::map> &dbs) override; int32_t Unsubscribe(int32_t userId, const std::map> &dbs) override; std::shared_ptr ConnectAssetLoader(uint32_t tokenId, const DBMeta &dbMeta) override; std::shared_ptr ConnectAssetLoader( const std::string &bundleName, int user, const DBMeta &dbMeta) override; std::shared_ptr ConnectCloudDB(uint32_t tokenId, const DBMeta &dbMeta) override; std::shared_ptr ConnectCloudDB(const std::string &bundleName, int user, const DBMeta &dbMeta) override; private: static constexpr uint64_t INTERVAL = 6 * 24; void GetAppInfo(std::shared_ptr briefInfo, DBCloudInfo &cloudInfo); void GetDatabases(std::shared_ptr databases, DBSchemaMeta &dbSchema); void GetTables(std::shared_ptr tables, DBMeta &dbMeta); void GetTableInfo(std::shared_ptr pTable, DBTable &dbTable); void GetFields(std::shared_ptr fields, DBTable &dbTable); int32_t DoSubscribe(int32_t userId, std::shared_ptr server, std::shared_ptr databases); int32_t SaveSubscription(int32_t userId, std::shared_ptr relations, std::shared_ptr server); int32_t SaveRelation(std::shared_ptr keys, std::shared_ptr values, DBSub &sub); int32_t GetRelation(std::shared_ptr relations, DBRelation &dbRelation); int32_t DoUnsubscribe(std::shared_ptr server, std::shared_ptr relations, const std::vector &bundles, DBSub &sub); }; } // namespace OHOS::CloudData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H