• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_TLV_BOX_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_TLV_BOX_H
18 
19 #include <vector>
20 #include <string>
21 #include <map>
22 
23 namespace OHOS {
24 namespace Notification {
25 
26 enum NotificationEventType : int32_t {
27     PUBLISH_NOTIFICATION = 0,
28     UPDATE_NOTIFICATION = 1,
29     REMOVE_NOTIFICATION = 2,
30     CLICK_TO_JUMP = 3,
31     NOTIFICATION_QUICK_REPLY = 4,
32     NOTIFICATION_STATE_SYNC = 5,
33     NOTIFICATION_MATCH_SYNC = 6,
34     BUNDLE_ICON_SYNC = 7,
35     REMOVE_ALL_NOTIFICATIONS = 8,
36     NOTIFICATION_RESPONSE_SYNC = 9,
37     SYNC_NOTIFICATION = 10,
38     NOTIFICATION_RESPONSE_REPLY_SYNC = 11,
39 };
40 
41 enum TlvType : int32_t {
42     MESSAGE_TYPE_ID = 0,
43     NOTIFICATION_HASHCODE,
44     NOTIFICATION_SLOT_TYPE,
45     NOTIFICATION_REMINDERFLAG,
46     BUNDLE_NAME,
47     NOTIFICATION_TITLE,
48     NOTIFICATION_CONTENT,
49     BUNDLE_ICON,
50     NOTIFICATION_BIG_ICON = 8,
51     NOTIFICATION_OVERLAY_ICON = 9,
52     NOTIFICATION_CONTENT_TYPE = 10,
53     NOTIFICATION_COMMON_LIVEVIEW = 11,
54     BATCH_REMOVE_SLOT_TYPE = 14,
55     AUTO_DELETE_TIME = 15,
56     FINISH_DEADLINE_TIME = 16,
57     ACTION_BUTTON_NAME = 17,
58     ACTION_USER_INPUT = 18,
59     NOTIFICATION_ADDITIONAL_TEXT = 19,
60     NOTIFICATION_BRIEF_TEXT = 20,
61     NOTIFICATION_EXPANDED_TITLE = 21,
62     NOTIFICATION_LONG_TITLE = 22,
63     RESULT_CODE = 989,
64     OPERATION_TYPE = 990,
65     OPERATION_EVENT_ID = 991,
66     BUNDLE_ICON_SYNC_TYPE = 992,
67     MATCH_TYPE = 993,
68     PEER_DEVICE_ID = 994,
69     PEER_DEVICE_TYPE = 995,
70     LOCAL_DEVICE_STATUE = 996,
71     LOCAL_DEVICE_ID = 997,
72     LOCAL_DEVICE_TYPE = 998,
73     LOCAL_VERSION = 999,
74     CHECK_SUM = 1000,
75 };
76 
77 class TlvItem {
78 public:
79     TlvItem(int32_t type, bool value);
80     TlvItem(int32_t type, int32_t value);
81     TlvItem(int32_t type, int64_t value);
82     TlvItem(int32_t type, std::string value);
83     TlvItem(int32_t type, const unsigned char* value, int32_t length);
84     TlvItem(int32_t type, const TlvItem& value);
85     ~TlvItem();
86 
87     int32_t GetType() const;
88     int32_t GetLength() const;
89     unsigned char* GetValue() const;
90 
91 private:
92     void Initialize(const void* value, int32_t length);
93 
94     int32_t type_;
95     int32_t length_ = 0;
96     unsigned char* value_ = nullptr;
97 };
98 
99 class TlvBox {
100 public:
101     ~TlvBox();
102     bool Serialize(bool addCheck = true);
103     bool Parse(const unsigned char* buffer, int32_t buffersize);
104     bool PutValue(std::shared_ptr<TlvItem> value);
105     bool SetMessageType(int32_t messageType);
106     void AddMessageCRC(std::string& content);
107     static bool CheckMessageCRC(const unsigned char* data, uint32_t dataLen);
108 
109     bool GetMessageType(int32_t& messageType);
110     bool GetBoolValue(int32_t type, bool& value);
111     bool GetBytes(int32_t type, std::vector<uint8_t>& value);
112     bool GetStringValue(int32_t type, std::string& value);
113     bool GetInt32Value(int32_t type, int32_t& value);
114     bool GetInt64Value(int32_t type, int64_t& value);
115     bool GetObjectValue(int32_t type, TlvBox& value);
116 
117     int32_t bytesLength_ = 0;
118     unsigned char* byteBuffer_ = nullptr;
119     std::map<int32_t, std::shared_ptr<TlvItem>> TlvMap_;
120 };
121 }  // namespace Notification
122 }  // namespace OHOS
123 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_TLV_BOX_H
124 
125