• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define MLOG_TAG "MediaLibraryHelperContainer"
16 
17 #include "medialibrary_helper_container.h"
18 
19 namespace OHOS {
20 namespace Media {
21 std::shared_ptr<MediaLibraryHelperContainer> MediaLibraryHelperContainer::instance_ = nullptr;
22 std::mutex MediaLibraryHelperContainer::mutex_;
23 std::shared_ptr<DataShare::DataShareHelper> MediaLibraryHelperContainer::dataShareHelper_ = nullptr;
24 
GetInstance()25 std::shared_ptr<MediaLibraryHelperContainer> MediaLibraryHelperContainer::GetInstance()
26 {
27     if (instance_ == nullptr) {
28         std::lock_guard<std::mutex> lock(mutex_);
29         if (instance_ == nullptr) {
30             instance_ = std::make_shared<MediaLibraryHelperContainer>();
31         }
32     }
33     return instance_;
34 }
35 
CreateDataShareHelper(const sptr<IRemoteObject> & token,const std::string & uri)36 void MediaLibraryHelperContainer::CreateDataShareHelper(const sptr<IRemoteObject> &token,
37     const std::string &uri)
38 {
39     if (dataShareHelper_ == nullptr) {
40         dataShareHelper_ = DataShare::DataShareHelper::Creator(token, uri);
41     }
42 }
43 
SetDataShareHelper(const std::shared_ptr<DataShare::DataShareHelper> & helper)44 void MediaLibraryHelperContainer::SetDataShareHelper(const std::shared_ptr<DataShare::DataShareHelper> &helper)
45 {
46     dataShareHelper_ = helper;
47 }
48 
GetDataShareHelper()49 std::shared_ptr<DataShare::DataShareHelper> MediaLibraryHelperContainer::GetDataShareHelper()
50 {
51     return dataShareHelper_;
52 }
53 } // namespace Media
54 } // namespace OHOS
55