From 74ef8f1a91bc4af8709679ee6c21a262f6568a21 Mon Sep 17 00:00:00 2001 From: mahaoyun1 Date: Thu, 24 Nov 2022 15:46:27 +0800 Subject: [PATCH] fix:repair the windows format Signed-off-by: mahaoyun1 --- OAT.xml | 148 +-- .../src/lnn_time_sync_impl_virtual.c | 94 +- .../time_sync/src/lnn_time_sync_manager.c | 1114 ++++++++--------- .../src/lnn_time_sync_manager_virtual.c | 90 +- .../monitor/include/lnn_event_monitor.h | 60 +- .../monitor/src/lnn_event_monitor.c | 158 +-- .../monitor/src/lnn_event_monitor_virtual.c | 58 +- .../utils/include/lnn_async_callback_utils.h | 74 +- .../bus_center/utils/include/lnn_file_utils.h | 74 +- core/bus_center/utils/include/lnn_ipc_utils.h | 66 +- .../utils/src/lnn_async_callback_utils.c | 266 ++-- core/bus_center/utils/src/lnn_file_utils.c | 146 +-- core/bus_center/utils/src/lnn_ipc_utils.c | 138 +- interfaces/inner_kits/transport/dfs_session.h | 66 +- .../inner_kits/transport/inner_session.h | 60 +- 15 files changed, 1306 insertions(+), 1306 deletions(-) diff --git a/OAT.xml b/OAT.xml index efb2ef264..2dcb2360b 100644 --- a/OAT.xml +++ b/OAT.xml @@ -1,74 +1,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_impl_virtual.c b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_impl_virtual.c index f310497e2..b207b37f3 100644 --- a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_impl_virtual.c +++ b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_impl_virtual.c @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_time_sync_impl.h" - -#include "softbus_errcode.h" -#include "softbus_log.h" - -int32_t LnnTimeSyncImplInit(void) -{ - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync impl stub init success"); - return SOFTBUS_OK; -} - -void LnnTimeSyncImplDeinit(void) -{ - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync impl stub deinit"); -} - -int32_t LnnStartTimeSyncImpl(const char *targetNetworkId, TimeSyncAccuracy accuracy, - TimeSyncPeriod period, const TimeSyncImplCallback *callback) -{ - (void)targetNetworkId; - (void)accuracy; - (void)period; - (void)callback; - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync stub impl"); - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t LnnStopTimeSyncImpl(const char *targetNetworkId) -{ - (void)targetNetworkId; - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync stub impl"); - return SOFTBUS_NOT_IMPLEMENT; +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_time_sync_impl.h" + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t LnnTimeSyncImplInit(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync impl stub init success"); + return SOFTBUS_OK; +} + +void LnnTimeSyncImplDeinit(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync impl stub deinit"); +} + +int32_t LnnStartTimeSyncImpl(const char *targetNetworkId, TimeSyncAccuracy accuracy, + TimeSyncPeriod period, const TimeSyncImplCallback *callback) +{ + (void)targetNetworkId; + (void)accuracy; + (void)period; + (void)callback; + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync stub impl"); + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t LnnStopTimeSyncImpl(const char *targetNetworkId) +{ + (void)targetNetworkId; + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync stub impl"); + return SOFTBUS_NOT_IMPLEMENT; } \ No newline at end of file diff --git a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager.c b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager.c index f0b47a03b..dd5da0677 100644 --- a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager.c +++ b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager.c @@ -1,558 +1,558 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_time_sync_manager.h" - -#include -#include - -#include "bus_center_manager.h" -#include "lnn_time_sync_impl.h" -#include "message_handler.h" -#include "softbus_adapter_mem.h" -#include "softbus_def.h" -#include "softbus_errcode.h" -#include "softbus_log.h" - -#define THOUSAND 1000 - -typedef enum { - MSG_TYPE_START_TIME_SYNC = 0, - MSG_TYPE_STOP_TIME_SYNC, - MSG_TYPE_TIME_SYNC_COMPLETE, - MSG_TYPE_REMOVE_ALL, - MSG_TYPE_MAX, -} TimeSyncMessageType; - -typedef struct { - ListNode node; - char pkgName[PKG_NAME_SIZE_MAX]; - TimeSyncAccuracy accuracy; - TimeSyncPeriod period; -} StartTimeSyncReq; - -typedef struct { - ListNode node; - char targetNetworkId[NETWORK_ID_BUF_LEN]; - // list of StartTimeSyncReq - ListNode startReqList; - TimeSyncAccuracy curAccuracy; - TimeSyncPeriod curPeriod; -} TimeSyncReqInfo; - -typedef struct { - // list of TimeSyncRequestInfo - ListNode reqList; - SoftBusLooper *looper; - SoftBusHandler handler; -} TimeSyncCtrl; - -typedef struct { - char pkgName[PKG_NAME_SIZE_MAX]; - char targetNetworkId[NETWORK_ID_BUF_LEN]; - TimeSyncAccuracy accuracy; - TimeSyncPeriod period; -} StartTimeSyncReqMsgPara; - -typedef struct { - char pkgName[PKG_NAME_SIZE_MAX]; - char targetNetworkId[NETWORK_ID_BUF_LEN]; -} StopTimeSyncReqMsgPara; - -typedef struct { - char networkId[NETWORK_ID_BUF_LEN]; - double offset; - int32_t retCode; -} TimeSyncCompleteMsgPara; - -static void OnTimeSyncImplComplete(const char *networkId, double offset, int32_t retCode); - -static TimeSyncCtrl g_timeSyncCtrl; - -static TimeSyncImplCallback g_timeSyncImplCb = { - .onTimeSyncImplComplete = OnTimeSyncImplComplete, -}; - -static TimeSyncReqInfo *FindTimeSyncReqInfo(const char *networkId) -{ - TimeSyncReqInfo *item = NULL; - - LIST_FOR_EACH_ENTRY(item, &g_timeSyncCtrl.reqList, TimeSyncReqInfo, node) { - if (strcmp(networkId, item->targetNetworkId) == 0) { - return item; - } - } - return NULL; -} - -static StartTimeSyncReq *CreateStartTimeSyncReq(const char *pkgName, TimeSyncAccuracy accuracy, - TimeSyncPeriod period) -{ - StartTimeSyncReq *req = SoftBusMalloc(sizeof(StartTimeSyncReq)); - - if (req == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc start time sync request fail: %s", pkgName); - return NULL; - } - if (strncpy_s(req->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail: %s", pkgName); - SoftBusFree(req); - return NULL; - } - req->accuracy = accuracy; - req->period = period; - ListInit(&req->node); - return req; -} - -static TimeSyncReqInfo *CreateTimeSyncReqInfo(const StartTimeSyncReqMsgPara *para) -{ - TimeSyncReqInfo *info = SoftBusMalloc(sizeof(TimeSyncReqInfo)); - - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync request info fail"); - return NULL; - } - if (strncpy_s(info->targetNetworkId, NETWORK_ID_BUF_LEN, para->targetNetworkId, - strlen(para->targetNetworkId)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync networkId fail"); - SoftBusFree(info); - return NULL; - } - info->curAccuracy = para->accuracy; - info->curPeriod = para->period; - ListInit(&info->node); - ListInit(&info->startReqList); - return info; -} - -static int32_t TryUpdateStartTimeSyncReq(TimeSyncReqInfo *info, const StartTimeSyncReqMsgPara *startReq) -{ - StartTimeSyncReq *item = NULL; - - LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { - if (strcmp(startReq->pkgName, item->pkgName) != 0) { - continue; - } - if (item->accuracy < startReq->accuracy || item->period > startReq->period) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update exist request(%d-->%d, %d-->%d) for %s", - item->accuracy, startReq->accuracy, item->period, startReq->period, startReq->pkgName); - item->accuracy = startReq->accuracy; - item->period = startReq->period; - } - return SOFTBUS_OK; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "add start time sync request(%d, %d) for %s", - startReq->accuracy, startReq->period, startReq->pkgName); - item = CreateStartTimeSyncReq(startReq->pkgName, startReq->accuracy, startReq->period); - if (item == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create start time sync request fail"); - return SOFTBUS_ERR; - } - ListAdd(&info->startReqList, &item->node); - return SOFTBUS_OK; -} - -static void RemoveStartTimeSyncReq(const TimeSyncReqInfo *info, const char *pkgName) -{ - StartTimeSyncReq *item = NULL; - - LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { - if (strcmp(pkgName, item->pkgName) != 0) { - continue; - } - ListDelete(&item->node); - SoftBusFree(item); - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "remove start time sync req for %s", pkgName); - break; - } -} - -static bool TryUpdateTimeSyncReqInfo(TimeSyncReqInfo *info, TimeSyncAccuracy accuracy, TimeSyncPeriod period) -{ - if (info->curAccuracy < accuracy || info->curPeriod > period) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update exist request(%d-->%d, %d-->%d)", - info->curAccuracy, accuracy, info->curPeriod, period); - info->curAccuracy = accuracy; - info->curPeriod = period; - return true; - } else { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "exist request already can satify"); - } - return false; -} - -static int32_t ProcessStartTimeSyncRequest(const StartTimeSyncReqMsgPara *para) -{ - TimeSyncReqInfo *existInfo = NULL; - bool isCreateTimeSyncReq = false; - bool isUpdateTimeSyncReq = false; - int32_t rc = SOFTBUS_ERR; - - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync request msg para null"); - return SOFTBUS_INVALID_PARAM; - } - do { - existInfo = FindTimeSyncReqInfo(para->targetNetworkId); - if (existInfo == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "start new time sync request"); - existInfo = CreateTimeSyncReqInfo(para); - if (existInfo == NULL) { - break; - } - isCreateTimeSyncReq = true; - } else { - isUpdateTimeSyncReq = TryUpdateTimeSyncReqInfo(existInfo, para->accuracy, para->period); - } - if (TryUpdateStartTimeSyncReq(existInfo, para) != SOFTBUS_OK) { - break; - } - if (isCreateTimeSyncReq || isUpdateTimeSyncReq) { - if (LnnStartTimeSyncImpl(existInfo->targetNetworkId, existInfo->curAccuracy, - existInfo->curPeriod, &g_timeSyncImplCb) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync fail"); - RemoveStartTimeSyncReq(existInfo, para->pkgName); - break; - } - } - rc = SOFTBUS_OK; - } while (false); - if (rc != SOFTBUS_OK) { - if (isCreateTimeSyncReq && existInfo != NULL) { - SoftBusFree(existInfo); - } - } else { - if (isCreateTimeSyncReq) { - ListAdd(&g_timeSyncCtrl.reqList, &existInfo->node); - } - } - SoftBusFree((void *)para); - return rc; -} - -static void TryUpdateTimeSyncReq(TimeSyncReqInfo *info) -{ - StartTimeSyncReq *item = NULL; - TimeSyncAccuracy curAccuracy = LOW_ACCURACY; - TimeSyncPeriod curPeriod = LONG_PERIOD; - uint32_t count = 0; - - LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { - ++count; - if (item->accuracy > curAccuracy) { - curAccuracy = item->accuracy; - } - if (item->period < curPeriod) { - curPeriod = item->period; - } - } - if (count > 0) { - if (curAccuracy > info->curAccuracy || curPeriod < info->curPeriod) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update time sync request(%d-->%d, %d-->%d) for", - info->curAccuracy, curAccuracy, info->curPeriod, curPeriod); - info->curAccuracy = curAccuracy; - info->curPeriod = curPeriod; - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update time sync request rc=%d", - LnnStartTimeSyncImpl(info->targetNetworkId, curAccuracy, curPeriod, &g_timeSyncImplCb)); - } - } else { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop time sync request rc=%d", - LnnStopTimeSyncImpl(info->targetNetworkId)); - ListDelete(&info->node); - SoftBusFree(info); - } -} - -static int32_t ProcessStopTimeSyncRequest(const StopTimeSyncReqMsgPara *para) -{ - TimeSyncReqInfo *info = NULL; - - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync request msg para null"); - return SOFTBUS_INVALID_PARAM; - } - info = FindTimeSyncReqInfo(para->targetNetworkId); - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "no specific networkId for %s", para->pkgName); - SoftBusFree((void *)para); - return SOFTBUS_ERR; - } - RemoveStartTimeSyncReq(info, para->pkgName); - TryUpdateTimeSyncReq(info); - SoftBusFree((void *)para); - return SOFTBUS_OK; -} - -static void NotifyTimeSyncResult(const TimeSyncReqInfo *info, double offset, int32_t retCode) -{ - StartTimeSyncReq *item = NULL; - TimeSyncResultInfo resultInfo; - - (void)memset_s(&resultInfo, sizeof(TimeSyncResultInfo), 0, sizeof(TimeSyncResultInfo)); - if (retCode == SOFTBUS_OK || retCode == SOFTBUS_NETWORK_TIME_SYNC_INTERFERENCE) { - resultInfo.result.millisecond = (int32_t)offset; - resultInfo.result.microsecond = ((int32_t)(offset * THOUSAND)) % THOUSAND; - resultInfo.result.accuracy = info->curAccuracy; - resultInfo.flag = NODE_SPECIFIC; - } else { - resultInfo.result.millisecond = -1; - resultInfo.result.microsecond = -1; - resultInfo.result.accuracy = UNAVAIL_ACCURACY; - } - if (strncpy_s(resultInfo.target.targetNetworkId, NETWORK_ID_BUF_LEN, info->targetNetworkId, - strlen(info->targetNetworkId)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy networkId fail"); - return; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify time sync result(%d, %d, %d, %d)", - resultInfo.result.millisecond, resultInfo.result.microsecond, resultInfo.result.accuracy, resultInfo.flag); - LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify time sync result to %s", item->pkgName); - LnnNotifyTimeSyncResult(item->pkgName, &resultInfo, retCode); - } -} - - -static void RemoveAllStartTimeSyncReq(TimeSyncReqInfo *info) -{ - StartTimeSyncReq *startTimeSyncItem = NULL; - StartTimeSyncReq *startTimeSyncNextItem = NULL; - - LIST_FOR_EACH_ENTRY_SAFE(startTimeSyncItem, startTimeSyncNextItem, &info->startReqList, StartTimeSyncReq, node) { - RemoveStartTimeSyncReq(info, startTimeSyncItem->pkgName); - } - (void)LnnStopTimeSyncImpl(info->targetNetworkId); - ListDelete(&info->node); - SoftBusFree(info); -} - -static int32_t ProcessTimeSyncComplete(const TimeSyncCompleteMsgPara *para) -{ - TimeSyncReqInfo *info = NULL; - - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync complete msg para null"); - return SOFTBUS_INVALID_PARAM; - } - info = FindTimeSyncReqInfo(para->networkId); - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "no specific networkId"); - SoftBusFree((void *)para); - return SOFTBUS_ERR; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync complete result(offset=%.6lf, retCode=%d)", - para->offset, para->retCode); - NotifyTimeSyncResult(info, para->offset, para->retCode); - if (para->retCode == SOFTBUS_NETWORK_TIME_SYNC_HANDSHAKE_ERR || para->retCode == SOFTBUS_ERR) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync fail(%d), stop it internal", para->retCode); - RemoveAllStartTimeSyncReq(info); - } - SoftBusFree((void *)para); - return SOFTBUS_OK; -} - -static void ProcessRemoveAll(void) -{ - TimeSyncReqInfo *timeSyncItem = NULL; - TimeSyncReqInfo *timeSyncNextItem = NULL; - - LIST_FOR_EACH_ENTRY_SAFE(timeSyncItem, timeSyncNextItem, &g_timeSyncCtrl.reqList, TimeSyncReqInfo, node) { - RemoveAllStartTimeSyncReq(timeSyncItem); - } -} - -static void TimeSyncMessageHandler(SoftBusMessage *msg) -{ - if (msg == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync msg is null"); - return; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "process time sync msg: %d", msg->what); - switch (msg->what) { - case MSG_TYPE_START_TIME_SYNC: - ProcessStartTimeSyncRequest((const StartTimeSyncReqMsgPara *)msg->obj); - break; - case MSG_TYPE_STOP_TIME_SYNC: - ProcessStopTimeSyncRequest((const StopTimeSyncReqMsgPara *)msg->obj); - break; - case MSG_TYPE_TIME_SYNC_COMPLETE: - ProcessTimeSyncComplete((const TimeSyncCompleteMsgPara *)msg->obj); - break; - case MSG_TYPE_REMOVE_ALL: - ProcessRemoveAll(); - break; - default: - break; - } -} - -static SoftBusMessage *CreateTimeSyncMessage(int32_t msgType, void *para) -{ - SoftBusMessage *msg = (SoftBusMessage *)SoftBusCalloc(sizeof(SoftBusMessage)); - if (msg == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync message failed"); - return NULL; - } - msg->what = msgType; - msg->obj = para; - msg->handler = &g_timeSyncCtrl.handler; - return msg; -} - -static int32_t PostMessageToHandler(int32_t msgType, void *para) -{ - SoftBusMessage *msg = CreateTimeSyncMessage(msgType, para); - if (msg == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create time sync message failed"); - return SOFTBUS_ERR; - } - g_timeSyncCtrl.looper->PostMessage(g_timeSyncCtrl.looper, msg); - return SOFTBUS_OK; -} - -static void OnTimeSyncImplComplete(const char *networkId, double offset, int32_t retCode) -{ - TimeSyncCompleteMsgPara *para = NULL; - - if (networkId == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync complete para invalid"); - return; - } - para = SoftBusMalloc(sizeof(TimeSyncCompleteMsgPara)); - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync complete msg para fail"); - return; - } - if (strncpy_s(para->networkId, NETWORK_ID_BUF_LEN, networkId, strlen(networkId)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync complete msg info fail"); - SoftBusFree(para); - return; - } - para->offset = offset; - para->retCode = retCode; - if (PostMessageToHandler(MSG_TYPE_TIME_SYNC_COMPLETE, para) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post time sync complete msg fail"); - SoftBusFree(para); - } -} - -static bool CheckTimeSyncReqInfo(const StartTimeSyncReqMsgPara *info) -{ - char uuid[UUID_BUF_LEN] = {0}; - - if (LnnGetRemoteStrInfo(info->targetNetworkId, STRING_KEY_UUID, uuid, UUID_BUF_LEN) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get uuid fail"); - return false; - } - return true; -} - -int32_t LnnInitTimeSync(void) -{ - ListInit(&g_timeSyncCtrl.reqList); - g_timeSyncCtrl.looper = GetLooper(LOOP_TYPE_DEFAULT); - if (g_timeSyncCtrl.looper == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync get default looper fail"); - return SOFTBUS_ERR; - } - g_timeSyncCtrl.handler.name = "TimeSync"; - g_timeSyncCtrl.handler.looper = g_timeSyncCtrl.looper; - g_timeSyncCtrl.handler.HandleMessage = TimeSyncMessageHandler; - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init time sync success"); - return LnnTimeSyncImplInit(); -} - -void LnnDeinitTimeSync(void) -{ - if (g_timeSyncCtrl.looper == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); - return; - } - if (PostMessageToHandler(MSG_TYPE_REMOVE_ALL, NULL) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post remove all time sync msg fail"); - } - LnnTimeSyncImplDeinit(); -} - -int32_t LnnStartTimeSync(const char *pkgName, const char *targetNetworkId, - TimeSyncAccuracy accuracy, TimeSyncPeriod period) -{ - StartTimeSyncReqMsgPara *para = NULL; - - if (pkgName == NULL || targetNetworkId == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync para invalid"); - return SOFTBUS_INVALID_PARAM; - } - if (g_timeSyncCtrl.looper == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); - return SOFTBUS_NO_INIT; - } - para = SoftBusMalloc(sizeof(StartTimeSyncReqMsgPara)); - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc stop time sync request msg para fail"); - return SOFTBUS_MALLOC_ERR; - } - if (strncpy_s(para->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK || - strncpy_s(para->targetNetworkId, NETWORK_ID_BUF_LEN, targetNetworkId, strlen(targetNetworkId)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync request info fail"); - SoftBusFree(para); - return SOFTBUS_ERR; - } - para->accuracy = accuracy; - para->period = period; - if (!CheckTimeSyncReqInfo(para)) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "check time sync request info fail"); - SoftBusFree(para); - return SOFTBUS_INVALID_PARAM; - } - if (PostMessageToHandler(MSG_TYPE_START_TIME_SYNC, para) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post start time sync msg fail"); - SoftBusFree(para); - return SOFTBUS_NETWORK_LOOPER_ERR; - } - return SOFTBUS_OK; -} - -int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId) -{ - StopTimeSyncReqMsgPara *para = NULL; - - if (pkgName == NULL || targetNetworkId == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync para invalid"); - return SOFTBUS_INVALID_PARAM; - } - if (g_timeSyncCtrl.looper == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); - return SOFTBUS_NO_INIT; - } - para = SoftBusMalloc(sizeof(StopTimeSyncReqMsgPara)); - if (para == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc stop time sync request msg para fail"); - return SOFTBUS_MALLOC_ERR; - } - if (strncpy_s(para->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK || - strncpy_s(para->targetNetworkId, NETWORK_ID_BUF_LEN, targetNetworkId, strlen(targetNetworkId)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync request info fail"); - SoftBusFree(para); - return SOFTBUS_ERR; - } - if (PostMessageToHandler(MSG_TYPE_STOP_TIME_SYNC, para) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post stop time sync msg fail"); - SoftBusFree(para); - return SOFTBUS_NETWORK_LOOPER_ERR; - } - return SOFTBUS_OK; +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_time_sync_manager.h" + +#include +#include + +#include "bus_center_manager.h" +#include "lnn_time_sync_impl.h" +#include "message_handler.h" +#include "softbus_adapter_mem.h" +#include "softbus_def.h" +#include "softbus_errcode.h" +#include "softbus_log.h" + +#define THOUSAND 1000 + +typedef enum { + MSG_TYPE_START_TIME_SYNC = 0, + MSG_TYPE_STOP_TIME_SYNC, + MSG_TYPE_TIME_SYNC_COMPLETE, + MSG_TYPE_REMOVE_ALL, + MSG_TYPE_MAX, +} TimeSyncMessageType; + +typedef struct { + ListNode node; + char pkgName[PKG_NAME_SIZE_MAX]; + TimeSyncAccuracy accuracy; + TimeSyncPeriod period; +} StartTimeSyncReq; + +typedef struct { + ListNode node; + char targetNetworkId[NETWORK_ID_BUF_LEN]; + // list of StartTimeSyncReq + ListNode startReqList; + TimeSyncAccuracy curAccuracy; + TimeSyncPeriod curPeriod; +} TimeSyncReqInfo; + +typedef struct { + // list of TimeSyncRequestInfo + ListNode reqList; + SoftBusLooper *looper; + SoftBusHandler handler; +} TimeSyncCtrl; + +typedef struct { + char pkgName[PKG_NAME_SIZE_MAX]; + char targetNetworkId[NETWORK_ID_BUF_LEN]; + TimeSyncAccuracy accuracy; + TimeSyncPeriod period; +} StartTimeSyncReqMsgPara; + +typedef struct { + char pkgName[PKG_NAME_SIZE_MAX]; + char targetNetworkId[NETWORK_ID_BUF_LEN]; +} StopTimeSyncReqMsgPara; + +typedef struct { + char networkId[NETWORK_ID_BUF_LEN]; + double offset; + int32_t retCode; +} TimeSyncCompleteMsgPara; + +static void OnTimeSyncImplComplete(const char *networkId, double offset, int32_t retCode); + +static TimeSyncCtrl g_timeSyncCtrl; + +static TimeSyncImplCallback g_timeSyncImplCb = { + .onTimeSyncImplComplete = OnTimeSyncImplComplete, +}; + +static TimeSyncReqInfo *FindTimeSyncReqInfo(const char *networkId) +{ + TimeSyncReqInfo *item = NULL; + + LIST_FOR_EACH_ENTRY(item, &g_timeSyncCtrl.reqList, TimeSyncReqInfo, node) { + if (strcmp(networkId, item->targetNetworkId) == 0) { + return item; + } + } + return NULL; +} + +static StartTimeSyncReq *CreateStartTimeSyncReq(const char *pkgName, TimeSyncAccuracy accuracy, + TimeSyncPeriod period) +{ + StartTimeSyncReq *req = SoftBusMalloc(sizeof(StartTimeSyncReq)); + + if (req == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc start time sync request fail: %s", pkgName); + return NULL; + } + if (strncpy_s(req->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail: %s", pkgName); + SoftBusFree(req); + return NULL; + } + req->accuracy = accuracy; + req->period = period; + ListInit(&req->node); + return req; +} + +static TimeSyncReqInfo *CreateTimeSyncReqInfo(const StartTimeSyncReqMsgPara *para) +{ + TimeSyncReqInfo *info = SoftBusMalloc(sizeof(TimeSyncReqInfo)); + + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync request info fail"); + return NULL; + } + if (strncpy_s(info->targetNetworkId, NETWORK_ID_BUF_LEN, para->targetNetworkId, + strlen(para->targetNetworkId)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync networkId fail"); + SoftBusFree(info); + return NULL; + } + info->curAccuracy = para->accuracy; + info->curPeriod = para->period; + ListInit(&info->node); + ListInit(&info->startReqList); + return info; +} + +static int32_t TryUpdateStartTimeSyncReq(TimeSyncReqInfo *info, const StartTimeSyncReqMsgPara *startReq) +{ + StartTimeSyncReq *item = NULL; + + LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { + if (strcmp(startReq->pkgName, item->pkgName) != 0) { + continue; + } + if (item->accuracy < startReq->accuracy || item->period > startReq->period) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update exist request(%d-->%d, %d-->%d) for %s", + item->accuracy, startReq->accuracy, item->period, startReq->period, startReq->pkgName); + item->accuracy = startReq->accuracy; + item->period = startReq->period; + } + return SOFTBUS_OK; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "add start time sync request(%d, %d) for %s", + startReq->accuracy, startReq->period, startReq->pkgName); + item = CreateStartTimeSyncReq(startReq->pkgName, startReq->accuracy, startReq->period); + if (item == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create start time sync request fail"); + return SOFTBUS_ERR; + } + ListAdd(&info->startReqList, &item->node); + return SOFTBUS_OK; +} + +static void RemoveStartTimeSyncReq(const TimeSyncReqInfo *info, const char *pkgName) +{ + StartTimeSyncReq *item = NULL; + + LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { + if (strcmp(pkgName, item->pkgName) != 0) { + continue; + } + ListDelete(&item->node); + SoftBusFree(item); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "remove start time sync req for %s", pkgName); + break; + } +} + +static bool TryUpdateTimeSyncReqInfo(TimeSyncReqInfo *info, TimeSyncAccuracy accuracy, TimeSyncPeriod period) +{ + if (info->curAccuracy < accuracy || info->curPeriod > period) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update exist request(%d-->%d, %d-->%d)", + info->curAccuracy, accuracy, info->curPeriod, period); + info->curAccuracy = accuracy; + info->curPeriod = period; + return true; + } else { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "exist request already can satify"); + } + return false; +} + +static int32_t ProcessStartTimeSyncRequest(const StartTimeSyncReqMsgPara *para) +{ + TimeSyncReqInfo *existInfo = NULL; + bool isCreateTimeSyncReq = false; + bool isUpdateTimeSyncReq = false; + int32_t rc = SOFTBUS_ERR; + + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync request msg para null"); + return SOFTBUS_INVALID_PARAM; + } + do { + existInfo = FindTimeSyncReqInfo(para->targetNetworkId); + if (existInfo == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "start new time sync request"); + existInfo = CreateTimeSyncReqInfo(para); + if (existInfo == NULL) { + break; + } + isCreateTimeSyncReq = true; + } else { + isUpdateTimeSyncReq = TryUpdateTimeSyncReqInfo(existInfo, para->accuracy, para->period); + } + if (TryUpdateStartTimeSyncReq(existInfo, para) != SOFTBUS_OK) { + break; + } + if (isCreateTimeSyncReq || isUpdateTimeSyncReq) { + if (LnnStartTimeSyncImpl(existInfo->targetNetworkId, existInfo->curAccuracy, + existInfo->curPeriod, &g_timeSyncImplCb) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync fail"); + RemoveStartTimeSyncReq(existInfo, para->pkgName); + break; + } + } + rc = SOFTBUS_OK; + } while (false); + if (rc != SOFTBUS_OK) { + if (isCreateTimeSyncReq && existInfo != NULL) { + SoftBusFree(existInfo); + } + } else { + if (isCreateTimeSyncReq) { + ListAdd(&g_timeSyncCtrl.reqList, &existInfo->node); + } + } + SoftBusFree((void *)para); + return rc; +} + +static void TryUpdateTimeSyncReq(TimeSyncReqInfo *info) +{ + StartTimeSyncReq *item = NULL; + TimeSyncAccuracy curAccuracy = LOW_ACCURACY; + TimeSyncPeriod curPeriod = LONG_PERIOD; + uint32_t count = 0; + + LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { + ++count; + if (item->accuracy > curAccuracy) { + curAccuracy = item->accuracy; + } + if (item->period < curPeriod) { + curPeriod = item->period; + } + } + if (count > 0) { + if (curAccuracy > info->curAccuracy || curPeriod < info->curPeriod) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update time sync request(%d-->%d, %d-->%d) for", + info->curAccuracy, curAccuracy, info->curPeriod, curPeriod); + info->curAccuracy = curAccuracy; + info->curPeriod = curPeriod; + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update time sync request rc=%d", + LnnStartTimeSyncImpl(info->targetNetworkId, curAccuracy, curPeriod, &g_timeSyncImplCb)); + } + } else { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop time sync request rc=%d", + LnnStopTimeSyncImpl(info->targetNetworkId)); + ListDelete(&info->node); + SoftBusFree(info); + } +} + +static int32_t ProcessStopTimeSyncRequest(const StopTimeSyncReqMsgPara *para) +{ + TimeSyncReqInfo *info = NULL; + + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync request msg para null"); + return SOFTBUS_INVALID_PARAM; + } + info = FindTimeSyncReqInfo(para->targetNetworkId); + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "no specific networkId for %s", para->pkgName); + SoftBusFree((void *)para); + return SOFTBUS_ERR; + } + RemoveStartTimeSyncReq(info, para->pkgName); + TryUpdateTimeSyncReq(info); + SoftBusFree((void *)para); + return SOFTBUS_OK; +} + +static void NotifyTimeSyncResult(const TimeSyncReqInfo *info, double offset, int32_t retCode) +{ + StartTimeSyncReq *item = NULL; + TimeSyncResultInfo resultInfo; + + (void)memset_s(&resultInfo, sizeof(TimeSyncResultInfo), 0, sizeof(TimeSyncResultInfo)); + if (retCode == SOFTBUS_OK || retCode == SOFTBUS_NETWORK_TIME_SYNC_INTERFERENCE) { + resultInfo.result.millisecond = (int32_t)offset; + resultInfo.result.microsecond = ((int32_t)(offset * THOUSAND)) % THOUSAND; + resultInfo.result.accuracy = info->curAccuracy; + resultInfo.flag = NODE_SPECIFIC; + } else { + resultInfo.result.millisecond = -1; + resultInfo.result.microsecond = -1; + resultInfo.result.accuracy = UNAVAIL_ACCURACY; + } + if (strncpy_s(resultInfo.target.targetNetworkId, NETWORK_ID_BUF_LEN, info->targetNetworkId, + strlen(info->targetNetworkId)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy networkId fail"); + return; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify time sync result(%d, %d, %d, %d)", + resultInfo.result.millisecond, resultInfo.result.microsecond, resultInfo.result.accuracy, resultInfo.flag); + LIST_FOR_EACH_ENTRY(item, &info->startReqList, StartTimeSyncReq, node) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify time sync result to %s", item->pkgName); + LnnNotifyTimeSyncResult(item->pkgName, &resultInfo, retCode); + } +} + + +static void RemoveAllStartTimeSyncReq(TimeSyncReqInfo *info) +{ + StartTimeSyncReq *startTimeSyncItem = NULL; + StartTimeSyncReq *startTimeSyncNextItem = NULL; + + LIST_FOR_EACH_ENTRY_SAFE(startTimeSyncItem, startTimeSyncNextItem, &info->startReqList, StartTimeSyncReq, node) { + RemoveStartTimeSyncReq(info, startTimeSyncItem->pkgName); + } + (void)LnnStopTimeSyncImpl(info->targetNetworkId); + ListDelete(&info->node); + SoftBusFree(info); +} + +static int32_t ProcessTimeSyncComplete(const TimeSyncCompleteMsgPara *para) +{ + TimeSyncReqInfo *info = NULL; + + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync complete msg para null"); + return SOFTBUS_INVALID_PARAM; + } + info = FindTimeSyncReqInfo(para->networkId); + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "no specific networkId"); + SoftBusFree((void *)para); + return SOFTBUS_ERR; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync complete result(offset=%.6lf, retCode=%d)", + para->offset, para->retCode); + NotifyTimeSyncResult(info, para->offset, para->retCode); + if (para->retCode == SOFTBUS_NETWORK_TIME_SYNC_HANDSHAKE_ERR || para->retCode == SOFTBUS_ERR) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync fail(%d), stop it internal", para->retCode); + RemoveAllStartTimeSyncReq(info); + } + SoftBusFree((void *)para); + return SOFTBUS_OK; +} + +static void ProcessRemoveAll(void) +{ + TimeSyncReqInfo *timeSyncItem = NULL; + TimeSyncReqInfo *timeSyncNextItem = NULL; + + LIST_FOR_EACH_ENTRY_SAFE(timeSyncItem, timeSyncNextItem, &g_timeSyncCtrl.reqList, TimeSyncReqInfo, node) { + RemoveAllStartTimeSyncReq(timeSyncItem); + } +} + +static void TimeSyncMessageHandler(SoftBusMessage *msg) +{ + if (msg == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync msg is null"); + return; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "process time sync msg: %d", msg->what); + switch (msg->what) { + case MSG_TYPE_START_TIME_SYNC: + ProcessStartTimeSyncRequest((const StartTimeSyncReqMsgPara *)msg->obj); + break; + case MSG_TYPE_STOP_TIME_SYNC: + ProcessStopTimeSyncRequest((const StopTimeSyncReqMsgPara *)msg->obj); + break; + case MSG_TYPE_TIME_SYNC_COMPLETE: + ProcessTimeSyncComplete((const TimeSyncCompleteMsgPara *)msg->obj); + break; + case MSG_TYPE_REMOVE_ALL: + ProcessRemoveAll(); + break; + default: + break; + } +} + +static SoftBusMessage *CreateTimeSyncMessage(int32_t msgType, void *para) +{ + SoftBusMessage *msg = (SoftBusMessage *)SoftBusCalloc(sizeof(SoftBusMessage)); + if (msg == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync message failed"); + return NULL; + } + msg->what = msgType; + msg->obj = para; + msg->handler = &g_timeSyncCtrl.handler; + return msg; +} + +static int32_t PostMessageToHandler(int32_t msgType, void *para) +{ + SoftBusMessage *msg = CreateTimeSyncMessage(msgType, para); + if (msg == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create time sync message failed"); + return SOFTBUS_ERR; + } + g_timeSyncCtrl.looper->PostMessage(g_timeSyncCtrl.looper, msg); + return SOFTBUS_OK; +} + +static void OnTimeSyncImplComplete(const char *networkId, double offset, int32_t retCode) +{ + TimeSyncCompleteMsgPara *para = NULL; + + if (networkId == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync complete para invalid"); + return; + } + para = SoftBusMalloc(sizeof(TimeSyncCompleteMsgPara)); + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc time sync complete msg para fail"); + return; + } + if (strncpy_s(para->networkId, NETWORK_ID_BUF_LEN, networkId, strlen(networkId)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync complete msg info fail"); + SoftBusFree(para); + return; + } + para->offset = offset; + para->retCode = retCode; + if (PostMessageToHandler(MSG_TYPE_TIME_SYNC_COMPLETE, para) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post time sync complete msg fail"); + SoftBusFree(para); + } +} + +static bool CheckTimeSyncReqInfo(const StartTimeSyncReqMsgPara *info) +{ + char uuid[UUID_BUF_LEN] = {0}; + + if (LnnGetRemoteStrInfo(info->targetNetworkId, STRING_KEY_UUID, uuid, UUID_BUF_LEN) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get uuid fail"); + return false; + } + return true; +} + +int32_t LnnInitTimeSync(void) +{ + ListInit(&g_timeSyncCtrl.reqList); + g_timeSyncCtrl.looper = GetLooper(LOOP_TYPE_DEFAULT); + if (g_timeSyncCtrl.looper == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync get default looper fail"); + return SOFTBUS_ERR; + } + g_timeSyncCtrl.handler.name = "TimeSync"; + g_timeSyncCtrl.handler.looper = g_timeSyncCtrl.looper; + g_timeSyncCtrl.handler.HandleMessage = TimeSyncMessageHandler; + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init time sync success"); + return LnnTimeSyncImplInit(); +} + +void LnnDeinitTimeSync(void) +{ + if (g_timeSyncCtrl.looper == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); + return; + } + if (PostMessageToHandler(MSG_TYPE_REMOVE_ALL, NULL) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post remove all time sync msg fail"); + } + LnnTimeSyncImplDeinit(); +} + +int32_t LnnStartTimeSync(const char *pkgName, const char *targetNetworkId, + TimeSyncAccuracy accuracy, TimeSyncPeriod period) +{ + StartTimeSyncReqMsgPara *para = NULL; + + if (pkgName == NULL || targetNetworkId == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start time sync para invalid"); + return SOFTBUS_INVALID_PARAM; + } + if (g_timeSyncCtrl.looper == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); + return SOFTBUS_NO_INIT; + } + para = SoftBusMalloc(sizeof(StartTimeSyncReqMsgPara)); + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc stop time sync request msg para fail"); + return SOFTBUS_MALLOC_ERR; + } + if (strncpy_s(para->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK || + strncpy_s(para->targetNetworkId, NETWORK_ID_BUF_LEN, targetNetworkId, strlen(targetNetworkId)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync request info fail"); + SoftBusFree(para); + return SOFTBUS_ERR; + } + para->accuracy = accuracy; + para->period = period; + if (!CheckTimeSyncReqInfo(para)) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "check time sync request info fail"); + SoftBusFree(para); + return SOFTBUS_INVALID_PARAM; + } + if (PostMessageToHandler(MSG_TYPE_START_TIME_SYNC, para) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post start time sync msg fail"); + SoftBusFree(para); + return SOFTBUS_NETWORK_LOOPER_ERR; + } + return SOFTBUS_OK; +} + +int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId) +{ + StopTimeSyncReqMsgPara *para = NULL; + + if (pkgName == NULL || targetNetworkId == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "stop time sync para invalid"); + return SOFTBUS_INVALID_PARAM; + } + if (g_timeSyncCtrl.looper == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "time sync not init"); + return SOFTBUS_NO_INIT; + } + para = SoftBusMalloc(sizeof(StopTimeSyncReqMsgPara)); + if (para == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc stop time sync request msg para fail"); + return SOFTBUS_MALLOC_ERR; + } + if (strncpy_s(para->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK || + strncpy_s(para->targetNetworkId, NETWORK_ID_BUF_LEN, targetNetworkId, strlen(targetNetworkId)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy time sync request info fail"); + SoftBusFree(para); + return SOFTBUS_ERR; + } + if (PostMessageToHandler(MSG_TYPE_STOP_TIME_SYNC, para) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post stop time sync msg fail"); + SoftBusFree(para); + return SOFTBUS_NETWORK_LOOPER_ERR; + } + return SOFTBUS_OK; } \ No newline at end of file diff --git a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager_virtual.c b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager_virtual.c index efd851fb5..9afe5478c 100644 --- a/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager_virtual.c +++ b/core/bus_center/lnn/lane_hub/time_sync/src/lnn_time_sync_manager_virtual.c @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_time_sync_manager.h" - -#include "softbus_errcode.h" -#include "softbus_log.h" - -int32_t LnnStartTimeSync(const char *pkgName, const char *targetNetworkId, - TimeSyncAccuracy accuracy, TimeSyncPeriod period) -{ - (void)pkgName; - (void)targetNetworkId; - (void)accuracy; - (void)period; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId) -{ - (void)pkgName; - (void)targetNetworkId; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t LnnInitTimeSync(void) -{ - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync virtual init success"); - return SOFTBUS_OK; -} - -void LnnDeinitTimeSync(void) -{ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_time_sync_manager.h" + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t LnnStartTimeSync(const char *pkgName, const char *targetNetworkId, + TimeSyncAccuracy accuracy, TimeSyncPeriod period) +{ + (void)pkgName; + (void)targetNetworkId; + (void)accuracy; + (void)period; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t LnnStopTimeSync(const char *pkgName, const char *targetNetworkId) +{ + (void)pkgName; + (void)targetNetworkId; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t LnnInitTimeSync(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "time sync virtual init success"); + return SOFTBUS_OK; +} + +void LnnDeinitTimeSync(void) +{ } \ No newline at end of file diff --git a/core/bus_center/monitor/include/lnn_event_monitor.h b/core/bus_center/monitor/include/lnn_event_monitor.h index afb74f0f2..c9743f6c4 100644 --- a/core/bus_center/monitor/include/lnn_event_monitor.h +++ b/core/bus_center/monitor/include/lnn_event_monitor.h @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LNN_EVENT_MONITOR_H -#define LNN_EVENT_MONITOR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t LnnInitEventMonitor(void); -void LnnDeinitEventMonitor(); - -#ifdef __cplusplus -} -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LNN_EVENT_MONITOR_H +#define LNN_EVENT_MONITOR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t LnnInitEventMonitor(void); +void LnnDeinitEventMonitor(); + +#ifdef __cplusplus +} +#endif #endif /* LNN_EVENT_MONITOR_H */ \ No newline at end of file diff --git a/core/bus_center/monitor/src/lnn_event_monitor.c b/core/bus_center/monitor/src/lnn_event_monitor.c index bfa6c4ada..703a08023 100644 --- a/core/bus_center/monitor/src/lnn_event_monitor.c +++ b/core/bus_center/monitor/src/lnn_event_monitor.c @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_event_monitor.h" - -#include -#include - -#include "bus_center_event.h" -#include "lnn_event_monitor_impl.h" -#include "lnn_devicename_info.h" -#include "lnn_settingdata_event_monitor.h" -#include "softbus_errcode.h" -#include "softbus_log.h" -#include "softbus_adapter_mem.h" - -typedef enum { - MONITOR_IMPL_NETLINK_TYPE = 0, - MONITOR_IMPL_PRODUCT_TYPE, - MONITOR_IMPL_LWIP_TYPE, - MONITOR_IMPL_WIFISERVICE_TYPE, - MONITOR_IMPL_BT_STATE_TYPE, - MONITOR_IMPL_DRIVER_TYPE, - MONITOR_IMPL_SCREENSTATE_TYPE, - MONITOR_IMPL_DEVICENAME_TYPE, - MONITOR_IMPL_MAX_TYPE, -} MonitorImplType; - -static LnnInitEventMonitorImpl g_monitorImplInit[MONITOR_IMPL_MAX_TYPE] = { - LnnInitNetlinkMonitorImpl, - LnnInitProductMonitorImpl, - LnnInitLwipMonitorImpl, - LnnInitWifiServiceMonitorImpl, - LnnInitBtStateMonitorImpl, - LnnInitDriverMonitorImpl, - LnnInitCommonEventMonitorImpl, - LnnInitDeviceNameMonitorImpl, -}; - -static LnnDeinitEventMonitorImpl g_monitorImplDeinit[MONITOR_IMPL_MAX_TYPE] = { - LnnDeinitBtStateMonitorImpl, -}; - -int32_t LnnInitEventMonitor(void) -{ - for (uint32_t i = 0; i < MONITOR_IMPL_MAX_TYPE; ++i) { - if (g_monitorImplInit[i] == NULL) { - continue; - } - if (g_monitorImplInit[i]() != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init event monitor impl(%u) failed", i); - return SOFTBUS_ERR; - } - } - return SOFTBUS_OK; -} - -void LnnDeinitEventMonitor(void) -{ - uint32_t i; - - for (i = 0; i < MONITOR_IMPL_MAX_TYPE; ++i) { - if (g_monitorImplDeinit[i] == NULL) { - continue; - } - g_monitorImplDeinit[i](); - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_event_monitor.h" + +#include +#include + +#include "bus_center_event.h" +#include "lnn_event_monitor_impl.h" +#include "lnn_devicename_info.h" +#include "lnn_settingdata_event_monitor.h" +#include "softbus_errcode.h" +#include "softbus_log.h" +#include "softbus_adapter_mem.h" + +typedef enum { + MONITOR_IMPL_NETLINK_TYPE = 0, + MONITOR_IMPL_PRODUCT_TYPE, + MONITOR_IMPL_LWIP_TYPE, + MONITOR_IMPL_WIFISERVICE_TYPE, + MONITOR_IMPL_BT_STATE_TYPE, + MONITOR_IMPL_DRIVER_TYPE, + MONITOR_IMPL_SCREENSTATE_TYPE, + MONITOR_IMPL_DEVICENAME_TYPE, + MONITOR_IMPL_MAX_TYPE, +} MonitorImplType; + +static LnnInitEventMonitorImpl g_monitorImplInit[MONITOR_IMPL_MAX_TYPE] = { + LnnInitNetlinkMonitorImpl, + LnnInitProductMonitorImpl, + LnnInitLwipMonitorImpl, + LnnInitWifiServiceMonitorImpl, + LnnInitBtStateMonitorImpl, + LnnInitDriverMonitorImpl, + LnnInitCommonEventMonitorImpl, + LnnInitDeviceNameMonitorImpl, +}; + +static LnnDeinitEventMonitorImpl g_monitorImplDeinit[MONITOR_IMPL_MAX_TYPE] = { + LnnDeinitBtStateMonitorImpl, +}; + +int32_t LnnInitEventMonitor(void) +{ + for (uint32_t i = 0; i < MONITOR_IMPL_MAX_TYPE; ++i) { + if (g_monitorImplInit[i] == NULL) { + continue; + } + if (g_monitorImplInit[i]() != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init event monitor impl(%u) failed", i); + return SOFTBUS_ERR; + } + } + return SOFTBUS_OK; +} + +void LnnDeinitEventMonitor(void) +{ + uint32_t i; + + for (i = 0; i < MONITOR_IMPL_MAX_TYPE; ++i) { + if (g_monitorImplDeinit[i] == NULL) { + continue; + } + g_monitorImplDeinit[i](); + } } \ No newline at end of file diff --git a/core/bus_center/monitor/src/lnn_event_monitor_virtual.c b/core/bus_center/monitor/src/lnn_event_monitor_virtual.c index b94b28beb..3efeadebb 100644 --- a/core/bus_center/monitor/src/lnn_event_monitor_virtual.c +++ b/core/bus_center/monitor/src/lnn_event_monitor_virtual.c @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_event_monitor.h" - -#include "softbus_errcode.h" -#include "softbus_log.h" - -int32_t LnnInitEventMonitor(void) -{ - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init virtual event monitor"); - return SOFTBUS_OK; -} - -void LnnDeinitEventMonitor(void) -{ -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_event_monitor.h" + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t LnnInitEventMonitor(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init virtual event monitor"); + return SOFTBUS_OK; +} + +void LnnDeinitEventMonitor(void) +{ +} diff --git a/core/bus_center/utils/include/lnn_async_callback_utils.h b/core/bus_center/utils/include/lnn_async_callback_utils.h index 5442c9ad0..1cc06639a 100644 --- a/core/bus_center/utils/include/lnn_async_callback_utils.h +++ b/core/bus_center/utils/include/lnn_async_callback_utils.h @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LNN_ASYNC_CALLBACK_UTILS_H -#define LNN_ASYNC_CALLBACK_UTILS_H - -#include - -#include "message_handler.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*LnnAsyncCallbackFunc)(void *para); - -int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para); -int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, - void *para, uint64_t delayMillis); - -#ifdef __cplusplus -} -#endif -#endif /* LNN_CONNECTION_ADDR_UTILS_H */ - +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LNN_ASYNC_CALLBACK_UTILS_H +#define LNN_ASYNC_CALLBACK_UTILS_H + +#include + +#include "message_handler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*LnnAsyncCallbackFunc)(void *para); + +int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para); +int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, + void *para, uint64_t delayMillis); + +#ifdef __cplusplus +} +#endif +#endif /* LNN_CONNECTION_ADDR_UTILS_H */ + diff --git a/core/bus_center/utils/include/lnn_file_utils.h b/core/bus_center/utils/include/lnn_file_utils.h index 08253908e..f07bc8d9e 100644 --- a/core/bus_center/utils/include/lnn_file_utils.h +++ b/core/bus_center/utils/include/lnn_file_utils.h @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LNN_FILE_UTILS_H -#define LNN_FILE_UTILS_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - LNN_FILE_ID_UUID, - LNN_FILE_ID_DB_KEY, - LNN_FILE_ID_MAX -} LnnFileId; - -int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len); - -#ifdef __cplusplus -} -#endif -#endif /* LNN_FILE_UTILS_H */ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LNN_FILE_UTILS_H +#define LNN_FILE_UTILS_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + LNN_FILE_ID_UUID, + LNN_FILE_ID_DB_KEY, + LNN_FILE_ID_MAX +} LnnFileId; + +int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len); + +#ifdef __cplusplus +} +#endif +#endif /* LNN_FILE_UTILS_H */ diff --git a/core/bus_center/utils/include/lnn_ipc_utils.h b/core/bus_center/utils/include/lnn_ipc_utils.h index db3816312..aebb55ef3 100644 --- a/core/bus_center/utils/include/lnn_ipc_utils.h +++ b/core/bus_center/utils/include/lnn_ipc_utils.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LNN_IPC_UTILS_H -#define LNN_IPC_UTILS_H - -#include -#include - -#include "softbus_bus_center.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo); -void ConvertVoidToSubscribeInfo(const void *info, SubscribeInfo *subInfo); - -#ifdef __cplusplus -} -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LNN_IPC_UTILS_H +#define LNN_IPC_UTILS_H + +#include +#include + +#include "softbus_bus_center.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo); +void ConvertVoidToSubscribeInfo(const void *info, SubscribeInfo *subInfo); + +#ifdef __cplusplus +} +#endif #endif /* LNN_IPC_UTILS_H */ \ No newline at end of file diff --git a/core/bus_center/utils/src/lnn_async_callback_utils.c b/core/bus_center/utils/src/lnn_async_callback_utils.c index 7269607c2..8be68a2ce 100644 --- a/core/bus_center/utils/src/lnn_async_callback_utils.c +++ b/core/bus_center/utils/src/lnn_async_callback_utils.c @@ -1,133 +1,133 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_async_callback_utils.h" - -#include "common_list.h" -#include "softbus_adapter_mem.h" -#include "softbus_errcode.h" -#include "softbus_log.h" - -#define LNN_ASYNC_CALLBACK_HANDLER_NAME "LnnAsyncHandler" - -#define LNN_ASYNC_CALLBACK_REG 0 - -typedef struct { - SoftBusMessage msg; - SoftBusHandler handler; - LnnAsyncCallbackFunc callback; - void *cbPara; -} AsyncCallbackInfo; - -#define TO_ASYNC_CALLBACK_INFO(cb) CONTAINER_OF(cb, AsyncCallbackInfo, callback) - -static void AsyncCallbackHandler(SoftBusMessage *msg) -{ - AsyncCallbackInfo *info = NULL; - - if (msg == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback recv null msg"); - return; - } - info = (AsyncCallbackInfo *)msg->obj; - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback recv null info"); - return; - } - if (info->callback == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback function is null"); - return; - } - info->callback(info->cbPara); -} - -static void FreeAsyncCallbackMessage(SoftBusMessage *msg) -{ - AsyncCallbackInfo *info = NULL; - - if (msg == NULL || msg->obj == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); - return; - } - info = (AsyncCallbackInfo *)msg->obj; - SoftBusFree(info); -} - -static void InitAsyncCallbackMessage(SoftBusMessage *msg, int32_t what, void *obj, SoftBusHandler *handler) -{ - msg->what = what; - msg->obj = obj; - msg->handler = handler; - msg->FreeMessage = FreeAsyncCallbackMessage; -} - -static void InitAsyncCallbackHandler(SoftBusHandler *handler, SoftBusLooper *looper) -{ - handler->name = LNN_ASYNC_CALLBACK_HANDLER_NAME; - handler->looper = looper; - handler->HandleMessage = AsyncCallbackHandler; -} - -static AsyncCallbackInfo *CreateAsyncCallbackInfo(SoftBusLooper *looper, - LnnAsyncCallbackFunc callback, void *para, int32_t msgType) -{ - AsyncCallbackInfo *info = NULL; - - info = SoftBusCalloc(sizeof(AsyncCallbackInfo)); - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to malloc async callback info"); - return NULL; - } - info->callback = callback; - info->cbPara = para; - InitAsyncCallbackHandler(&info->handler, looper); - InitAsyncCallbackMessage(&info->msg, msgType, (void *)info, &info->handler); - return info; -} - -int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para) -{ - AsyncCallbackInfo *info = NULL; - - if (looper == NULL || callback == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); - return SOFTBUS_INVALID_PARAM; - } - info = CreateAsyncCallbackInfo(looper, callback, para, LNN_ASYNC_CALLBACK_REG); - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to create async callback info"); - return SOFTBUS_MEM_ERR; - } - looper->PostMessage(looper, &info->msg); - return SOFTBUS_OK; -} - -int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, - void *para, uint64_t delayMillis) -{ - AsyncCallbackInfo *info = NULL; - - if (looper == NULL || callback == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); - return SOFTBUS_INVALID_PARAM; - } - info = CreateAsyncCallbackInfo(looper, callback, para, LNN_ASYNC_CALLBACK_REG); - if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to create async callback info"); - return SOFTBUS_MEM_ERR; - } - looper->PostMessageDelay(looper, &info->msg, delayMillis); - return SOFTBUS_OK; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_async_callback_utils.h" + +#include "common_list.h" +#include "softbus_adapter_mem.h" +#include "softbus_errcode.h" +#include "softbus_log.h" + +#define LNN_ASYNC_CALLBACK_HANDLER_NAME "LnnAsyncHandler" + +#define LNN_ASYNC_CALLBACK_REG 0 + +typedef struct { + SoftBusMessage msg; + SoftBusHandler handler; + LnnAsyncCallbackFunc callback; + void *cbPara; +} AsyncCallbackInfo; + +#define TO_ASYNC_CALLBACK_INFO(cb) CONTAINER_OF(cb, AsyncCallbackInfo, callback) + +static void AsyncCallbackHandler(SoftBusMessage *msg) +{ + AsyncCallbackInfo *info = NULL; + + if (msg == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback recv null msg"); + return; + } + info = (AsyncCallbackInfo *)msg->obj; + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback recv null info"); + return; + } + if (info->callback == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail async callback function is null"); + return; + } + info->callback(info->cbPara); +} + +static void FreeAsyncCallbackMessage(SoftBusMessage *msg) +{ + AsyncCallbackInfo *info = NULL; + + if (msg == NULL || msg->obj == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); + return; + } + info = (AsyncCallbackInfo *)msg->obj; + SoftBusFree(info); +} + +static void InitAsyncCallbackMessage(SoftBusMessage *msg, int32_t what, void *obj, SoftBusHandler *handler) +{ + msg->what = what; + msg->obj = obj; + msg->handler = handler; + msg->FreeMessage = FreeAsyncCallbackMessage; +} + +static void InitAsyncCallbackHandler(SoftBusHandler *handler, SoftBusLooper *looper) +{ + handler->name = LNN_ASYNC_CALLBACK_HANDLER_NAME; + handler->looper = looper; + handler->HandleMessage = AsyncCallbackHandler; +} + +static AsyncCallbackInfo *CreateAsyncCallbackInfo(SoftBusLooper *looper, + LnnAsyncCallbackFunc callback, void *para, int32_t msgType) +{ + AsyncCallbackInfo *info = NULL; + + info = SoftBusCalloc(sizeof(AsyncCallbackInfo)); + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to malloc async callback info"); + return NULL; + } + info->callback = callback; + info->cbPara = para; + InitAsyncCallbackHandler(&info->handler, looper); + InitAsyncCallbackMessage(&info->msg, msgType, (void *)info, &info->handler); + return info; +} + +int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para) +{ + AsyncCallbackInfo *info = NULL; + + if (looper == NULL || callback == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); + return SOFTBUS_INVALID_PARAM; + } + info = CreateAsyncCallbackInfo(looper, callback, para, LNN_ASYNC_CALLBACK_REG); + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to create async callback info"); + return SOFTBUS_MEM_ERR; + } + looper->PostMessage(looper, &info->msg); + return SOFTBUS_OK; +} + +int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, + void *para, uint64_t delayMillis) +{ + AsyncCallbackInfo *info = NULL; + + if (looper == NULL || callback == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail: looper or callback is null"); + return SOFTBUS_INVALID_PARAM; + } + info = CreateAsyncCallbackInfo(looper, callback, para, LNN_ASYNC_CALLBACK_REG); + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail to create async callback info"); + return SOFTBUS_MEM_ERR; + } + looper->PostMessageDelay(looper, &info->msg, delayMillis); + return SOFTBUS_OK; +} diff --git a/core/bus_center/utils/src/lnn_file_utils.c b/core/bus_center/utils/src/lnn_file_utils.c index 62e0b1271..c6afa3b91 100644 --- a/core/bus_center/utils/src/lnn_file_utils.c +++ b/core/bus_center/utils/src/lnn_file_utils.c @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_file_utils.h" - -#include - -#include "softbus_adapter_file.h" -#include "softbus_errcode.h" -#include "softbus_feature_config.h" -#include "softbus_log.h" - -#define DEFAULT_STORAGE_PATH "/data/service/el1/public" - -typedef struct { - LnnFileId fileId; - const char *filePath; -} FilePathInfo; - -static char g_storagePath[SOFTBUS_MAX_PATH_LEN] = {0}; - -static FilePathInfo g_filePath[LNN_FILE_ID_MAX] = { - { LNN_FILE_ID_UUID, "/dsoftbus/uuid" }, - { LNN_FILE_ID_DB_KEY, "/dsoftbus/dbKey" }, -}; - -static int32_t InitStorageConfigPath(void) -{ - if (SoftbusGetConfig(SOFTBUS_STR_STORAGE_DIRECTORY, (uint8_t *)g_storagePath, - SOFTBUS_MAX_PATH_LEN) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read storage path fail"); - if (strncpy_s(g_storagePath, SOFTBUS_MAX_PATH_LEN, DEFAULT_STORAGE_PATH, - strlen(DEFAULT_STORAGE_PATH)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy default storage path fail"); - g_storagePath[0] = '\0'; - return SOFTBUS_ERR; - } - } - return SOFTBUS_OK; -} - -int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len) -{ - if (path == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: path is null", __func__); - return SOFTBUS_INVALID_PARAM; - } - if (strlen(g_storagePath) == 0) { - if (InitStorageConfigPath() != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init storage config path fail"); - return SOFTBUS_ERR; - } - } - if (strncpy_s(path, len, g_storagePath, strlen(g_storagePath)) != EOK || - strncat_s(path, len, g_filePath[id].filePath, strlen(g_filePath[id].filePath)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "splice full path for %d fail", id); - return SOFTBUS_ERR; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "full path for %d is %s", id, path); - return SOFTBUS_OK; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_file_utils.h" + +#include + +#include "softbus_adapter_file.h" +#include "softbus_errcode.h" +#include "softbus_feature_config.h" +#include "softbus_log.h" + +#define DEFAULT_STORAGE_PATH "/data/service/el1/public" + +typedef struct { + LnnFileId fileId; + const char *filePath; +} FilePathInfo; + +static char g_storagePath[SOFTBUS_MAX_PATH_LEN] = {0}; + +static FilePathInfo g_filePath[LNN_FILE_ID_MAX] = { + { LNN_FILE_ID_UUID, "/dsoftbus/uuid" }, + { LNN_FILE_ID_DB_KEY, "/dsoftbus/dbKey" }, +}; + +static int32_t InitStorageConfigPath(void) +{ + if (SoftbusGetConfig(SOFTBUS_STR_STORAGE_DIRECTORY, (uint8_t *)g_storagePath, + SOFTBUS_MAX_PATH_LEN) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read storage path fail"); + if (strncpy_s(g_storagePath, SOFTBUS_MAX_PATH_LEN, DEFAULT_STORAGE_PATH, + strlen(DEFAULT_STORAGE_PATH)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy default storage path fail"); + g_storagePath[0] = '\0'; + return SOFTBUS_ERR; + } + } + return SOFTBUS_OK; +} + +int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len) +{ + if (path == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: path is null", __func__); + return SOFTBUS_INVALID_PARAM; + } + if (strlen(g_storagePath) == 0) { + if (InitStorageConfigPath() != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init storage config path fail"); + return SOFTBUS_ERR; + } + } + if (strncpy_s(path, len, g_storagePath, strlen(g_storagePath)) != EOK || + strncat_s(path, len, g_filePath[id].filePath, strlen(g_filePath[id].filePath)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "splice full path for %d fail", id); + return SOFTBUS_ERR; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "full path for %d is %s", id, path); + return SOFTBUS_OK; +} diff --git a/core/bus_center/utils/src/lnn_ipc_utils.c b/core/bus_center/utils/src/lnn_ipc_utils.c index 886856bf4..70b99b564 100644 --- a/core/bus_center/utils/src/lnn_ipc_utils.c +++ b/core/bus_center/utils/src/lnn_ipc_utils.c @@ -1,70 +1,70 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "lnn_ipc_utils.h" - -#include - -void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo) -{ - if (info == NULL || pubInfo == NULL) { - return; - } - char *info1 = (char *)info; - pubInfo->publishId = *(int32_t *)info1; - info1 += sizeof(int32_t); - pubInfo->mode = *(DiscoverMode *)info1; - info1 += sizeof(DiscoverMode); - pubInfo->medium = *(ExchangeMedium *)info1; - info1 += sizeof(ExchangeMedium); - pubInfo->freq = *(ExchangeFreq *)info1; - info1 += sizeof(ExchangeFreq); - pubInfo->capability = (const char *)info1; - info1 += strlen(pubInfo->capability) + 1; - pubInfo->dataLen = *(int32_t *)info1; - info1 += sizeof(int32_t); - if (pubInfo->dataLen > 0) { - pubInfo->capabilityData = (unsigned char *)info1; - info1 += pubInfo->dataLen + 1; - } - pubInfo->ranging = *(bool *)info1; -} - -void ConvertVoidToSubscribeInfo(const void *info, SubscribeInfo *subInfo) -{ - if (info == NULL || subInfo == NULL) { - return; - } - char *info1 = (char *)info; - subInfo->subscribeId = *(int32_t *)info1; - info1 += sizeof(int32_t); - subInfo->mode = *(DiscoverMode *)info1; - info1 += sizeof(DiscoverMode); - subInfo->medium = *(ExchangeMedium *)info1; - info1 += sizeof(ExchangeMedium); - subInfo->freq = *(ExchangeFreq *)info1; - info1 += sizeof(ExchangeFreq); - subInfo->isSameAccount = *(bool *)info1; - info1 += sizeof(bool); - subInfo->isWakeRemote = *(bool *)info1; - info1 += sizeof(bool); - subInfo->capability = (const char *)info1; - info1 += strlen(subInfo->capability) + 1; - subInfo->dataLen = *(int32_t *)info1; - info1 += sizeof(int32_t); - if (subInfo->dataLen > 0) { - subInfo->capabilityData = (unsigned char *)info1; - } +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_ipc_utils.h" + +#include + +void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo) +{ + if (info == NULL || pubInfo == NULL) { + return; + } + char *info1 = (char *)info; + pubInfo->publishId = *(int32_t *)info1; + info1 += sizeof(int32_t); + pubInfo->mode = *(DiscoverMode *)info1; + info1 += sizeof(DiscoverMode); + pubInfo->medium = *(ExchangeMedium *)info1; + info1 += sizeof(ExchangeMedium); + pubInfo->freq = *(ExchangeFreq *)info1; + info1 += sizeof(ExchangeFreq); + pubInfo->capability = (const char *)info1; + info1 += strlen(pubInfo->capability) + 1; + pubInfo->dataLen = *(int32_t *)info1; + info1 += sizeof(int32_t); + if (pubInfo->dataLen > 0) { + pubInfo->capabilityData = (unsigned char *)info1; + info1 += pubInfo->dataLen + 1; + } + pubInfo->ranging = *(bool *)info1; +} + +void ConvertVoidToSubscribeInfo(const void *info, SubscribeInfo *subInfo) +{ + if (info == NULL || subInfo == NULL) { + return; + } + char *info1 = (char *)info; + subInfo->subscribeId = *(int32_t *)info1; + info1 += sizeof(int32_t); + subInfo->mode = *(DiscoverMode *)info1; + info1 += sizeof(DiscoverMode); + subInfo->medium = *(ExchangeMedium *)info1; + info1 += sizeof(ExchangeMedium); + subInfo->freq = *(ExchangeFreq *)info1; + info1 += sizeof(ExchangeFreq); + subInfo->isSameAccount = *(bool *)info1; + info1 += sizeof(bool); + subInfo->isWakeRemote = *(bool *)info1; + info1 += sizeof(bool); + subInfo->capability = (const char *)info1; + info1 += strlen(subInfo->capability) + 1; + subInfo->dataLen = *(int32_t *)info1; + info1 += sizeof(int32_t); + if (subInfo->dataLen > 0) { + subInfo->capabilityData = (unsigned char *)info1; + } } \ No newline at end of file diff --git a/interfaces/inner_kits/transport/dfs_session.h b/interfaces/inner_kits/transport/dfs_session.h index 854079cac..31fe6dd23 100644 --- a/interfaces/inner_kits/transport/dfs_session.h +++ b/interfaces/inner_kits/transport/dfs_session.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DFS_SESSION_H -#define DFS_SESSION_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define SESSION_KEY_LEN 32 - -int32_t GetSessionKey(int32_t sessionId, char *key, unsigned int len); -int32_t GetSessionHandle(int32_t sessionId, int *handle); -int32_t DisableSessionListener(int32_t sessionId); - -#ifdef __cplusplus -} -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DFS_SESSION_H +#define DFS_SESSION_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SESSION_KEY_LEN 32 + +int32_t GetSessionKey(int32_t sessionId, char *key, unsigned int len); +int32_t GetSessionHandle(int32_t sessionId, int *handle); +int32_t DisableSessionListener(int32_t sessionId); + +#ifdef __cplusplus +} +#endif #endif // DFS_SESSION_H \ No newline at end of file diff --git a/interfaces/inner_kits/transport/inner_session.h b/interfaces/inner_kits/transport/inner_session.h index 1e65345aa..5c477b097 100644 --- a/interfaces/inner_kits/transport/inner_session.h +++ b/interfaces/inner_kits/transport/inner_session.h @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INNER_SESSION_H -#define INNER_SESSION_H - -#include "softbus_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo, int num, const char *mixAddr); -void NotifyAuthSuccess(int sessionId); - -#ifdef __cplusplus -} -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INNER_SESSION_H +#define INNER_SESSION_H + +#include "softbus_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo, int num, const char *mixAddr); +void NotifyAuthSuccess(int sessionId); + +#ifdef __cplusplus +} +#endif #endif \ No newline at end of file