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 #ifndef DATA_PROXY_OBSERVER_STUB_H 17 #define DATA_PROXY_OBSERVER_STUB_H 18 19 #include "data_proxy_observer.h" 20 #include "datashare_template.h" 21 #include "iremote_stub.h" 22 23 namespace OHOS { 24 namespace DataShare { 25 using RdbCallback = std::function<void(const RdbChangeNode &changeNode)>; 26 class RdbObserverStub : public IRemoteStub<IDataProxyRdbObserver> { 27 public: 28 RdbObserverStub(RdbCallback callback); 29 virtual ~RdbObserverStub(); 30 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 31 void OnChangeFromRdb(const RdbChangeNode &changeNode); 32 void ClearCallback(); 33 private: 34 std::mutex mutex_; 35 RdbCallback callback_; 36 }; 37 38 using PublishedDataCallback = std::function<void(PublishedDataChangeNode &changeNode)>; 39 class PublishedDataObserverStub : public IRemoteStub<IDataProxyPublishedDataObserver> { 40 public: 41 virtual ~PublishedDataObserverStub(); 42 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; PublishedDataObserverStub(PublishedDataCallback callback)43 explicit PublishedDataObserverStub(PublishedDataCallback callback) : callback_(callback){}; 44 void OnChangeFromPublishedData(PublishedDataChangeNode &changeNode); 45 void ClearCallback(); 46 private: 47 std::mutex mutex_; 48 PublishedDataCallback callback_; 49 }; 50 } // namespace DataShare 51 } // namespace OHOS 52 #endif //DATA_PROXY_OBSERVER_STUB_H 53