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 #ifndef HI_APP_EVENT_USER_INFO_H
16 #define HI_APP_EVENT_USER_INFO_H
17 
18 #include <string>
19 #include <unordered_map>
20 
21 #include "app_event_observer.h"
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 namespace HiAppEvent {
27 class UserInfo : public NoCopyable {
28 public:
29     static UserInfo& GetInstance();
30 
31     int SetUserId(const std::string& name, const std::string& value);
32     int GetUserId(const std::string& name, std::string& out);
33     int RemoveUserId(const std::string& name);
34     int SetUserProperty(const std::string& name, const std::string& value);
35     int GetUserProperty(const std::string& name, std::string& out);
36     int RemoveUserProperty(const std::string& name);
37     std::vector<HiAppEvent::UserId> GetUserIds();
38     std::vector<HiAppEvent::UserProperty> GetUserProperties();
39     int64_t GetUserIdVersion();
40     int64_t GetUserPropertyVersion();
41     void ClearData();
42 
43 private:
44     UserInfo();
45     ~UserInfo() = default;
46     void InitUserIds();
47     void InitUserProperties();
48 
49 private:
50     int64_t userIdVersion_;
51     int64_t userPropertyVersion_;
52     std::unordered_map<std::string, std::string> userIds_;
53     std::unordered_map<std::string, std::string> userProperties_;
54 };
55 } // namespace HiAppEvent
56 } // namespace HiviewDFX
57 } // namespace OHOS
58 #endif // HI_APP_EVENT_CONFIG_H
59