Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
7d4009b6
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7d4009b6
编写于
6月 08, 2023
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use thread to check
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
836ccc39
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
10 deletion
+26
-10
device_info/device_info_stub.cpp
device_info/device_info_stub.cpp
+22
-10
device_info/device_info_stub.h
device_info/device_info_stub.h
+4
-0
未找到文件。
device_info/device_info_stub.cpp
浏览文件 @
7d4009b6
...
@@ -16,8 +16,7 @@
...
@@ -16,8 +16,7 @@
#include "device_info_stub.h"
#include "device_info_stub.h"
#include <chrono>
#include <chrono>
#include <csignal>
#include <thread>
#include <unistd.h>
#include "beget_ext.h"
#include "beget_ext.h"
#include "idevice_info.h"
#include "idevice_info.h"
...
@@ -48,23 +47,23 @@ static const int DEVICE_INFO_EXIT_TIMEOUT_S = 15;
...
@@ -48,23 +47,23 @@ static const int DEVICE_INFO_EXIT_TIMEOUT_S = 15;
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_S
=
3
;
static
const
int
DEVICE_INFO_EXIT_TIMEOUT_S
=
3
;
#endif
#endif
static
void
UnloadDeviceInfoSa
(
int
signo
)
static
int
UnloadDeviceInfoSa
(
void
)
{
{
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
g_lock
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
g_lock
);
struct
timespec
currTimer
=
{
0
};
struct
timespec
currTimer
=
{
0
};
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
currTimer
);
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
currTimer
);
if
(
IntervalTime
(
&
g_lastTime
,
&
currTimer
)
<
DEVICE_INFO_EXIT_TIMEOUT_S
)
{
if
(
IntervalTime
(
&
g_lastTime
,
&
currTimer
)
<
DEVICE_INFO_EXIT_TIMEOUT_S
)
{
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_S
/
3
);
// 3 half
return
0
;
return
;
}
}
}
}
DINFO_LOGI
(
"DeviceInfoService::UnloadDeviceInfoSa"
);
DINFO_LOGI
(
"DeviceInfoService::UnloadDeviceInfoSa"
);
auto
sam
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
auto
sam
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
DINFO_CHECK
(
sam
!=
nullptr
,
return
,
"GetSystemAbilityManager return null"
);
DINFO_CHECK
(
sam
!=
nullptr
,
return
0
,
"GetSystemAbilityManager return null"
);
int32_t
ret
=
sam
->
UnloadSystemAbility
(
SYSPARAM_DEVICE_SERVICE_ID
);
int32_t
ret
=
sam
->
UnloadSystemAbility
(
SYSPARAM_DEVICE_SERVICE_ID
);
DINFO_CHECK
(
ret
==
ERR_OK
,
return
,
"UnLoadSystemAbility deviceinfo sa failed"
);
DINFO_CHECK
(
ret
==
ERR_OK
,
return
0
,
"UnLoadSystemAbility deviceinfo sa failed"
);
return
1
;
}
}
int32_t
DeviceInfoStub
::
OnRemoteRequest
(
uint32_t
code
,
int32_t
DeviceInfoStub
::
OnRemoteRequest
(
uint32_t
code
,
...
@@ -144,14 +143,14 @@ void DeviceInfoService::OnStart(void)
...
@@ -144,14 +143,14 @@ void DeviceInfoService::OnStart(void)
if
(
!
res
)
{
if
(
!
res
)
{
DINFO_LOGE
(
"DeviceInfoService Publish failed"
);
DINFO_LOGE
(
"DeviceInfoService Publish failed"
);
}
}
signal
(
SIGALRM
,
UnloadDeviceInfoSa
)
;
threadStarted_
=
true
;
alarm
(
DEVICE_INFO_EXIT_TIMEOUT_S
/
2
);
// 2 half
std
::
thread
(
&
DeviceInfoService
::
ThreadForUnloadSa
,
this
).
detach
();
return
;
return
;
}
}
void
DeviceInfoService
::
OnStop
(
void
)
void
DeviceInfoService
::
OnStop
(
void
)
{
{
signal
(
SIGALRM
,
nullptr
)
;
threadStarted_
=
false
;
DINFO_LOGI
(
"DeviceInfoService OnStop"
);
DINFO_LOGI
(
"DeviceInfoService OnStop"
);
}
}
...
@@ -162,5 +161,18 @@ int DeviceInfoService::Dump(int fd, const std::vector<std::u16string>& args)
...
@@ -162,5 +161,18 @@ int DeviceInfoService::Dump(int fd, const std::vector<std::u16string>& args)
DINFO_CHECK
(
fd
>=
0
,
return
-
1
,
"Invalid fd for dump %d"
,
fd
);
DINFO_CHECK
(
fd
>=
0
,
return
-
1
,
"Invalid fd for dump %d"
,
fd
);
return
dprintf
(
fd
,
"%s
\n
"
,
"No information to dump for this service"
);
return
dprintf
(
fd
,
"%s
\n
"
,
"No information to dump for this service"
);
}
}
void
DeviceInfoService
::
ThreadForUnloadSa
(
void
)
{
while
(
1
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
DEVICE_INFO_EXIT_TIMEOUT_S
/
3
));
// 3 count
if
(
!
threadStarted_
)
{
break
;
}
if
(
UnloadDeviceInfoSa
()
==
1
)
{
break
;
}
}
}
}
// namespace device_info
}
// namespace device_info
}
// namespace OHOS
}
// namespace OHOS
device_info/device_info_stub.h
浏览文件 @
7d4009b6
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
#ifndef OHOS_SYSTEM_DEVICEIDSTUB_H
#ifndef OHOS_SYSTEM_DEVICEIDSTUB_H
#define OHOS_SYSTEM_DEVICEIDSTUB_H
#define OHOS_SYSTEM_DEVICEIDSTUB_H
#include <atomic>
#include <mutex>
#include "iremote_stub.h"
#include "iremote_stub.h"
#include "idevice_info.h"
#include "idevice_info.h"
#include "system_ability.h"
#include "system_ability.h"
...
@@ -45,6 +47,8 @@ protected:
...
@@ -45,6 +47,8 @@ protected:
void
OnStart
(
void
)
override
;
void
OnStart
(
void
)
override
;
void
OnStop
(
void
)
override
;
void
OnStop
(
void
)
override
;
int
Dump
(
int
fd
,
const
std
::
vector
<
std
::
u16string
>&
args
)
override
;
int
Dump
(
int
fd
,
const
std
::
vector
<
std
::
u16string
>&
args
)
override
;
void
ThreadForUnloadSa
(
void
);
std
::
atomic_bool
threadStarted_
{
false
};
};
};
}
// namespace device_info
}
// namespace device_info
}
// namespace OHOS
}
// namespace OHOS
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录