提交 c1970b93 编写于 作者: Y yangguangzhao

code review fixed

Signed-off-by: Nyangguangzhao <yangguangzhao1@huawei.com>
上级 79e70a70
...@@ -16,44 +16,18 @@ ...@@ -16,44 +16,18 @@
#ifndef DBINDER_SERVICE_H #ifndef DBINDER_SERVICE_H
#define DBINDER_SERVICE_H #define DBINDER_SERVICE_H
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "dbinder_types.h"
#include "utils_list.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif #endif
#endif #endif
typedef struct {
struct DHandleEntryHead head;
uint32_t transType;
uint32_t dBinderCode;
uint16_t fromPort;
uint16_t toPort;
uint64_t stubIndex;
uint32_t seqNumber;
uintptr_t binderObject;
struct DeviceIdInfo deviceIdInfo;
uintptr_t stub;
uint16_t serviceNameLength;
char serviceName[SERVICENAME_LENGTH + 1];
uint32_t pid;
uint32_t uid;
} DHandleEntryTxRx;
int32_t StartDBinderService(void); int32_t StartDBinderService(void);
int32_t RegisterRemoteProxy(const void *name, uint32_t len, int32_t systemAbility); int32_t RegisterRemoteProxy(const void *name, uint32_t len, int32_t systemAbility);
int32_t MakeRemoteBinder(const void *serviceName, uint32_t nameLen, const char *deviceID, uint32_t idLen, int32_t MakeRemoteBinder(const void *serviceName, uint32_t nameLen, const char *deviceID, uint32_t idLen,
uintptr_t binderObject, uint64_t pid, void *remoteObject); uintptr_t binderObject, uint64_t pid, void *remoteObject);
int32_t OnRemoteMessageTask(const DHandleEntryTxRx *message);
SessionInfo *QuerySessionObject(uintptr_t stub);
void DetachProxyObject(ProxyObject *proxy);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "rpc_process_skeleton.h" #include "rpc_process_skeleton.h"
#include "dbinder_invoker.h" #include "dbinder_invoker.h"
#include "dbinder_types.h" #include "dbinder_types.h"
#include "dbinder_service_inner.h"
#include "rpc_errno.h" #include "rpc_errno.h"
#include "rpc_log.h" #include "rpc_log.h"
......
...@@ -34,10 +34,10 @@ typedef struct { ...@@ -34,10 +34,10 @@ typedef struct {
int32_t (*Connect)(const char *SaSessionName, const char *peerDeviceId, void *args); int32_t (*Connect)(const char *SaSessionName, const char *peerDeviceId, void *args);
int32_t (*Disconnect)(int32_t sessionId); int32_t (*Disconnect)(int32_t sessionId);
int32_t (*Send)(int32_t sessionId, const void *data, uint32_t len); int32_t (*Send)(int32_t sessionId, const void *data, uint32_t len);
char (*GetLocalDeviceID)(void);
} TransInterface; } TransInterface;
TransInterface *GetRpcTrans(void); TransInterface *GetRpcTrans(void);
char *GetLocalDeviceID(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -29,12 +29,3 @@ TransInterface *GetRpcTrans(void) ...@@ -29,12 +29,3 @@ TransInterface *GetRpcTrans(void)
return NULL; return NULL;
} }
char *GetLocalDeviceID(void)
{
#if defined(RPC_SOCKET_TRANS)
return GetSocketLocalDeviceID();
#endif
return NULL;
}
\ No newline at end of file
...@@ -106,13 +106,8 @@ int main(int argc, char *argv[]) ...@@ -106,13 +106,8 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
RPC_LOG_INFO("argv 1 is %s", argv[1]);
if (strcmp(argv[1], "deviceId") == 0) {
RPC_LOG_INFO("local deviceId is %s", GetLocalDeviceID());
return 0;
}
const char *deviceId = argv[1]; const char *deviceId = argv[1];
RPC_LOG_INFO("input deviceid is %s", deviceId);
IpcIo data1; IpcIo data1;
uint8_t tmpData1[IPC_LENGTH]; uint8_t tmpData1[IPC_LENGTH];
......
...@@ -34,7 +34,6 @@ static const uint16_t DEFAULT_HASH_SEED = 5381; ...@@ -34,7 +34,6 @@ static const uint16_t DEFAULT_HASH_SEED = 5381;
static const uint16_t DEFAULT_PORT_MIN = 10000; static const uint16_t DEFAULT_PORT_MIN = 10000;
TransInterface *GetSocketTrans(void); TransInterface *GetSocketTrans(void);
char *GetSocketLocalDeviceID(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -353,12 +353,28 @@ static int32_t Send(int32_t sessionId, const void *data, uint32_t len) ...@@ -353,12 +353,28 @@ static int32_t Send(int32_t sessionId, const void *data, uint32_t len)
return ERR_NONE; return ERR_NONE;
} }
static char *GetSocketLocalDeviceID(void)
{
extern struct netif if_wifi;
uint32_t ip = ((ip4_addr_t *)&if_wifi.ip_addr)->addr;
char *localDeviceId = inet_ntoa(ip);
if (localDeviceId == NULL) {
RPC_LOG_ERROR("GetSocketLocalDeviceID inet_ntoa return null");
return NULL;
}
RPC_LOG_INFO("GetSocketLocalDeviceID %s\n", localDeviceId);
return localDeviceId;
}
static TransInterface g_socketTrans = { static TransInterface g_socketTrans = {
.StartListen = StartListen, .StartListen = StartListen,
.StopListen = StopListen, .StopListen = StopListen,
.Connect = Connect, .Connect = Connect,
.Disconnect = Disconnect, .Disconnect = Disconnect,
.Send = Send .Send = Send,
.GetLocalDeviceID = GetSocketLocalDeviceID
}; };
TransInterface *GetSocketTrans(void) TransInterface *GetSocketTrans(void)
...@@ -372,18 +388,3 @@ TransInterface *GetSocketTrans(void) ...@@ -372,18 +388,3 @@ TransInterface *GetSocketTrans(void)
} }
return &g_socketTrans; return &g_socketTrans;
} }
\ No newline at end of file
char *GetSocketLocalDeviceID(void)
{
extern struct netif if_wifi;
uint32_t ip = ((ip4_addr_t *)&if_wifi.ip_addr)->addr;
char *localDeviceId = inet_ntoa(ip);
if (localDeviceId == NULL) {
RPC_LOG_ERROR("GetSocketLocalDeviceID inet_ntoa return null");
return NULL;
}
RPC_LOG_INFO("GetSocketLocalDeviceID %s\n", localDeviceId);
return localDeviceId;
}
\ No newline at end of file
...@@ -296,26 +296,7 @@ static int32_t Send(int32_t sessionId, const void *data, uint32_t len) ...@@ -296,26 +296,7 @@ static int32_t Send(int32_t sessionId, const void *data, uint32_t len)
return ERR_NONE; return ERR_NONE;
} }
static TransInterface g_socketTrans = { static char *GetSocketLocalDeviceID(void)
.StartListen = StartListen,
.StopListen = StopListen,
.Connect = Connect,
.Disconnect = Disconnect,
.Send = Send
};
TransInterface *GetSocketTrans(void)
{
if (g_init == -1) {
pthread_mutex_lock(&g_socketNodeList.mutex);
UtilsListInit(&g_socketNodeList.list);
g_init = 0;
pthread_mutex_unlock(&g_socketNodeList.mutex);
}
return &g_socketTrans;
}
char *GetSocketLocalDeviceID(void)
{ {
if (g_localDeviceId != NULL) { if (g_localDeviceId != NULL) {
return g_localDeviceId; return g_localDeviceId;
...@@ -366,3 +347,23 @@ char *GetSocketLocalDeviceID(void) ...@@ -366,3 +347,23 @@ char *GetSocketLocalDeviceID(void)
return g_localDeviceId; return g_localDeviceId;
} }
static TransInterface g_socketTrans = {
.StartListen = StartListen,
.StopListen = StopListen,
.Connect = Connect,
.Disconnect = Disconnect,
.Send = Send,
.GetLocalDeviceID = GetSocketLocalDeviceID,
};
TransInterface *GetSocketTrans(void)
{
if (g_init == -1) {
pthread_mutex_lock(&g_socketNodeList.mutex);
UtilsListInit(&g_socketNodeList.list);
g_init = 0;
pthread_mutex_unlock(&g_socketNodeList.mutex);
}
return &g_socketTrans;
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DBINDER_SERVICE_INNER_H
#define DBINDER_SERVICE_INNER_H
#include "dbinder_types.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int32_t OnRemoteMessageTask(const DHandleEntryTxRx *message);
SessionInfo *QuerySessionObject(uintptr_t stub);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* DBINDER_SERVICE_INNER_H */
\ No newline at end of file
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "rpc_trans.h" #include "rpc_trans.h"
#include "dbinder_service.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -99,6 +99,23 @@ typedef struct { ...@@ -99,6 +99,23 @@ typedef struct {
char *buffer; char *buffer;
} dbinder_transaction_data; } dbinder_transaction_data;
typedef struct {
struct DHandleEntryHead head;
uint32_t transType;
uint32_t dBinderCode;
uint16_t fromPort;
uint16_t toPort;
uint64_t stubIndex;
uint32_t seqNumber;
uintptr_t binderObject;
struct DeviceIdInfo deviceIdInfo;
uintptr_t stub;
uint16_t serviceNameLength;
char serviceName[SERVICENAME_LENGTH + 1];
uint32_t pid;
uint32_t uid;
} DHandleEntryTxRx;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "rpc_trans.h" #include "rpc_trans.h"
#include "dbinder_trans_callback.h" #include "dbinder_trans_callback.h"
#include "dbinder_ipc_adapter.h" #include "dbinder_ipc_adapter.h"
#include "dbinder_service_inner.h"
#include "serializer.h" #include "serializer.h"
#include "dbinder_stub.h" #include "dbinder_stub.h"
#include "ipc_skeleton.h" #include "ipc_skeleton.h"
...@@ -214,7 +215,7 @@ static int32_t SendEntryToRemote(DBinderServiceStub *stub, const uint32_t seqNum ...@@ -214,7 +215,7 @@ static int32_t SendEntryToRemote(DBinderServiceStub *stub, const uint32_t seqNum
} }
uint32_t toDeviceIDLength = (uint32_t)strlen(toDeviceID); uint32_t toDeviceIDLength = (uint32_t)strlen(toDeviceID);
char *localDeviceID = GetLocalDeviceID(); char *localDeviceID = g_trans->GetLocalDeviceID();
if (localDeviceID == NULL) { if (localDeviceID == NULL) {
RPC_LOG_ERROR("GetLocalDeviceID failed"); RPC_LOG_ERROR("GetLocalDeviceID failed");
return ERR_FAILED; return ERR_FAILED;
...@@ -400,7 +401,7 @@ static int32_t AttachProxyObject(ProxyObject *proxy) ...@@ -400,7 +401,7 @@ static int32_t AttachProxyObject(ProxyObject *proxy)
return ERR_NONE; return ERR_NONE;
} }
void DetachProxyObject(ProxyObject *proxy) static void DetachProxyObject(ProxyObject *proxy)
{ {
pthread_mutex_lock(&g_proxyObjectList.mutex); pthread_mutex_lock(&g_proxyObjectList.mutex);
UtilsListDelete(&proxy->list); UtilsListDelete(&proxy->list);
...@@ -496,7 +497,7 @@ static int32_t OnRemoteInvokerDataBusMessage(ProxyObject *proxy, DHandleEntryTxR ...@@ -496,7 +497,7 @@ static int32_t OnRemoteInvokerDataBusMessage(ProxyObject *proxy, DHandleEntryTxR
IpcIo reply; IpcIo reply;
uintptr_t ptr; uintptr_t ptr;
int32_t ret = InvokerListenThread(proxy, GetLocalDeviceID(), remoteDeviceID, pid, uid, &reply, &ptr); int32_t ret = InvokerListenThread(proxy, g_trans->GetLocalDeviceID(), remoteDeviceID, pid, uid, &reply, &ptr);
if (ret != ERR_NONE) { if (ret != ERR_NONE) {
RPC_LOG_ERROR("INVOKE_LISTEN_THREAD failed"); RPC_LOG_ERROR("INVOKE_LISTEN_THREAD failed");
FreeBuffer((void *)ptr); FreeBuffer((void *)ptr);
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include "ipc_thread_pool.h" #include "ipc_thread_pool.h"
#include "ipc_skeleton.h" #include "ipc_skeleton.h"
#include "ipc_process_skeleton.h" #include "ipc_process_skeleton.h"
#include "dbinder_service.h"
#include "dbinder_ipc_adapter.h" #include "dbinder_ipc_adapter.h"
#include "dbinder_service_inner.h"
#define IPC_INVALID_HANDLE (-1) #define IPC_INVALID_HANDLE (-1)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "dbinder_service.h" #include "dbinder_service_inner.h"
#include "rpc_log.h" #include "rpc_log.h"
#include "rpc_errno.h" #include "rpc_errno.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册