• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RECORD_H
17 #define OHOS_FORM_FWK_FORM_DATA_PROXY_RECORD_H
18 
19 #include <vector>
20 
21 #include "datashare_helper.h"
22 #include "form_ashmem.h"
23 #include "form_provider_data_proxy.h"
24 #include "form_info_base.h"
25 #include "nlohmann/json.hpp"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 /**
30  * @class FormDataSharerRecord
31  * data share form record.
32  */
33 class FormDataProxyRecord : public std::enable_shared_from_this<FormDataProxyRecord> {
34 public:
35     FormDataProxyRecord(int64_t formId, const std::string &bundleName, FormType uiSyntax, uint32_t tokenId);
36     ~FormDataProxyRecord();
37 
38     ErrCode SubscribeFormData(const std::vector<FormDataProxy> &formDataProxies);
39     ErrCode UnsubscribeFormData();
40     void UpdateSubscribeFormData(const std::vector<FormDataProxy> &formDataProxies);
41     void EnableSubscribeFormData();
42     void DisableSubscribeFormData();
43 private:
44     struct FormDataProxyRequest {
45         int64_t subscribeId;
46         std::vector<std::string> uris;
47     };
48     void ParseFormDataProxies(const std::vector<FormDataProxy> &formDataProxies);
49     void ConvertSubscribeMapToRequests(std::map<std::string, std::string> &subscribeMap,
50         std::vector<FormDataProxyRequest> &formDataProxyRequests);
51     void UpdatePublishedDataForm(const std::vector<DataShare::PublishedDataItem> &data);
52     void UpdateRdbDataForm(const std::vector<std::string> &data);
53     ErrCode SubscribeRdbFormData(std::map<std::string, std::string> &rdbSubscribeMap);
54     ErrCode SubscribePublishFormData(std::map<std::string, std::string> &publishSubscribeMap);
55     ErrCode UnsubscribeFormData(std::map<std::string, std::string> &rdbSubscribeMap,
56         std::map<std::string, std::string> &publishSubscribeMap);
57     void OnRdbDataChange(const DataShare::RdbChangeNode &changeNode);
58     void OnPublishedDataChange(const DataShare::PublishedDataChangeNode &changeNode);
59 
60     void UpdateSubscribeMap(const std::vector<FormDataProxy> &formDataProxies,
61         std::map<std::string, std::string> &originRdbMap,
62         std::map<std::string, std::string> &newRdbMap,
63         std::map<std::string, std::string> &originPublishMap,
64         std::map<std::string, std::string> &newPublishMap);
65 
66     ErrCode SetRdbSubsState(std::map<std::string, std::string> &rdbSubscribeMap, bool subsState);
67     ErrCode SetPublishSubsState(std::map<std::string, std::string> &publishSubscribeMap, bool subsState);
68 
69     bool PrepareImageData(const DataShare::PublishedDataItem &data, nlohmann::json &jsonObj,
70         std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> &imageDataMap);
71 
72     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper_;
73     int64_t formId_ = -1;
74     std::string bundleName_;
75     FormType uiSyntax_;
76     int32_t tokenId_;
77     std::map<std::string, std::string> rdbSubscribeMap_; // key: subscribeId
78     std::map<std::string, std::string> publishSubscribeMap_; // key: subscribeId
79 };
80 } // namespace AppExecFwk
81 } // namespace OHOS
82 
83 #endif // OHOS_FORM_FWK_FORM_DATA_PROXY_RECORD_H