• 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H
18 
19 #include <vector>
20 
21 #include "notification_bundle_option.h"
22 #include "reminder_request.h"
23 #include "rdb_errno.h"
24 #include "rdb_helper.h"
25 #include "rdb_open_callback.h"
26 #include "rdb_store_config.h"
27 
28 namespace OHOS {
29 namespace Notification {
30 class ReminderStore {
31 public:
ReminderStore()32     ReminderStore() {};
~ReminderStore()33     virtual ~ReminderStore() {};
34     int32_t Init();
35     int32_t Delete(int32_t reminderId);
36     int32_t Delete(const std::string &pkg, int32_t userId);
37     int32_t DeleteUser(int32_t userId);
38     std::vector<sptr<ReminderRequest>> GetAllValidReminders();
39     bool GetBundleOption(const int32_t &reminderId, sptr<NotificationBundleOption> &bundleOption) const;
40     int32_t GetMaxId();
41     int64_t UpdateOrInsert(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption);
42 
43     static void GetInt32Val(const std::shared_ptr<NativeRdb::ResultSet>& resultSet,
44         const std::string& name, int32_t& value);
45     static void GetInt64Val(const std::shared_ptr<NativeRdb::ResultSet>& resultSet,
46         const std::string& name, int64_t& value);
47     static void GetStringVal(const std::shared_ptr<NativeRdb::ResultSet>& resultSet,
48         const std::string& name, std::string& value);
49 
50     static const int32_t STATE_OK;
51 
52     static const std::string REMINDER_DB_DIR;
53     static const std::string REMINDER_DB_NAME;
54     static const std::string REMINDER_DB_TABLE;
55 private:
56     /**
57      * @brief Inits the data in database when system boot on or proxy process reboot on.
58      *
59      * 1. Deletes all the reminders which IS_EXPIRED is true.
60      * 2. Sets all the value of STATE to ReminderRequest::REMINDER_STATUS_INACTIVE
61      * 3. Sets all the value of IS_ACTIVE to false.
62      * 4. Sets all the value of HAS_SCHEDULED_TIMEOUT to false.
63      *
64      * @return int32_t result code.
65      */
66     int32_t InitData();
67     sptr<ReminderRequest> BuildReminder(const std::shared_ptr<NativeRdb::ResultSet> &resultSet);
68     int32_t Delete(const std::string &deleteCondition);
69     std::vector<sptr<ReminderRequest>> GetReminders(const std::string &queryCondition);
70     void GenerateData(const sptr<ReminderRequest> &reminder,
71         const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values) const;
72     bool IsReminderExist(const sptr<ReminderRequest> &reminder);
73     int64_t Insert(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption);
74     std::shared_ptr<NativeRdb::ResultSet> Query(const std::string &queryCondition) const;
75     int64_t Update(const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption);
76     static void AddRdbColum(NativeRdb::RdbStore &rdbStore, const std::string &columName,
77         const std::string &type);
78 class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback {
79 public:
80     int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override;
81     int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
82 };
83 
84 private:
85     std::shared_ptr<NativeRdb::RdbStore> rdbStore_ = nullptr;
86 };
87 }  // namespace Notification
88 }  // namespace OHOS
89 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H