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 #include "pasteboard_disposable_observer_proxy.h"
17
18 #include "errors.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "pasteboard_hilog.h"
22 #include "pasteboard_serv_ipc_interface_code.h"
23
24 using namespace OHOS::Security::PasteboardServ;
25 namespace OHOS {
26 namespace MiscServices {
PasteboardDisposableObserverProxy(const sptr<IRemoteObject> & object)27 PasteboardDisposableObserverProxy::PasteboardDisposableObserverProxy(const sptr<IRemoteObject> &object)
28 : IRemoteProxy<IPasteboardDisposableObserver>(object)
29 {
30 }
31
OnTextReceived(const std::string & text,int32_t errCode)32 void PasteboardDisposableObserverProxy::OnTextReceived(const std::string &text, int32_t errCode)
33 {
34 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ret=%{public}d, textLen=%{public}zu", errCode, text.length());
35 MessageParcel data;
36 MessageParcel reply;
37 MessageOption option = { MessageOption::TF_ASYNC };
38 PASTEBOARD_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), PASTEBOARD_MODULE_SERVICE,
39 "write descriptor failed");
40 PASTEBOARD_CHECK_AND_RETURN_LOGE(data.WriteString(text), PASTEBOARD_MODULE_SERVICE, "write text failed");
41 PASTEBOARD_CHECK_AND_RETURN_LOGE(data.WriteInt32(errCode), PASTEBOARD_MODULE_SERVICE, "write errCode failed");
42 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(PasteboardDisposableInterfaceCode::ON_TEXT_RECEIVED),
43 data, reply, option);
44 PASTEBOARD_CHECK_AND_RETURN_LOGE(ret == ERR_OK, PASTEBOARD_MODULE_SERVICE,
45 "send request failed, ret=%{public}d", ret);
46 }
47 } // namespace MiscServices
48 } // namespace OHOS
49