• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DATA_HANDLER_FACTORY_H
17 #define OHOS_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DATA_HANDLER_FACTORY_H
18 
19 #include <map>
20 #include <vector>
21 
22 #include "i_cloud_media_data_handler.h"
23 #include "cloud_media_album_handler.h"
24 #include "cloud_media_photo_handler.h"
25 
26 namespace OHOS::Media::CloudSync {
27 class CloudMediaDataHandlerFactory {
28 private:
29     const std::map<std::string, std::shared_ptr<ICloudMediaDataHandler>> DATA_HANDLER = {
30         {"PhotoAlbum", std::make_shared<CloudMediaAlbumHandler>()},
31         {"Photos", std::make_shared<CloudMediaPhotoHandler>()}};
32 
33 public:  // constructor
34     CloudMediaDataHandlerFactory() = default;
35     virtual ~CloudMediaDataHandlerFactory() = default;
36 
37 public:
GetDataHandler(const std::string & tableName,const int32_t userId)38     std::shared_ptr<ICloudMediaDataHandler> GetDataHandler(const std::string &tableName, const int32_t userId)
39     {
40         std::shared_ptr<ICloudMediaDataHandler> handler = nullptr;
41         auto iter = this->DATA_HANDLER.find(tableName);
42         if (iter != this->DATA_HANDLER.end()) {
43             handler = iter->second;
44         }
45         CHECK_AND_RETURN_RET_LOG(handler != nullptr, handler, "handler is null");
46         handler->SetUserId(userId);
47         return handler;
48     }
49 };
50 }  // namespace OHOS::Media::CloudSync
51 #endif  // OHOS_MEDIA_CLOUD_SYNC_CLOUD_MEDIA_DATA_HANDLER_FACTORY_H