Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
02fc38af
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
02fc38af
编写于
5月 11, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 11, 2023
浏览文件
操作
浏览文件
下载
差异文件
!665 decouple data in ipc_core and ipc_single
Merge pull request !665 from wanghaoxu/master
上级
db6e9dfe
6d0c4773
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
222 addition
and
114 deletion
+222
-114
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
+0
-1
ipc/native/src/core/include/ipc_process_skeleton.h
ipc/native/src/core/include/ipc_process_skeleton.h
+6
-12
ipc/native/src/core/include/process_skeleton.h
ipc/native/src/core/include/process_skeleton.h
+12
-2
ipc/native/src/core/source/ipc_object_proxy.cpp
ipc/native/src/core/source/ipc_object_proxy.cpp
+0
-1
ipc/native/src/core/source/ipc_object_stub.cpp
ipc/native/src/core/source/ipc_object_stub.cpp
+0
-1
ipc/native/src/core/source/ipc_process_skeleton.cpp
ipc/native/src/core/source/ipc_process_skeleton.cpp
+69
-72
ipc/native/src/core/source/ipc_skeleton.cpp
ipc/native/src/core/source/ipc_skeleton.cpp
+0
-1
ipc/native/src/core/source/ipc_thread_skeleton.cpp
ipc/native/src/core/source/ipc_thread_skeleton.cpp
+1
-3
ipc/native/src/core/source/iremote_object.cpp
ipc/native/src/core/source/iremote_object.cpp
+0
-1
ipc/native/src/core/source/process_skeleton.cpp
ipc/native/src/core/source/process_skeleton.cpp
+68
-0
ipc/native/src/mock/include/binder_connector.h
ipc/native/src/mock/include/binder_connector.h
+0
-1
ipc/native/src/mock/include/invoker_factory.h
ipc/native/src/mock/include/invoker_factory.h
+0
-1
ipc/native/src/mock/include/iremote_invoker.h
ipc/native/src/mock/include/iremote_invoker.h
+0
-1
ipc/native/src/mock/source/binder_connector.cpp
ipc/native/src/mock/source/binder_connector.cpp
+0
-1
ipc/native/test/unittest/common/BUILD.gn
ipc/native/test/unittest/common/BUILD.gn
+2
-0
ipc/native/test/unittest/common/dbinder_callback_stub_unittest.cpp
...e/test/unittest/common/dbinder_callback_stub_unittest.cpp
+1
-0
ipc/native/test/unittest/common/ipc_process_skeleton_unittest.cpp
...ve/test/unittest/common/ipc_process_skeleton_unittest.cpp
+0
-16
ipc/native/test/unittest/common/process_skeleton_unittest.cpp
...native/test/unittest/common/process_skeleton_unittest.cpp
+63
-0
未找到文件。
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
浏览文件 @
02fc38af
...
...
@@ -196,7 +196,6 @@ public:
* @since 9
*/
virtual
int
GetObjectType
()
const
;
#ifndef CONFIG_IPC_SINGLE
/**
* @brief Invoker the calling thread.
...
...
ipc/native/src/core/include/ipc_process_skeleton.h
浏览文件 @
02fc38af
...
...
@@ -45,7 +45,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
#ifndef CONFIG_IPC_SINGLE
struct
SocketThreadLockInfo
{
std
::
mutex
mutex
;
...
...
@@ -90,27 +89,25 @@ public:
static
bool
IsHandleMadeByUser
(
uint32_t
handle
);
#endif
bool
SetMaxWorkThread
(
int
maxThreadNum
);
std
::
u16string
MakeHandleDescriptor
(
int
handle
);
sptr
<
IRemoteObject
>
GetRegistryObject
();
bool
OnThreadTerminated
(
const
std
::
string
&
threadName
);
bool
SpawnThread
(
int
policy
=
IPCWorkThread
::
SPAWN_PASSIVE
,
int
proto
=
IRemoteObject
::
IF_PROT_DEFAULT
);
std
::
u16string
MakeHandleDescriptor
(
int
handle
);
sptr
<
IRemoteObject
>
FindOrNewObject
(
int
handle
);
bool
IsContainsObject
(
IRemoteObject
*
object
);
sptr
<
IRemoteObject
>
QueryObject
(
const
std
::
u16string
&
descriptor
);
bool
AttachObject
(
IRemoteObject
*
object
);
bool
DetachObject
(
IRemoteObject
*
object
);
bool
OnThreadTerminated
(
const
std
::
string
&
threadName
);
sptr
<
IRemoteObject
>
GetRegistryObject
();
bool
SetRegistryObject
(
sptr
<
IRemoteObject
>
&
object
);
#ifndef CONFIG_IPC_SINGLE
bool
AttachRawData
(
uint32_t
fd
,
std
::
shared_ptr
<
InvokerRawData
>
rawData
);
bool
DetachRawData
(
uint32_t
fd
);
std
::
shared_ptr
<
InvokerRawData
>
QueryRawData
(
uint32_t
fd
);
#ifndef CONFIG_IPC_SINGLE
sptr
<
IRemoteObject
>
GetSAMgrObject
();
std
::
shared_ptr
<
DBinderSessionObject
>
ProxyDetachDBinderSession
(
uint32_t
handle
,
IPCObjectProxy
*
proxy
);
bool
ProxyAttachDBinderSession
(
uint32_t
handle
,
std
::
shared_ptr
<
DBinderSessionObject
>
object
);
...
...
@@ -127,7 +124,6 @@ public:
std
::
shared_ptr
<
ThreadMessageInfo
>
QueryThreadBySeqNumber
(
uint64_t
seqNumber
);
bool
AddSendThreadInWait
(
uint64_t
seqNumber
,
std
::
shared_ptr
<
ThreadMessageInfo
>
messageInfo
,
int
userWaitTime
);
std
::
thread
::
id
GetIdleSocketThread
();
int
GetSocketIdleThreadNum
()
const
;
int
GetSocketTotalThreadNum
()
const
;
int
PopSocketIdFromThread
(
const
std
::
thread
::
id
&
threadId
);
...
...
@@ -195,10 +191,8 @@ private:
IPCProcessSkeleton
();
static
IPCProcessSkeleton
*
instance_
;
static
std
::
mutex
procMutex_
;
std
::
shared_mutex
mutex_
;
std
::
shared_mutex
rawDataMutex_
;
std
::
map
<
std
::
u16string
,
wptr
<
IRemoteObject
>>
objects_
;
std
::
map
<
IRemoteObject
*
,
bool
>
isContainStub_
;
std
::
map
<
uint32_t
,
std
::
shared_ptr
<
InvokerRawData
>>
rawData_
;
IPCWorkThreadPool
*
threadPool_
=
nullptr
;
...
...
ipc/native/src/core/include/process_skeleton.h
浏览文件 @
02fc38af
...
...
@@ -16,13 +16,14 @@
#ifndef OHOS_IPC_PROCESS_SKELETON_H
#define OHOS_IPC_PROCESS_SKELETON_H
#include <map>
#include <mutex>
#include <shared_mutex>
#include <refbase.h>
#include "iremote_object.h"
namespace
OHOS
{
class
ProcessSkeleton
:
public
virtual
RefBase
{
public:
...
...
@@ -32,15 +33,24 @@ public:
void
SetSamgrFlag
(
bool
flag
);
bool
GetSamgrFlag
();
bool
IsContainsObject
(
IRemoteObject
*
object
);
sptr
<
IRemoteObject
>
QueryObject
(
const
std
::
u16string
&
descriptor
);
bool
AttachObject
(
IRemoteObject
*
object
,
const
std
::
u16string
&
descriptor
);
bool
DetachObject
(
IRemoteObject
*
object
,
const
std
::
u16string
&
descriptor
);
private:
DISALLOW_COPY_AND_MOVE
(
ProcessSkeleton
);
ProcessSkeleton
()
=
default
;
~
ProcessSkeleton
()
=
default
;
~
ProcessSkeleton
();
static
sptr
<
ProcessSkeleton
>
instance_
;
static
std
::
mutex
mutex_
;
std
::
shared_mutex
objMutex_
;
sptr
<
IRemoteObject
>
registryObject_
=
nullptr
;
bool
isSamgr_
=
false
;
std
::
map
<
std
::
u16string
,
wptr
<
IRemoteObject
>>
objects_
;
std
::
map
<
IRemoteObject
*
,
bool
>
isContainStub_
;
};
}
// namespace OHOS
#endif // OHOS_IPC_PROCESS_SKELETON_H
ipc/native/src/core/source/ipc_object_proxy.cpp
浏览文件 @
02fc38af
...
...
@@ -49,7 +49,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
using
namespace
IPC_SINGLE
;
#endif
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"IPCObjectProxy"
};
IPCObjectProxy
::
IPCObjectProxy
(
int
handle
,
std
::
u16string
descriptor
,
int
proto
)
...
...
ipc/native/src/core/source/ipc_object_stub.cpp
浏览文件 @
02fc38af
...
...
@@ -49,7 +49,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
using
namespace
IPC_SINGLE
;
#endif
using
namespace
OHOS
::
HiviewDFX
;
static
constexpr
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"IPCObjectStub"
};
#ifndef CONFIG_IPC_SINGLE
...
...
ipc/native/src/core/source/ipc_process_skeleton.cpp
浏览文件 @
02fc38af
...
...
@@ -15,6 +15,7 @@
#include "ipc_process_skeleton.h"
#include <functional>
#include <securec.h>
#include <unistd.h>
#include <random>
...
...
@@ -23,6 +24,7 @@
#include "ipc_debug.h"
#include "ipc_types.h"
#include "ipc_object_proxy.h"
#include "ipc_thread_skeleton.h"
#include "process_skeleton.h"
#include "sys_binder.h"
...
...
@@ -37,7 +39,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
#ifndef CONFIG_IPC_SINGLE
using
namespace
Communication
;
#endif
...
...
@@ -93,8 +94,6 @@ IPCProcessSkeleton::~IPCProcessSkeleton()
delete
threadPool_
;
threadPool_
=
nullptr
;
objects_
.
clear
();
isContainStub_
.
clear
();
rawData_
.
clear
();
#ifndef CONFIG_IPC_SINGLE
threadLockInfo_
.
clear
();
...
...
@@ -138,10 +137,11 @@ std::u16string IPCProcessSkeleton::MakeHandleDescriptor(int handle)
sptr
<
IRemoteObject
>
IPCProcessSkeleton
::
FindOrNewObject
(
int
handle
)
{
sptr
<
IRemoteObject
>
result
=
nullptr
;
std
::
u16string
descriptor
=
MakeHandleDescriptor
(
handle
);
if
(
descriptor
.
length
()
==
0
)
{
ZLOGE
(
LOG_LABEL
,
"make handle descriptor failed"
);
return
nullptr
;
return
result
;
}
{
result
=
QueryObject
(
descriptor
);
...
...
@@ -161,13 +161,14 @@ sptr<IRemoteObject> IPCProcessSkeleton::FindOrNewObject(int handle)
}
// OnFirstStrongRef will be called.
result
=
new
(
std
::
nothrow
)
IPCObjectProxy
(
handle
,
descriptor
);
if
(
result
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"new IPCObjectProxy failed!"
);
return
result
;
}
AttachObject
(
result
.
GetRefPtr
());
}
}
sptr
<
IPCObjectProxy
>
proxy
=
reinterpret_cast
<
IPCObjectProxy
*>
(
result
.
GetRefPtr
());
// When a new proxy is initializing, other thread will find an existed proxy and need to wait,
// this makes sure proxy has been initialized when ReadRemoteObject return.
proxy
->
WaitForInit
();
#ifndef CONFIG_IPC_SINGLE
if
(
proxy
->
GetProto
()
==
IRemoteObject
::
IF_PROT_ERROR
)
{
...
...
@@ -178,29 +179,6 @@ sptr<IRemoteObject> IPCProcessSkeleton::FindOrNewObject(int handle)
return
result
;
}
bool
IPCProcessSkeleton
::
SetMaxWorkThread
(
int
maxThreadNum
)
{
if
(
maxThreadNum
<=
0
)
{
ZLOGE
(
LOG_LABEL
,
"Set Invalid thread Number %d"
,
maxThreadNum
);
return
false
;
}
if
(
threadPool_
==
nullptr
)
{
threadPool_
=
new
(
std
::
nothrow
)
IPCWorkThreadPool
(
maxThreadNum
);
if
(
threadPool_
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"create IPCWorkThreadPool object failed"
);
return
false
;
}
}
threadPool_
->
UpdateMaxThreadNum
(
maxThreadNum
);
IRemoteInvoker
*
invoker
=
IPCThreadSkeleton
::
GetRemoteInvoker
(
IRemoteObject
::
IF_PROT_DEFAULT
);
if
(
invoker
!=
nullptr
)
{
return
invoker
->
SetMaxWorkThread
(
maxThreadNum
);
}
return
false
;
}
bool
IPCProcessSkeleton
::
SetRegistryObject
(
sptr
<
IRemoteObject
>
&
object
)
{
if
(
object
==
nullptr
)
{
...
...
@@ -226,6 +204,29 @@ bool IPCProcessSkeleton::SetRegistryObject(sptr<IRemoteObject> &object)
return
ret
;
}
bool
IPCProcessSkeleton
::
SetMaxWorkThread
(
int
maxThreadNum
)
{
if
(
maxThreadNum
<=
0
)
{
ZLOGE
(
LOG_LABEL
,
"Set Invalid thread Number %d"
,
maxThreadNum
);
return
false
;
}
if
(
threadPool_
==
nullptr
)
{
threadPool_
=
new
(
std
::
nothrow
)
IPCWorkThreadPool
(
maxThreadNum
);
if
(
threadPool_
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"create IPCWorkThreadPool object failed"
);
return
false
;
}
}
threadPool_
->
UpdateMaxThreadNum
(
maxThreadNum
);
IRemoteInvoker
*
invoker
=
IPCThreadSkeleton
::
GetRemoteInvoker
(
IRemoteObject
::
IF_PROT_DEFAULT
);
if
(
invoker
!=
nullptr
)
{
return
invoker
->
SetMaxWorkThread
(
maxThreadNum
);
}
return
false
;
}
bool
IPCProcessSkeleton
::
SpawnThread
(
int
policy
,
int
proto
)
{
if
(
threadPool_
!=
nullptr
)
{
...
...
@@ -245,72 +246,69 @@ bool IPCProcessSkeleton::OnThreadTerminated(const std::string &threadName)
return
true
;
}
bool
IPCProcessSkeleton
::
IsContainsObject
(
IRemoteObject
*
object
)
{
// check whether it is a valid IPCObjectStub object.
std
::
shared_lock
<
std
::
shared_mutex
>
lockGuard
(
mutex_
);
auto
it
=
isContainStub_
.
find
(
object
);
if
(
it
!=
isContainStub_
.
end
())
{
return
it
->
second
;
if
(
object
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"object is null"
);
return
false
;
}
return
false
;
auto
current
=
ProcessSkeleton
::
GetInstance
();
if
(
current
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"get process skeleton failed"
);
return
false
;
}
return
current
->
IsContainsObject
(
object
);
}
bool
IPCProcessSkeleton
::
DetachObject
(
IRemoteObject
*
object
)
{
std
::
unique_lock
<
std
::
shared_mutex
>
lockGuard
(
mutex_
);
(
void
)
isContainStub_
.
erase
(
object
);
if
(
object
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"object is null"
);
return
false
;
}
std
::
u16string
descriptor
=
object
->
GetObjectDescriptor
();
if
(
descriptor
.
empty
())
{
return
false
;
}
// This handle may have already been replaced with a new IPCObjectProxy,
// if someone failed the AttemptIncStrong.
auto
iterator
=
objects_
.
find
(
descriptor
);
if
(
iterator
->
second
==
object
)
{
objects_
.
erase
(
iterator
);
return
true
;
auto
current
=
ProcessSkeleton
::
GetInstance
();
if
(
current
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"get process skeleton failed"
);
return
false
;
}
return
false
;
return
current
->
DetachObject
(
object
,
descriptor
)
;
}
bool
IPCProcessSkeleton
::
AttachObject
(
IRemoteObject
*
object
)
{
std
::
unique_lock
<
std
::
shared_mutex
>
lockGuard
(
mutex_
);
(
void
)
isContainStub_
.
insert
(
std
::
pair
<
IRemoteObject
*
,
bool
>
(
object
,
true
));
if
(
object
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"object is null"
);
return
false
;
}
std
::
u16string
descriptor
=
object
->
GetObjectDescriptor
();
if
(
descriptor
.
empty
())
{
return
false
;
}
// If attemptIncStrong failed, old proxy might still exist, replace it with the new proxy.
wptr
<
IRemoteObject
>
wp
=
object
;
auto
result
=
objects_
.
insert_or_assign
(
descriptor
,
wp
);
return
result
.
second
;
auto
current
=
ProcessSkeleton
::
GetInstance
();
if
(
current
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"get process skeleton failed"
);
return
false
;
}
return
current
->
AttachObject
(
object
,
descriptor
);
}
sptr
<
IRemoteObject
>
IPCProcessSkeleton
::
QueryObject
(
const
std
::
u16string
&
descriptor
)
{
sptr
<
IRemoteObject
>
result
=
nullptr
;
if
(
descriptor
.
empty
())
{
return
result
;
}
std
::
shared_lock
<
std
::
shared_mutex
>
lockGuard
(
mutex_
);
IRemoteObject
*
remoteObject
=
nullptr
;
auto
it
=
objects_
.
find
(
descriptor
);
if
(
it
!=
objects_
.
end
())
{
// Life-time of IPCObjectProxy is extended to WEAK
// now it's weak reference counted, so it's safe to get raw pointer
remoteObject
=
it
->
second
.
GetRefPtr
();
if
(
descriptor
.
length
()
==
0
)
{
ZLOGE
(
LOG_LABEL
,
"enter descriptor is empty"
);
return
nullptr
;
}
if
(
remoteObject
==
nullptr
||
!
remoteObject
->
AttemptIncStrong
(
this
))
{
return
result
;
auto
current
=
ProcessSkeleton
::
GetInstance
();
if
(
current
==
nullptr
)
{
ZLOGE
(
LOG_LABEL
,
"get process skeleton failed"
);
return
nullptr
;
}
result
=
remoteObject
;
return
result
;
return
current
->
QueryObject
(
descriptor
);
}
#ifndef CONFIG_IPC_SINGLE
...
...
@@ -595,12 +593,12 @@ int IPCProcessSkeleton::GetSocketIdleThreadNum() const
return
0
;
}
int
IPCProcessSkeleton
::
GetSocketTotalThreadNum
()
const
{
if
(
threadPool_
!=
nullptr
)
{
return
threadPool_
->
GetSocketTotalThreadNum
();
}
return
0
;
}
...
...
@@ -1181,7 +1179,6 @@ sptr<IRemoteObject> IPCProcessSkeleton::QueryDBinderCallbackProxy(sptr<IRemoteOb
return
nullptr
;
}
#endif
#ifdef CONFIG_IPC_SINGLE
}
// namespace IPC_SINGLE
...
...
ipc/native/src/core/source/ipc_skeleton.cpp
浏览文件 @
02fc38af
...
...
@@ -33,7 +33,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
using
namespace
IPC_SINGLE
;
#endif
void
IPCSkeleton
::
JoinWorkThread
()
{
IPCThreadSkeleton
*
current
=
IPCThreadSkeleton
::
GetCurrent
();
...
...
ipc/native/src/core/source/ipc_thread_skeleton.cpp
浏览文件 @
02fc38af
...
...
@@ -33,7 +33,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
using
namespace
OHOS
::
HiviewDFX
;
pthread_key_t
IPCThreadSkeleton
::
TLSKey_
=
0
;
pthread_once_t
IPCThreadSkeleton
::
TLSKeyOnce_
=
PTHREAD_ONCE_INIT
;
...
...
@@ -82,8 +81,8 @@ IPCThreadSkeleton::IPCThreadSkeleton()
IPCThreadSkeleton
::~
IPCThreadSkeleton
()
{
ZLOGE
(
LABEL
,
"IPCThreadSkeleton delete"
);
std
::
lock_guard
<
std
::
recursive_mutex
>
lockGuard
(
mutex_
);
ZLOGE
(
LABEL
,
"IPCThreadSkeleton delete"
);
for
(
auto
it
=
invokers_
.
begin
();
it
!=
invokers_
.
end
();)
{
delete
it
->
second
;
it
=
invokers_
.
erase
(
it
);
...
...
@@ -97,7 +96,6 @@ IRemoteInvoker *IPCThreadSkeleton::GetRemoteInvoker(int proto)
if
(
current
==
nullptr
)
{
return
nullptr
;
}
std
::
lock_guard
<
std
::
recursive_mutex
>
lockGuard
(
mutex_
);
auto
it
=
current
->
invokers_
.
find
(
proto
);
if
(
it
!=
current
->
invokers_
.
end
())
{
...
...
ipc/native/src/core/source/iremote_object.cpp
浏览文件 @
02fc38af
...
...
@@ -25,7 +25,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
using
namespace
IPC_SINGLE
;
#endif
bool
IRemoteObject
::
CheckObjectLegality
()
const
{
return
false
;
...
...
ipc/native/src/core/source/process_skeleton.cpp
浏览文件 @
02fc38af
...
...
@@ -17,6 +17,7 @@
#include "log_tags.h"
#include "ipc_debug.h"
#include "string_ex.h"
namespace
OHOS
{
static
constexpr
OHOS
::
HiviewDFX
::
HiLogLabel
LOG_LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"ProcessSkeleton"
};
...
...
@@ -39,6 +40,13 @@ sptr<ProcessSkeleton> ProcessSkeleton::GetInstance()
return
instance_
;
}
ProcessSkeleton
::~
ProcessSkeleton
()
{
std
::
lock_guard
<
std
::
shared_mutex
>
lockGuard
(
objMutex_
);
objects_
.
clear
();
isContainStub_
.
clear
();
}
sptr
<
IRemoteObject
>
ProcessSkeleton
::
GetRegistryObject
()
{
std
::
lock_guard
<
std
::
mutex
>
lockGuard
(
mutex_
);
...
...
@@ -60,4 +68,64 @@ bool ProcessSkeleton::GetSamgrFlag()
{
return
isSamgr_
;
}
bool
ProcessSkeleton
::
IsContainsObject
(
IRemoteObject
*
object
)
{
// check whether it is a valid IPCObjectStub object.
std
::
shared_lock
<
std
::
shared_mutex
>
lockGuard
(
objMutex_
);
auto
it
=
isContainStub_
.
find
(
object
);
if
(
it
!=
isContainStub_
.
end
())
{
return
it
->
second
;
}
return
false
;
}
bool
ProcessSkeleton
::
DetachObject
(
IRemoteObject
*
object
,
const
std
::
u16string
&
descriptor
)
{
std
::
unique_lock
<
std
::
shared_mutex
>
lockGuard
(
objMutex_
);
(
void
)
isContainStub_
.
erase
(
object
);
// This handle may have already been replaced with a new IPCObjectProxy,
// if someone failed the AttemptIncStrong.
auto
iterator
=
objects_
.
find
(
descriptor
);
if
(
iterator
!=
objects_
.
end
())
{
objects_
.
erase
(
iterator
);
return
true
;
}
return
false
;
}
bool
ProcessSkeleton
::
AttachObject
(
IRemoteObject
*
object
,
const
std
::
u16string
&
descriptor
)
{
std
::
unique_lock
<
std
::
shared_mutex
>
lockGuard
(
objMutex_
);
(
void
)
isContainStub_
.
insert
(
std
::
pair
<
IRemoteObject
*
,
bool
>
(
object
,
true
));
// If attemptIncStrong failed, old proxy might still exist, replace it with the new proxy.
wptr
<
IRemoteObject
>
wp
=
object
;
auto
result
=
objects_
.
insert_or_assign
(
descriptor
,
wp
);
return
result
.
second
;
}
sptr
<
IRemoteObject
>
ProcessSkeleton
::
QueryObject
(
const
std
::
u16string
&
descriptor
)
{
sptr
<
IRemoteObject
>
result
=
nullptr
;
if
(
descriptor
.
empty
())
{
return
result
;
}
std
::
shared_lock
<
std
::
shared_mutex
>
lockGuard
(
objMutex_
);
IRemoteObject
*
remoteObject
=
nullptr
;
auto
it
=
objects_
.
find
(
descriptor
);
if
(
it
!=
objects_
.
end
())
{
// Life-time of IPCObjectProxy is extended to WEAK
// now it's weak reference counted, so it's safe to get raw pointer
remoteObject
=
it
->
second
.
GetRefPtr
();
}
if
(
remoteObject
==
nullptr
||
!
remoteObject
->
AttemptIncStrong
(
this
))
{
return
result
;
}
result
=
remoteObject
;
return
result
;
}
}
// namespace OHOS
\ No newline at end of file
ipc/native/src/mock/include/binder_connector.h
浏览文件 @
02fc38af
...
...
@@ -23,7 +23,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
class
BinderConnector
{
public:
static
BinderConnector
*
GetInstance
();
...
...
ipc/native/src/mock/include/invoker_factory.h
浏览文件 @
02fc38af
...
...
@@ -41,7 +41,6 @@ private:
std
::
mutex
factoryMutex_
;
std
::
unordered_map
<
int
,
InvokerCreator
>
creators_
;
};
template
<
typename
T
>
class
InvokerDelegator
{
public:
InvokerDelegator
(
int
prot
);
...
...
ipc/native/src/mock/include/iremote_invoker.h
浏览文件 @
02fc38af
...
...
@@ -27,7 +27,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
class
IRemoteInvoker
{
public:
enum
{
...
...
ipc/native/src/mock/source/binder_connector.cpp
浏览文件 @
02fc38af
...
...
@@ -37,7 +37,6 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace
IPC_SINGLE
{
#endif
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"BinderConnector"
};
std
::
mutex
BinderConnector
::
skeletonMutex
;
constexpr
int
SZ_1_M
=
1048576
;
...
...
ipc/native/test/unittest/common/BUILD.gn
浏览文件 @
02fc38af
...
...
@@ -45,6 +45,7 @@ ohos_unittest("IPCNativeUnitTest") {
"ipc_thread_skeleton_unittest.cpp",
"iremote_object_unitest.cpp",
"message_parcel_unittest.cpp",
"process_skeleton_unittest.cpp",
]
configs = [
...
...
@@ -53,6 +54,7 @@ ohos_unittest("IPCNativeUnitTest") {
]
deps = [
"$IPC_CORE_ROOT/src/core:ipc_common",
"$IPC_TEST_ROOT/auxiliary/native:TestAssistance",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
...
...
ipc/native/test/unittest/common/dbinder_callback_stub_unittest.cpp
浏览文件 @
02fc38af
...
...
@@ -18,6 +18,7 @@
#define private public
#define protected public
#include "binder_invoker.h"
#include "dbinder_callback_stub.h"
#include "ipc_types.h"
#include "ipc_thread_skeleton.h"
...
...
ipc/native/test/unittest/common/ipc_process_skeleton_unittest.cpp
浏览文件 @
02fc38af
...
...
@@ -1693,22 +1693,6 @@ HWTEST_F(IPCProcessSkeletonUnitTest, QueryDBinderCallbackProxyTest002, TestSize.
EXPECT_EQ
(
ret
,
nullptr
);
}
/**
* @tc.name: IsContainsObjectTest002
* @tc.desc: Verify the IsContainsObject function
* @tc.type: FUNC
*/
HWTEST_F
(
IPCProcessSkeletonUnitTest
,
IsContainsObjectTest002
,
TestSize
.
Level1
)
{
IPCProcessSkeleton
*
skeleton
=
IPCProcessSkeleton
::
GetCurrent
();
ASSERT_TRUE
(
skeleton
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
new
IPCObjectStub
(
u"testObject"
);
skeleton
->
isContainStub_
.
clear
();
bool
ret
=
skeleton
->
IsContainsObject
(
object
.
GetRefPtr
());
EXPECT_EQ
(
ret
,
false
);
}
/**
* @tc.name: ProxyQueryDBinderSessionTest002
* @tc.desc: Verify the ProxyQueryDBinderSession function
...
...
ipc/native/test/unittest/common/process_skeleton_unittest.cpp
0 → 100644
浏览文件 @
02fc38af
/*
* 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.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#define private public
#include "process_skeleton.h"
#include "ipc_types.h"
#include "iremote_object.h"
#include "ipc_object_stub.h"
#undef private
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
class
ProcessSkeletonUnitTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
);
static
void
TearDownTestCase
(
void
);
void
SetUp
();
void
TearDown
();
};
void
ProcessSkeletonUnitTest
::
SetUpTestCase
()
{
}
void
ProcessSkeletonUnitTest
::
TearDownTestCase
()
{
}
void
ProcessSkeletonUnitTest
::
SetUp
()
{}
void
ProcessSkeletonUnitTest
::
TearDown
()
{}
/**
* @tc.name: IsContainsObjectTest001
* @tc.desc: Verify the IsContainsObject function
* @tc.type: FUNC
*/
HWTEST_F
(
ProcessSkeletonUnitTest
,
IsContainsObjectTest001
,
TestSize
.
Level1
)
{
ProcessSkeleton
*
skeleton
=
ProcessSkeleton
::
GetInstance
();
ASSERT_TRUE
(
skeleton
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
new
IPCObjectStub
(
u"testObject"
);
skeleton
->
isContainStub_
.
clear
();
bool
ret
=
skeleton
->
IsContainsObject
(
object
.
GetRefPtr
());
EXPECT_EQ
(
ret
,
false
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录