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 #ifndef OHOS_AAFWK_DATA_ABILITY_OBSERVER_STUB_H 16 #define OHOS_AAFWK_DATA_ABILITY_OBSERVER_STUB_H 17 18 #include <memory> 19 #include <map> 20 21 #include "data_ability_observer_interface.h" 22 #include "nocopyable.h" 23 24 #include <iremote_object.h> 25 #include <iremote_stub.h> 26 27 namespace OHOS { 28 namespace AAFwk { 29 30 class DataAbilityObserverStub : public IRemoteStub<IDataAbilityObserver> { 31 public: 32 DataAbilityObserverStub(); 33 virtual ~DataAbilityObserverStub(); 34 35 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 36 37 private: 38 /** 39 * @brief Called back to notify that the data being observed has changed. 40 * 41 * @param uri Indicates the path of the data to operate. 42 * 43 * @return Returns 0 on success, others on failure. 44 * 45 */ 46 int OnChangeInner(MessageParcel &data, MessageParcel &reply); 47 48 using RequestFuncType = int (DataAbilityObserverStub::*)(MessageParcel &data, MessageParcel &reply); 49 std::map<uint32_t, RequestFuncType> requestFuncMap_; 50 51 DISALLOW_COPY_AND_MOVE(DataAbilityObserverStub); 52 }; 53 54 /** 55 * @class DataObsCallbackRecipient 56 * DataObsCallbackRecipient notices IRemoteBroker died. 57 */ 58 class DataObsCallbackRecipient : public IRemoteObject::DeathRecipient { 59 public: 60 using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>; 61 DataObsCallbackRecipient(RemoteDiedHandler handler); 62 virtual ~DataObsCallbackRecipient(); 63 virtual void OnRemoteDied(const wptr<IRemoteObject> &remote); 64 65 private: 66 RemoteDiedHandler handler_; 67 }; 68 69 } // namespace AAFwk 70 } // namespace OHOS 71 #endif // OHOS_AAFWK_DATA_ABILITY_OBSERVER_STUB_H