1 /*
2 * Copyright (c) 2024-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 #include "entry_getter.h"
17 #include "pasteboard_entry_getter.h"
18 #include "pasteboard_error.h"
19 #include "pasteboard_hilog.h"
20 #include "pasteboard_service_loader.h"
21
22 namespace OHOS {
23 namespace MiscServices {
24 using namespace OHOS::UDMF;
25 __attribute__((used)) PasteboardEntryGetter::Factory PasteboardEntryGetter::factory_;
Factory()26 PasteboardEntryGetter::Factory::Factory()
27 {
28 GetterSystem::GetInstance().RegisterCreator("pasteboard", [this]() {
29 if (getter_ == nullptr) {
30 getter_ = std::make_shared<PasteboardEntryGetter>();
31 }
32 return getter_;
33 });
34 }
35
~Factory()36 PasteboardEntryGetter::Factory::~Factory()
37 {
38 getter_ = nullptr;
39 }
40
GetValueByType(uint32_t dataId,uint32_t recordId,const std::string & utdId)41 UDMF::ValueType PasteboardEntryGetter::GetValueByType(uint32_t dataId, uint32_t recordId, const std::string &utdId)
42 {
43 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "dataId:%{public}d. recordId:%{public}d, utdId:%{public}s", dataId,
44 recordId, utdId.c_str());
45 auto pasteType = CommonUtils::Convert2MimeType(utdId);
46 PasteDataEntry entryValue;
47 entryValue.SetUtdId(utdId);
48 entryValue.SetMimeType(pasteType);
49 auto result = PasteboardServiceLoader::GetInstance().GetRecordValueByType(dataId, recordId, entryValue);
50 if (result != static_cast<int32_t>(PasteboardError::E_OK)) {
51 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "get entry value fail, result:%{public}d", result);
52 }
53 return entryValue.GetValue();
54 }
55 } // namespace MiscServices
56 } // namespace OHOS