• 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 SEC_MESSENGER_INFO_H
17 #define SEC_MESSENGER_INFO_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifndef DEVICE_SECURITY_DEFINES_H
27 #define DEVICE_ID_MAX_LEN 64
28 typedef struct DeviceIdentify {
29     uint32_t length;
30     uint8_t identity[DEVICE_ID_MAX_LEN];
31 } DeviceIdentify;
32 #endif
33 
34 typedef int32_t (*DeviceMessageReceiver)(const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen);
35 
36 typedef int32_t (*DeviceStatusReceiver)(const DeviceIdentify *devId, uint32_t status, uint32_t devType);
37 
38 typedef int32_t (*MessageSendResultNotifier)(const DeviceIdentify *devId, uint64_t transNo, uint32_t result);
39 
40 typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, uint32_t devType, void *para);
41 
42 typedef struct MessengerConfig {
43     const char *pkgName;
44     const char *primarySessName;
45     const char *secondarySessName;
46     DeviceMessageReceiver messageReceiver;
47     DeviceStatusReceiver statusReceiver;
48     MessageSendResultNotifier sendResultNotifier;
49     uint32_t threadCnt;
50 } MessengerConfig;
51 
52 typedef struct StatisticInformation {
53     uint64_t firstOnlineTime;
54     uint64_t lastOnlineTime;
55     uint64_t firstOfflineTime;
56     uint64_t lastOfflineTime;
57     uint64_t lastSessOpenTime;
58     uint32_t lastSessOpenResult;
59     uint32_t lastSessOpenCost;
60     uint64_t lastSessCloseTime;
61     uint64_t lastMsgSendTime;
62     uint32_t lastMsgSendResult;
63     uint32_t lastMsgSendCost;
64     uint64_t lastMsgRecvTime;
65     uint64_t packetRx;
66     uint64_t packetTotalRx;
67     uint64_t packetTx;
68     uint64_t packetTotalTx;
69     uint64_t packetTxFailed;
70     uint64_t packetTotalTxFailed;
71 } StatisticInformation;
72 
73 typedef struct Messenger Messenger;
74 
75 Messenger *CreateMessenger(const MessengerConfig *config);
76 
77 void DestroyMessenger(Messenger *messenger);
78 
79 bool IsMessengerReady(const Messenger *messenger);
80 
81 void SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg,
82     uint32_t msgLen);
83 
84 bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType);
85 
86 bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType);
87 
88 void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para);
89 
90 bool GetDeviceStatisticInfo(const Messenger *messenger, const DeviceIdentify *devId, StatisticInformation *info);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif // SEC_MESSENGER_INFO_H
97