From 714a7f83e96500e0089895bad8fd00318e0295ec Mon Sep 17 00:00:00 2001 From: toutes Date: Wed, 4 May 2022 22:08:42 -0700 Subject: [PATCH] fixed 050e25b from https://gitee.com/liubb940516/powermgr_powermgr_lite/pulls/39 fix: Modify IPC Function Interface Signed-off-by: toutes Change-Id: I34b9e3d116ee10b9edb76a3db455d87dbc042d50 --- bundle.json | 2 +- frameworks/BUILD.gn | 3 ++ frameworks/include/hilog_wrapper.h | 6 ++- frameworks/src/small/power_manage.c | 40 +++++++++++++------ frameworks/src/small/power_screen_saver.c | 4 +- services/BUILD.gn | 11 ++++- .../power/small/power_manage_feature_impl.c | 35 ++++++++++------ .../small/screen_saver_feature_impl.c | 7 ++-- 8 files changed, 74 insertions(+), 34 deletions(-) diff --git a/bundle.json b/bundle.json index d3dddfd..184a589 100644 --- a/bundle.json +++ b/bundle.json @@ -40,7 +40,7 @@ "samgr_lite", "peripheral_input", "ui", - "ipc_lite", + "ipc_single", "aafwk_lite", "appexecfwk_lite", "hilog", diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index 9b419f7..0da4962 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -24,8 +24,11 @@ if (is_liteos_m) { ] local_deps += [ "//kernel/liteos_m/kal/posix:posix" ] } else { + local_include_dirs += + [ "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include" ] local_deps += [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//third_party/bounds_checking_function:libsec_shared", ] } diff --git a/frameworks/include/hilog_wrapper.h b/frameworks/include/hilog_wrapper.h index 8007eee..b36c3a2 100644 --- a/frameworks/include/hilog_wrapper.h +++ b/frameworks/include/hilog_wrapper.h @@ -18,7 +18,11 @@ #define LOG_TAG "PowerMgr" -#include +#if defined(__LITEOS_M__) +#include "log.h" +#else +#include "hilog/log.h" +#endif #ifdef __cplusplus extern "C" { diff --git a/frameworks/src/small/power_manage.c b/frameworks/src/small/power_manage.c index 9bce216..afaecb2 100644 --- a/frameworks/src/small/power_manage.c +++ b/frameworks/src/small/power_manage.c @@ -115,7 +115,7 @@ static int32_t AcquireReleaseCallback(IOwner owner, int32_t code, IpcIo *reply) } int32_t *ret = (int32_t *)owner; - *ret = IpcIoPopInt32(reply); + ReadInt32(reply, ret); POWER_HILOGD("Running lock callback: %d, code: %d", *ret, code); return EC_SUCCESS; } @@ -130,12 +130,17 @@ static int32_t AcquireRunningLockEntryProxy(IUnknown *iUnknown, RunningLockEntry IpcIo request; char buffer[MAX_DATA_LEN]; IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); - IpcIoPushFlatObj(&request, entry, sizeof(RunningLockEntry)); - IpcIoPushInt32(&request, timeoutMs); + bool value = WriteRawData(&request, entry, sizeof(RunningLockEntry)); + if (!value) { + POWER_HILOGE("WriteRawData faild"); + return EC_INVALID; + } + WriteInt32(&request, timeoutMs); int32_t ret; PowerManageProxyInterface *proxy = (PowerManageProxyInterface *)iUnknown; - proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_ACQUIRERUNNINGLOCK, &request, &ret, AcquireReleaseCallback); + proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_ACQUIRERUNNINGLOCK, + &request, &ret, AcquireReleaseCallback); POWER_HILOGD("Acquire running lock done, name: %s, type: %d", entry->lock.name, entry->lock.type); return ret; @@ -151,11 +156,16 @@ static int32_t ReleaseRunningLockEntryProxy(IUnknown *iUnknown, RunningLockEntry IpcIo request; char buffer[MAX_DATA_LEN]; IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); - IpcIoPushFlatObj(&request, entry, sizeof(RunningLockEntry)); + bool value = WriteRawData(&request, entry, sizeof(RunningLockEntry)); + if (!value) { + POWER_HILOGE("WriteRawData faild"); + return EC_INVALID; + } int32_t ret; PowerManageProxyInterface *proxy = (PowerManageProxyInterface *)iUnknown; - proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_RELEASERUNNINGLOCK, &request, &ret, AcquireReleaseCallback); + proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_RELEASERUNNINGLOCK, + &request, &ret, AcquireReleaseCallback); POWER_HILOGD("Release running lock done, name: %s, type: %d", entry->lock.name, entry->lock.type); return ret; @@ -169,7 +179,9 @@ static int32_t IsAnyHoldingCallback(IOwner owner, int32_t code, IpcIo *reply) } BOOL *ret = (BOOL *)owner; - *ret = IpcIoPopBool(reply) ? TRUE : FALSE; + bool readRet; + ReadBool(reply, &readRet); + *ret = readRet ? TRUE : FALSE; POWER_HILOGD("Any running lock holding: %d, code: %d", *ret, code); return EC_SUCCESS; } @@ -178,7 +190,11 @@ static BOOL IsAnyRunningLockHoldingProxy(IUnknown *iUnknown) { BOOL ret; PowerManageProxyInterface *proxy = (PowerManageProxyInterface *)iUnknown; - proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_ISANYRUNNINGLOCKHOLDING, NULL, &ret, IsAnyHoldingCallback); + IpcIo request; + char buffer[MAX_DATA_LEN]; + IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); + proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_ISANYRUNNINGLOCKHOLDING, + &request, &ret, IsAnyHoldingCallback); return ret; } @@ -226,8 +242,8 @@ static void SuspendDeviceProxy(IUnknown *iUnknown, SuspendDeviceType reason, BOO IpcIo request; char buffer[MAX_DATA_LEN]; IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); - IpcIoPushInt32(&request, reason); - IpcIoPushBool(&request, (suspendImmed == TRUE)); + WriteInt32(&request, (int32_t)reason); + WriteBool(&request, (suspendImmed == TRUE)); PowerManageProxyInterface *proxy = (PowerManageProxyInterface *)iUnknown; proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_SUSPEND, &request, NULL, NULL); @@ -239,8 +255,8 @@ static void WakeupDeviceProxy(IUnknown *iUnknown, WakeupDeviceType reason, const IpcIo request; char buffer[MAX_DATA_LEN]; IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); - IpcIoPushInt32(&request, reason); - IpcIoPushString(&request, details); + WriteInt32(&request, (int32_t)reason); + WriteString(&request, details); PowerManageProxyInterface *proxy = (PowerManageProxyInterface *)iUnknown; proxy->Invoke((IClientProxy *)proxy, POWERMANAGE_FUNCID_WAKEUP, &request, NULL, NULL); diff --git a/frameworks/src/small/power_screen_saver.c b/frameworks/src/small/power_screen_saver.c index a6dd9e9..2792aac 100644 --- a/frameworks/src/small/power_screen_saver.c +++ b/frameworks/src/small/power_screen_saver.c @@ -104,7 +104,7 @@ static int32_t Callback(IOwner owner, int32_t code, IpcIo *reply) } int32_t *ret = (int32_t *)owner; - *ret = IpcIoPopInt32(reply); + ReadInt32(reply, ret); POWER_HILOGD("Power screen saver callback: %d, code: %d", *ret, code); return EC_SUCCESS; } @@ -114,7 +114,7 @@ static int32_t SetScreenSaverStateProxy(IUnknown *iUnknown, BOOL enable) IpcIo request; char buffer[MAX_DATA_LEN]; IpcIoInit(&request, buffer, MAX_DATA_LEN, 0); - IpcIoPushBool(&request, enable == TRUE); + WriteBool(&request, enable == TRUE); int32_t ret; ScreenSaverProxyInterface *proxy = (ScreenSaverProxyInterface *)iUnknown; diff --git a/services/BUILD.gn b/services/BUILD.gn index 57e428a..5d72b1a 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -25,8 +25,15 @@ if (is_liteos_m) { ] local_deps += [ "//kernel/liteos_m/kal/posix:posix" ] } else { - local_deps += - [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ] + local_include_dirs += [ + "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", + ] + local_deps += [ + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", + ] if (enable_screensaver) { local_sources += [ "src/screen_saver_feature.c" ] diff --git a/services/src/power/small/power_manage_feature_impl.c b/services/src/power/small/power_manage_feature_impl.c index b9f6d10..bf5ebbf 100644 --- a/services/src/power/small/power_manage_feature_impl.c +++ b/services/src/power/small/power_manage_feature_impl.c @@ -54,7 +54,7 @@ PowerManageFeature *GetPowerManageFeatureImpl(void) static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply) { - if ((iProxy == NULL) || (origin == NULL) || (req == NULL)) { + if ((iProxy == NULL) || (req == NULL)) { POWER_HILOGE("Invalid parameter"); return EC_INVALID; } @@ -65,43 +65,52 @@ static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, static int32_t AcquireInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply) { - size_t len = 0; - void *data = (void *)IpcIoPopFlatObj(req, &len); - int32_t timeoutMs = IpcIoPopInt32(req); + uint32_t len = 0; + ReadUint32(req, &len); + void *data = (void*)ReadBuffer(req, len); + int32_t timeoutMs = 0; + ReadInt32(req, &timeoutMs); int32_t ret = OnAcquireRunningLockEntry((IUnknown *)iProxy, (RunningLockEntry *)data, timeoutMs); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return EC_SUCCESS; } static int32_t ReleaseInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply) { - size_t len = 0; - void *data = (void *)IpcIoPopFlatObj(req, &len); + uint32_t len = 0; + ReadUint32(req, &len); + void *data = (void*)ReadBuffer(req, len); int32_t ret = OnReleaseRunningLockEntry((IUnknown *)iProxy, (RunningLockEntry *)data); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return EC_SUCCESS; } static int32_t IsAnyHoldingInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply) { BOOL ret = OnIsAnyRunningLockHolding((IUnknown *)iProxy); - IpcIoPushBool(reply, ret == TRUE); + WriteBool(reply, ret == TRUE); return EC_SUCCESS; } static int32_t SuspendInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply) { - SuspendDeviceType reason = (SuspendDeviceType)IpcIoPopInt32(req); - BOOL suspendImmed = IpcIoPopBool(req) ? TRUE : FALSE; + int32_t ret = 0; + ReadInt32(req, &ret); + SuspendDeviceType reason = (SuspendDeviceType)ret; + bool ret1 = false; + ReadBool(req, &ret1); + BOOL suspendImmed = ret1 ? TRUE : FALSE; OnSuspendDevice((IUnknown *)iProxy, reason, suspendImmed); return EC_SUCCESS; } static int32_t WakeupInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply) { - WakeupDeviceType reason = (WakeupDeviceType)IpcIoPopInt32(req); + int32_t ret = 0; + ReadInt32(req, &ret); + WakeupDeviceType reason = (WakeupDeviceType)ret; size_t len = 0; - const char *details = (const char *)IpcIoPopString(req, &len); + const char *details = (const char *)ReadString(req, &len); OnWakeupDevice((IUnknown *)iProxy, reason, details); return EC_SUCCESS; } diff --git a/services/src/screensaver/small/screen_saver_feature_impl.c b/services/src/screensaver/small/screen_saver_feature_impl.c index 8b5b856..1a85880 100644 --- a/services/src/screensaver/small/screen_saver_feature_impl.c +++ b/services/src/screensaver/small/screen_saver_feature_impl.c @@ -44,15 +44,16 @@ static int32_t SetStateInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, Ip POWER_HILOGE("Invalid parameter"); return EC_INVALID; } - bool enable = IpcIoPopBool(req); + bool enable = false; + ReadBool(req, &enable); int32_t ret = OnSetScreenSaverState((IUnknown *)iProxy, enable ? TRUE : FALSE); - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return EC_SUCCESS; } static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply) { - if ((iProxy == NULL) || (origin == NULL) || (req == NULL)) { + if ((iProxy == NULL) || (req == NULL)) { POWER_HILOGE("Invalid parameter"); return EC_INVALID; } -- Gitee