Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d33e91dd
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d33e91dd
编写于
3月 28, 2022
作者:
X
xuyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make_shared使用规范说明
Signed-off-by:
N
xuyong
<
xuyong59@huawei.com
>
上级
a7a39eed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
32 deletion
+60
-32
en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md
en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md
+19
-12
en/device-dev/subsystems/subsys-dfx-hisysevent-query.md
en/device-dev/subsystems/subsys-dfx-hisysevent-query.md
+11
-4
zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-listening.md
.../device-dev/subsystems/subsys-dfx-hisysevent-listening.md
+19
-12
zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-query.md
zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-query.md
+11
-4
未找到文件。
en/device-dev/subsystems/subsys-dfx-hisysevent-listening.md
浏览文件 @
d33e91dd
...
...
@@ -101,18 +101,25 @@ C++
Call the **AddEventListener** API of the **HiSysEventManager** class to add a listener for system events.
```
auto demoListener = std::make_shared<DemoListener>();
// Add a ListenerRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD).
ListenerRule tagRule("dfx");
// Add a ListenerRule object based on the event tag, with RuleType set as REGULAR.
ListenerRule regRule("dfx.*", RuleType::REGULAR);
// Add a ListenerRule object based on the event domain and event name, with RuleType set as PREFIX.
ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX);
std::vector<ListenerRule> sysRules;
sysRules.push_back(tagRule);
sysRules.push_back(regRule);
sysRules.push_back(domainNameRule);
HiSysEventManager::AddEventListener(demoListener, sysRules);
std::shared_ptr<DemoListener> demoListener = nullptr;
try {
demoListener = std::make_shared<DemoListener>();
} catch(...) {
// Catch exception thrown by make_shared
}
if (demoListener != nullptr) {
// Add a ListenerRule object based on the event tag, with RuleType left unspecified (in this case, ruleType is defaulted to WHOLE_WORD).
ListenerRule tagRule("dfx");
// Add a ListenerRule object based on the event tag, with RuleType set as REGULAR.
ListenerRule regRule("dfx.*", RuleType::REGULAR);
// Add a ListenerRule object based on the event domain and event name, with RuleType set as PREFIX.
ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX);
std::vector<ListenerRule> sysRules;
sysRules.push_back(tagRule);
sysRules.push_back(regRule);
sysRules.push_back(domainNameRule);
HiSysEventManager::AddEventListener(demoListener, sysRules);
}
```
2.
Configure the
**BUILD.gn**
file.
...
...
en/device-dev/subsystems/subsys-dfx-hisysevent-query.md
浏览文件 @
d33e91dd
...
...
@@ -86,10 +86,17 @@ C++
} // namespace OHOS
// Invoke the query callback API to obtain system events.
auto queryCallBack = std::make_shared<HiSysEventToolQuery>();
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<QueryRule> mRules;
HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack);
std::shared_ptr<HiSysEventToolQuery> queryCallBack = nullptr;
try {
queryCallBack = std::make_shared<HiSysEventToolQuery>();
} catch(...) {
// Catch exception thrown by make_shared
}
if (queryCallBack != nullptr) {
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<QueryRule> rules;
HiSysEventManager::QueryHiSysEvent(args, rules, queryCallBack);
}
```
2.
Modify the
**BUILD.gn**
file.
...
...
zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-listening.md
浏览文件 @
d33e91dd
...
...
@@ -103,18 +103,25 @@ HiSysEvent提供了跨进程订阅机制,开发者可以通过注册订阅接
通过HiSysEventManager类提供的AddEventListener接口注册回调对象,完成对HiSysEvent的订阅:
```
auto demoListener = std::make_shared<DemoListener>();
// 事件标签规则订阅,规则类型为默认的全词匹配类型
ListenerRule tagRule("dfx");
// 事件标签规则订阅,规则类型为正则匹配类型
ListenerRule regRule("dfx.*", RuleType::REGULAR);
// 事件领域及事件名称规则订阅,规则类型为前缀匹配类型
ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX);
std::vector<ListenerRule> sysRules;
sysRules.push_back(tagRule);
sysRules.push_back(regRule);
sysRules.push_back(domainNameRule);
HiSysEventManager::AddEventListener(demoListener, sysRules);
std::shared_ptr<DemoListener> demoListener = nullptr;
try {
demoListener = std::make_shared<DemoListener>();
} catch(...) {
// 智能指针获取失败异常处理
}
if (demoListener != nullptr) {
// 事件标签规则订阅,规则类型为默认的全词匹配类型
ListenerRule tagRule("dfx");
// 事件标签规则订阅,规则类型为正则匹配类型
ListenerRule regRule("dfx.*", RuleType::REGULAR);
// 事件领域及事件名称规则订阅,规则类型为前缀匹配类型
ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX);
std::vector<ListenerRule> sysRules;
sysRules.push_back(tagRule);
sysRules.push_back(regRule);
sysRules.push_back(domainNameRule);
HiSysEventManager::AddEventListener(demoListener, sysRules);
}
```
2.
编译配置
...
...
zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-query.md
浏览文件 @
d33e91dd
...
...
@@ -86,10 +86,17 @@ C++接口实例。
} // namespace OHOS
// 调用查询接口获取HiSysEvent事件
auto queryCallBack = std::make_shared<HiSysEventToolQuery>();
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<QueryRule> mRules;
HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack);
std::shared_ptr<HiSysEventToolQuery> queryCallBack = nullptr;
try {
queryCallBack = std::make_shared<HiSysEventToolQuery>();
} catch (...) {
// 智能指针获取失败处理
}
if (queryCallBack != nullptr) {
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<QueryRule> rules;
HiSysEventManager::QueryHiSysEvent(args, rules, queryCallBack);
}
```
2.
编译设置:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录