• 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 "data_ability_observer_stub.h"
17 #include "hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace AAFwk {
DataAbilityObserverStub()21 DataAbilityObserverStub::DataAbilityObserverStub()
22 {
23     requestFuncMap_[DATA_ABILITY_OBSERVER_CHANGE] = &DataAbilityObserverStub::OnChangeInner;
24 }
25 
~DataAbilityObserverStub()26 DataAbilityObserverStub::~DataAbilityObserverStub()
27 {
28     requestFuncMap_.clear();
29 }
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int DataAbilityObserverStub::OnRemoteRequest(
32     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34     HILOG_DEBUG("%{public}s, cmd = %d, flags= %d", __func__, code, option.GetFlags());
35     std::u16string descriptor = DataAbilityObserverStub::GetDescriptor();
36     std::u16string remoteDescriptor = data.ReadInterfaceToken();
37     if (descriptor != remoteDescriptor) {
38         HILOG_INFO("local descriptor is not equal to remote");
39         return ERR_INVALID_STATE;
40     }
41 
42     auto itFunc = requestFuncMap_.find(code);
43     if (itFunc != requestFuncMap_.end()) {
44         auto requestFunc = itFunc->second;
45         if (requestFunc != nullptr) {
46             return (this->*requestFunc)(data, reply);
47         }
48     }
49     HILOG_WARN("%{public}s, default case, need check.", __func__);
50     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51 }
52 
53 /**
54  * @brief Called back to notify that the data being observed has changed.
55  *
56  * @param uri Indicates the path of the data to operate.
57  *
58  * @return Returns 0 on success, others on failure.
59  */
OnChangeInner(MessageParcel & data,MessageParcel & reply)60 int DataAbilityObserverStub::OnChangeInner(MessageParcel &data, MessageParcel &reply)
61 {
62     OnChange();
63     return ERR_NONE;
64 }
65 
OnRemoteDied(const wptr<IRemoteObject> & remote)66 void DataObsCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
67 {
68     HILOG_ERROR("recv DataObsCallbackRecipient death notice");
69 
70     if (handler_) {
71         handler_(remote);
72     }
73 }
74 
DataObsCallbackRecipient(RemoteDiedHandler handler)75 DataObsCallbackRecipient::DataObsCallbackRecipient(RemoteDiedHandler handler) : handler_(handler)
76 {}
77 
~DataObsCallbackRecipient()78 DataObsCallbackRecipient::~DataObsCallbackRecipient()
79 {}
80 }  // namespace AAFwk
81 }  // namespace OHOS
82