12ee81decSopenharmony_ci/* 22ee81decSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 32ee81decSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42ee81decSopenharmony_ci * you may not use this file except in compliance with the License. 52ee81decSopenharmony_ci * You may obtain a copy of the License at 62ee81decSopenharmony_ci * 72ee81decSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82ee81decSopenharmony_ci * 92ee81decSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102ee81decSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112ee81decSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122ee81decSopenharmony_ci * See the License for the specific language governing permissions and 132ee81decSopenharmony_ci * limitations under the License. 142ee81decSopenharmony_ci */ 152ee81decSopenharmony_ci 162ee81decSopenharmony_ci#ifndef SEC_MESSENGER_INFO_H 172ee81decSopenharmony_ci#define SEC_MESSENGER_INFO_H 182ee81decSopenharmony_ci 192ee81decSopenharmony_ci#include <stdint.h> 202ee81decSopenharmony_ci#include <stdbool.h> 212ee81decSopenharmony_ci 222ee81decSopenharmony_ci#ifdef __cplusplus 232ee81decSopenharmony_ciextern "C" { 242ee81decSopenharmony_ci#endif 252ee81decSopenharmony_ci 262ee81decSopenharmony_ci#ifndef DEVICE_SECURITY_DEFINES_H 272ee81decSopenharmony_ci#define DEVICE_ID_MAX_LEN 64 282ee81decSopenharmony_citypedef struct DeviceIdentify { 292ee81decSopenharmony_ci uint32_t length; 302ee81decSopenharmony_ci uint8_t identity[DEVICE_ID_MAX_LEN]; 312ee81decSopenharmony_ci} DeviceIdentify; 322ee81decSopenharmony_ci#endif 332ee81decSopenharmony_ci 342ee81decSopenharmony_citypedef int32_t (*DeviceMessageReceiver)(const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen); 352ee81decSopenharmony_ci 362ee81decSopenharmony_citypedef int32_t (*DeviceStatusReceiver)(const DeviceIdentify *devId, uint32_t status, int32_t level); 372ee81decSopenharmony_ci 382ee81decSopenharmony_citypedef int32_t (*MessageSendResultNotifier)(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); 392ee81decSopenharmony_ci 402ee81decSopenharmony_citypedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, int32_t level, void *para); 412ee81decSopenharmony_ci 422ee81decSopenharmony_citypedef struct MessengerConfig { 432ee81decSopenharmony_ci const char *pkgName; 442ee81decSopenharmony_ci#ifdef L2_STANDARD 452ee81decSopenharmony_ci const char *primarySockName; 462ee81decSopenharmony_ci const char *secondarySockName; 472ee81decSopenharmony_ci#else 482ee81decSopenharmony_ci const char *primarySessName; 492ee81decSopenharmony_ci const char *secondarySessName; 502ee81decSopenharmony_ci#endif 512ee81decSopenharmony_ci DeviceMessageReceiver messageReceiver; 522ee81decSopenharmony_ci DeviceStatusReceiver statusReceiver; 532ee81decSopenharmony_ci MessageSendResultNotifier sendResultNotifier; 542ee81decSopenharmony_ci uint32_t threadCnt; 552ee81decSopenharmony_ci} MessengerConfig; 562ee81decSopenharmony_ci 572ee81decSopenharmony_citypedef struct StatisticInformation { 582ee81decSopenharmony_ci uint64_t firstOnlineTime; 592ee81decSopenharmony_ci uint64_t lastOnlineTime; 602ee81decSopenharmony_ci uint64_t firstOfflineTime; 612ee81decSopenharmony_ci uint64_t lastOfflineTime; 622ee81decSopenharmony_ci uint64_t lastSessOpenTime; 632ee81decSopenharmony_ci uint32_t lastSessOpenResult; 642ee81decSopenharmony_ci uint32_t lastSessOpenCost; 652ee81decSopenharmony_ci uint64_t lastSessCloseTime; 662ee81decSopenharmony_ci uint64_t lastMsgSendTime; 672ee81decSopenharmony_ci uint32_t lastMsgSendResult; 682ee81decSopenharmony_ci uint32_t lastMsgSendCost; 692ee81decSopenharmony_ci uint64_t lastMsgRecvTime; 702ee81decSopenharmony_ci uint64_t packetRx; 712ee81decSopenharmony_ci uint64_t packetTotalRx; 722ee81decSopenharmony_ci uint64_t packetTx; 732ee81decSopenharmony_ci uint64_t packetTotalTx; 742ee81decSopenharmony_ci uint64_t packetTxFailed; 752ee81decSopenharmony_ci uint64_t packetTotalTxFailed; 762ee81decSopenharmony_ci} StatisticInformation; 772ee81decSopenharmony_ci 782ee81decSopenharmony_citypedef struct Messenger Messenger; 792ee81decSopenharmony_ci 802ee81decSopenharmony_ciMessenger *CreateMessenger(const MessengerConfig *config); 812ee81decSopenharmony_ci 822ee81decSopenharmony_civoid DestroyMessenger(Messenger *messenger); 832ee81decSopenharmony_ci 842ee81decSopenharmony_cibool IsMessengerReady(const Messenger *messenger); 852ee81decSopenharmony_ci 862ee81decSopenharmony_civoid SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, 872ee81decSopenharmony_ci uint32_t msgLen); 882ee81decSopenharmony_ci 892ee81decSopenharmony_cibool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level); 902ee81decSopenharmony_ci 912ee81decSopenharmony_cibool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level); 922ee81decSopenharmony_ci 932ee81decSopenharmony_civoid ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para); 942ee81decSopenharmony_ci 952ee81decSopenharmony_cibool GetDeviceStatisticInfo(const Messenger *messenger, const DeviceIdentify *devId, StatisticInformation *info); 962ee81decSopenharmony_ci 972ee81decSopenharmony_ci#ifdef __cplusplus 982ee81decSopenharmony_ci} 992ee81decSopenharmony_ci#endif 1002ee81decSopenharmony_ci 1012ee81decSopenharmony_ci#endif // SEC_MESSENGER_INFO_H 102