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 GALLERY_DATA_SYNCER_H 17 #define GALLERY_DATA_SYNCER_H 18 19 #include "functional" 20 21 #include "album_data_handler.h" 22 #include "data_syncer.h" 23 #include "file_data_handler.h" 24 25 namespace OHOS { 26 namespace FileManagement { 27 namespace CloudSync { 28 class GalleryDataSyncer : public DataSyncer, std::enable_shared_from_this<GalleryDataSyncer> { 29 public: 30 GalleryDataSyncer(const std::string bundleName, const int32_t userId); 31 virtual ~GalleryDataSyncer() = default; 32 33 virtual void Schedule() override; 34 virtual void Reset() override; 35 36 virtual int32_t StartDownloadFile(const std::string path, const int32_t userId) override; 37 virtual int32_t StopDownloadFile(const std::string path, const int32_t userId) override; 38 virtual int32_t Init(const std::string bundleName, const int32_t userId) override; 39 virtual int32_t Clean(const int action) override; 40 41 private: 42 enum { 43 BEGIN, 44 DOWNLOADALBUM, 45 DOWNLOADFILE, 46 COMPLETEPULL, 47 UPLOADALBUM, 48 UPLOADFILE, 49 COMPLETEPUSH, 50 END 51 }; 52 53 int32_t DownloadAlbum(); 54 int32_t DownloadFile(); 55 int32_t UploadAlbum(); 56 int32_t UploadFile(); 57 int32_t Complete(); 58 59 /* stage */ 60 int32_t stage_ = BEGIN; 61 62 /* rdb */ 63 const std::string DATA_APP_EL2 = "/data/app/el2/"; 64 const std::string DATABASE_DIR = "/database/com.ohos.medialibrary.medialibrarydata/rdb/"; 65 const std::string DATABASE_NAME = "media_library.db"; 66 const std::string BUNDLE_NAME = "com.ohos.medialibrary.medialibrarydata"; 67 const int32_t CONNECT_SIZE = 10; 68 std::shared_ptr<NativeRdb::RdbStore> rdb_; 69 70 /* handler */ 71 std::shared_ptr<FileDataHandler> fileHandler_; 72 std::shared_ptr<AlbumDataHandler> albumHandler_; 73 }; 74 75 class RdbCallback : public NativeRdb::RdbOpenCallback { 76 public: OnCreate(NativeRdb::RdbStore & r)77 virtual int32_t OnCreate(NativeRdb::RdbStore &r) override 78 { 79 return 0; 80 } 81 OnUpgrade(NativeRdb::RdbStore & r,int32_t oldVersion,int32_t newVersion)82 virtual int32_t OnUpgrade(NativeRdb::RdbStore &r, int32_t oldVersion, 83 int32_t newVersion) override 84 { 85 return 0; 86 } 87 }; 88 } // namespace CloudSync 89 } // namespace FileManagement 90 } // namespace OHOS 91 #endif // GALLERY_DATA_SYNCER_H 92