From 8e2361961af6f29c7e225868a3e857e3a9533715 Mon Sep 17 00:00:00 2001 From: "wangkai399@huawei.com" Date: Sun, 27 Mar 2022 16:49:33 +0800 Subject: [PATCH] =?UTF-8?q?IPC=E7=BB=9F=E4=B8=80=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai399@huawei.com --- BUILD.gn | 2 +- frameworks/ims/input_event_client_proxy.h | 4 +- frameworks/ims/input_event_listener_proxy.cpp | 22 ++-- frameworks/wms/lite_win_requestor.cpp | 29 ++--- frameworks/wms/lite_wm_requestor.cpp | 55 +++++---- frameworks/wms/lite_wm_requestor.h | 9 +- .../innerkits/input_event_listener_proxy.h | 6 +- services/ims/input_event_client_proxy.cpp | 46 +++---- services/wms/lite_win.cpp | 4 - services/wms/lite_win.h | 3 +- services/wms/lite_wms.cpp | 112 +++++++++--------- services/wms/lite_wms.h | 13 +- 12 files changed, 150 insertions(+), 155 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index f444b58..23d344a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,7 +29,7 @@ ndk_lib("lite_wms_ndk") { commonDeps = [ "//foundation/distributedschedule/samgr_lite/samgr:samgr", "//foundation/distributedschedule/samgr_lite/communication/broadcast:broadcast", - "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//foundation/graphic/surface:surface", "//foundation/graphic/utils:lite_graphic_utils", "//third_party/bounds_checking_function:libsec_shared", diff --git a/frameworks/ims/input_event_client_proxy.h b/frameworks/ims/input_event_client_proxy.h index 610280c..a874f9b 100755 --- a/frameworks/ims/input_event_client_proxy.h +++ b/frameworks/ims/input_event_client_proxy.h @@ -19,7 +19,7 @@ #include "input_event_distributer.h" #include "gfx_utils/input_event_info.h" #include "input_manager_service.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "serializer.h" #include #include @@ -62,7 +62,7 @@ private: void OnRawEvent(const RawEvent& event) override; void AddListener(const void* origin, IpcIo* req, IpcIo* reply); void RemoveListener(const void* origin, IpcIo* req, IpcIo* reply); - static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* origin); + static void DeathCallback(void* origin); }; } #endif \ No newline at end of file diff --git a/frameworks/ims/input_event_listener_proxy.cpp b/frameworks/ims/input_event_listener_proxy.cpp index 6807dc5..b23c2da 100755 --- a/frameworks/ims/input_event_listener_proxy.cpp +++ b/frameworks/ims/input_event_listener_proxy.cpp @@ -50,20 +50,18 @@ bool InputEventListenerProxy::GetIClientProxy() return true; } -int32_t InputEventListenerProxy::ReceiveMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg) +int32_t InputEventListenerProxy::ReceiveMsgHandler(uint32_t code, IpcIo* io, IpcIo* reply, MessageOption option) { if (listener_ == nullptr) { return -1; } - uint32_t size; - RawEvent* eventTemp = static_cast(IpcIoPopFlatObj(io, &size)); + RawEvent* eventTemp = static_cast(ReadRawData(io, sizeof(RawEvent))); if (eventTemp == nullptr) { GRAPHIC_LOGE("pop raw event failed."); return -1; } RawEvent event = *eventTemp; listener_->OnRawEvent(event); - FreeBuffer(nullptr, ipcMsg); return 0; } @@ -81,13 +79,15 @@ bool InputEventListenerProxy::RegisterInputEventListener(RawEventListener* liste IpcIo io; uint8_t tmpData[IMS_DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, IMS_DEFAULT_IPC_SIZE, 1); - SvcIdentity svc; - if (RegisterIpcCallback(ReceiveMsgHandler, 0, IPC_WAIT_FOREVER, &svc, NULL) != LITEIPC_OK) { - GRAPHIC_LOGE("RegisterIpcCallback failed."); - return false; - } - IpcIoPushSvc(&io, &svc); - IpcIoPushBool(&io, listener->IsAlwaysInvoke()); + + objectStub_.func = ReceiveMsgHandler; + objectStub_.args = nullptr; + objectStub_.isRemote = false; + sid_.handle = IPC_INVALID_HANDLE; + sid_.token = SERVICE_TYPE_ANONYMOUS; + sid_.cookie = reinterpret_cast(&objectStub_); + WriteRemoteObject(&io, &sid_); + WriteBool(&io, listener->IsAlwaysInvoke()); int32_t ret = proxy_->Invoke(proxy_, LITEIMS_CLIENT_REGISTER, &io, NULL, NULL); if (ret != 0) { GRAPHIC_LOGE("Client register failed, ret=%d", ret); diff --git a/frameworks/wms/lite_win_requestor.cpp b/frameworks/wms/lite_win_requestor.cpp index e5a732f..f147126 100755 --- a/frameworks/wms/lite_win_requestor.cpp +++ b/frameworks/wms/lite_win_requestor.cpp @@ -49,8 +49,9 @@ int LiteWinRequestor::Callback(void* owner, int code, IpcIo* reply) switch (para->funcId) { case LiteWMS_GetSurface: { LiteWinRequestor* requestor = (LiteWinRequestor*)(para->data); - int32_t ret = IpcIoPopInt32(reply); - if ((ret == LITEIPC_OK) && (requestor != nullptr)) { + int32_t ret; + ReadInt32(reply, &ret); + if ((ret == LiteWMS_EOK) && (requestor != nullptr)) { requestor->GenericSurface(reply); } break; @@ -72,7 +73,7 @@ Surface* LiteWinRequestor::GetSurface() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); CallBackPara para = {}; para.funcId = LiteWMS_GetSurface; @@ -90,7 +91,7 @@ void LiteWinRequestor::Show() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Show, &io, NULL, NULL); if (ret != 0) { @@ -103,7 +104,7 @@ void LiteWinRequestor::Hide() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Hide, &io, NULL, NULL); if (ret != 0) { @@ -116,7 +117,7 @@ void LiteWinRequestor::RaiseToTop() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_RaiseToTop, &io, NULL, NULL); if (ret != 0) { @@ -129,7 +130,7 @@ void LiteWinRequestor::LowerToBottom() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_LowerToBottom, &io, NULL, NULL); if (ret != 0) { @@ -142,9 +143,9 @@ void LiteWinRequestor::MoveTo(int16_t x, int16_t y) IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); - IpcIoPushUint32(&io, x); - IpcIoPushUint32(&io, y); + WriteInt32(&io, id_); + WriteUint32(&io, x); + WriteUint32(&io, y); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_MoveTo, &io, NULL, NULL); if (ret != 0) { @@ -157,9 +158,9 @@ void LiteWinRequestor::Resize(int16_t width, int16_t height) IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); - IpcIoPushUint32(&io, width); - IpcIoPushUint32(&io, height); + WriteInt32(&io, id_); + WriteUint32(&io, width); + WriteUint32(&io, height); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Resize, &io, NULL, Callback); if (ret != 0) { @@ -172,7 +173,7 @@ void LiteWinRequestor::Update() IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id_); + WriteInt32(&io, id_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Update, &io, NULL, NULL); if (ret != 0) { diff --git a/frameworks/wms/lite_wm_requestor.cpp b/frameworks/wms/lite_wm_requestor.cpp index a652c41..a73c8d4 100755 --- a/frameworks/wms/lite_wm_requestor.cpp +++ b/frameworks/wms/lite_wm_requestor.cpp @@ -45,7 +45,8 @@ int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply) if (requestor == nullptr) { break; } - int32_t id = IpcIoPopInt32(reply); + int32_t id; + ReadInt32(reply, &id); GRAPHIC_LOGI("CreateWindow, id=%d", id); if (id == INVALID_WINDOW_ID) { *requestor = nullptr; @@ -55,8 +56,7 @@ int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply) break; } case LiteWMS_GetEventData: { - uint32_t size; - DeviceData* data = static_cast(IpcIoPopFlatObj(reply, &size)); + DeviceData* data = static_cast(ReadRawData(reply, sizeof(DeviceData))); DeviceData* retData = (DeviceData*)(para->data); if (data != nullptr && retData != nullptr) { *retData = *data; @@ -64,7 +64,8 @@ int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply) break; } case LiteWMS_Screenshot: { - int32_t ret = IpcIoPopInt32(reply); + int32_t ret; + ReadInt32(reply, &ret); if (ret != LiteWMS_EOK) { GRAPHIC_LOGW("Screenshot busy!"); LiteWMRequestor::GetInstance()->ScreenShotClearup(); @@ -72,8 +73,7 @@ int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply) break; } case LiteWMS_GetLayerInfo: { - uint32_t size; - LiteLayerInfo* data = static_cast(IpcIoPopFlatObj(reply, &size)); + LiteLayerInfo* data = static_cast(ReadRawData(reply, sizeof(LiteLayerInfo))); LiteLayerInfo* retData = (LiteLayerInfo*)(para->data); if (data != nullptr && retData != nullptr) { *retData = *data; @@ -86,7 +86,7 @@ int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply) return 0; } -int32_t LiteWMRequestor::WmsMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg) +int32_t LiteWMRequestor::WmsMsgHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { // It's not used yet return 0; @@ -98,12 +98,13 @@ void LiteWMRequestor::ClientRegister() uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 1); - SvcIdentity svc; - if (RegisterIpcCallback(WmsMsgHandler, 0, IPC_WAIT_FOREVER, &svc, NULL) != LITEIPC_OK) { - GRAPHIC_LOGE("RegisterIpcCallback failed."); - return; - } - IpcIoPushSvc(&io, &svc); + objectStub_.func = WmsMsgHandler; + objectStub_.args = nullptr; + objectStub_.isRemote = false; + sid_.handle = IPC_INVALID_HANDLE; + sid_.token = SERVICE_TYPE_ANONYMOUS; + sid_.cookie = reinterpret_cast(&objectStub_); + WriteRemoteObject(&io, &sid_); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_ClientRegister, &io, NULL, Callback); if (ret != 0) { GRAPHIC_LOGE("ClientRegister failed, ret=%d", ret); @@ -130,7 +131,7 @@ LiteWinRequestor* LiteWMRequestor::CreateWindow(const LiteWinConfig& config) IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushFlatObj(&io, &config, sizeof(LiteWinConfig)); + WriteRawData(&io, &config, sizeof(LiteWinConfig)); LiteWinRequestor* requestor = nullptr; CallBackPara para = {}; @@ -149,7 +150,7 @@ void LiteWMRequestor::RemoveWindow(int32_t id) IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); - IpcIoPushInt32(&io, id); + WriteInt32(&io, id); int32_t ret = proxy_->Invoke(proxy_, LiteWMS_RemoveWindow, &io, NULL, Callback); if (ret != 0) { @@ -169,19 +170,18 @@ void LiteWMRequestor::GetEventData(DeviceData* data) (void)proxy_->Invoke(proxy_, LiteWMS_GetEventData, &io, ¶, Callback); } -int LiteWMRequestor::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg) +int LiteWMRequestor::SurfaceRequestHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { - SurfaceImpl* surface = (SurfaceImpl*)arg; + SurfaceImpl* surface = (SurfaceImpl*)(option.args); if (surface == nullptr) { return 0; } - surface->DoIpcMsg(ipcMsg, io); + surface->DoIpcMsg(code, data, reply, option); return 0; } void LiteWMRequestor::ScreenShotClearup() { - UnregisterIpcCallback(sid_); if (surface_ != nullptr) { delete surface_; surface_ = nullptr; @@ -224,21 +224,20 @@ void LiteWMRequestor::Screenshot() surface_->SetUsage(1); surface_->RegisterConsumerListener(*this); - int32_t ret = RegisterIpcCallback(SurfaceRequestHandler, 0, IPC_WAIT_FOREVER, &sid_, surface_); - if (ret != LITEIPC_OK) { - GRAPHIC_LOGE("RegisterIpcCallback failed."); - delete surface_; - surface_ = nullptr; - return; - } + objectStub_ .func = SurfaceRequestHandler; + objectStub_ .args = surface_; + objectStub_ .isRemote = false; + sid_.handle = IPC_INVALID_HANDLE; + sid_.token = SERVICE_TYPE_ANONYMOUS; + sid_.cookie = reinterpret_cast(&objectStub_); IpcIo io; uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 1); - IpcIoPushSvc(&io, &sid_); + WriteRemoteObject(&io, &sid_); CallBackPara para = {}; para.funcId = LiteWMS_Screenshot; - ret = proxy_->Invoke(proxy_, LiteWMS_Screenshot, &io, ¶, Callback); + int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Screenshot, &io, ¶, Callback); if (ret != 0) { GRAPHIC_LOGE("Screenshot failed, ret=%d", ret); } diff --git a/frameworks/wms/lite_wm_requestor.h b/frameworks/wms/lite_wm_requestor.h index 043a973..a1ff3b6 100755 --- a/frameworks/wms/lite_wm_requestor.h +++ b/frameworks/wms/lite_wm_requestor.h @@ -21,15 +21,15 @@ #include "iwindows_manager.h" #include "lite_win_requestor.h" #include "lite_wm_type.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" namespace OHOS { class LiteWMRequestor : public IBufferConsumerListener { public: static LiteWMRequestor* GetInstance(); static int Callback(void* owner, int code, IpcIo* reply); - static int32_t WmsMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg); - static int32_t SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg); + static int32_t WmsMsgHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option); + static int32_t SurfaceRequestHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option); virtual void OnBufferAvailable() override; @@ -54,7 +54,8 @@ private: IWindowsManager::ScreenshotListener* listener_; Surface* surface_; SvcIdentity sid_; + IpcObjectStub objectStub_; LiteLayerInfo layerInfo_; }; } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/interfaces/innerkits/input_event_listener_proxy.h b/interfaces/innerkits/input_event_listener_proxy.h index eb35669..0835950 100755 --- a/interfaces/innerkits/input_event_listener_proxy.h +++ b/interfaces/innerkits/input_event_listener_proxy.h @@ -17,7 +17,7 @@ #define GRAPHIC_LITE_IMS_CLIENT_PROXY_H #include -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "gfx_utils/input_event_info.h" namespace OHOS { @@ -53,7 +53,7 @@ private: ~InputEventListenerProxy(); bool GetIClientProxy(); - static int32_t ReceiveMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg); + static int32_t ReceiveMsgHandler(uint32_t code, IpcIo* io, IpcIo* reply, MessageOption option); IClientProxy* proxy_; static RawEventListener* listener_; @@ -62,6 +62,8 @@ private: InputEventListenerProxy& operator=(const InputEventListenerProxy&) = delete; InputEventListenerProxy(InputEventListenerProxy&&) = delete; InputEventListenerProxy& operator=(InputEventListenerProxy&&) = delete; + SvcIdentity sid_; + IpcObjectStub objectStub_; }; } // namespace OHOS #endif diff --git a/services/ims/input_event_client_proxy.cpp b/services/ims/input_event_client_proxy.cpp index ce3a5bf..01819f3 100755 --- a/services/ims/input_event_client_proxy.cpp +++ b/services/ims/input_event_client_proxy.cpp @@ -48,23 +48,19 @@ void InputEventClientProxy::AddListener(const void* origin, IpcIo* req, IpcIo* r GRAPHIC_LOGE("Exceeded the maximum number!"); return; } - pid_t pid = GetCallingPid(origin); - SvcIdentity* sid = IpcIoPopSvc(req); - bool alwaysInvoke = IpcIoPopBool(req); - if (sid == nullptr) { - GRAPHIC_LOGE("Pop Svc failed."); + pid_t pid = GetCallingPid(); + SvcIdentity svc = {0}; + bool ret = ReadRemoteObject(req, &svc); + bool alwaysInvoke; + ReadBool(req, &alwaysInvoke); + if (!ret) { + GRAPHIC_LOGE("ReadRemoteObject failed."); return; } - SvcIdentity svc = *sid; -#ifdef __LINUX__ - BinderAcquire(svc.ipcContext, svc.handle); - free(sid); - sid = nullptr; -#endif uint32_t cbId = 0; - if (RegisterDeathCallback(NULL, svc, DeathCallback, const_cast(origin), &cbId) != LITEIPC_OK) { - GRAPHIC_LOGE("Register death callback failed!"); - return; + if (AddDeathRecipient(svc, DeathCallback, nullptr, &cbId) != 0) { + GRAPHIC_LOGE("Register death callback failed!"); + return; } struct ClientInfo clientInfo = { svc, cbId, alwaysInvoke }; pthread_mutex_lock(&lock_); @@ -72,23 +68,16 @@ void InputEventClientProxy::AddListener(const void* origin, IpcIo* req, IpcIo* r pthread_mutex_unlock(&lock_); } -int32_t InputEventClientProxy::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* origin) +void InputEventClientProxy::DeathCallback(void* origin) { - if (origin != nullptr) { - InputEventClientProxy::GetInstance()->RemoveListener(origin, nullptr, nullptr); - return 0; - } - return -1; + InputEventClientProxy::GetInstance()->RemoveListener(origin, nullptr, nullptr); } void InputEventClientProxy::RemoveListener(const void* origin, IpcIo* req, IpcIo* reply) { - pid_t pid = GetCallingPid(origin); + pid_t pid = GetCallingPid(); if (clientInfoMap_.count(pid) > 0) { -#ifdef __LINUX__ - BinderRelease(clientInfoMap_[pid].svc.ipcContext, clientInfoMap_[pid].svc.handle); -#endif - UnregisterDeathCallback(clientInfoMap_[pid].svc, clientInfoMap_[pid].cdId); + ReleaseSvc(clientInfoMap_[pid].svc); pthread_mutex_lock(&lock_); clientInfoMap_.erase(pid); pthread_mutex_unlock(&lock_); @@ -100,12 +89,15 @@ void InputEventClientProxy::OnRawEvent(const RawEvent& event) IpcIo io; uint8_t tmpData[IMS_DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, IMS_DEFAULT_IPC_SIZE, 1); - IpcIoPushFlatObj(&io, static_cast(&event), sizeof(RawEvent)); + WriteRawData(&io, static_cast(&event), sizeof(RawEvent)); pthread_mutex_lock(&lock_); std::map::iterator it; for (it = clientInfoMap_.begin(); it != clientInfoMap_.end(); it++) { if (it->second.alwaysInvoke || (event.state != lastState_)) { - SendRequest(nullptr, it->second.svc, 0, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr); + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; + SendRequest(it->second.svc, 0, &io, nullptr, option, nullptr); } } lastState_ = event.state; diff --git a/services/wms/lite_win.cpp b/services/wms/lite_win.cpp index d8b842c..353fc12 100644 --- a/services/wms/lite_win.cpp +++ b/services/wms/lite_win.cpp @@ -56,10 +56,6 @@ LiteWindow::LiteWindow(const LiteWinConfig& config) LiteWindow::~LiteWindow() { - if (needUnregister_) { - GRAPHIC_LOGI("UnregisterIpcCallback"); - UnregisterIpcCallback(sid_); - } if (surface_ != nullptr) { if (backBuf_ != nullptr) { diff --git a/services/wms/lite_win.h b/services/wms/lite_win.h index 4cce079..b215338 100755 --- a/services/wms/lite_win.h +++ b/services/wms/lite_win.h @@ -22,7 +22,7 @@ #include "gfx_utils/geometry2d.h" #include "isurface.h" #include "lite_wm_type.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "serializer.h" #include "surface.h" @@ -102,6 +102,7 @@ private: SurfaceBuffer* backBuf_; pthread_mutex_t backBufMutex_; SvcIdentity sid_; + IpcObjectStub objectStub_; bool needUnregister_; }; } diff --git a/services/wms/lite_wms.cpp b/services/wms/lite_wms.cpp index 83452dd..50532c7 100755 --- a/services/wms/lite_wms.cpp +++ b/services/wms/lite_wms.cpp @@ -55,7 +55,7 @@ void LiteWMS::WMSRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* repl LiteWMS::GetInstance()->Update(req, reply); break; case LiteWMS_CreateWindow: - LiteWMS::GetInstance()->CreateWindow(origin, req, reply); + LiteWMS::GetInstance()->CreateWindow(req, reply); break; case LiteWMS_RemoveWindow: LiteWMS::GetInstance()->RemoveWindow(req, reply); @@ -67,7 +67,7 @@ void LiteWMS::WMSRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* repl LiteWMS::GetInstance()->Screenshot(req, reply); break; case LiteWMS_ClientRegister: - LiteWMS::GetInstance()->ClientRegister(origin, req, reply); + LiteWMS::GetInstance()->ClientRegister(req, reply); break; case LiteWMS_GetLayerInfo: LiteWMS::GetInstance()->GetLayerInfo(req, reply); @@ -78,11 +78,9 @@ void LiteWMS::WMSRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* repl } } -int32_t LiteWMS::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg) +int32_t LiteWMS::SurfaceRequestHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { - uint32_t code; - (void)GetCode(ipcMsg, &code); - LiteWindow* window = reinterpret_cast(arg); + LiteWindow* window = reinterpret_cast(option.args); if (code == 0) { GRAPHIC_LOGI("requestBuffer"); window->UpdateBackBuf(); @@ -90,103 +88,114 @@ int32_t LiteWMS::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, Surface* surface = window->GetSurface(); SurfaceImpl* liteSurface = reinterpret_cast(surface); - liteSurface->DoIpcMsg(ipcMsg, io); + liteSurface->DoIpcMsg(code, data, reply, option); return 0; } void LiteWMS::GetSurface(IpcIo* req, IpcIo* reply) { - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); GRAPHIC_LOGI("GetSurface,id=%d", id); LiteWindow* window = LiteWM::GetInstance()->GetWindowById(id); if (window == nullptr) { GRAPHIC_LOGE("window not found, id = %d", id); return; } - SvcIdentity svc; - int32_t ret = RegisterIpcCallback(SurfaceRequestHandler, 0, IPC_WAIT_FOREVER, &svc, window); - IpcIoPushInt32(reply, ret); - if (ret != LITEIPC_OK) { - GRAPHIC_LOGE("RegisterIpcCallback failed."); - return; - } - window->SetSid(svc); - IpcIoPushSvc(reply, &svc); + objectStub_.func = SurfaceRequestHandler; + objectStub_.args = window; + objectStub_.isRemote = false; + sid_.handle = IPC_INVALID_HANDLE; + sid_.token = SERVICE_TYPE_ANONYMOUS; + sid_.cookie = reinterpret_cast(&objectStub_); + window->SetSid(sid_); + WriteRemoteObject(reply, &sid_); } void LiteWMS::Show(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("Show"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->Show(id); } void LiteWMS::Hide(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("Hide"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->Hide(id); } void LiteWMS::RaiseToTop(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("RaiseToTop"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->RaiseToTop(id); } void LiteWMS::LowerToBottom(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("LowerToBottom"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->LowerToBottom(id); } void LiteWMS::MoveTo(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("MoveTo"); - int32_t id = IpcIoPopInt32(req); - uint32_t x = IpcIoPopUint32(req); - uint32_t y = IpcIoPopUint32(req); + int32_t id; + ReadInt32(req, &id); + uint32_t x; + ReadUint32(req, &x); + uint32_t y; + ReadUint32(req, &y); LiteWM::GetInstance()->MoveTo(id, x, y); } void LiteWMS::Resize(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("Resize"); - int32_t id = IpcIoPopInt32(req); - uint32_t width = IpcIoPopUint32(req); - uint32_t height = IpcIoPopUint32(req); + int32_t id; + ReadInt32(req, &id); + uint32_t width; + ReadUint32(req, &width); + uint32_t height; + ReadUint32(req, &height); LiteWM::GetInstance()->Resize(id, width, height); } void LiteWMS::Update(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("Update"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->UpdateWindow(id); } -void LiteWMS::CreateWindow(const void* origin, IpcIo* req, IpcIo* reply) +void LiteWMS::CreateWindow(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("CreateWindow"); - uint32_t size; - LiteWinConfig* config = static_cast(IpcIoPopFlatObj(req, &size)); + LiteWinConfig* config = static_cast(ReadRawData(req, sizeof(LiteWinConfig))); if (config != nullptr) { - pid_t pid = GetCallingPid(origin); + pid_t pid = GetCallingPid(); LiteWindow* window = LiteWM::GetInstance()->CreateWindow(*config, pid); if (window != nullptr) { - IpcIoPushInt32(reply, window->GetWindowId()); + WriteInt32(reply, window->GetWindowId()); return; } } - IpcIoPushInt32(reply, INVALID_WINDOW_ID); + WriteInt32(reply, INVALID_WINDOW_ID); } void LiteWMS::RemoveWindow(IpcIo* req, IpcIo* reply) { GRAPHIC_LOGI("RemoveWindow"); - int32_t id = IpcIoPopInt32(req); + int32_t id; + ReadInt32(req, &id); LiteWM::GetInstance()->RemoveWindow(id); } @@ -194,55 +203,48 @@ void LiteWMS::GetEventData(IpcIo* req, IpcIo* reply) { DeviceData data; LiteWM::GetInstance()->GetEventData(&data); - IpcIoPushFlatObj(reply, &data, sizeof(DeviceData)); + WriteRawData(reply, &data, sizeof(DeviceData)); } void LiteWMS::Screenshot(IpcIo* req, IpcIo* reply) { Surface* surface = SurfaceImpl::GenericSurfaceByIpcIo(*req); bool ret = LiteWM::GetInstance()->OnScreenshot(surface); - IpcIoPushInt32(reply, ret ? LiteWMS_EOK : LiteWMS_EUNKONW); + WriteInt32(reply, ret ? LiteWMS_EOK : LiteWMS_EUNKONW); } -void LiteWMS::ClientRegister(const void* origin, IpcIo* req, IpcIo* reply) +void LiteWMS::ClientRegister(IpcIo* req, IpcIo* reply) { - pid_t pid = GetCallingPid(origin); - SvcIdentity* sid = IpcIoPopSvc(req); - if (sid == nullptr) { + pid_t pid = GetCallingPid(); + SvcIdentity sid; + bool ret = ReadRemoteObject(req, &sid); + if (!ret) { return; } DeathCallbackArg* arg = new DeathCallbackArg; arg->pid = pid; - arg->sid = *sid; + arg->sid = sid; uint32_t cbId = -1; -#ifdef __LINUX__ - BinderAcquire(sid->ipcContext, sid->handle); - free(sid); - sid = nullptr; -#endif - if (RegisterDeathCallback(NULL, arg->sid, DeathCallback, arg, &cbId) != LITEIPC_OK) { - GRAPHIC_LOGE("RegisterDeathCallback failed!"); + if (AddDeathRecipient(arg->sid, DeathCallback, arg, &cbId) != 0) { + GRAPHIC_LOGE("AddDeathRecipient failed!"); } } -int32_t LiteWMS::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg) +void LiteWMS::DeathCallback(void* arg) { if (arg != nullptr) { DeathCallbackArg* cbArg = static_cast(arg); LiteWM::GetInstance()->OnClientDeathNotify(cbArg->pid); -#ifdef __LINUX__ - BinderRelease(cbArg->sid.ipcContext, cbArg->sid.handle); -#endif + ReleaseSvc(cbArg->sid); delete cbArg; } - return 0; } void LiteWMS::GetLayerInfo(IpcIo* req, IpcIo* reply) { LiteLayerInfo layerInfo = {}; LiteWM::GetInstance()->GetLayerInfo(layerInfo); - IpcIoPushFlatObj(reply, &layerInfo, sizeof(LiteLayerInfo)); + WriteRawData(reply, &layerInfo, sizeof(LiteLayerInfo)); } } // namespace OHOS \ No newline at end of file diff --git a/services/wms/lite_wms.h b/services/wms/lite_wms.h index 2bf84d0..5f26383 100755 --- a/services/wms/lite_wms.h +++ b/services/wms/lite_wms.h @@ -18,8 +18,7 @@ #include "gfx_utils/geometry2d.h" #include "lite_wm_type.h" -#include "liteipc_adapter.h" -#include "serializer.h" +#include "ipc_skeleton.h" namespace OHOS { class LiteWMS { @@ -36,8 +35,8 @@ public: private: LiteWMS(){}; ~LiteWMS() {} - static int32_t SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg); - static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg); + static int32_t SurfaceRequestHandler(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option); + static void DeathCallback(void* arg); void GetSurface(IpcIo* req, IpcIo* reply); void Show(IpcIo* req, IpcIo* reply); @@ -47,12 +46,14 @@ private: void MoveTo(IpcIo* req, IpcIo* reply); void Resize(IpcIo* req, IpcIo* reply); void Update(IpcIo* req, IpcIo* reply); - void CreateWindow(const void* origin, IpcIo* req, IpcIo* reply); + void CreateWindow(IpcIo* req, IpcIo* reply); void RemoveWindow(IpcIo* req, IpcIo* reply); void GetEventData(IpcIo* req, IpcIo* reply); void Screenshot(IpcIo* req, IpcIo* reply); - void ClientRegister(const void* origin, IpcIo* req, IpcIo* reply); + void ClientRegister(IpcIo* req, IpcIo* reply); void GetLayerInfo(IpcIo* req, IpcIo* reply); + SvcIdentity sid_; + IpcObjectStub objectStub_; }; } // namespace OHOS #endif -- Gitee