1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H 18 19 #include "basic_rust_types.h" 20 #include "cloud_db_impl.h" 21 #include "cloud/asset_loader.h" 22 #include "cloud/cloud_db.h" 23 #include "cloud/cloud_server.h" 24 #include "cloud/subscription.h" 25 26 namespace OHOS::CloudData { 27 using DBMeta = DistributedData::SchemaMeta::Database; 28 using DBAssetLoader = DistributedData::AssetLoader; 29 using DBCloudDB = DistributedData::CloudDB; 30 using DBCloudInfo = DistributedData::CloudInfo; 31 using DBSchemaMeta = DistributedData::SchemaMeta; 32 using DBTable = DistributedData::Table; 33 using DBField = DistributedData::Field; 34 using DBSub = DistributedData::Subscription; 35 using DBRelation = DBSub::Relation; 36 using DBErr = DistributedData::GeneralError; 37 class CloudServerImpl : public DistributedData::CloudServer { 38 public: 39 DBCloudInfo GetServerInfo(int32_t userId) override; 40 DBSchemaMeta GetAppSchema(int32_t userId, const std::string &bundleName) override; 41 int32_t Subscribe(int32_t userId, const std::map<std::string, std::vector<DBMeta>> &dbs) override; 42 int32_t Unsubscribe(int32_t userId, const std::map<std::string, std::vector<DBMeta>> &dbs) override; 43 std::shared_ptr<DBAssetLoader> ConnectAssetLoader(uint32_t tokenId, const DBMeta &dbMeta) override; 44 std::shared_ptr<DBCloudDB> ConnectCloudDB(uint32_t tokenId, const DBMeta &dbMeta) override; 45 46 private: 47 static constexpr uint64_t INTERVAL = 6 * 24; 48 void GetAppInfo(std::shared_ptr<OhCloudExtHashMap> briefInfo, DBCloudInfo &cloudInfo); 49 void GetDatabases(std::shared_ptr<OhCloudExtVector> databases, DBSchemaMeta &dbSchema); 50 void GetTables(std::shared_ptr<OhCloudExtHashMap> tables, DBMeta &dbMeta); 51 void GetTableInfo(std::shared_ptr<OhCloudExtTable> pTable, DBTable &dbTable); 52 void GetFields(std::shared_ptr<OhCloudExtVector> fields, DBTable &dbTable); 53 int32_t DoSubscribe(int32_t userId, std::shared_ptr<OhCloudExtCloudSync> server, 54 std::shared_ptr<OhCloudExtHashMap> databases); 55 int32_t SaveSubscription(int32_t userId, std::shared_ptr<OhCloudExtHashMap> relations, 56 std::shared_ptr<OhCloudExtCloudSync> server); 57 int32_t SaveRelation(std::shared_ptr<OhCloudExtVector> keys, 58 std::shared_ptr<OhCloudExtVector> values, DBSub &sub); 59 int32_t GetRelation(std::shared_ptr<OhCloudExtHashMap> relations, DBRelation &dbRelation); 60 int32_t DoUnsubscribe(std::shared_ptr<OhCloudExtCloudSync> server, 61 std::shared_ptr<OhCloudExtHashMap> relations, const std::vector<std::string> &bundles, DBSub &sub); 62 }; 63 } // namespace OHOS::CloudData 64 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_CLOUD_SERVER_IMPL_H 65