Description: IPC switching interface

IssueNo: https://gitee.com/openharmony/communication_ipc/issues/I52D5F
Feature or Bugfix: Bugfix
Binary Source:No
Signed-off-by: xing-tai-zhang <zhangxingtai@huawei.com>
This commit is contained in:
xing-tai-zhang
2022-05-06 19:01:10 +08:00
parent d7405591fc
commit 20ae0f3e23
12 changed files with 160 additions and 150 deletions
+1 -1
View File
@@ -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",
+2 -2
View File
@@ -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 <pthread.h>
#include <map>
@@ -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
+12 -10
View File
@@ -18,6 +18,7 @@
#include "samgr_lite.h"
namespace OHOS {
static IpcObjectStub objectStub;
InputEventListenerProxy::RawEventListener* InputEventListenerProxy::listener_ = nullptr;
InputEventListenerProxy::~InputEventListenerProxy()
{
@@ -50,20 +51,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<RawEvent*>(IpcIoPopFlatObj(io, &size));
RawEvent* eventTemp = static_cast<RawEvent*>(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 +80,16 @@ 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;
svc.handle = IPC_INVALID_HANDLE;
svc.token = SERVICE_TYPE_ANONYMOUS;
svc.cookie = reinterpret_cast<uintptr_t>(&objectStub);
WriteRemoteObject(&io, &svc);
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);
+15 -14
View File
@@ -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) {
+32 -27
View File
@@ -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<DeviceData*>(IpcIoPopFlatObj(reply, &size));
DeviceData* data = static_cast<DeviceData*>(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<LiteLayerInfo*>(IpcIoPopFlatObj(reply, &size));
LiteLayerInfo* data = static_cast<LiteLayerInfo*>(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,16 +98,23 @@ 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.");
IpcObjectStub* objectStub = new IpcObjectStub();
if (objectStub == nullptr) {
return;
}
IpcIoPushSvc(&io, &svc);
SvcIdentity svc;
objectStub->func = WmsMsgHandler;
objectStub->args = nullptr;
objectStub->isRemote = false;
svc.handle = IPC_INVALID_HANDLE;
svc.token = SERVICE_TYPE_ANONYMOUS;
svc.cookie = reinterpret_cast<uintptr_t>(objectStub);
WriteRemoteObject(&io, &svc);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_ClientRegister, &io, NULL, Callback);
if (ret != 0) {
GRAPHIC_LOGE("ClientRegister failed, ret=%d", ret);
}
delete objectStub;
}
void LiteWMRequestor::GetLayerInfo()
@@ -130,7 +137,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 +156,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 +176,18 @@ void LiteWMRequestor::GetEventData(DeviceData* data)
(void)proxy_->Invoke(proxy_, LiteWMS_GetEventData, &io, &para, 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,23 +230,22 @@ 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<uintptr_t>(&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, &para, Callback);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Screenshot, &io, &para, Callback);
if (ret != 0) {
GRAPHIC_LOGE("Screenshot failed, ret=%d", ret);
}
}
} // namespace OHOS
} // namespace OHOS
+5 -4
View File
@@ -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
#endif
@@ -17,9 +17,8 @@
#define GRAPHIC_LITE_IMS_CLIENT_PROXY_H
#include <iproxy_client.h>
#include "ipc_skeleton.h"
#include "gfx_utils/input_event_info.h"
#include "liteipc_adapter.h"
namespace OHOS {
class InputEventListenerProxy {
@@ -71,7 +70,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_;
+17 -25
View File
@@ -48,21 +48,17 @@ 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<void*>(origin), &cbId) != LITEIPC_OK) {
if (AddDeathRecipient(svc, DeathCallback, nullptr, &cbId) != 0) {
GRAPHIC_LOGE("Register death callback failed!");
return;
}
@@ -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<const void*>(&event), sizeof(RawEvent));
WriteRawData(&io, static_cast<const void*>(&event), sizeof(RawEvent));
pthread_mutex_lock(&lock_);
std::map<pid_t, ClientInfo>::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;
+6 -4
View File
@@ -57,10 +57,12 @@ LiteWindow::LiteWindow(const LiteWinConfig& config)
LiteWindow::~LiteWindow()
{
if (needUnregister_) {
GRAPHIC_LOGI("UnregisterIpcCallback");
UnregisterIpcCallback(sid_);
GRAPHIC_LOGI("release svc cookie");
if (sid_.cookie != 0) {
delete reinterpret_cast<IpcObjectStub*>(sid_.cookie);
sid_.cookie = 0;
}
}
if (surface_ != nullptr) {
if (backBuf_ != nullptr) {
surface_->CancelBuffer(backBuf_);
@@ -273,4 +275,4 @@ void LiteWindow::Resize(int16_t width, int16_t height)
config_.rect.Resize(width, height);
ResizeSurface(width, height);
}
}
}
+2 -1
View File
@@ -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_;
};
}
+61 -53
View File
@@ -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<LiteWindow*>(arg);
LiteWindow* window = reinterpret_cast<LiteWindow*>(option.args);
if (code == 0) {
GRAPHIC_LOGI("requestBuffer");
window->UpdateBackBuf();
@@ -90,103 +88,120 @@ int32_t LiteWMS::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg,
Surface* surface = window->GetSurface();
SurfaceImpl* liteSurface = reinterpret_cast<SurfaceImpl*>(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.");
IpcObjectStub* objectStub = new IpcObjectStub();
if (objectStub == nullptr) {
return;
}
SvcIdentity svc;
objectStub->func = SurfaceRequestHandler;
objectStub->args = window;
objectStub->isRemote = false;
svc.handle = IPC_INVALID_HANDLE;
svc.token = SERVICE_TYPE_ANONYMOUS;
svc.cookie = reinterpret_cast<uintptr_t>(objectStub);
WriteInt32(reply, 0);
window->SetSid(svc);
IpcIoPushSvc(reply, &svc);
WriteRemoteObject(reply, &svc);
}
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<LiteWinConfig*>(IpcIoPopFlatObj(req, &size));
LiteWinConfig* config = static_cast<LiteWinConfig*>(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 +209,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_EUNKNOWN);
WriteInt32(reply, ret ? LiteWMS_EOK : LiteWMS_EUNKNOWN);
}
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<DeathCallbackArg*>(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
} // namespace OHOS
+5 -6
View File
@@ -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,11 +46,11 @@ 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);
};
} // namespace OHOS