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, int32_t level); 37 38 typedef int32_t (*MessageSendResultNotifier)(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); 39 40 typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, int32_t level, void *para); 41 42 typedef struct MessengerConfig { 43 const char *pkgName; 44 #ifdef L2_STANDARD 45 const char *primarySockName; 46 const char *secondarySockName; 47 #else 48 const char *primarySessName; 49 const char *secondarySessName; 50 #endif 51 DeviceMessageReceiver messageReceiver; 52 DeviceStatusReceiver statusReceiver; 53 MessageSendResultNotifier sendResultNotifier; 54 uint32_t threadCnt; 55 } MessengerConfig; 56 57 typedef struct StatisticInformation { 58 uint64_t firstOnlineTime; 59 uint64_t lastOnlineTime; 60 uint64_t firstOfflineTime; 61 uint64_t lastOfflineTime; 62 uint64_t lastSessOpenTime; 63 uint32_t lastSessOpenResult; 64 uint32_t lastSessOpenCost; 65 uint64_t lastSessCloseTime; 66 uint64_t lastMsgSendTime; 67 uint32_t lastMsgSendResult; 68 uint32_t lastMsgSendCost; 69 uint64_t lastMsgRecvTime; 70 uint64_t packetRx; 71 uint64_t packetTotalRx; 72 uint64_t packetTx; 73 uint64_t packetTotalTx; 74 uint64_t packetTxFailed; 75 uint64_t packetTotalTxFailed; 76 } StatisticInformation; 77 78 typedef struct Messenger Messenger; 79 80 Messenger *CreateMessenger(const MessengerConfig *config); 81 82 void DestroyMessenger(Messenger *messenger); 83 84 bool IsMessengerReady(const Messenger *messenger); 85 86 void SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, 87 uint32_t msgLen); 88 89 bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level); 90 91 bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level); 92 93 void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para); 94 95 bool GetDeviceStatisticInfo(const Messenger *messenger, const DeviceIdentify *devId, StatisticInformation *info); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif // SEC_MESSENGER_INFO_H 102