• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "want_sender_stub.h"
17 
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
WantSenderStub()23 WantSenderStub::WantSenderStub()
24 {
25     requestFuncMap_[WANT_SENDER_SEND] = &WantSenderStub::SendInner;
26 }
27 
~WantSenderStub()28 WantSenderStub::~WantSenderStub()
29 {
30     requestFuncMap_.clear();
31 }
32 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int WantSenderStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35     HILOG_DEBUG("WantSendStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
36     std::u16string descriptor = WantSenderStub::GetDescriptor();
37     std::u16string remoteDescriptor = data.ReadInterfaceToken();
38     if (descriptor != remoteDescriptor) {
39         HILOG_INFO("local descriptor is not equal to remote");
40         return ERR_INVALID_STATE;
41     }
42 
43     auto itFunc = requestFuncMap_.find(code);
44     if (itFunc != requestFuncMap_.end()) {
45         auto requestFunc = itFunc->second;
46         if (requestFunc != nullptr) {
47             return (this->*requestFunc)(data, reply);
48         }
49     }
50     HILOG_WARN("WantSenderStub::OnRemoteRequest, default case, need check.");
51     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52 }
53 
SendInner(MessageParcel & data,MessageParcel & reply)54 int WantSenderStub::SendInner(MessageParcel &data, MessageParcel &reply)
55 {
56     SenderInfo *senderInfo = data.ReadParcelable<SenderInfo>();
57     if (senderInfo == nullptr) {
58         HILOG_ERROR("WantSenderStub: senderInfo is nullptr");
59         return ERR_INVALID_VALUE;
60     }
61     Send(*senderInfo);
62     delete senderInfo;
63     return NO_ERROR;
64 }
65 }  // namespace AAFwk
66 }  // namespace OHOS