• 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 #define LOG_TAG "UdmfNotifierStub"
16 #include "udmf_notifier_stub.h"
17 
18 #include "error_code.h"
19 #include "ipc_skeleton.h"
20 #include "logger.h"
21 #include "udmf_async_client.h"
22 #include "udmf_types_util.h"
23 #include "udmf_conversion.h"
24 #include "unified_html_record_process.h"
25 
26 namespace OHOS {
27 namespace UDMF {
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t UdmfNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30     MessageOption &option)
31 {
32     LOG_INFO(UDMF_SERVICE, "code:%{public}u callingPid:%{public}u", code, IPCSkeleton::GetCallingPid());
33     std::u16string local = GetDescriptor();
34     std::u16string remote = data.ReadInterfaceToken();
35     if (local != remote) {
36         LOG_ERROR(UDMF_SERVICE, "local is not equal to remote");
37         return -1;
38     }
39 
40     std::string key;
41     DataLoadInfo dataLoadInfo;
42     if (!ITypesUtil::Unmarshal(data, key, dataLoadInfo)) {
43         LOG_ERROR(UDMF_SERVICE, "Unmarshal failed!");
44         return E_READ_PARCEL_ERROR;
45     }
46 
47     HandleDelayObserver(key, dataLoadInfo);
48     return 0;
49 }
50 
UdmfNotifierClient(LoadHandler loadHandler)51 UdmfNotifierClient::UdmfNotifierClient(LoadHandler loadHandler):loadHandler_(loadHandler) {}
52 
HandleDelayObserver(const std::string & key,const DataLoadInfo & dataLoadInfo)53 void UdmfNotifierClient::HandleDelayObserver(const std::string &key, const DataLoadInfo &dataLoadInfo)
54 {
55     auto loadHandler = loadHandler_;
56     UdmfAsyncClient::GetInstance().PushTaskToExecutor(
57         [loadHandler, key, dataLoadInfo] { loadHandler(key, dataLoadInfo); });
58 }
59 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)60 int32_t DelayDataCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
61     MessageOption &option)
62 {
63     LOG_INFO(UDMF_SERVICE, "code:%{public}u callingPid:%{public}u", code, IPCSkeleton::GetCallingPid());
64     std::u16string local = GetDescriptor();
65     std::u16string remote = data.ReadInterfaceToken();
66     if (local != remote) {
67         LOG_ERROR(UDMF_SERVICE, "local is not equal to remote");
68         return -1;
69     }
70 
71     std::string key;
72     UnifiedData unifiedData;
73     if (!ITypesUtil::Unmarshal(data, key, unifiedData)) {
74         LOG_ERROR(UDMF_SERVICE, "Unmarshal failed!");
75         return E_READ_PARCEL_ERROR;
76     }
77     UdmfConversion::ConvertRecordToSubclass(unifiedData);
78 
79     if (unifiedData.HasType(UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML))) {
80         UnifiedHtmlRecordProcess::RebuildHtmlRecord(unifiedData);
81     }
82     DelayDataCallback(key, unifiedData);
83     return 0;
84 }
85 
DelayDataCallbackClient(DataCallback dataCallback)86 DelayDataCallbackClient::DelayDataCallbackClient(DataCallback dataCallback):dataCallback_(dataCallback) {}
87 
DelayDataCallback(const std::string & key,const UnifiedData & unifiedData)88 void DelayDataCallbackClient::DelayDataCallback(const std::string &key, const UnifiedData &unifiedData)
89 {
90     auto dataCallback = dataCallback_;
91     UdmfAsyncClient::GetInstance().PushTaskToExecutor(
92         [dataCallback, key, unifiedData] { dataCallback(key, unifiedData); });
93 }
94 
95 } // namespace UDMF
96 } // namespace OHOS