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 DRIVE_KIT_H 17 #define DRIVE_KIT_H 18 #include <map> 19 #include <mutex> 20 #include <string> 21 #include <time.h> 22 #include <vector> 23 24 #include "dk_cloud_callback.h" 25 #include "dk_container.h" 26 #include "dk_error.h" 27 #include "dk_record.h" 28 29 namespace DriveKit { 30 using DKAppId = std::string; 31 using DKDatabaseName = std::string; 32 struct DKContainerInfo { 33 DKAppBundleName appBundleName; 34 DKContainerName containerName; 35 DKDatabaseName databaseName; 36 DKSchema schema; 37 }; 38 struct DKAppInfo { 39 DKAppBundleName appBundleName; 40 DKAppId appId; 41 std::string appFinger; 42 int schemaGroupVersion; 43 int enableCloud; 44 DKAppSwitchStatus switchStatus; 45 DKContainerInfo defaultContainer; 46 std::vector<DKContainerInfo> shareContainer; 47 }; 48 enum class DKSpaceStatus { 49 DK_SPACE_STATUS_NORMAL = 0, 50 DK_SPACE_STATUS_ALREADY_FULL, 51 }; 52 struct DKUserInfo { 53 std::string accountId; 54 DKCloudStatus cloudStatus; 55 DKSpaceStatus spaceStatus; 56 uint64_t totalSpace; 57 uint64_t remainSpace; 58 }; 59 class DriveKitNative : public std::enable_shared_from_this<DriveKitNative> { 60 friend class DKContainer; 61 friend class DKDatabase; 62 63 public: 64 DriveKitNative(const DriveKitNative &) = delete; 65 DriveKitNative(DriveKitNative &&) = delete; 66 DriveKitNative &operator=(const DriveKitNative &) = delete; 67 DriveKitNative &operator=(DriveKitNative &&) = delete; 68 static std::shared_ptr<DriveKitNative> GetInstance(int userId); 69 virtual ~DriveKitNative(); 70 71 std::shared_ptr<DKContainer> GetDefaultContainer(DKAppBundleName bundleName); 72 std::shared_ptr<DKContainer> GetContainer(DKAppBundleName bundleName, DKContainerName containerName); 73 DKError GetCloudUserInfo(DKUserInfo &userInfo); 74 DKError GetCloudAppInfo(const std::vector<DKAppBundleName> &bundleNames, 75 std::map<DKAppBundleName, DKAppInfo> &appInfos); 76 DKError GetCloudAppSwitches(const std::vector<DKAppBundleName> &bundleNames, 77 std::map<DKAppBundleName, DKAppSwitchStatus> &appSwitchs); 78 DKError GetServerTime(time_t &time); 79 int32_t OnUploadAsset(const std::string &request, const std::string &result); 80 private: 81 DriveKitNative(int userId); 82 83 std::mutex containMutex_; 84 std::map<std::string, std::shared_ptr<DKContainer>> containers_; 85 std::mutex appInfoMutex_; 86 std::map<DKAppBundleName, DKAppInfo> appInfos_; 87 static std::mutex drivekitMutex_; 88 static std::map<int, std::shared_ptr<DriveKitNative>> driveKits_; 89 DKUserInfo userInfo_; 90 int userId_; 91 }; 92 } // namespace DriveKit 93 #endif 94