From 437ace2ba6440aa528bf30890d6a3f9debc90eee Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Fri, 29 Apr 2022 11:44:12 +0800 Subject: [PATCH 1/2] modify napi code Signed-off-by: hellohyh001 --- bundle.json | 2 +- frameworks/include/sensor_agent_proxy.h | 2 +- frameworks/src/BUILD.gn | 3 +- frameworks/src/sensor_agent_proxy.c | 148 ++++++++++-------------- services/BUILD.gn | 6 +- services/include/sensor_service_impl.h | 2 +- services/src/sensor_service.c | 92 ++++++++------- services/src/sensor_service_impl.c | 43 +++---- 8 files changed, 137 insertions(+), 161 deletions(-) mode change 100755 => 100644 services/src/sensor_service.c diff --git a/bundle.json b/bundle.json index 2b0ea54..ac11ab3 100644 --- a/bundle.json +++ b/bundle.json @@ -17,7 +17,7 @@ "deps": { "components": [ "samgr_lite", - "ipc_lite", + "ipc", "utils_base", "peripheral_sensor" ], diff --git a/frameworks/include/sensor_agent_proxy.h b/frameworks/include/sensor_agent_proxy.h index 96b2b32..446aadc 100644 --- a/frameworks/include/sensor_agent_proxy.h +++ b/frameworks/include/sensor_agent_proxy.h @@ -20,7 +20,7 @@ #include #include -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "samgr_lite.h" #include "sensor_agent_type.h" #include "serializer.h" diff --git a/frameworks/src/BUILD.gn b/frameworks/src/BUILD.gn index 1afb930..6079564 100644 --- a/frameworks/src/BUILD.gn +++ b/frameworks/src/BUILD.gn @@ -37,8 +37,7 @@ shared_library("sensor_client") { "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast", "//foundation/distributedschedule/samgr_lite/samgr/source", - "//foundation/communication/ipc_lite/frameworks/liteipc/include", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//base/sensors/sensor_lite/services/include", ] diff --git a/frameworks/src/sensor_agent_proxy.c b/frameworks/src/sensor_agent_proxy.c index f528c89..62c347c 100644 --- a/frameworks/src/sensor_agent_proxy.c +++ b/frameworks/src/sensor_agent_proxy.c @@ -28,6 +28,7 @@ static SvcIdentity g_svcIdentity = { .handle = 0, .token = 0, }; +static IpcObjectStub g_objectStub; typedef struct CallbackNode { RecordSensorCallback callback; @@ -130,23 +131,24 @@ int32_t GetSensorInfos(IOwner owner, IpcIo *reply) HILOG_ERROR(HILOG_MODULE_APP, "%s notify is null", __func__); return SENSOR_ERROR_INVALID_PARAM; } else { - notify->retCode = IpcIoPopInt32(reply); + ReadInt32(reply, &(notify->retCode)); if (notify->retCode < 0) { HILOG_ERROR(HILOG_MODULE_APP, "%s failed, retCode: %d", __func__, notify->retCode); return SENSOR_ERROR_INVALID_PARAM; } - notify->count = IpcIoPopInt32(reply); - BuffPtr *dataBuf = IpcIoPopDataBuff(reply); - if ((notify->count <= 0) || (dataBuf == NULL) || (dataBuf->buff == NULL)) { + ReadInt32(reply, &(notify->count)); + uint32_t len; + ReadUint32(reply, &len); + uint8_t *data = (uint8_t *)ReadBuffer(reply, (size_t)len); + if ((notify->count <= 0) || (data == NULL)) { HILOG_ERROR(HILOG_MODULE_APP, "%s failed, count is incorrect or dataBuf is NULL or buff is NULL", __func__); notify->retCode = SENSOR_ERROR_INVALID_PARAM; return SENSOR_ERROR_INVALID_PARAM; } - SensorInfo *sensorInfo = (SensorInfo *)(dataBuf->buff); + SensorInfo *sensorInfo = (SensorInfo *)(data); *(notify->sensorInfo) = (SensorInfo *)malloc(sizeof(SensorInfo) * notify->count); if (*(notify->sensorInfo) == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "%s malloc sensorInfo failed", __func__); - FreeBuffer(NULL, dataBuf->buff); notify->retCode = SENSOR_ERROR_INVALID_PARAM; return SENSOR_ERROR_INVALID_PARAM; } @@ -154,14 +156,12 @@ int32_t GetSensorInfos(IOwner owner, IpcIo *reply) if (memcpy_s((*(notify->sensorInfo) + i), sizeof(SensorInfo), (sensorInfo + i), sizeof(SensorInfo))) { HILOG_ERROR(HILOG_MODULE_APP, "%s copy sensorInfo failed", __func__); - FreeBuffer(NULL, dataBuf->buff); free(*(notify->sensorInfo)); *(notify->sensorInfo) = NULL; notify->retCode = SENSOR_ERROR_INVALID_PARAM; return SENSOR_ERROR_INVALID_PARAM; } } - FreeBuffer(NULL, dataBuf->buff); return notify->retCode; } } @@ -169,7 +169,8 @@ int32_t GetSensorInfos(IOwner owner, IpcIo *reply) int32_t Notify(IOwner owner, int32_t code, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "%s begin", __func__); - int32_t functionId = IpcIoPopInt32(reply); + int32_t functionId; + ReadInt32(reply, &functionId); if (functionId == SENSOR_SERVICE_ID_GetAllSensors) { return GetSensorInfos(owner, reply); } @@ -179,7 +180,7 @@ int32_t Notify(IOwner owner, int32_t code, IpcIo *reply) return SENSOR_ERROR_INVALID_PARAM; } else { if ((functionId > SENSOR_SERVICE_ID_GetAllSensors) && (functionId < SENSORMGR_LISTENER_NAME_LEN)) { - *ret = IpcIoPopInt32(reply); + ReadInt32(reply, ret); HILOG_DEBUG(HILOG_MODULE_APP, "%s ret: %d", __func__, *ret); } else { *ret = SENSOR_ERROR_INVALID_PARAM; @@ -204,22 +205,24 @@ void DispatchData(SensorEvent *sensorEvent) } } -int32_t SensorChannelCallback(const IpcContext *context, void *ipcMsg, IpcIo *io, void *arg) +int32_t SensorChannelCallback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) { HILOG_DEBUG(HILOG_MODULE_APP, "%s begin", __func__); - if (ipcMsg == NULL || io == NULL) { - HILOG_ERROR(HILOG_MODULE_APP, "%s failed, ipcMsg or io is NULL", __func__); + if (data == NULL) { + HILOG_ERROR(HILOG_MODULE_APP, "%s failed, data is NULL", __func__); return SENSOR_ERROR_INVALID_PARAM; } - BuffPtr *eventBuff = IpcIoPopDataBuff(io); - BuffPtr *sensorDataBuff = IpcIoPopDataBuff(io); - if ((eventBuff == NULL) || (eventBuff->buff == NULL) || (sensorDataBuff == NULL) || - (sensorDataBuff->buff == NULL)) { + uint32_t len1; + ReadUint32(data, &len1); + uint8_t *eventData = (uint8_t *)ReadBuffer(data, (size_t)len1); + uint32_t len2; + ReadUint32(data, &len2); + uint8_t *sensorData = (uint8_t *)ReadBuffer(data, (size_t)len2); + if ((eventData == NULL) || (sensorData == NULL)) { HILOG_ERROR(HILOG_MODULE_APP, "%s failed, eventBuff or sensorDataBuff or buff is NULL", __func__); return SENSOR_ERROR_INVALID_PARAM; } - SensorEvent *event = (SensorEvent *)(eventBuff->buff); - uint8_t *sensorData = (uint8_t *)(sensorDataBuff->buff); + SensorEvent *event = (SensorEvent *)(eventData); g_sensorEvent->dataLen = event->dataLen; g_sensorEvent->timestamp = event->timestamp; g_sensorEvent->mode = event->mode; @@ -228,8 +231,6 @@ int32_t SensorChannelCallback(const IpcContext *context, void *ipcMsg, IpcIo *io g_sensorEvent->version = event->version; g_sensorEvent->data = sensorData; DispatchData(g_sensorEvent); - FreeBuffer(NULL, eventBuff->buff); - FreeBuffer(NULL, sensorDataBuff->buff); return SENSOR_OK; } @@ -240,18 +241,20 @@ int32_t RegisterSensorChannel(const void *proxy, int32_t sensorId) HILOG_DEBUG(HILOG_MODULE_APP, "%s sensorChannel has been registered ", __func__); return SENSOR_OK; } - int32_t ret = RegisterIpcCallback(SensorChannelCallback, 0, IPC_WAIT_FOREVER, &g_svcIdentity, NULL); - if (ret != LITEIPC_OK) { - HILOG_ERROR(HILOG_MODULE_APP, "%s failed, ret: %d", __func__, ret); - return SENSOR_ERROR_INVALID_PARAM; - } + g_objectStub.func = SensorChannelCallback; + g_objectStub.args = NULL; + g_objectStub.isRemote = false; + + g_svcIdentity.handle = IPC_INVALID_HANDLE; + g_svcIdentity.token = SERVICE_TYPE_ANONYMOUS; + g_svcIdentity.cookie = (uintptr_t)&g_objectStub; IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, IPC_MAX_OBJECTS); - IpcIoPushInt32(&request, sensorId); - IpcIoPushSvc(&request, &g_svcIdentity); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, IPC_MAX_OBJECTS); + WriteInt32(&request, sensorId); + bool writeRemote = WriteRemoteObject(&request, &g_svcIdentity); + if (!writeRemote) { + HILOG_ERROR(HILOG_MODULE_APP, "%s WriteRemoteObject failed.", __func__); return SENSOR_ERROR_INVALID_PARAM; } IClientProxy *client = (IClientProxy *)proxy; @@ -260,8 +263,8 @@ int32_t RegisterSensorChannel(const void *proxy, int32_t sensorId) return SENSOR_ERROR_INVALID_PARAM; } int32_t retCode = -1; - ret = client->Invoke(client, SENSOR_SERVICE_ID_SubscribeSensor, &request, &retCode, Notify); - if ((ret != LITEIPC_OK) || (retCode != SENSOR_OK)) { + int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_SubscribeSensor, &request, &retCode, Notify); + if ((ret != SENSOR_OK) || (retCode != SENSOR_OK)) { HILOG_ERROR(HILOG_MODULE_APP, "%s failed, ret: %d, retCode: %d", __func__, ret, retCode); return SENSOR_ERROR_INVALID_PARAM; } @@ -279,15 +282,10 @@ int32_t UnregisterSensorChannel(const void *proxy, int32_t sensorId) { HILOG_DEBUG(HILOG_MODULE_APP, "%s begin", __func__); if (!IsRegisterCallback()) { - (void) UnregisterIpcCallback(g_svcIdentity); IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); IClientProxy *client = (IClientProxy *)proxy; if (client == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "%s client is null", __func__); @@ -322,12 +320,8 @@ int32_t InitSensorList(const void *proxy) .sensorInfo = &g_sensorLists, }; IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, IPC_MAX_OBJECTS); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, IPC_MAX_OBJECTS); IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_GetAllSensors, &request, &owner, Notify); if ((ret != SENSOR_OK) || (owner.retCode != SENSOR_OK)) { @@ -365,13 +359,9 @@ int32_t ActivateSensorByProxy(const void *proxy, int32_t sensorId, const SensorU return SENSOR_ERROR_INVALID_PARAM; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); int32_t retCode = -1; IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_ActivateSensor, &request, &retCode, Notify); @@ -390,13 +380,9 @@ int32_t DeactivateSensorByProxy(const void *proxy, int32_t sensorId, const Senso return SENSOR_ERROR_INVALID_PARAM; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); int32_t retCode = -1; IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_DeactivateSensor, &request, &retCode, Notify); @@ -416,15 +402,11 @@ int32_t SetBatchByProxy(const void *proxy, int32_t sensorId, const SensorUser *u return SENSOR_ERROR_INVALID_PARAM; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - IpcIoPushInt64(&request, samplingInterval); - IpcIoPushInt64(&request, reportInterval); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); + WriteInt64(&request, samplingInterval); + WriteInt64(&request, reportInterval); int32_t retCode = -1; IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_SetBatchs, &request, &retCode, Notify); @@ -506,14 +488,10 @@ int32_t SetModeByProxy(const void *proxy, int32_t sensorId, const SensorUser *us return SENSOR_ERROR_INVALID_PARAM; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - IpcIoPushInt32(&request, mode); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); + WriteInt32(&request, mode); int32_t retCode = -1; IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_SetMode, &request, &retCode, Notify); @@ -532,14 +510,10 @@ int32_t SetOptionByProxy(const void *proxy, int32_t sensorId, const SensorUser * return SENSOR_ERROR_INVALID_PARAM; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, sensorId); - IpcIoPushInt32(&request, option); - if (!IpcIoAvailable(&request)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s ipc communication failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, sensorId); + WriteInt32(&request, option); int32_t retCode = -1; IClientProxy *client = (IClientProxy *)proxy; int32_t ret = client->Invoke(client, SENSOR_SERVICE_ID_SetOption, &request, &retCode, Notify); diff --git a/services/BUILD.gn b/services/BUILD.gn index a3f9f6b..be94c15 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -29,8 +29,9 @@ executable("sensor_service") { "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast", "//foundation/distributedschedule/samgr_lite/samgr/source", - "//foundation/communication/ipc_lite/frameworks/liteipc/include", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", + "//foundation/communication/ipc/ipc/native/c/manager/include", + "//foundation/communication/ipc/services/dbinder/c/include", "//drivers/peripheral/sensor/interfaces/include", "//base/sensors/sensor_lite/frameworks/include", ] @@ -38,5 +39,6 @@ executable("sensor_service") { deps = [ "//drivers/peripheral/sensor/hal:hdi_sensor", "//foundation/distributedschedule/samgr_lite/samgr:samgr", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", ] } diff --git a/services/include/sensor_service_impl.h b/services/include/sensor_service_impl.h index aa3cbc8..a786be6 100644 --- a/services/include/sensor_service_impl.h +++ b/services/include/sensor_service_impl.h @@ -17,7 +17,7 @@ #define SENSOR_SERVICE_INTERFACE_H #include "iproxy_server.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "sensor_if.h" #include "sensor_service.h" diff --git a/services/src/sensor_service.c b/services/src/sensor_service.c old mode 100755 new mode 100644 index 10dff13..1bfd09d --- a/services/src/sensor_service.c +++ b/services/src/sensor_service.c @@ -24,10 +24,10 @@ int32_t GetAllSensorsInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_GetAllSensors); + WriteInt32(reply, SENSOR_SERVICE_ID_GetAllSensors); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } SensorInfo *sensorInfo = NULL; @@ -35,32 +35,30 @@ int32_t GetAllSensorsInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *rep int32_t ret = defaultApi->GetAllSensors(&sensorInfo, &count); if (ret != SENSOR_OK) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, ret: %d", SENSOR_SERVICE, __func__, ret); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } - BuffPtr dataBuff = { - .buffSz = (uint32_t)(count * sizeof(SensorInfo)), - .buff = sensorInfo - }; - IpcIoPushInt32(reply, SENSOR_OK); - IpcIoPushInt32(reply, count); - IpcIoPushDataBuff(reply, &dataBuff); + WriteInt32(reply, SENSOR_OK); + WriteInt32(reply, count); + WriteUint32(reply, (uint32_t)(count * sizeof(SensorInfo))); + WriteBuffer(reply, (void *)(sensorInfo), (uint32_t)(count * sizeof(SensorInfo))); return SENSOR_OK; } int32_t ActivateSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_ActivateSensor); - int32_t sensorId = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_ActivateSensor); + int32_t sensorId; + ReadInt32(req, &sensorId); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->ActivateSensor(sensorId, &sensorUser); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -68,16 +66,17 @@ int32_t ActivateSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *re int32_t DeactivateSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_DeactivateSensor); - int32_t sensorId = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_DeactivateSensor); + int32_t sensorId; + ReadInt32(req, &sensorId); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->DeactivateSensor(sensorId, &sensorUser); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -85,18 +84,21 @@ int32_t DeactivateSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo * int32_t SetBatchInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_SetBatchs); - int32_t sensorId = IpcIoPopInt32(req); - int64_t updateInterval = IpcIoPopInt64(req); - int64_t maxDelay = IpcIoPopInt64(req); + WriteInt32(reply, SENSOR_SERVICE_ID_SetBatchs); + int32_t sensorId; + ReadInt32(req, &sensorId); + int64_t updateInterval; + ReadInt64(req, &updateInterval); + int64_t maxDelay; + ReadInt64(req, &maxDelay); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->SetBatch(sensorId, &sensorUser, updateInterval, maxDelay); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -104,17 +106,18 @@ int32_t SetBatchInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) int32_t SubscribeSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_SubscribeSensor); - int32_t sensorId = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_SubscribeSensor); + int32_t sensorId; + ReadInt32(req, &sensorId); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->SubscribeSensor(sensorId, &sensorUser); SetSvcIdentity(req, reply); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -122,16 +125,17 @@ int32_t SubscribeSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *r int32_t UnsubscribeSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_UnsubscribeSensor); - int32_t sensorId = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_UnsubscribeSensor); + int32_t sensorId; + ReadInt32(req, &sensorId); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->UnsubscribeSensor(sensorId, &sensorUser); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -139,17 +143,19 @@ int32_t UnsubscribeSensorInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo int32_t SetModeInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_SetMode); - int32_t sensorId = IpcIoPopInt32(req); - int32_t mode = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_SetMode); + int32_t sensorId; + ReadInt32(req, &sensorId); + int32_t mode; + ReadInt32(req, &mode); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->SetMode(sensorId, &sensorUser, mode); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } @@ -157,17 +163,19 @@ int32_t SetModeInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) int32_t SetOptionInvoke(SensorFeatureApi *defaultApi, IpcIo *req, IpcIo *reply) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_SERVICE_ID_SetOption); - int32_t sensorId = IpcIoPopInt32(req); - int32_t option = IpcIoPopInt32(req); + WriteInt32(reply, SENSOR_SERVICE_ID_SetOption); + int32_t sensorId; + ReadInt32(req, &sensorId); + int32_t option; + ReadInt32(req, &option); if (defaultApi == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s failed, defaultApi is null", SENSOR_SERVICE, __func__); - IpcIoPushInt32(reply, SENSOR_ERROR_UNKNOWN); + WriteInt32(reply, SENSOR_ERROR_UNKNOWN); return SENSOR_ERROR_UNKNOWN; } else { SensorUser sensorUser; int32_t ret = defaultApi->SetOption(sensorId, &sensorUser, option); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; } } diff --git a/services/src/sensor_service_impl.c b/services/src/sensor_service_impl.c index e62d096..2477b38 100644 --- a/services/src/sensor_service_impl.c +++ b/services/src/sensor_service_impl.c @@ -18,8 +18,7 @@ #include #include #include - -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "sensor_service.h" #include "sensor_type.h" @@ -64,36 +63,30 @@ static int SensorDataCallback(const struct SensorEvent *event) return SENSOR_ERROR_INVALID_ID; } IpcIo io; - uint8_t data[IPC_IO_DATA_MAX]; - IpcIoInit(&io, data, IPC_IO_DATA_MAX, IPC_MAX_OBJECTS); - BuffPtr eventBuff = { - .buffSz = (uint32_t)(sizeof(struct SensorEvent)), - .buff = (void *)(event) - }; - BuffPtr sensorDataBuff = { - .buffSz = (uint32_t)(event->dataLen), - .buff = event->data - }; - IpcIoPushDataBuff(&io, &eventBuff); - IpcIoPushDataBuff(&io, &sensorDataBuff); - if (!IpcIoAvailable(&io)) { - HILOG_ERROR(HILOG_MODULE_APP, "%s TransmitServiceId ipc failed", __func__); - return SENSOR_ERROR_INVALID_PARAM; - } - IpcContext context; - SendRequest(&context, g_svcIdentity, 0, &io, NULL, LITEIPC_FLAG_ONEWAY, NULL); + uint8_t data[MAX_IO_SIZE]; + IpcIoInit(&io, data, MAX_IO_SIZE, IPC_MAX_OBJECTS); + + WriteUint32(&io, (uint32_t)(sizeof(struct SensorEvent))); + WriteBuffer(&io, (void *)(event), (uint32_t)(sizeof(struct SensorEvent))); + WriteUint32(&io, (uint32_t)(event->dataLen)); + WriteBuffer(&io, (void *)(event->data), (uint32_t)(event->dataLen)); + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; + SendRequest(g_svcIdentity, 0, &io, NULL, option, NULL); return SENSOR_OK; } void SetSvcIdentity(IpcIo *req, const IpcIo *reply) { - SvcIdentity *sid = IpcIoPopSvc(req); - if (sid == NULL) { - HILOG_ERROR(HILOG_MODULE_APP, "%s sid is NULL", __func__); + SvcIdentity sid; + bool ret = ReadRemoteObject(req, &sid); + if (!ret) { + HILOG_ERROR(HILOG_MODULE_APP, "%s ReadRemoteObject failed ", __func__); return; } - g_svcIdentity.handle = sid->handle; - g_svcIdentity.token = sid->token; + g_svcIdentity.handle = sid.handle; + g_svcIdentity.token = sid.token; } BOOL Initialize(Service *service, Identity identity) -- Gitee From 00e0801beb3f97e7699f0e4a8cfdd9fe540eca23 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Sat, 7 May 2022 10:35:38 +0800 Subject: [PATCH 2/2] modify kora warning Signed-off-by: hellohyh001 --- services/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index be94c15..d890c31 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -38,7 +38,7 @@ executable("sensor_service") { deps = [ "//drivers/peripheral/sensor/hal:hdi_sensor", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", ] } -- Gitee