提交 79e70a70 编写于 作者: Y yangguangzhao

make UpdateProto in one way on mini and small system

Signed-off-by: Nyangguangzhao <yangguangzhao1@huawei.com>
上级 78d7e61d
......@@ -72,7 +72,7 @@ int32_t OnRemoteRequestInner(uint32_t code, IpcIo *data, IpcIo *reply,
bool OnThreadTerminated(pthread_t threadId);
void SendObituary(DeathCallback *deathCallback);
void DeleteDeathCallback(DeathCallback *deathCallback);
void WaitForProxyInit(int32_t handle);
void WaitForProxyInit(SvcIdentity *svc);
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -270,7 +270,7 @@ static uint32_t SetDeathHandlerPair(DeathCallback *node, uint32_t index, OnRemot
int32_t ProcessAddDeathRecipient(int32_t handle, OnRemoteDead deathFunc, void *args, uint32_t *cbId)
{
int32_t ret = ERR_NONE;
int32_t ret = ERR_INVALID_PARAM;
if (g_ipcSkeleton == NULL) {
return ERR_IPC_SKELETON_NOT_INIT;
}
......@@ -419,9 +419,9 @@ void DeleteDeathCallback(DeathCallback *deathCallback)
free(deathCallback);
}
void WaitForProxyInit(int32_t handle)
void WaitForProxyInit(SvcIdentity *svc)
{
RPC_LOG_INFO("ipc skeleton wait for proxy init");
OnFirstStrongRef(handle);
UpdateProtoIfNeed(handle);
OnFirstStrongRef(svc->handle);
UpdateProtoIfNeed(svc);
}
\ No newline at end of file
......@@ -202,7 +202,7 @@ bool ReadRemoteObject(IpcIo *io, SvcIdentity *svc)
svc->handle = MIN_BINDER_HANDLE;
svc->cookie = obj->cookie;
} else {
WaitForProxyInit(obj->handle);
WaitForProxyInit(obj);
svc->handle = obj->handle;
svc->cookie = obj->cookie;
}
......@@ -273,7 +273,7 @@ bool ReadRemoteObject(IpcIo *io, SvcIdentity *svc)
svc->handle = svcId->handle;
svc->token = svcId->token;
svc->cookie = svcId->cookie;
WaitForProxyInit(svcId->handle);
WaitForProxyInit(svcId);
return true;
}
......
......@@ -134,7 +134,7 @@ ThreadMessageInfo *QueryThreadBySeqNumber(uint64_t seqNumber);
void WakeUpThreadBySeqNumber(uint64_t seqNumber, uint32_t handle);
int32_t RpcOnRemoteRequestInner(uint32_t code, IpcIo *data, IpcIo *reply,
MessageOption option, IpcObjectStub *objectStub);
void UpdateProtoIfNeed(int32_t handle);
void UpdateProtoIfNeed(SvcIdentity *svc);
void WakeUpDataThread(pthread_t threadId);
uint64_t GetNewStubIndex(void);
......
......@@ -29,7 +29,7 @@ int32_t InvokerListenThread(ProxyObject *proxyObject, const char *localDeviceID,
const char *remoteDeviceID, uint32_t pid, uint32_t uid, IpcIo *reply, uintptr_t *ptr);
int32_t GetPidAndUidInfo(ProxyObject *proxy);
char *GetDataBusName(void);
void UpdateProto(int32_t handle);
void UpdateProto(SvcIdentity *svc);
#ifdef __cplusplus
}
......
......@@ -169,12 +169,12 @@ static char *CreateDatabusName(void)
return sessionName;
}
static int GetSessionFromDBinderService(uint32_t handle)
static int GetSessionFromDBinderService(SvcIdentity *svc)
{
RPC_LOG_INFO("GetSessionFromDBinderService start");
int32_t proto = IF_PROT_DATABUS;
SessionInfo *session = QuerySessionObject((uintptr_t)handle);
SessionInfo *session = QuerySessionObject(svc->cookie);
if (session == NULL) {
RPC_LOG_ERROR("client find session is null");
return proto;
......@@ -197,7 +197,7 @@ static int GetSessionFromDBinderService(uint32_t handle)
free(sessionObject);
return proto;
}
handleToIndex->handle = handle;
handleToIndex->handle = svc->handle;
handleToIndex->index = session->stubIndex;
if (AttachHandleToIndex(handleToIndex) != ERR_NONE) {
......@@ -216,14 +216,14 @@ static int GetSessionFromDBinderService(uint32_t handle)
return proto;
}
UpdateClientSession(handle, sessionObject, localBusName, session->serviceName, session->deviceIdInfo.toDeviceId);
UpdateClientSession(svc->handle, sessionObject, localBusName, session->serviceName, session->deviceIdInfo.toDeviceId);
return proto;
}
void UpdateProto(int32_t handle)
void UpdateProto(SvcIdentity *svc)
{
if (handle < 0) {
if (svc->handle < 0) {
RPC_LOG_ERROR("UpdateProto handle invalid");
return;
}
......@@ -233,11 +233,11 @@ void UpdateProto(int32_t handle)
RPC_LOG_ERROR("UpdateProto threadContext is null");
return;
}
HandleSessionList *sessionObject = QueryProxySession(handle);
HandleSessionList *sessionObject = QueryProxySession(svc->handle);
if (sessionObject != NULL) {
threadContext->proto = IF_PROT_DATABUS;
return;
}
threadContext->proto = GetSessionFromDBinderService(handle);
threadContext->proto = GetSessionFromDBinderService(svc);
RPC_LOG_INFO("UpdateProto get proto: %d", threadContext->proto);
}
\ No newline at end of file
......@@ -225,9 +225,9 @@ char *GetDataBusName(void)
return sessionName;
}
void UpdateProto(int32_t handle)
void UpdateProto(SvcIdentity *svc)
{
if (handle < 0) {
if (svc->handle < 0) {
RPC_LOG_ERROR("UpdateProto handle invalid");
return;
}
......@@ -237,11 +237,11 @@ void UpdateProto(int32_t handle)
RPC_LOG_ERROR("UpdateProto threadContext is null");
return;
}
HandleSessionList *sessionObject = QueryProxySession(handle);
HandleSessionList *sessionObject = QueryProxySession(svc->handle);
if (sessionObject != NULL) {
threadContext->proto = IF_PROT_DATABUS;
return;
}
threadContext->proto = GetSessionFromDBinderService(handle);
threadContext->proto = GetSessionFromDBinderService(svc->handle);
RPC_LOG_INFO("UpdateProto get proto: %d", threadContext->proto);
}
\ No newline at end of file
......@@ -482,10 +482,10 @@ int32_t RpcOnRemoteRequestInner(uint32_t code, IpcIo *data, IpcIo *reply, Messag
return result;
}
void UpdateProtoIfNeed(int32_t handle)
void UpdateProtoIfNeed(SvcIdentity *svc)
{
RPC_LOG_INFO("rpc manager update proto, handle %d", handle);
UpdateProto(handle);
RPC_LOG_INFO("rpc manager update proto, handle %d", svc->handle);
UpdateProto(svc);
}
uint64_t GetNewStubIndex(void)
......
......@@ -34,7 +34,7 @@ int32_t RpcOnRemoteRequestInner(uint32_t code, IpcIo *data, IpcIo *reply, Messag
return ERR_NOT_RPC;
}
void UpdateProtoIfNeed(int32_t handle)
void UpdateProtoIfNeed(SvcIdentity *svc)
{
return;
}
......
......@@ -26,9 +26,9 @@ extern "C" {
void RpcStartSamgr(void);
int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid);
SvcIdentity *GetSystemAbilityById(int32_t systemAbility);
int32_t AddRemoteSystemAbility(int32_t saId, SvcIdentity *sid);
int32_t GetRemoteSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid);
int32_t GetSystemAbilityById(int32_t systemAbility, IpcIo *reply);
int32_t AddRemoteSystemAbility(IpcIo *data);
int32_t GetRemoteSystemAbility(int32_t saId, const char* deviceId, IpcIo *reply);
#ifdef __cplusplus
}
......
......@@ -37,6 +37,14 @@ static UTILS_DL_LIST *g_saList = NULL;
static pthread_mutex_t g_handleMutex = PTHREAD_MUTEX_INITIALIZER;
static int32_t g_handle = 0;
static int32_t GetNextHandle(void)
{
pthread_mutex_lock(&g_handleMutex);
int32_t handle = ++g_handle;
pthread_mutex_unlock(&g_handleMutex);
return handle;
}
int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid)
{
RPC_LOG_INFO("AddSystemAbility called.... handle = %d", sid->handle);
......@@ -59,15 +67,12 @@ int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid)
return ERR_FAILED;
}
pthread_mutex_lock(&g_handleMutex);
node->sid->handle = ++g_handle;
pthread_mutex_unlock(&g_handleMutex);
node->sid->handle = GetNextHandle();
UtilsListAdd(g_saList, &node->list);
return ERR_NONE;
}
SvcIdentity *GetSystemAbilityById(int32_t systemAbility)
int32_t GetSystemAbilityById(int32_t systemAbility, IpcIo *reply)
{
SvcInfo* node = NULL;
SvcInfo* next = NULL;
......@@ -75,15 +80,22 @@ SvcIdentity *GetSystemAbilityById(int32_t systemAbility)
{
RPC_LOG_INFO("GetSystemAbilityById %d", node->saId);
if (node->saId == systemAbility) {
return node->sid;
WriteRemoteObject(reply, node->sid);
reply->bufferCur = reply->bufferBase;
reply->offsetsCur = reply->offsetsCur;
return ERR_NONE;
}
}
return NULL;
return ERR_FAILED;
}
int32_t AddRemoteSystemAbility(int32_t saId, SvcIdentity *sid)
int32_t AddRemoteSystemAbility(IpcIo *data)
{
if (AddSystemAbility(saId, sid) == ERR_FAILED) {
int32_t saId;
ReadInt32(data, &saId);
SvcIdentity sid;
ReadRemoteObject(data, &sid);
if (AddSystemAbility(saId, &sid) == ERR_FAILED) {
RPC_LOG_ERROR("AddSystemAbility failed");
return ERR_FAILED;
}
......@@ -97,16 +109,22 @@ int32_t AddRemoteSystemAbility(int32_t saId, SvcIdentity *sid)
return ERR_NONE;
}
int32_t GetRemoteSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid)
int32_t GetRemoteSystemAbility(int32_t saId, const char* deviceId, IpcIo *reply)
{
RPC_LOG_INFO("GetRemoteSystemAbility start");
const char *name = "16";
uint32_t idLen = (uint32_t)strlen(deviceId);
int32_t ret = MakeRemoteBinder(name, 2, deviceId, idLen, (uintptr_t)saId, 0, (void *)sid);
SvcIdentity sid;
int32_t ret = MakeRemoteBinder(name, 2, deviceId, idLen, (uintptr_t)saId, 0, &sid);
if (ret != ERR_NONE) {
RPC_LOG_ERROR("MakeRemoteBinder failed");
}
sid.handle = GetNextHandle();
RPC_LOG_INFO("GetRemoteSystemAbility sid handle=%d", sid.handle);
WriteRemoteObject(reply, &sid);
reply->bufferCur = reply->bufferBase;
reply->offsetsCur = reply->offsetsBase;
return ret;
}
......@@ -117,6 +135,11 @@ void RpcStartSamgr(void)
g_saList = (UTILS_DL_LIST *)calloc(1, sizeof(UTILS_DL_LIST));
UtilsListInit(g_saList);
SvcIdentity target = {
.cookie = 0
};
(void)SetContextObject(target);
StartDBinderService();
RPC_LOG_INFO("StartDBinderService finished");
......
......@@ -28,8 +28,6 @@ extern "C" {
bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
const char *deviceID, uintptr_t binderObject);
int32_t GetDBinderHandle(uintptr_t stubAddr);
int32_t UpdateSessionIfNeed(uintptr_t stubAddr);
ProxyObject *RpcGetSystemAbility(int32_t systemAbility);
#ifdef __cplusplus
......
......@@ -28,24 +28,17 @@ bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
return false;
}
int32_t GetDBinderHandle(uintptr_t stubAddr)
{
return (int32_t)stubAddr;
}
int32_t UpdateSessionIfNeed(uintptr_t stubAddr)
{
UpdateProto((int32_t)stubAddr);
return ERR_NONE;
}
ProxyObject *RpcGetSystemAbility(int32_t systemAbility)
{
SvcIdentity *target = GetSystemAbilityById(systemAbility);
if (target == NULL) {
RPC_LOG_ERROR("GetSystemAbilityById return null");
IpcIo reply;
uint8_t replyAlloc[RPC_IPC_LENGTH];
IpcIoInit(&reply, replyAlloc, RPC_IPC_LENGTH, 0);
if (GetSystemAbilityById(systemAbility, &reply) != ERR_NONE) {
RPC_LOG_ERROR("GetSystemAbilityById failed");
return NULL;
}
SvcIdentity target;
ReadRemoteObject(&reply, &target);
ProxyObject *proxyObject = (ProxyObject *)calloc(1, sizeof(ProxyObject));
if (proxyObject == NULL) {
......@@ -57,7 +50,7 @@ ProxyObject *RpcGetSystemAbility(int32_t systemAbility)
return NULL;
}
if (memcpy_s(proxyObject->proxy, sizeof(SvcIdentity), target, sizeof(SvcIdentity)) != EOK) {
if (memcpy_s(proxyObject->proxy, sizeof(SvcIdentity), &target, sizeof(SvcIdentity)) != EOK) {
free(proxyObject->proxy);
free(proxyObject);
return NULL;
......
......@@ -23,8 +23,6 @@
#include "rpc_log.h"
#include "rpc_errno.h"
#define IPC_STUB_HANDLE (-1)
bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
const char *deviceID, uintptr_t binderObject)
{
......@@ -35,16 +33,6 @@ bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
&& stub->binderObject == binderObject);
}
int32_t GetDBinderHandle(uintptr_t stubAddr)
{
return IPC_STUB_HANDLE;
}
int32_t UpdateSessionIfNeed(uintptr_t stubAddr)
{
return ERR_NONE;
}
ProxyObject *RpcGetSystemAbility(int32_t systemAbility)
{
IpcIo data;
......
......@@ -319,11 +319,6 @@ static int32_t InvokerRemoteDBinder(DBinderServiceStub *dBinderServiceStub, uint
ret = ERR_FAILED;
}
if (UpdateSessionIfNeed(dBinderServiceStub->svc.cookie) != ERR_NONE) {
RPC_LOG_ERROR("UpdateSessionIfNeed failed");
ret = ERR_FAILED;
}
pthread_mutex_unlock(&threadLockInfo->mutex);
DetachThreadLockInfo(threadLockInfo);
free(threadLockInfo);
......
......@@ -27,6 +27,8 @@
#include "dbinder_service.h"
#include "dbinder_ipc_adapter.h"
#define IPC_INVALID_HANDLE (-1)
static int32_t GetDigits(int32_t number)
{
int32_t n = 0;
......@@ -135,7 +137,7 @@ int32_t GetDBinderStub(const char *serviceName, const char *deviceID,
objectStub->isRemote = true;
dBinderServiceStub->binderObject = binderObject;
dBinderServiceStub->svc.handle = GetDBinderHandle((uintptr_t)objectStub);
dBinderServiceStub->svc.handle = IPC_INVALID_HANDLE;
dBinderServiceStub->svc.token = (uintptr_t)objectStub;
dBinderServiceStub->svc.cookie = (uintptr_t)objectStub;
return ERR_NONE;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册