1 /*
2 * Copyright (c) 2021 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_observer_proxy.h"
17
18 #include "errors.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "pasteboard_hilog.h"
22
23 namespace OHOS {
24 namespace MiscServices {
PasteboardObserverProxy(const sptr<IRemoteObject> & object)25 PasteboardObserverProxy::PasteboardObserverProxy(const sptr<IRemoteObject> &object)
26 : IRemoteProxy<IPasteboardChangedObserver>(object)
27 {
28 }
29
OnPasteboardChanged()30 void PasteboardObserverProxy::OnPasteboardChanged()
31 {
32 MessageParcel data, reply;
33 MessageOption option;
34 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
35 if (!data.WriteInterfaceToken(GetDescriptor())) {
36 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
37 return;
38 }
39
40 int ret = Remote()->SendRequest(static_cast<int>(ON_PASTE_BOARD_CHANGE), data, reply, option);
41 if (ret != ERR_OK) {
42 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
43 }
44 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
45 return;
46 }
47
OnPasteboardEvent(std::string bundleName,int32_t status)48 void PasteboardObserverProxy::OnPasteboardEvent(std::string bundleName, int32_t status)
49 {
50 MessageParcel data, reply;
51 MessageOption option;
52 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start.");
53 if (!data.WriteInterfaceToken(GetDescriptor())) {
54 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
55 return;
56 }
57 data.WriteString(bundleName);
58 data.WriteInt32(status);
59 int ret = Remote()->SendRequest(static_cast<int>(ON_PASTE_BOARD_EVENT), data, reply, option);
60 if (ret != ERR_OK) {
61 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
62 }
63 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "end.");
64 return;
65 }
66 } // namespace MiscServices
67 } // namespace OHOS
68