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