• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_STORAGE_OPKEY_ABILITY_H
17 #define DATA_STORAGE_OPKEY_ABILITY_H
18 
19 #include "__functional_base"
20 #include "__mutex_base"
21 #include "ability.h"
22 #include "ability_lifecycle.h"
23 #include "iosfwd"
24 #include "map"
25 #include "memory"
26 #include "rdb_opkey_helper.h"
27 #include "string"
28 #include "vector"
29 
30 namespace OHOS {
31 namespace NativeRdb {
32 class AbsRdbPredicates;
33 class AbsSharedResultSet;
34 class DataAbilityPredicates;
35 class ValuesBucket;
36 }
37 namespace Telephony {
38 enum class OpKeyUriType {
39     UNKNOW, OPKEY_INFO
40 };
41 class OpKeyAbility : public AppExecFwk::Ability {
42 public:
43     virtual void OnStart(const AppExecFwk::Want &want) override;
44     virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
45     virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
46         const Uri &uri, const std::vector<std::string> &columns,
47         const NativeRdb::DataAbilityPredicates &predicates) override;
48     virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
49         const NativeRdb::DataAbilityPredicates &predicates) override;
50     virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
51     virtual std::string GetType(const Uri &uri) override;
52     virtual int OpenFile(const Uri &uri, const std::string &mode) override;
53 
54 private:
55     /**
56      * Parse Uri Type
57      *
58      * @param uri Resource address
59      * @return return OpKeyUriType
60      */
61     OpKeyUriType ParseUriType(Uri &uri);
62 
63     /**
64      * Convert DataAbilityPredicates to AbsRdbPredicates
65      *
66      * @param predicates DataAbilityPredicates
67      * @param absRdbPredicates AbsRdbPredicates
68      */
69     void ConvertPredicates(
70         const NativeRdb::DataAbilityPredicates &predicates, NativeRdb::AbsRdbPredicates *absRdbPredicates);
71 
72     /**
73     * Check whether the initialization succeeds
74     *
75     * @return true : succeed ,false : failed
76     */
77     bool IsInitOk();
78 
79     /**
80      * Init UriMap
81      */
82     void InitUriMap();
83 
84 private:
85     RdbOpKeyHelper helper_;
86     std::mutex lock_;
87     std::map<std::string, OpKeyUriType> opKeyUriMap_;
88     bool initDatabaseDir_ = false;
89     bool initRdbStore_ = false;
90 };
91 } // namespace Telephony
92 } // namespace OHOS
93 #endif // DATA_STORAGE_OPKEY_ABILITY_H