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