• 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 
16 #include "entity_recognition_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 {
EntityRecognitionObserverStub()25 EntityRecognitionObserverStub::EntityRecognitionObserverStub()
26 {
27     memberFuncMap_[static_cast<uint32_t>(EntityObserverInterfaceCode::ON_RECOGNITION_EVENT)] =
28         &EntityRecognitionObserverStub::OnRecognitionEventStub;
29 }
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t EntityRecognitionObserverStub::OnRemoteRequest(
32     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "start##code = %{public}u", code);
35     std::u16string myDescriptor = EntityRecognitionObserverStub::GetDescriptor();
36     std::u16string remoteDescriptor = data.ReadInterfaceToken();
37     if (myDescriptor != remoteDescriptor) {
38         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "end##descriptor checked fail");
39         return static_cast<int32_t>(PasteboardError::CHECK_DESCRIPTOR_ERROR);
40     }
41     auto itFunc = memberFuncMap_.find(code);
42     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(itFunc != memberFuncMap_.end(),
43         static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR),
44         PASTEBOARD_MODULE_SERVICE, "Not found error, code=%{public}u", code);
45     auto memberFunc = itFunc->second;
46     if (memberFunc != nullptr) {
47         return (this->*memberFunc)(data, reply);
48     }
49     return static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR);
50 }
51 
OnRecognitionEventStub(MessageParcel & data,MessageParcel & reply)52 int32_t EntityRecognitionObserverStub::OnRecognitionEventStub(MessageParcel &data, MessageParcel &reply)
53 {
54     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "start.");
55     std::string entity = data.ReadString();
56     uint32_t type = 0;
57     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(
58         data.ReadUint32(type), ERR_INVALID_VALUE, PASTEBOARD_MODULE_CLIENT, "Failed to read type");
59     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(type < static_cast<uint32_t>(EntityType::MAX), ERR_INVALID_VALUE,
60         PASTEBOARD_MODULE_CLIENT, "type invalid, type=%{public}u", type);
61     EntityType entityType = static_cast<EntityType>(type);
62     OnRecognitionEvent(entityType, entity);
63     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "end.");
64     return ERR_OK;
65 }
66 
~EntityRecognitionObserverStub()67 EntityRecognitionObserverStub::~EntityRecognitionObserverStub()
68 {
69     memberFuncMap_.clear();
70 }
71 } // namespace MiscServices
72 } // namespace OHOS
73