• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_STORE_H
16 #define HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_STORE_H
17 
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "app_event_dao.h"
24 #include "app_event_mapping_dao.h"
25 #include "app_event_observer_dao.h"
26 #include "user_id_dao.h"
27 #include "user_property_dao.h"
28 #include "rdb_store.h"
29 #include "singleton.h"
30 
31 namespace OHOS {
32 namespace HiviewDFX {
33 class AppEventPack;
34 
35 class AppEventStore : public DelayedRefSingleton<AppEventStore>  {
36 public:
37     AppEventStore();
38     ~AppEventStore();
39     int InitDbStore();
40     int DestroyDbStore();
41     int64_t InsertEvent(std::shared_ptr<AppEventPack> event);
42     int64_t InsertObserver(const std::string& observer, int64_t hashCode = 0);
43     int64_t InsertEventMapping(int64_t eventSeq, int64_t observerSeq);
44     int64_t InsertUserId(const std::string& name, const std::string& value);
45     int64_t InsertUserProperty(const std::string& name, const std::string& value);
46     int64_t UpdateUserId(const std::string& name, const std::string& value);
47     int64_t UpdateUserProperty(const std::string& name, const std::string& value);
48     int TakeEvents(std::vector<std::shared_ptr<AppEventPack>>& events, int64_t observerSeq);
49     int QueryEvents(std::vector<std::shared_ptr<AppEventPack>>& events, int64_t observerSeq);
50     int64_t QueryObserverSeq(const std::string& observer, int64_t hashCode = 0);
51     int QueryObserverSeqs(const std::string& observer, std::vector<int64_t>& observerSeqs);
52     int QueryUserIds(std::unordered_map<std::string, std::string>& out);
53     int QueryUserId(const std::string& name, std::string& out);
54     int QueryUserProperties(std::unordered_map<std::string, std::string>& out);
55     int QueryUserProperty(const std::string& name, std::string& out);
56     int DeleteObserver(int64_t observerSeq);
57     int DeleteEventMapping(int64_t observerSeq = 0, const std::vector<int64_t>& eventSeqs = {});
58     int DeleteUserId(const std::string& name = "");
59     int DeleteUserProperty(const std::string& name = "");
60     int DeleteEvent(int64_t eventSeq = 0);
61 
62 private:
63     bool InitDbStoreDir();
64 
65 private:
66     std::shared_ptr<NativeRdb::RdbStore> dbStore_;
67     std::shared_ptr<AppEventDao> appEventDao_;
68     std::shared_ptr<AppEventObserverDao> appEventObserverDao_;
69     std::shared_ptr<AppEventMappingDao> appEventMappingDao_;
70     std::shared_ptr<UserIdDao> userIdDao_;
71     std::shared_ptr<UserPropertyDao> userPropertyDao_;
72     std::string dirPath_;
73     std::mutex dbMutex_;
74 };
75 } // namespace HiviewDFX
76 } // namespace OHOS
77 #endif // HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_STORE_H
78