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 OHOS_FORM_FWK_FORM_DATA_PROXY_MGR_H 17 #define OHOS_FORM_FWK_FORM_DATA_PROXY_MGR_H 18 19 #include <memory> 20 #include <singleton.h> 21 22 #include "form_data_proxy_record.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 /** 27 * @class FormDataProxyMgr 28 * data proxy form mananger. 29 */ 30 class FormDataProxyMgr final : public DelayedRefSingleton<FormDataProxyMgr> { 31 DECLARE_DELAYED_REF_SINGLETON(FormDataProxyMgr) 32 public: 33 DISALLOW_COPY_AND_MOVE(FormDataProxyMgr); 34 35 ErrCode SubscribeFormData(int64_t formId, const std::vector<FormDataProxy> &formDataProxies, 36 const AAFwk::Want &want); 37 ErrCode UnsubscribeFormData(int64_t formId); 38 void UpdateSubscribeFormData(int64_t formId, const std::vector<FormDataProxy> &formDataProxies); 39 void ProduceFormDataProxies(int64_t formId, const std::vector<FormDataProxy> &formDataProxies); 40 bool ConsumeFormDataProxies(int64_t formId, std::vector<FormDataProxy> &formDataProxies); 41 void EnableSubscribeFormData(const std::vector<int64_t> &formIds); 42 void DisableSubscribeFormData(const std::vector<int64_t> &formIds); 43 // will run only once 44 void RetryFailureSubscribes(); 45 void GetFormSubscribeInfo(const int64_t formId, std::vector<std::string> &subscribedKeys, int32_t &count); 46 private: 47 std::mutex formDataProxyRecordMutex_; 48 std::map<int64_t, std::shared_ptr<FormDataProxyRecord>> formDataProxyRecordMap_; // formId:FormDataProxyRecord 49 std::mutex formDataProxiesMutex_; 50 std::map<int64_t, std::vector<FormDataProxy>> formDataProxiesMap_; // formId:FormDataProxies 51 }; 52 } // namespace AppExecFwk 53 } // namespace OHOS 54 55 #endif // OHOS_FORM_FWK_FORM_DATA_PROXY_MGR_H