• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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     if (itFunc != memberFuncMap_.end()) {
43         auto memberFunc = itFunc->second;
44         if (memberFunc != nullptr) {
45             return (this->*memberFunc)(data, reply);
46         }
47     }
48     int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "end##ret = %{public}d", ret);
50     return ret;
51 }
52 
OnRecognitionEventStub(MessageParcel & data,MessageParcel & reply)53 int32_t EntityRecognitionObserverStub::OnRecognitionEventStub(MessageParcel &data, MessageParcel &reply)
54 {
55     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "start.");
56     std::string entity = data.ReadString();
57     uint32_t type = 0;
58     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(
59         data.ReadUint32(type), ERR_INVALID_VALUE, PASTEBOARD_MODULE_CLIENT, "Failed to read type");
60     PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(type < static_cast<uint32_t>(EntityType::MAX), ERR_INVALID_VALUE,
61         PASTEBOARD_MODULE_CLIENT, "type invalid, type=%{public}u", type);
62     EntityType entityType = static_cast<EntityType>(type);
63     OnRecognitionEvent(entityType, entity);
64     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "end.");
65     return ERR_OK;
66 }
67 
~EntityRecognitionObserverStub()68 EntityRecognitionObserverStub::~EntityRecognitionObserverStub()
69 {
70     memberFuncMap_.clear();
71 }
72 } // namespace MiscServices
73 } // namespace OHOS
74