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_stub.h"
17
18 #include "pasteboard_error.h"
19 #include "pasteboard_hilog.h"
20 #include "pasteboard_serv_ipc_interface_code.h"
21
22 using namespace OHOS::Security::PasteboardServ;
23 namespace OHOS {
24 namespace MiscServices {
PasteboardDisposableObserverStub()25 PasteboardDisposableObserverStub::PasteboardDisposableObserverStub()
26 {
27 memberFuncMap_[static_cast<uint32_t>(PasteboardDisposableInterfaceCode::ON_TEXT_RECEIVED)] =
28 &PasteboardDisposableObserverStub::OnTextReceivedStub;
29 }
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t PasteboardDisposableObserverStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
32 MessageOption &option)
33 {
34 std::u16string myDescriptor = PasteboardDisposableObserverStub::GetDescriptor();
35 std::u16string remoteDescriptor = data.ReadInterfaceToken();
36 PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(myDescriptor == remoteDescriptor,
37 static_cast<int32_t>(PasteboardError::CHECK_DESCRIPTOR_ERROR), PASTEBOARD_MODULE_SERVICE,
38 "invalid descriptor, code=%{public}u", code);
39
40 auto iter = memberFuncMap_.find(code);
41 PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(iter != memberFuncMap_.end(),
42 static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), PASTEBOARD_MODULE_SERVICE,
43 "invalid code, code=%{public}u", code);
44 auto memberFunc = iter->second;
45 PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(memberFunc != nullptr,
46 static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), PASTEBOARD_MODULE_SERVICE,
47 "func is null, code=%{public}u", code);
48 return (this->*memberFunc)(data, reply);
49 }
50
OnTextReceivedStub(MessageParcel & data,MessageParcel & reply)51 int32_t PasteboardDisposableObserverStub::OnTextReceivedStub(MessageParcel &data, MessageParcel &reply)
52 {
53 std::string text = data.ReadString();
54 int32_t errCode = 0;
55 PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(errCode), ERR_INVALID_VALUE, PASTEBOARD_MODULE_CLIENT,
56 "read errCode failed");
57 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ret=%{public}d, textLen=%{public}zu", errCode, text.length());
58 OnTextReceived(text, errCode);
59 return ERR_OK;
60 }
61 } // namespace MiscServices
62 } // namespace OHOS
63