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 "entity_recognition_observer_proxy.h"
17 #include "errors.h"
18 #include "message_option.h"
19 #include "message_parcel.h"
20 #include "pasteboard_hilog.h"
21 #include "pasteboard_serv_ipc_interface_code.h"
22
23 using namespace OHOS::Security::PasteboardServ;
24 namespace OHOS {
25 namespace MiscServices {
EntityRecognitionObserverProxy(const sptr<IRemoteObject> & object)26 EntityRecognitionObserverProxy::EntityRecognitionObserverProxy(const sptr<IRemoteObject> &object)
27 : IRemoteProxy<IEntityRecognitionObserver>(object)
28 {
29 }
30
OnRecognitionEvent(EntityType entityType,std::string & entity)31 void EntityRecognitionObserverProxy::OnRecognitionEvent(EntityType entityType, std::string &entity)
32 {
33 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE,
34 "callback, type=%{public}u, entity=%{private}s", static_cast<uint32_t>(entityType), entity.c_str());
35 MessageParcel data;
36 MessageParcel reply;
37 MessageOption option;
38 PASTEBOARD_CHECK_AND_RETURN_LOGE(
39 data.WriteInterfaceToken(GetDescriptor()), PASTEBOARD_MODULE_SERVICE, "write descriptor failed!");
40 PASTEBOARD_CHECK_AND_RETURN_LOGE(data.WriteString(entity), PASTEBOARD_MODULE_SERVICE, "Write entity failed");
41 uint32_t type = static_cast<uint32_t>(entityType);
42 PASTEBOARD_CHECK_AND_RETURN_LOGE(data.WriteUint32(type), PASTEBOARD_MODULE_SERVICE, "Write type failed");
43 int32_t ret =
44 Remote()->SendRequest(static_cast<int>(EntityObserverInterfaceCode::ON_RECOGNITION_EVENT), data, reply, option);
45 PASTEBOARD_CHECK_AND_RETURN_LOGE(
46 ret == ERR_OK, PASTEBOARD_MODULE_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
47 return;
48 }
49 } // namespace MiscServices
50 } // namespace OHOS
51