mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 07:02:25 +00:00
quduoyu
Signed-off-by: cwx1252618 <chaifu1@huawei.com> Change-Id: I967db2417529b55e12e397a7a929208d8433e397
This commit is contained in:
parent
d878997407
commit
94c6741e75
11
BUILD.gn
11
BUILD.gn
@ -16,12 +16,7 @@ import("//foundation/graphic/graphic_2d/utils/wmlayout/wmlayout.gni")
|
||||
import("graphic_config.gni")
|
||||
|
||||
group("default") {
|
||||
public_deps = [
|
||||
":graphic.rc",
|
||||
"frameworks/dumper:gdumper",
|
||||
"frameworks/dumper:gdumper.ini",
|
||||
"frameworks/dumper:graphic_dumper_server",
|
||||
]
|
||||
public_deps = [ ":graphic.rc" ]
|
||||
|
||||
if (graphic_standard_feature_bootanimation_enable) {
|
||||
public_deps += [ "frameworks/bootanimation:bootanimation" ]
|
||||
@ -75,10 +70,6 @@ group("libvulkan") {
|
||||
public_deps = libvulkan
|
||||
}
|
||||
|
||||
group("libgraphic_dumper_client") {
|
||||
public_deps = [ "frameworks/dumper:libgraphic_dumper_client" ]
|
||||
}
|
||||
|
||||
group("libnative_image") {
|
||||
public_deps = [ "frameworks/surfaceimage:libnative_image" ]
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ foundataion/graphic/graphic_2d
|
||||
├── frameworks # framework code directory
|
||||
│ ├── animation_server # animationServer code
|
||||
│ ├── bootanimation # Boot animation directory
|
||||
│ ├── dumper # graphic dumper code
|
||||
│ ├── fence # fence code
|
||||
│ ├── vsync # Vsync code
|
||||
├── rosen # framework code directory
|
||||
|
@ -35,7 +35,6 @@ foundation/graphic/graphic_2d/
|
||||
├── frameworks # 框架代码目录
|
||||
│ ├── animation_server # AnimationServer代码
|
||||
│ ├── bootanimation # 开机动画目录
|
||||
│ ├── dumper # graphic dumper代码
|
||||
│ ├── fence # fence代码
|
||||
│ ├── opengl_wrapper # opengl_wrapper
|
||||
│ ├── surface # Surface代码
|
||||
|
@ -1,176 +0,0 @@
|
||||
# Copyright (c) 2021 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build libgraphic_dumper_client.so {{{
|
||||
config("graphic_dumper_client_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("graphic_dumper_client_public_config") {
|
||||
include_dirs = [ "common" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("libgraphic_dumper_client") {
|
||||
sources = [
|
||||
"src/graphic_dumper_helper.cpp",
|
||||
"src/graphic_dumper_helper_impl.cpp",
|
||||
"src/ipc/graphic_dumper_client_listener_stub.cpp",
|
||||
"src/ipc/graphic_dumper_service_proxy.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":graphic_dumper_client_config" ]
|
||||
|
||||
public_configs = [ ":graphic_dumper_client_public_config" ]
|
||||
|
||||
deps = [ "//foundation/graphic/graphic_2d/utils:libgraphic_utils" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
## Build libgraphic_dumper_client.so }}}
|
||||
|
||||
## Build graphic_dumper_server {{{
|
||||
config("graphic_dumper_server_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_executable("graphic_dumper_server") {
|
||||
install_enable = true
|
||||
|
||||
sources = [
|
||||
"src/graphic_dumper_server.cpp",
|
||||
"src/graphic_dumper_server_main.cpp",
|
||||
"src/graphic_dumper_tree.cpp",
|
||||
"src/graphic_dumper_util.cpp",
|
||||
"src/ipc/graphic_dumper_client_listener_death_recipient.cpp",
|
||||
"src/ipc/graphic_dumper_client_listener_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_command_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_command_stub.cpp",
|
||||
"src/ipc/graphic_dumper_info_listener_death_recipient.cpp",
|
||||
"src/ipc/graphic_dumper_info_listener_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_service_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_service_stub.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":graphic_dumper_server_config",
|
||||
":graphic_dumper_client_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||
"//third_party/zlib:libz",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
## Build graphic_dumper_server }}}
|
||||
|
||||
## Build gdumper {{{
|
||||
config("gdumper_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_executable("gdumper") {
|
||||
install_enable = true
|
||||
|
||||
sources = [
|
||||
"src/graphic_dumper_command_line.cpp",
|
||||
"src/graphic_dumper_command_line_main.cpp",
|
||||
"src/graphic_dumper_server.cpp",
|
||||
"src/graphic_dumper_tree.cpp",
|
||||
"src/graphic_dumper_util.cpp",
|
||||
"src/ipc/graphic_dumper_client_listener_death_recipient.cpp",
|
||||
"src/ipc/graphic_dumper_command_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_command_stub.cpp",
|
||||
"src/ipc/graphic_dumper_info_listener_death_recipient.cpp",
|
||||
"src/ipc/graphic_dumper_info_listener_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_info_listener_stub.cpp",
|
||||
"src/ipc/graphic_dumper_service_proxy.cpp",
|
||||
"src/ipc/graphic_dumper_service_stub.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":gdumper_config",
|
||||
":graphic_dumper_client_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||
"//third_party/zlib:libz",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
## Build gdumper }}}
|
||||
|
||||
## Install gdumper.ini to /system/etc/./gdumper.ini {{{
|
||||
ohos_prebuilt_etc("gdumper.ini") {
|
||||
source = "gdumper.ini"
|
||||
relative_install_dir = "."
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
## Install gdumper.ini to /system/etc/./gdumper.ini }}}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_H
|
||||
|
||||
#include "graphic_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <refbase.h>
|
||||
|
||||
namespace OHOS {
|
||||
using OnConfigChangeFunc = std::function<void(const std::string &, const std::string &)>;
|
||||
using OnDumpFunc = std::function<void()>;
|
||||
class GraphicDumperHelper : public RefBase {
|
||||
public:
|
||||
static sptr<GraphicDumperHelper> GetInstance();
|
||||
virtual GSError SendInfo(const std::string &tag, const char *fmt, ...) = 0;
|
||||
|
||||
virtual int32_t AddConfigChangeListener(const std::string &tag, OnConfigChangeFunc func) = 0;
|
||||
virtual GSError RemoveConfigChangeListener(const int32_t listenerId) = 0;
|
||||
virtual int32_t AddDumpListener(const std::string &tag, OnDumpFunc func) = 0;
|
||||
virtual GSError RemoveDumpListener(const int32_t listenerId) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void(*OnDumpFuncPtr)(void);
|
||||
typedef void(*OnConfigChangeFuncPtr)(const char *, const char *);
|
||||
|
||||
int SendInfo(const char* tag, const char *fmt, ...);
|
||||
int AddConfigChangeListener(const char* tag, OnConfigChangeFuncPtr func);
|
||||
int RemoveConfigChangeListener(int listenerId);
|
||||
int AddDumpListener(const char* tag, OnDumpFuncPtr func);
|
||||
int RemoveDumpListener(int listenerId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_H
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2021 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.
|
||||
|
||||
# [dumper]
|
||||
# A.B=true
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_LINE_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_LINE_H
|
||||
|
||||
#include <promise.h>
|
||||
#include <string>
|
||||
|
||||
#include "ipc/graphic_dumper_info_listener_stub.h"
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct DumperArgs {
|
||||
bool wait = false;
|
||||
std::string dumpTag = {};
|
||||
std::string logTag = {};
|
||||
std::string getCfgKey = {};
|
||||
std::string setCfgKey = {};
|
||||
std::string setCfgValue = {};
|
||||
};
|
||||
|
||||
class GraphicDumperCommandLine : public GraphicDumperInfoListenerStub {
|
||||
public:
|
||||
static sptr<GraphicDumperCommandLine> GetInstance();
|
||||
virtual void OnInfoComing(const std::string &info) override;
|
||||
GSError Main(int32_t argc, char *argv[]);
|
||||
|
||||
private:
|
||||
GraphicDumperCommandLine() = default;
|
||||
~GraphicDumperCommandLine() = default;
|
||||
static inline sptr<GraphicDumperCommandLine> instance_;
|
||||
|
||||
void HandlerOfArgs();
|
||||
GSError OptionParse(const char option);
|
||||
GSError Parse(int32_t argc, char *argv[]);
|
||||
GSError InitSA(int32_t systemAbilityId);
|
||||
|
||||
sptr<IGraphicDumperCommand> service_;
|
||||
DumperArgs dumperArgs_ = {};
|
||||
};
|
||||
|
||||
class GDumperCommandDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
GDumperCommandDeathRecipient() = default;
|
||||
virtual ~GDumperCommandDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_LINE_H
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_IMPL_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_IMPL_H
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "ipc/graphic_dumper_service_proxy.h"
|
||||
#include "ipc/graphic_dumper_client_listener_stub.h"
|
||||
#include "graphic_dumper_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
class GraphicDumperClientListener;
|
||||
}
|
||||
|
||||
using ConfigFuncMapPtr = std::unique_ptr<std::map<int32_t, OnConfigChangeFunc>>;
|
||||
using DumpFuncMapPtr = std::unique_ptr<std::map<int32_t, OnDumpFunc>>;
|
||||
|
||||
class GraphicDumperHelperImpl : public GraphicDumperHelper {
|
||||
friend class GraphicDumperClientListener;
|
||||
public:
|
||||
static sptr<GraphicDumperHelper> GetInstance();
|
||||
|
||||
virtual GSError SendInfo(const std::string &tag, const char *fmt, ...) override;
|
||||
virtual int32_t AddConfigChangeListener(const std::string &tag, OnConfigChangeFunc func) override;
|
||||
virtual GSError RemoveConfigChangeListener(const int32_t listenerId) override;
|
||||
virtual int32_t AddDumpListener(const std::string &tag, OnDumpFunc func) override;
|
||||
virtual GSError RemoveDumpListener(const int32_t listenerId) override;
|
||||
|
||||
void SetConnectState(bool state);
|
||||
|
||||
private:
|
||||
virtual ~GraphicDumperHelperImpl() = default;
|
||||
static inline sptr<GraphicDumperHelper> currentHelper = nullptr;
|
||||
static void SetNoopInstance();
|
||||
|
||||
GSError Init();
|
||||
GSError InitSA(int32_t systemAbilityId);
|
||||
GSError AddClientListener(const std::string &tag);
|
||||
void DispenseOnConfigChange(const std::string &tag, const std::string &val);
|
||||
void DispenseOnDump(const std::string &tag);
|
||||
|
||||
std::mutex initMutex_;
|
||||
std::atomic_int64_t requestConnectTime = 0;
|
||||
std::atomic_bool serverConnected = false;
|
||||
sptr<IGraphicDumperService> service_ = nullptr;
|
||||
|
||||
std::mutex clientListenerMutex_;
|
||||
sptr<IGraphicDumperClientListener> listener_ = nullptr;
|
||||
|
||||
int32_t onConfigChangeFuncId_ = 0;
|
||||
std::mutex onConfigChangeMutex_;
|
||||
std::map<std::string, ConfigFuncMapPtr> onConfigChangeMap_;
|
||||
|
||||
int32_t onDumperFuncId_ = 0;
|
||||
std::mutex onDumperFuncsMutex_;
|
||||
std::map<std::string, DumpFuncMapPtr> onDumpFuncsMap_;
|
||||
|
||||
struct InfoStruct {
|
||||
std::string tag;
|
||||
std::string info;
|
||||
};
|
||||
std::mutex cacheInfoMutex_;
|
||||
std::vector<InfoStruct> cacheInfo_;
|
||||
};
|
||||
|
||||
class GDumperServiceDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
GDumperServiceDeathRecipient() = default;
|
||||
virtual ~GDumperServiceDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
|
||||
class GraphicDumperHelperNoop : public GraphicDumperHelper {
|
||||
public:
|
||||
virtual GSError SendInfo(const std::string &tag, const char *fmt, ...)
|
||||
{
|
||||
return GSERROR_CONNOT_CONNECT_SERVER;
|
||||
}
|
||||
virtual int32_t AddConfigChangeListener(const std::string &tag, OnConfigChangeFunc func)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual GSError RemoveConfigChangeListener(const int32_t listenerId)
|
||||
{
|
||||
return GSERROR_CONNOT_CONNECT_SERVER;
|
||||
}
|
||||
virtual int32_t AddDumpListener(const std::string &tag, OnDumpFunc func)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual GSError RemoveDumpListener(const int32_t listenerId)
|
||||
{
|
||||
return GSERROR_CONNOT_CONNECT_SERVER;
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
class GraphicDumperClientListener : public GraphicDumperClientListenerStub {
|
||||
public:
|
||||
GraphicDumperClientListener(sptr<GraphicDumperHelperImpl>& helper);
|
||||
virtual ~GraphicDumperClientListener() = default;
|
||||
|
||||
void OnConfigChange(const std::string &tag, const std::string &val) override;
|
||||
void OnDump(const std::string &tag) override;
|
||||
|
||||
private:
|
||||
sptr<GraphicDumperHelperImpl> helperImpl_ = nullptr;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_HELPER_IMPL_H
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_HILOG_H
|
||||
#define FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_HILOG_H
|
||||
|
||||
#include "hilog/log.h"
|
||||
namespace OHOS {
|
||||
#define GD_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define GDLOGD(fmt, ...) GD_CPRINTF(HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__)
|
||||
#define GDLOGI(fmt, ...) GD_CPRINTF(HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
|
||||
#define GDLOGW(fmt, ...) GD_CPRINTF(HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__)
|
||||
#define GDLOGE(fmt, ...) GD_CPRINTF(HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define GDLOGFD(fmt, ...) GDLOGD("%{public}s: " fmt, __func__, ##__VA_ARGS__)
|
||||
#define GDLOGFI(fmt, ...) GDLOGI("%{public}s: " fmt, __func__, ##__VA_ARGS__)
|
||||
#define GDLOGFW(fmt, ...) GDLOGW("%{public}s: " fmt, __func__, ##__VA_ARGS__)
|
||||
#define GDLOGFE(fmt, ...) GDLOGE("%{public}s: " fmt, __func__, ##__VA_ARGS__)
|
||||
|
||||
#define GDLOG_SUCCESS(fmt, ...) GDLOGI("Success, Way: " fmt, ##__VA_ARGS__)
|
||||
#define GDLOG_FAILURE(fmt, ...) GDLOGE("Failure, Reason: " fmt, ##__VA_ARGS__)
|
||||
#define GDLOG_FAILURE_NO(gs_error) GDLOG_FAILURE("%{public}s", GSErrorStr(gs_error).c_str())
|
||||
#define GDLOG_FAILURE_RET(gs_error) \
|
||||
do { \
|
||||
GDLOG_FAILURE_NO(gs_error); \
|
||||
return gs_error; \
|
||||
} while (0)
|
||||
#define GDLOG_FAILURE_API(api, ret) GDLOG_FAILURE(#api " failed with %{public}s", GSErrorStr(ret).c_str())
|
||||
|
||||
#define GDLOG_ERROR(errno, fmt, ...) \
|
||||
GDLOGE(fmt ", means %{public}s", ##__VA_ARGS__, strerror(errno))
|
||||
|
||||
#define GDLOG_ERROR_API(ret, api) \
|
||||
GDLOG_ERROR(ret, #api " failed with %{public}d", ret)
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_HILOG_H
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVER_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVER_H
|
||||
|
||||
#include <any>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <ipc_skeleton.h>
|
||||
#include <refbase.h>
|
||||
|
||||
#include "graphic_dumper_tree.h"
|
||||
#include "ipc/igraphic_dumper_client_listener.h"
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
#include "ipc/igraphic_dumper_info_listener.h"
|
||||
#include "ipc/igraphic_dumper_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct LogBuffer {
|
||||
bool canSave = false;
|
||||
bool needSave = false;
|
||||
bool sync = false;
|
||||
uint32_t index = 0;
|
||||
uint32_t size[2] = {0};
|
||||
std::mutex mutex[2];
|
||||
std::vector<std::unique_ptr<std::vector<std::string>>> vec;
|
||||
std::string mask = {};
|
||||
};
|
||||
|
||||
struct LogBlock {
|
||||
uint32_t size;
|
||||
uint32_t length;
|
||||
uint8_t data[0];
|
||||
};
|
||||
|
||||
struct ConfigTags {
|
||||
uint32_t id = 0;
|
||||
sptr<IGraphicDumperClientListener> listener = nullptr;
|
||||
std::vector<std::string> tags = {};
|
||||
};
|
||||
|
||||
class GraphicDumperServer : public RefBase {
|
||||
public:
|
||||
static sptr<GraphicDumperServer> GetInstance();
|
||||
int32_t Init();
|
||||
|
||||
GSError AddConfigListener(const std::string &tag, sptr<IGraphicDumperClientListener> &listener);
|
||||
GSError RemoveConfigListener(sptr<IRemoteObject> object);
|
||||
GSError GetConfig(const std::string &k, std::string &v);
|
||||
GSError SetConfig(const std::string &k, const std::string &v);
|
||||
GSError Dump(const std::string &tag);
|
||||
|
||||
GSError AddInfoListener(sptr<IGraphicDumperInfoListener> &listener);
|
||||
GSError RemoveInfoListener(const wptr<IRemoteObject> &object);
|
||||
GSError InfoHandle(const std::string &tag, const std::string &info);
|
||||
GSError GetLog(const std::string &tag, const std::string &info);
|
||||
|
||||
private:
|
||||
GraphicDumperServer() = default;
|
||||
virtual ~GraphicDumperServer() = default;
|
||||
static inline sptr<GraphicDumperServer> instance_;
|
||||
|
||||
int32_t StartServer(int32_t systemAbility, sptr<IRemoteObject> obj);
|
||||
int32_t ReadDefaultConfig();
|
||||
void AddConfigDeathRecipient(sptr<IRemoteObject> &object);
|
||||
bool HaveConfigDeathRecipient(sptr<IRemoteObject> &object);
|
||||
bool HaveObject(const sptr<IRemoteObject> &obj);
|
||||
void VisitEach(const TreeNodePtr &node, std::function<void(const TreeNodePtr&)> func);
|
||||
void RemoveNode(std::vector<std::string> &vec, TreeNodePtr &sub, uint32_t &listenerId);
|
||||
void DispenseConfig(const TreeNodePtr &node, const std::string &k, const std::string &v);
|
||||
void DispenseDump(const TreeNodePtr &node, const std::string &tag);
|
||||
|
||||
void AddInfoDeathRecipient(sptr<IRemoteObject> &object);
|
||||
bool HaveInfoDeathRecipient(sptr<IRemoteObject> &object);
|
||||
void SendToInfoListener(const std::string &info);
|
||||
static void SaveLog(std::any server);
|
||||
GSError LogHandle(const std::string &tag, const std::string &info);
|
||||
|
||||
private:
|
||||
std::mutex infoListenersMutex_;
|
||||
std::map<sptr<IRemoteObject>, sptr<IGraphicDumperInfoListener>> infoListeners_;
|
||||
std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> infoListenerDeathRecipientMap_;
|
||||
|
||||
uint32_t objectId_ = 0;
|
||||
std::map<uint32_t, ConfigTags> configTagsMap_;
|
||||
std::map<sptr<IRemoteObject>, uint32_t> objectIdMap_;
|
||||
std::mutex treeMutex_;
|
||||
const TreeNodePtr root = std::make_shared<GraphicDumperTree>();
|
||||
|
||||
LogBuffer logBuf_;
|
||||
uint32_t logBlockSize_ = 0;
|
||||
std::mutex logBlockVectorMutex_;
|
||||
std::vector<std::unique_ptr<uint8_t[]>> logBlockVector_;
|
||||
std::unique_ptr<std::thread> thread_ = nullptr;
|
||||
std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> configListenerDeathRecipientMap_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVER_H
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_TREE_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_TREE_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_client_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperTree;
|
||||
using TreeNodePtr = std::shared_ptr<GraphicDumperTree>;
|
||||
using TreeNodeVisitFunc = std::function<void(const TreeNodePtr &v)>;
|
||||
using TreeNodeMap = std::map<const std::string, TreeNodePtr>;
|
||||
|
||||
class GraphicDumperTree {
|
||||
public:
|
||||
TreeNodePtr GetSetNode(const std::string str);
|
||||
bool HasNode(const std::string str);
|
||||
bool IsEmptyNode();
|
||||
void EraseNode(const std::string &tag);
|
||||
std::string GetTag();
|
||||
void SetValue(const std::string str);
|
||||
std::string GetValue();
|
||||
void AddListenerId(uint32_t &listenerId);
|
||||
void RemoveListenerId(uint32_t &listenerId);
|
||||
std::vector<uint32_t> GetListenerIds() const;
|
||||
void Foreach(TreeNodeVisitFunc func) const;
|
||||
|
||||
private:
|
||||
std::string tag_ = "";
|
||||
std::string value_ = "";
|
||||
std::unique_ptr<TreeNodeMap> nodeMap_ = nullptr;
|
||||
std::vector<uint32_t> listenerIds_ = {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_TREE_H
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_UTIL_H
|
||||
#define FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_UTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
constexpr int32_t CFGTERMSIZE = 2;
|
||||
|
||||
std::vector<std::string> Split(std::string src, const std::string &splitStr);
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPER_INCLUDE_GRAPHIC_DUMPER_UTIL_H
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_DEATH_RECIPIENT_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_DEATH_RECIPIENT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <iremote_proxy.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperClientListenerDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
GraphicDumperClientListenerDeathRecipient() = default;
|
||||
virtual ~GraphicDumperClientListenerDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_H
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_PROXY_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_PROXY_H
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_client_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperClientListenerProxy : public IRemoteProxy<IGraphicDumperClientListener> {
|
||||
public:
|
||||
GraphicDumperClientListenerProxy(const sptr<IRemoteObject>& impl);
|
||||
virtual ~GraphicDumperClientListenerProxy() = default;
|
||||
|
||||
void OnConfigChange(const std::string &tag, const std::string &val) override;
|
||||
void OnDump(const std::string &tag) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<GraphicDumperClientListenerProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_STUB_H
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_STUB_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_client_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperClientListenerStub : public IRemoteStub<IGraphicDumperClientListener> {
|
||||
public:
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_CLIENT_LISTENER_STUB_H
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_PROXY_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_PROXY_H
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperCommandProxy : public IRemoteProxy<IGraphicDumperCommand> {
|
||||
public:
|
||||
GraphicDumperCommandProxy(const sptr<IRemoteObject>& impl);
|
||||
virtual ~GraphicDumperCommandProxy() = default;
|
||||
|
||||
GSError GetConfig(const std::string &k, std::string &v) override;
|
||||
GSError SetConfig(const std::string &k, const std::string &v) override;
|
||||
GSError Dump(const std::string &key) override;
|
||||
GSError GetLog(const std::string &tag, std::string &log) override;
|
||||
GSError AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<GraphicDumperCommandProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_STUB_H
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_STUB_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperCommandStub : public IRemoteStub<IGraphicDumperCommand> {
|
||||
public:
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option) override;
|
||||
virtual GSError GetConfig(const std::string &k, std::string &v) override;
|
||||
virtual GSError SetConfig(const std::string &k, const std::string &v) override;
|
||||
|
||||
using IPCObjectStub::Dump;
|
||||
virtual GSError Dump(const std::string &tag) override;
|
||||
virtual GSError GetLog(const std::string &tag, std::string &log) override;
|
||||
virtual GSError AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_H
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_DEATH_RECIPIENT_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_DEATH_RECIPIENT_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperInfoListenerDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
GraphicDumperInfoListenerDeathRecipient() = default;
|
||||
virtual ~GraphicDumperInfoListenerDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_COMMAND_H
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_PROXY_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_PROXY_H
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_info_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperInfoListenerProxy : public IRemoteProxy<IGraphicDumperInfoListener> {
|
||||
public:
|
||||
GraphicDumperInfoListenerProxy(const sptr<IRemoteObject>& impl);
|
||||
virtual ~GraphicDumperInfoListenerProxy() = default;
|
||||
void OnInfoComing(const std::string &info) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<GraphicDumperInfoListenerProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_STUB_H
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_STUB_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_info_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperInfoListenerStub : public IRemoteStub<IGraphicDumperInfoListener> {
|
||||
public:
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_INFO_LISTENER_STUB_H
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_PROXY_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_PROXY_H
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperServiceProxy : public IRemoteProxy<IGraphicDumperService> {
|
||||
public:
|
||||
GraphicDumperServiceProxy(const sptr<IRemoteObject>& impl);
|
||||
virtual ~GraphicDumperServiceProxy() = default;
|
||||
GSError AddClientListener(const std::string &tag, sptr<IGraphicDumperClientListener> &listener) override;
|
||||
GSError SendInfo(const std::string &tag, const std::string &info) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<GraphicDumperServiceProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_PROXY_H
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_STUB_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_STUB_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <iremote_proxy.h>
|
||||
#include <message_parcel.h>
|
||||
#include <message_option.h>
|
||||
|
||||
#include "ipc/igraphic_dumper_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicDumperServiceStub : public IRemoteStub<IGraphicDumperService> {
|
||||
public:
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option) override;
|
||||
GSError AddClientListener(const std::string &tag, sptr<IGraphicDumperClientListener> &listener) override;
|
||||
GSError SendInfo(const std::string &tag, const std::string &info) override;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_GRAPHIC_DUMPER_SERVICE_H
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_CLIENT_LISTENER_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_CLIENT_LISTENER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
class IGraphicDumperClientListener : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnConfigChange(const std::string &tag, const std::string &val) = 0;
|
||||
virtual void OnDump(const std::string &key) = 0;
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"IGraphicDumperClientListener");
|
||||
|
||||
protected:
|
||||
enum {
|
||||
IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_CONFIG_CHANGE,
|
||||
IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_DUMP,
|
||||
};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_CLIENT_LISTENER_H
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_COMMAND_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_COMMAND_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
#include "graphic_common.h"
|
||||
#include "ipc/igraphic_dumper_info_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IGraphicDumperCommand : public IRemoteBroker {
|
||||
public:
|
||||
virtual GSError GetConfig(const std::string &k, std::string &v) = 0;
|
||||
virtual GSError SetConfig(const std::string &k, const std::string &v) = 0;
|
||||
virtual GSError Dump(const std::string &tag) = 0;
|
||||
virtual GSError GetLog(const std::string &tag, std::string &log) = 0;
|
||||
virtual GSError AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"IGraphicDumperCommand");
|
||||
|
||||
protected:
|
||||
enum {
|
||||
IGRAPHIC_DUMPER_COMMAND_GET_CONFIG,
|
||||
IGRAPHIC_DUMPER_COMMAND_SET_CONFIG,
|
||||
IGRAPHIC_DUMPER_COMMAND_DUMP,
|
||||
IGRAPHIC_DUMPER_COMMAND_GET_LOG,
|
||||
IGRAPHIC_DUMPER_COMMAND_ADD_INFO_LISTENER,
|
||||
};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_COMMAND_H
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_INFO_LISTENER_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_INFO_LISTENER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
class IGraphicDumperInfoListener : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnInfoComing(const std::string &info) = 0;
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"IGraphicDumperInfoListener");
|
||||
|
||||
protected:
|
||||
enum {
|
||||
IGRAPHIC_DUMPER_INFO_LISTENER_ON_INFO_COMING,
|
||||
};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_INFO_LISTENER_H
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_SERVICE_H
|
||||
#define FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_SERVICE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
#include "graphic_common.h"
|
||||
#include "ipc/igraphic_dumper_client_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IGraphicDumperService : public IRemoteBroker {
|
||||
public:
|
||||
virtual GSError AddClientListener(const std::string &tag, sptr<IGraphicDumperClientListener> &listener) = 0;
|
||||
virtual GSError SendInfo(const std::string &tag, const std::string &info) = 0;
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"IGraphicDumperService");
|
||||
|
||||
protected:
|
||||
enum {
|
||||
IGRAPHIC_DUMPER_SERVICE_ADD_CLIENT_LISTENER,
|
||||
IGRAPHIC_DUMPER_SERVICE_SEND_INFO,
|
||||
};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DUMPRE_INCLUDE_IGRAPHIC_DUMPER_SERVICE_H
|
@ -1,266 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_command_line.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <ipc_skeleton.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_dumper_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperCommandLine" };
|
||||
constexpr int SLEEP_TIME = 5 * 1000;
|
||||
Promise<int> signalPromise;
|
||||
|
||||
static void Helper()
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: [options]\n"
|
||||
"options include:\n"
|
||||
" -h --help show this message.\n"
|
||||
" -w --wait wait mode; listen for new prints.\n"
|
||||
" -g <key>, --get <key>\n"
|
||||
" get config with key.\n"
|
||||
" -s <key>=<value>, --set <key>=<value>\n"
|
||||
" set config of key is equal to value.\n"
|
||||
" -l <tag> --log <tag>\n"
|
||||
" read log with tag.\n"
|
||||
" -d <tag> --dump <tag>\n"
|
||||
" read dump info with tag.\n"
|
||||
" read all dump info with --all.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
sptr<GraphicDumperCommandLine> GraphicDumperCommandLine::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new GraphicDumperCommandLine();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void GraphicDumperCommandLine::OnInfoComing(const std::string &info)
|
||||
{
|
||||
std::cerr << info.c_str() << std::endl;
|
||||
}
|
||||
|
||||
void Handler(int signal)
|
||||
{
|
||||
switch (signal) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
case SIGTSTP:
|
||||
case SIGQUIT:
|
||||
case SIGHUP: {
|
||||
signalPromise.Resolve(signal);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SignalInit()
|
||||
{
|
||||
std::signal(SIGINT, Handler);
|
||||
std::signal(SIGKILL, Handler);
|
||||
std::signal(SIGTERM, Handler);
|
||||
std::signal(SIGTSTP, Handler);
|
||||
std::signal(SIGQUIT, Handler);
|
||||
std::signal(SIGHUP, Handler);
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandLine::Main(int32_t argc, char *argv[])
|
||||
{
|
||||
GSError iRet = GSERROR_OK;
|
||||
if (argc <= 1) {
|
||||
Helper();
|
||||
return iRet;
|
||||
}
|
||||
|
||||
iRet = Parse(argc, argv);
|
||||
if (iRet != GSERROR_OK) {
|
||||
return iRet;
|
||||
}
|
||||
|
||||
SignalInit();
|
||||
|
||||
iRet = InitSA(GRAPHIC_DUMPER_COMMAND_SA_ID);
|
||||
if (iRet != GSERROR_OK) {
|
||||
std::cerr << "Init SA failed: " << GSErrorStr(iRet) << std::endl;
|
||||
return iRet;
|
||||
}
|
||||
|
||||
sptr<IGraphicDumperInfoListener> listener = this;
|
||||
iRet = service_->AddInfoListener("", listener);
|
||||
if (iRet != GSERROR_OK) {
|
||||
std::cerr << "Add info listener failed: " << GSErrorStr(iRet) << std::endl;
|
||||
return iRet;
|
||||
}
|
||||
|
||||
HandlerOfArgs();
|
||||
usleep(SLEEP_TIME);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
void GraphicDumperCommandLine::HandlerOfArgs()
|
||||
{
|
||||
if (!dumperArgs_.dumpTag.empty()) {
|
||||
service_->Dump("*#dp#*." + dumperArgs_.dumpTag);
|
||||
std::cerr << "get dump with tag:" << dumperArgs_.dumpTag.c_str() << std::endl;
|
||||
}
|
||||
if (!dumperArgs_.logTag.empty()) {
|
||||
std::string getLog = {};
|
||||
std::cerr << "get log with tag:" << dumperArgs_.logTag.c_str() << std::endl;
|
||||
service_->GetLog(dumperArgs_.logTag, getLog);
|
||||
std::cerr << "log is" << getLog.c_str() << std::endl;
|
||||
}
|
||||
if (!dumperArgs_.getCfgKey.empty()) {
|
||||
std::string getCfgValue = {};
|
||||
service_->GetConfig(dumperArgs_.getCfgKey, getCfgValue);
|
||||
std::cerr << "get cfg with key:" << dumperArgs_.getCfgKey.c_str() << "value is:"
|
||||
<< getCfgValue.c_str() << std::endl;
|
||||
}
|
||||
if ((!dumperArgs_.setCfgKey.empty()) && (!dumperArgs_.setCfgKey.empty())) {
|
||||
service_->SetConfig(dumperArgs_.setCfgKey, dumperArgs_.setCfgValue);
|
||||
std::cerr << "set cfg with key:" << dumperArgs_.setCfgKey.c_str() << "value is:"
|
||||
<< dumperArgs_.setCfgValue.c_str() << std::endl;
|
||||
}
|
||||
if (dumperArgs_.wait) {
|
||||
signalPromise.Await();
|
||||
}
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandLine::OptionParse(const char option)
|
||||
{
|
||||
switch (option) {
|
||||
case 'h': {
|
||||
Helper();
|
||||
return GSERROR_OK;
|
||||
}
|
||||
case 'w': {
|
||||
dumperArgs_.wait = true;
|
||||
break;
|
||||
}
|
||||
case 'g': {
|
||||
dumperArgs_.getCfgKey = optarg;
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
auto ret = Split(optarg, "=");
|
||||
if (ret.size() != CFGTERMSIZE) {
|
||||
std::cerr << "Parameter format error." << std::endl;
|
||||
return GSERROR_INVALID_OPERATING;
|
||||
}
|
||||
dumperArgs_.setCfgKey = ret[0];
|
||||
dumperArgs_.setCfgValue = ret[1];
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
dumperArgs_.logTag = optarg;
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
dumperArgs_.dumpTag = optarg;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
std::cerr << "Command not found." << std::endl;
|
||||
return GSERROR_INVALID_OPERATING;
|
||||
}
|
||||
} // switch
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandLine::Parse(int32_t argc, char *argv[])
|
||||
{
|
||||
int optIndex = 0;
|
||||
static const struct option longOptions[] = {
|
||||
{ "help", no_argument, nullptr, 'h' },
|
||||
{ "wait", no_argument, nullptr, 'w' },
|
||||
{ "log", required_argument, nullptr, 'l' },
|
||||
{ "dump", required_argument, nullptr, 'd' },
|
||||
{ "get", required_argument, nullptr, 'g' },
|
||||
{ "set", required_argument, nullptr, 's' },
|
||||
{nullptr, 0, nullptr, 0}
|
||||
};
|
||||
|
||||
while (true) {
|
||||
int opt = getopt_long(argc, argv, "hwg:s:l:d:", longOptions, &optIndex);
|
||||
if (opt == -1) {
|
||||
break;
|
||||
}
|
||||
auto ret = OptionParse(opt);
|
||||
if (ret != GSERROR_OK) {
|
||||
return ret;
|
||||
}
|
||||
} // while
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandLine::InitSA(int32_t systemAbilityId)
|
||||
{
|
||||
if (service_ != nullptr) {
|
||||
GDLOG_SUCCESS("_instance != nullptr");
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sm == nullptr) {
|
||||
GDLOG_FAILURE_RET(GSERROR_CONNOT_CONNECT_SAMGR);
|
||||
}
|
||||
|
||||
auto remoteObject = sm->GetSystemAbility(systemAbilityId);
|
||||
if (remoteObject == nullptr) {
|
||||
GDLOG_FAILURE_RET(GSERROR_CONNOT_CONNECT_SERVER);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = new GDumperCommandDeathRecipient();
|
||||
if ((remoteObject->IsProxyObject()) && (!remoteObject->AddDeathRecipient(deathRecipient))) {
|
||||
GDLOGFE("Failed to add death recipient");
|
||||
}
|
||||
|
||||
service_ = iface_cast<IGraphicDumperCommand>(remoteObject);
|
||||
if (service_ == nullptr) {
|
||||
GDLOG_FAILURE_RET(GSERROR_PROXY_NOT_INCLUDE);
|
||||
}
|
||||
|
||||
GDLOG_SUCCESS("service_ = iface_cast");
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
void GDumperCommandDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
GDLOGFE("Command server Died!");
|
||||
std::raise(SIGQUIT);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_command_line.h"
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
int32_t main(int32_t argc, char *argv[])
|
||||
{
|
||||
return GraphicDumperCommandLine::GetInstance()->Main(argc, argv);
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_helper.h"
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "graphic_dumper_helper_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
sptr<GraphicDumperHelper> GraphicDumperHelper::GetInstance()
|
||||
{
|
||||
return GraphicDumperHelperImpl::GetInstance();
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
int SendInfo(const char* tag, const char *fmt, ...)
|
||||
{
|
||||
constexpr int infoSize = 4096;
|
||||
char info[infoSize];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = vsnprintf_s(info, sizeof(info), (sizeof(info) - 1), fmt, args);
|
||||
if (ret < 0) {
|
||||
va_end(args);
|
||||
return 0;
|
||||
}
|
||||
va_end(args);
|
||||
return OHOS::GraphicDumperHelperImpl::GetInstance()->SendInfo(std::string(tag), "%s", info);
|
||||
}
|
||||
|
||||
int AddConfigChangeListener(const char* tag, OnConfigChangeFuncPtr func)
|
||||
{
|
||||
auto cfunc = [func](const std::string &a, const std::string &b) {
|
||||
func(a.c_str(), b.c_str());
|
||||
};
|
||||
return OHOS::GraphicDumperHelperImpl::GetInstance()->AddConfigChangeListener(std::string(tag), cfunc);
|
||||
}
|
||||
|
||||
int RemoveConfigChangeListener(int listenerId)
|
||||
{
|
||||
return OHOS::GraphicDumperHelperImpl::GetInstance()->RemoveConfigChangeListener(listenerId);
|
||||
}
|
||||
|
||||
int AddDumpListener(const char* tag, OnDumpFuncPtr func)
|
||||
{
|
||||
return OHOS::GraphicDumperHelperImpl::GetInstance()->AddDumpListener(std::string(tag), func);
|
||||
}
|
||||
|
||||
int RemoveDumpListener(int listenerId)
|
||||
{
|
||||
return OHOS::GraphicDumperHelperImpl::GetInstance()->RemoveDumpListener(listenerId);
|
||||
}
|
@ -1,339 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_helper_impl.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdarg>
|
||||
#include <vector>
|
||||
|
||||
#include <gslogger.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <securec.h>
|
||||
#include <system_ability_definition.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
DEFINE_HILOG_LABEL("GraphicDumperHelperImpl");
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperHelperImpl" };
|
||||
constexpr int INFO_SIZE_MAX = 4096;
|
||||
}
|
||||
|
||||
GraphicDumperClientListener::GraphicDumperClientListener(sptr<GraphicDumperHelperImpl>& helper)
|
||||
: helperImpl_(helper)
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicDumperClientListener::OnConfigChange(const std::string &tag, const std::string &val)
|
||||
{
|
||||
GDLOGI("%{public}s -> %{public}s", tag.c_str(), val.c_str());
|
||||
if (helperImpl_) {
|
||||
helperImpl_->DispenseOnConfigChange(tag, val);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicDumperClientListener::OnDump(const std::string &tag)
|
||||
{
|
||||
if (helperImpl_) {
|
||||
std::string flag = "*#dp#*.";
|
||||
if (tag.find(flag) == 0) {
|
||||
std::string sTag = tag.substr(flag.length());
|
||||
helperImpl_->DispenseOnDump(sTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sptr<GraphicDumperHelper> GraphicDumperHelperImpl::GetInstance()
|
||||
{
|
||||
if (currentHelper == nullptr) {
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
if (currentHelper == nullptr) {
|
||||
currentHelper = new GraphicDumperHelperImpl();
|
||||
}
|
||||
}
|
||||
return currentHelper;
|
||||
}
|
||||
|
||||
void GraphicDumperHelperImpl::SetNoopInstance()
|
||||
{
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
currentHelper = new GraphicDumperHelperNoop();
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::Init()
|
||||
{
|
||||
if (serverConnected) {
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
if (access("/data/gdumper_enable", F_OK) != 0) {
|
||||
SetNoopInstance();
|
||||
return GSERROR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
auto now = std::chrono::steady_clock::now().time_since_epoch();
|
||||
auto nowTime = (int64_t)std::chrono::duration_cast<std::chrono::milliseconds>(now).count();
|
||||
constexpr int64_t reconnectTime = 1000;
|
||||
if ((nowTime - requestConnectTime) < reconnectTime) {
|
||||
return GSERROR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
requestConnectTime = nowTime;
|
||||
GSError ret = InitSA(GRAPHIC_DUMPER_SERVICE_SA_ID);
|
||||
if (ret != GSERROR_OK) {
|
||||
GSLOG2HI(ERROR) << "InitSA failed with " << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onConfigChangeMutex_);
|
||||
for (const auto& iter : onConfigChangeMap_) {
|
||||
ret = AddClientListener(iter.first);
|
||||
if (ret != GSERROR_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onDumperFuncsMutex_);
|
||||
for (const auto& iter : onDumpFuncsMap_) {
|
||||
ret = AddClientListener(iter.first);
|
||||
if (ret != GSERROR_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(cacheInfoMutex_);
|
||||
for (const auto& infoStruct : cacheInfo_) {
|
||||
ret = service_->SendInfo(infoStruct.tag, infoStruct.info);
|
||||
GDLOG_SUCCESS("SendInfo is %{public}d", ret);
|
||||
}
|
||||
cacheInfo_.clear();
|
||||
cacheInfo_.shrink_to_fit();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::InitSA(int32_t systemAbilityId)
|
||||
{
|
||||
if (serverConnected) {
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sam == nullptr) {
|
||||
GSLOG2HI(ERROR) << "failed with " << GSERROR_CONNOT_CONNECT_SAMGR;
|
||||
return GSERROR_CONNOT_CONNECT_SAMGR;
|
||||
}
|
||||
|
||||
auto remoteObject = sam->GetSystemAbility(systemAbilityId);
|
||||
if (remoteObject == nullptr) {
|
||||
GSLOG2HI(ERROR) << "failed with " << GSERROR_CONNOT_CONNECT_SERVER;
|
||||
return GSERROR_CONNOT_CONNECT_SERVER;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = new GDumperServiceDeathRecipient();
|
||||
if ((remoteObject->IsProxyObject()) && (!remoteObject->AddDeathRecipient(deathRecipient))) {
|
||||
GSLOG2HI(WARN) << "failed to add death recipient";
|
||||
}
|
||||
|
||||
service_ = iface_cast<IGraphicDumperService>(remoteObject);
|
||||
if (service_ == nullptr) {
|
||||
GSLOG2HI(ERROR) << "failed with " << GSERROR_PROXY_NOT_INCLUDE;
|
||||
return GSERROR_PROXY_NOT_INCLUDE;
|
||||
}
|
||||
|
||||
serverConnected = true;
|
||||
GSLOG2HI(INFO) << "service_ = iface_cast";
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::AddClientListener(const std::string &tag)
|
||||
{
|
||||
if (Init() != GSERROR_OK) {
|
||||
GSLOG2HI(ERROR) << "Init() failed";
|
||||
return GSERROR_CONNOT_CONNECT_SERVER;
|
||||
}
|
||||
|
||||
if (listener_ == nullptr) {
|
||||
std::lock_guard<std::mutex> guard(clientListenerMutex_);
|
||||
if (listener_ == nullptr) {
|
||||
sptr<GraphicDumperHelperImpl> helper = this;
|
||||
listener_ = new GraphicDumperClientListener(helper);
|
||||
}
|
||||
}
|
||||
|
||||
GSLOG2HI(INFO) << "AddClientListener Success";
|
||||
return service_->AddClientListener(tag, listener_);
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::SendInfo(const std::string &tag, const char *fmt, ...)
|
||||
{
|
||||
char info[INFO_SIZE_MAX]; // clear by vsnprintf
|
||||
{
|
||||
static std::mutex sprintfMutex_;
|
||||
std::lock_guard<std::mutex> lock(sprintfMutex_);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = vsnprintf_s(info, sizeof(info), (sizeof(info) - 1), fmt, args);
|
||||
if (ret < 0) {
|
||||
va_end(args);
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
GSError retInit = Init();
|
||||
if (retInit == GSERROR_OK) {
|
||||
return service_->SendInfo(tag, std::string(info));
|
||||
} else if (retInit == GSERROR_NOT_SUPPORT) {
|
||||
return retInit;
|
||||
} else {
|
||||
struct InfoStruct infoStruct = {
|
||||
.tag = tag,
|
||||
.info = info,
|
||||
};
|
||||
std::lock_guard<std::mutex> guard(cacheInfoMutex_);
|
||||
cacheInfo_.push_back(infoStruct);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t GraphicDumperHelperImpl::AddConfigChangeListener(const std::string &tag, OnConfigChangeFunc func)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onConfigChangeMutex_);
|
||||
if (onConfigChangeMap_.find(tag) != onConfigChangeMap_.end()) {
|
||||
(*onConfigChangeMap_[tag])[++onConfigChangeFuncId_] = func;
|
||||
return onConfigChangeFuncId_;
|
||||
}
|
||||
}
|
||||
int ret = AddClientListener(tag);
|
||||
if (ret != GSERROR_OK) {
|
||||
return 0;
|
||||
}
|
||||
auto onConfigChangeFuncs = std::make_unique<std::map<int32_t, OnConfigChangeFunc>>();
|
||||
(*onConfigChangeFuncs)[++onConfigChangeFuncId_] = func;
|
||||
onConfigChangeMap_[tag] = std::move(onConfigChangeFuncs);
|
||||
return onConfigChangeFuncId_;
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::RemoveConfigChangeListener(const int32_t listenerId)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onConfigChangeMutex_);
|
||||
for (auto& [k, v] : onConfigChangeMap_) {
|
||||
if (v->find(listenerId) != v->end()) {
|
||||
v->erase(listenerId);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
}
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
int32_t GraphicDumperHelperImpl::AddDumpListener(const std::string &tag, OnDumpFunc func)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onDumperFuncsMutex_);
|
||||
if (onDumpFuncsMap_.find(tag) != onDumpFuncsMap_.end()) {
|
||||
(*onDumpFuncsMap_[tag])[++onDumperFuncId_] = func;
|
||||
return onDumperFuncId_;
|
||||
}
|
||||
}
|
||||
auto dumpTag = "*#dp#*." + tag;
|
||||
int ret = AddClientListener(dumpTag);
|
||||
if (ret != GSERROR_OK) {
|
||||
GSLOG2HI(ERROR) << "AddClientListener failed with " << ret;
|
||||
return 0;
|
||||
}
|
||||
auto onDumpFuncs = std::make_unique<std::map<int32_t, OnDumpFunc>>();
|
||||
(*onDumpFuncs)[++onDumperFuncId_] = func;
|
||||
onDumpFuncsMap_[tag] = std::move(onDumpFuncs);
|
||||
return onDumperFuncId_;
|
||||
}
|
||||
|
||||
GSError GraphicDumperHelperImpl::RemoveDumpListener(const int32_t listenerId)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onDumperFuncsMutex_);
|
||||
for (auto& [k, v] : onDumpFuncsMap_) {
|
||||
if (v->find(listenerId) != v->end()) {
|
||||
v->erase(listenerId);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
}
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
void GraphicDumperHelperImpl::SetConnectState(bool state)
|
||||
{
|
||||
GDLOGFI("");
|
||||
serverConnected = state;
|
||||
}
|
||||
|
||||
void GraphicDumperHelperImpl::DispenseOnConfigChange(const std::string &tag, const std::string &val)
|
||||
{
|
||||
GDLOGI("%{public}s -> %{public}s", tag.c_str(), val.c_str());
|
||||
std::lock_guard<std::mutex> guard(onConfigChangeMutex_);
|
||||
if (onConfigChangeMap_.empty()) {
|
||||
return;
|
||||
}
|
||||
if (!onConfigChangeMap_[tag]->empty()) {
|
||||
for (const auto &[id, func] : *onConfigChangeMap_[tag]) {
|
||||
func(tag, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicDumperHelperImpl::DispenseOnDump(const std::string &tag)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(onDumperFuncsMutex_);
|
||||
if (onDumpFuncsMap_.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tag == "--all") {
|
||||
for (const auto& [t, mapPtr] : onDumpFuncsMap_) {
|
||||
if (mapPtr != nullptr) {
|
||||
for (const auto &[id, func] : *mapPtr) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (onDumpFuncsMap_.find(tag) != onDumpFuncsMap_.end()) {
|
||||
if (onDumpFuncsMap_[tag] != nullptr) {
|
||||
for (const auto &[id, func] : *onDumpFuncsMap_[tag]) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GDumperServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
auto helper = GraphicDumperHelperImpl::GetInstance();
|
||||
auto helperImpl = reinterpret_cast<GraphicDumperHelperImpl *>(helper.GetRefPtr());
|
||||
helperImpl->SetConnectState(false);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,567 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_server.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
#include <iremote_object.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <securec.h>
|
||||
#include <system_ability_definition.h>
|
||||
#include <unistd.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "ipc/graphic_dumper_info_listener_death_recipient.h"
|
||||
#include "ipc/graphic_dumper_client_listener_death_recipient.h"
|
||||
#include "ipc/graphic_dumper_service_stub.h"
|
||||
#include "ipc/graphic_dumper_command_stub.h"
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_dumper_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperServer" };
|
||||
constexpr int SLEEP_TIME = 500 * 1000;
|
||||
constexpr uint32_t LOG_BUF_SIZE_MAX = 192 * 1024;
|
||||
constexpr uint32_t LOG_BLOCK_SIZE_MAX = 4 * 1000 * 1024;
|
||||
constexpr uint32_t LOG_VEC_SIZE = 2;
|
||||
constexpr const char *GDUMPER_INI_PATH = "/system/etc/gdumper.ini";
|
||||
|
||||
std::string& Trim (std::string &s)
|
||||
{
|
||||
std::regex fmt("\\s");
|
||||
s = std::regex_replace(s, fmt, "");
|
||||
return s;
|
||||
}
|
||||
|
||||
void StrLogRomveTag(bool getAll, const std::string &tag,
|
||||
const std::string &strIn, std::string &strOut)
|
||||
{
|
||||
auto pos = strIn.find_first_of("| [");
|
||||
constexpr int offset = 2;
|
||||
if (pos == std::string::npos) {
|
||||
pos = 0;
|
||||
} else {
|
||||
pos += offset;
|
||||
}
|
||||
if (getAll) {
|
||||
strOut += strIn.substr(pos);
|
||||
} else if (strIn.compare(0, tag.size(), tag) == 0) {
|
||||
strOut += strIn.substr(pos);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
sptr<GraphicDumperServer> GraphicDumperServer::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new GraphicDumperServer();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int32_t GraphicDumperServer::Init()
|
||||
{
|
||||
int32_t ret = 0;
|
||||
ret = ReadDefaultConfig();
|
||||
if (ret) {
|
||||
GDLOGI("Read default config error with %d.\n", ret);
|
||||
}
|
||||
|
||||
for (auto& s : logBuf_.size) {
|
||||
s = 0;
|
||||
logBuf_.vec.push_back(std::make_unique<std::vector<std::string>>());
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> service = new GraphicDumperServiceStub();
|
||||
ret = StartServer(GRAPHIC_DUMPER_SERVICE_SA_ID, service);
|
||||
if (ret) {
|
||||
GDLOGI("Start graphic dumper service failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> command = new GraphicDumperCommandStub();
|
||||
ret = StartServer(GRAPHIC_DUMPER_COMMAND_SA_ID, command);
|
||||
if (ret) {
|
||||
GDLOGI("Start graphic dumper command failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::AddConfigListener(const std::string &tag,
|
||||
sptr<IGraphicDumperClientListener> &listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
GDLOGFE("%{public}s", tag.c_str());
|
||||
|
||||
auto object = listener->AsObject();
|
||||
AddConfigDeathRecipient(object);
|
||||
|
||||
if (HaveObject(object) == false) {
|
||||
objectIdMap_[object] = ++objectId_;
|
||||
configTagsMap_[objectId_].id = objectId_;
|
||||
configTagsMap_[objectId_].listener = listener;
|
||||
}
|
||||
auto &objectId = objectIdMap_[object];
|
||||
auto &configTags = configTagsMap_[objectId];
|
||||
for (const auto &iter : configTags.tags) {
|
||||
if (iter == tag) {
|
||||
return GSERROR_OK;
|
||||
}
|
||||
}
|
||||
configTags.tags.push_back(tag);
|
||||
|
||||
for (auto &tag__ : configTags.tags) {
|
||||
GDLOGFE("configTagsMap %{public}s", tag__.c_str());
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
std::vector<std::string> nodes = Split(tag, ".");
|
||||
TreeNodePtr sub = root;
|
||||
for (const auto& iter : nodes) {
|
||||
sub = sub->GetSetNode(iter);
|
||||
}
|
||||
sub->AddListenerId(configTags.id);
|
||||
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::RemoveConfigListener(sptr<IRemoteObject> object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
auto &deathRecipient = configListenerDeathRecipientMap_[object];
|
||||
if (deathRecipient != nullptr) {
|
||||
object->RemoveDeathRecipient(deathRecipient);
|
||||
}
|
||||
configListenerDeathRecipientMap_.erase(object);
|
||||
|
||||
auto &objectId = objectIdMap_[object];
|
||||
auto &configTags = configTagsMap_[objectId];
|
||||
|
||||
for (auto &tag : configTags.tags) {
|
||||
GDLOGFE("configTagsMap %{public}s", tag.c_str());
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
std::vector<std::string> nodes = Split(tag, ".");
|
||||
TreeNodePtr sub = root;
|
||||
RemoveNode(nodes, sub, configTags.id);
|
||||
}
|
||||
|
||||
object = nullptr;
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::GetConfig(const std::string &k, std::string &v)
|
||||
{
|
||||
GDLOGI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
std::vector<std::string> nodes = Split(k, ".");
|
||||
TreeNodePtr sub = root;
|
||||
for (const auto& iter : nodes) {
|
||||
if (sub->HasNode(iter)) {
|
||||
sub = sub->GetSetNode(iter);
|
||||
} else {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
}
|
||||
v = sub->GetValue();
|
||||
GDLOGI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::SetConfig(const std::string &k, const std::string &v)
|
||||
{
|
||||
GDLOGI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
std::vector<std::string> nodes = Split(k, ".");
|
||||
TreeNodePtr sub = root;
|
||||
for (const auto& iter : nodes) {
|
||||
sub = sub->GetSetNode(iter);
|
||||
}
|
||||
if (sub->GetValue().compare(v)) {
|
||||
sub->SetValue(v);
|
||||
DispenseConfig(sub, k, v);
|
||||
}
|
||||
GDLOGI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::Dump(const std::string &tag)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
std::vector<std::string> nodes = Split(tag, ".");
|
||||
TreeNodePtr sub = root;
|
||||
for (const auto& iter : nodes) {
|
||||
if (iter.compare("--all") == 0) {
|
||||
break;
|
||||
}
|
||||
GDLOGFE("%{public}s", iter.c_str());
|
||||
sub = sub->GetSetNode(iter);
|
||||
}
|
||||
DispenseDump(sub, tag);
|
||||
GDLOGFE("%{public}s", tag.c_str());
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::AddInfoListener(sptr<IGraphicDumperInfoListener> &listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(infoListenersMutex_);
|
||||
auto object = listener->AsObject();
|
||||
AddInfoDeathRecipient(object);
|
||||
infoListeners_[object] = listener;
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::RemoveInfoListener(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(infoListenersMutex_);
|
||||
auto sObject = object.promote();
|
||||
if (infoListeners_.find(sObject) != infoListeners_.end()) {
|
||||
infoListeners_.erase(sObject);
|
||||
}
|
||||
if (infoListeners_.empty()) {
|
||||
logBuf_.sync = false;
|
||||
logBuf_.mask.clear();
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::InfoHandle(const std::string &tag, const std::string &info)
|
||||
{
|
||||
GDLOGFE("GraphicDumperServer::InfoHandle --start!!!!!!!!!");
|
||||
std::string logFlag = {"log."};
|
||||
GDLOGFE("%{public}s -> %{public}s", tag.c_str(), info.c_str());
|
||||
if (tag.compare(0, logFlag.size(), logFlag) == 0) {
|
||||
GDLOGFE("InfoHandle to LogHandle");
|
||||
return LogHandle(tag.substr(logFlag.size()), info);
|
||||
}
|
||||
GDLOGFE("InfoHandle to SendToInfoListener");
|
||||
SendToInfoListener(tag + " : " + info);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
GSError GraphicDumperServer::GetLog(const std::string &tag, const std::string &info)
|
||||
{
|
||||
GDLOGFE("%{public}s -> %{public}s", tag.c_str(), info.c_str());
|
||||
bool getAll = false;
|
||||
if (tag.compare("--all") == 0) {
|
||||
getAll = true;
|
||||
logBuf_.mask.clear();
|
||||
} else {
|
||||
logBuf_.mask = tag;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logBlockVectorMutex_);
|
||||
for (const auto& array : logBlockVector_) {
|
||||
auto logBlock = reinterpret_cast<LogBlock *>(array.get());
|
||||
std::string toSendStr = {};
|
||||
uint32_t offset = 0;
|
||||
GDLOGFE("logBlock->size = %{public}d", logBlock->size);
|
||||
while (offset < logBlock->size) {
|
||||
std::string str(reinterpret_cast<const char*>(logBlock->data + offset));
|
||||
GDLOGFE("logBlock = %{public}s", str.c_str());
|
||||
StrLogRomveTag(getAll, tag, str, toSendStr);
|
||||
offset += (str.size() + 1);
|
||||
}
|
||||
SendToInfoListener(toSendStr);
|
||||
}
|
||||
}
|
||||
|
||||
std::string logStr = {};
|
||||
if (logBuf_.canSave || logBuf_.needSave) {
|
||||
uint32_t index = (logBuf_.index + 1) % LOG_VEC_SIZE;
|
||||
std::lock_guard<std::mutex> guard(logBuf_.mutex[index]);
|
||||
for (const auto& str : *logBuf_.vec[index]) {
|
||||
GDLOGFE("logBuf_cansave = %{public}s", str.c_str());
|
||||
StrLogRomveTag(getAll, tag, str, logStr);
|
||||
}
|
||||
}
|
||||
SendToInfoListener(logStr);
|
||||
|
||||
logStr.clear();
|
||||
|
||||
{
|
||||
uint32_t index = logBuf_.index;
|
||||
std::lock_guard<std::mutex> guard(logBuf_.mutex[index]);
|
||||
for (const auto& str : *logBuf_.vec[index]) {
|
||||
GDLOGFE("logBuf_ = %{public}s", str.c_str());
|
||||
StrLogRomveTag(getAll, tag, str, logStr);
|
||||
}
|
||||
}
|
||||
SendToInfoListener(logStr);
|
||||
|
||||
logBuf_.sync = true;
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
int32_t GraphicDumperServer::StartServer(int32_t systemAbility, sptr<IRemoteObject> obj)
|
||||
{
|
||||
if (systemAbility == 0 || obj == nullptr) {
|
||||
GDLOGI("graphic dumper start_server parameter error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
while (1) {
|
||||
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sm != nullptr) {
|
||||
result = sm->AddSystemAbility(systemAbility, obj);
|
||||
break;
|
||||
}
|
||||
GDLOGI("graphic dumper start_server SystemAbilityManager is nullptr");
|
||||
usleep(SLEEP_TIME);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t GraphicDumperServer::ReadDefaultConfig()
|
||||
{
|
||||
int32_t successConst = 0;
|
||||
int32_t failConst = 0;
|
||||
std::string getLineStr = {};
|
||||
std::vector<std::string> cfgStrs = {};
|
||||
std::ifstream input(GDUMPER_INI_PATH);
|
||||
if (!input.is_open()) {
|
||||
GDLOGE("failed to open: %{public}s", GDUMPER_INI_PATH);
|
||||
} else {
|
||||
while (!input.eof()) {
|
||||
getline(input, getLineStr);
|
||||
Trim(getLineStr);
|
||||
std::string first = getLineStr.substr(0, 1);
|
||||
if (first != "#" && first != "") {
|
||||
cfgStrs.push_back(getLineStr);
|
||||
}
|
||||
}
|
||||
input.clear();
|
||||
input.close();
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(treeMutex_);
|
||||
for (auto iter : cfgStrs) {
|
||||
if (!iter.empty()) {
|
||||
std::vector<std::string> cfg = Split(iter, "=");
|
||||
if (cfg.size() != CFGTERMSIZE) {
|
||||
failConst++;
|
||||
GDLOGE("fail cfg(%{public}d): %{public}s", failConst, iter.c_str());
|
||||
}
|
||||
std::vector<std::string> nodes = Split(cfg[0], ".");
|
||||
TreeNodePtr sub = root;
|
||||
for (const auto& iter : nodes) {
|
||||
sub = sub->GetSetNode(iter);
|
||||
}
|
||||
sub->SetValue(cfg[1]);
|
||||
successConst++;
|
||||
}
|
||||
}
|
||||
GDLOGI("There are %{public}d items successfully configured", successConst);
|
||||
return failConst;
|
||||
}
|
||||
|
||||
void GraphicDumperServer::AddConfigDeathRecipient(sptr<IRemoteObject> &object)
|
||||
{
|
||||
if (!HaveConfigDeathRecipient(object)) {
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = new GraphicDumperClientListenerDeathRecipient();
|
||||
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient))) {
|
||||
GDLOGFE("Failed to add death recipient");
|
||||
}
|
||||
configListenerDeathRecipientMap_[object] = deathRecipient;
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphicDumperServer::HaveConfigDeathRecipient(sptr<IRemoteObject> &object)
|
||||
{
|
||||
auto &map = configListenerDeathRecipientMap_;
|
||||
return map.find(object) != map.end();
|
||||
}
|
||||
|
||||
bool GraphicDumperServer::HaveObject(const sptr<IRemoteObject> &obj)
|
||||
{
|
||||
return objectIdMap_.find(obj) != objectIdMap_.end();
|
||||
}
|
||||
|
||||
void GraphicDumperServer::VisitEach(const TreeNodePtr &node, TreeNodeVisitFunc func)
|
||||
{
|
||||
GDLOGFI("");
|
||||
TreeNodeVisitFunc getV = [&](const TreeNodePtr &v) {
|
||||
GDLOGFI("");
|
||||
func(v);
|
||||
v->Foreach(getV);
|
||||
};
|
||||
node->Foreach(getV);
|
||||
}
|
||||
|
||||
void GraphicDumperServer::RemoveNode(std::vector<std::string> &vec,
|
||||
TreeNodePtr &sub,
|
||||
uint32_t &listenerId)
|
||||
{
|
||||
GDLOGFE("listener: %{public}u", listenerId);
|
||||
if (vec.empty() || sub == nullptr || listenerId == 0) {
|
||||
return;
|
||||
}
|
||||
std::string tag = *vec.begin();
|
||||
GDLOGFE("tag: %{public}s", tag.c_str());
|
||||
vec.erase(vec.begin());
|
||||
|
||||
if (sub->HasNode(tag)) {
|
||||
TreeNodePtr subNd = sub->GetSetNode(tag);
|
||||
if (vec.empty()) {
|
||||
subNd->RemoveListenerId(listenerId);
|
||||
return;
|
||||
}
|
||||
RemoveNode(vec, subNd, listenerId);
|
||||
if (subNd->IsEmptyNode()) {
|
||||
sub->EraseNode(subNd->GetTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicDumperServer::DispenseConfig(const TreeNodePtr &node, const std::string &k, const std::string &v)
|
||||
{
|
||||
GDLOGFI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
auto dispenseConfig = [&](const TreeNodePtr &nd) {
|
||||
GDLOGFI("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
auto ls = nd->GetListenerIds();
|
||||
for (const auto& id : ls) {
|
||||
configTagsMap_[id].listener->OnConfigChange(k, v);
|
||||
}
|
||||
};
|
||||
dispenseConfig(node);
|
||||
VisitEach(node, dispenseConfig);
|
||||
}
|
||||
|
||||
void GraphicDumperServer::DispenseDump(const TreeNodePtr &node, const std::string &tag)
|
||||
{
|
||||
GDLOGFI("%{public}s", tag.c_str());
|
||||
auto dispenseDump = [&](const TreeNodePtr &nd) {
|
||||
GDLOGFI("%{public}s", tag.c_str());
|
||||
auto ls = nd->GetListenerIds();
|
||||
for (const auto& id : ls) {
|
||||
configTagsMap_[id].listener->OnDump(tag);
|
||||
}
|
||||
};
|
||||
dispenseDump(node);
|
||||
VisitEach(node, dispenseDump);
|
||||
}
|
||||
|
||||
void GraphicDumperServer::AddInfoDeathRecipient(sptr<IRemoteObject> &object)
|
||||
{
|
||||
if (!HaveInfoDeathRecipient(object)) {
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient = new GraphicDumperInfoListenerDeathRecipient();
|
||||
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient))) {
|
||||
GDLOGFE("Failed to add death recipient");
|
||||
}
|
||||
infoListenerDeathRecipientMap_[object] = deathRecipient;
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphicDumperServer::HaveInfoDeathRecipient(sptr<IRemoteObject> &object)
|
||||
{
|
||||
auto &map = infoListenerDeathRecipientMap_;
|
||||
return map.find(object) != map.end();
|
||||
}
|
||||
|
||||
void GraphicDumperServer::SendToInfoListener(const std::string &info)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(infoListenersMutex_);
|
||||
for (const auto& [k, v] : infoListeners_) {
|
||||
v->OnInfoComing(info);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicDumperServer::SaveLog(std::any server)
|
||||
{
|
||||
auto serverPtr = std::any_cast<GraphicDumperServer *>(server);
|
||||
uint32_t index = (serverPtr->logBuf_.index + 1) % LOG_VEC_SIZE;
|
||||
std::lock_guard<std::mutex> guard(serverPtr->logBuf_.mutex[index]);
|
||||
|
||||
uint32_t size = sizeof(LogBlock) + serverPtr->logBuf_.size[index] + 1;
|
||||
auto logArray = std::make_unique<uint8_t[]>(size);
|
||||
auto logBlock = reinterpret_cast<LogBlock *>(logArray.get());
|
||||
logBlock->size = serverPtr->logBuf_.size[index];
|
||||
logBlock->length = serverPtr->logBuf_.size[index];
|
||||
uint32_t offset = 0;
|
||||
for (const auto& str : *serverPtr->logBuf_.vec[index]) {
|
||||
int ret = memcpy_s(logBlock->data + offset,
|
||||
serverPtr->logBuf_.size[index] - offset,
|
||||
str.c_str(), str.size() + 1);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
offset += str.size() + 1;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(serverPtr->logBlockVectorMutex_);
|
||||
if ((serverPtr->logBlockSize_ + serverPtr->logBuf_.size[index]) > LOG_BLOCK_SIZE_MAX) {
|
||||
auto logFirstBlock = reinterpret_cast<LogBlock *>(serverPtr->logBlockVector_.begin()->get());
|
||||
serverPtr->logBlockSize_ -= logFirstBlock->size;
|
||||
serverPtr->logBlockVector_.erase(serverPtr->logBlockVector_.begin());
|
||||
}
|
||||
serverPtr->logBlockVector_.push_back(std::move(logArray));
|
||||
serverPtr->logBlockSize_ += serverPtr->logBuf_.size[index];
|
||||
serverPtr->logBuf_.vec[index]->clear();
|
||||
serverPtr->logBuf_.size[index] = 0;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServer::LogHandle(const std::string &tag, const std::string &info)
|
||||
{
|
||||
std::string log = tag + " | " + info;
|
||||
GDLOGFI("%{public}s -> %{public}s", tag.c_str(), info.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(logBuf_.mutex[logBuf_.index]);
|
||||
logBuf_.size[logBuf_.index] += log.size() + 1;
|
||||
logBuf_.vec[logBuf_.index]->push_back(log);
|
||||
if (logBuf_.canSave && (logBuf_.size[logBuf_.index] > (LOG_BUF_SIZE_MAX / LOG_VEC_SIZE))) {
|
||||
thread_ = std::make_unique<std::thread>(&GraphicDumperServer::SaveLog, this);
|
||||
logBuf_.needSave = true;
|
||||
logBuf_.canSave = false;
|
||||
}
|
||||
if (logBuf_.size[logBuf_.index] >= LOG_BUF_SIZE_MAX) {
|
||||
logBuf_.vec[logBuf_.index]->shrink_to_fit();
|
||||
if (logBuf_.needSave) {
|
||||
thread_->join();
|
||||
logBuf_.needSave = false;
|
||||
}
|
||||
logBuf_.index = (logBuf_.index + 1) % LOG_VEC_SIZE;
|
||||
logBuf_.canSave = true;
|
||||
}
|
||||
}
|
||||
if (logBuf_.sync) {
|
||||
if ((!logBuf_.mask.empty()) && (log.compare(0, logBuf_.mask.size(), logBuf_.mask) != 0)) {
|
||||
return GSERROR_OK;
|
||||
}
|
||||
auto pos = log.find_first_of("| [");
|
||||
constexpr int offset = 2;
|
||||
if (pos == std::string::npos) {
|
||||
pos = 0;
|
||||
} else {
|
||||
pos += offset;
|
||||
}
|
||||
SendToInfoListener(log.substr(pos));
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <ipc_skeleton.h>
|
||||
|
||||
#include "graphic_dumper_server.h"
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
int main()
|
||||
{
|
||||
int ret = GraphicDumperServer::GetInstance()->Init();
|
||||
if (ret == 0) {
|
||||
IPCSkeleton::JoinWorkThread();
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_tree.h"
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperTree" };
|
||||
} // namespace
|
||||
|
||||
TreeNodePtr GraphicDumperTree::GetSetNode(const std::string s)
|
||||
{
|
||||
if (nodeMap_ == nullptr) {
|
||||
nodeMap_ = std::make_unique<TreeNodeMap>();
|
||||
}
|
||||
if (!HasNode(s)) {
|
||||
(*nodeMap_)[s] = std::make_shared<GraphicDumperTree>();
|
||||
(*nodeMap_)[s]->tag_ = s;
|
||||
}
|
||||
return (*nodeMap_)[s];
|
||||
}
|
||||
|
||||
bool GraphicDumperTree::HasNode(const std::string s)
|
||||
{
|
||||
return nodeMap_->find(s) != nodeMap_->end();
|
||||
}
|
||||
|
||||
bool GraphicDumperTree::IsEmptyNode()
|
||||
{
|
||||
if (nodeMap_->empty() && listenerIds_.empty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GraphicDumperTree::EraseNode(const std::string &s)
|
||||
{
|
||||
(*nodeMap_)[s] = nullptr;
|
||||
nodeMap_->erase(s);
|
||||
}
|
||||
|
||||
std::string GraphicDumperTree::GetTag()
|
||||
{
|
||||
return tag_;
|
||||
}
|
||||
|
||||
void GraphicDumperTree::SetValue(const std::string s)
|
||||
{
|
||||
value_ = s;
|
||||
}
|
||||
|
||||
std::string GraphicDumperTree::GetValue()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
void GraphicDumperTree::AddListenerId(uint32_t &listenerId)
|
||||
{
|
||||
GDLOGFI("");
|
||||
listenerIds_.push_back(listenerId);
|
||||
}
|
||||
|
||||
void GraphicDumperTree::RemoveListenerId(uint32_t &listenerId)
|
||||
{
|
||||
GDLOGFI("%{public}u", listenerId);
|
||||
for (auto iter = listenerIds_.begin(); iter != listenerIds_.end(); ++iter) {
|
||||
GDLOGFI("%{public}u <==> %{public}u", (*iter), listenerId);
|
||||
if (*iter == listenerId) {
|
||||
GDLOGFI("");
|
||||
listenerIds_.erase(iter--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint32_t> GraphicDumperTree::GetListenerIds() const
|
||||
{
|
||||
GDLOGFI("");
|
||||
return listenerIds_;
|
||||
}
|
||||
|
||||
void GraphicDumperTree::Foreach(TreeNodeVisitFunc func) const
|
||||
{
|
||||
GDLOGFI("");
|
||||
if (nodeMap_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (const auto& [k, v] : (*nodeMap_)) {
|
||||
GDLOGFI("%{public}s", k.c_str());
|
||||
func(v);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "graphic_dumper_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
std::vector<std::string> Split(std::string src, const std::string &splitStr)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
std::string::size_type pos = 0;
|
||||
while (pos != std::string::npos) {
|
||||
pos = src.find(splitStr);
|
||||
if (pos == std::string::npos) {
|
||||
if (!src.empty()) {
|
||||
ret.push_back(src);
|
||||
}
|
||||
} else {
|
||||
if (!src.empty()) {
|
||||
ret.push_back(src.substr(0, pos));
|
||||
}
|
||||
src = src.substr(pos + splitStr.size());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_client_listener_death_recipient.h"
|
||||
|
||||
#include "graphic_dumper_server.h"
|
||||
|
||||
namespace OHOS {
|
||||
void GraphicDumperClientListenerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
return;
|
||||
}
|
||||
GraphicDumperServer::GetInstance()->RemoveConfigListener(object.promote());
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_client_listener_proxy.h"
|
||||
|
||||
#include <message_option.h>
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperClientListenerProxy" };
|
||||
}
|
||||
|
||||
GraphicDumperClientListenerProxy::GraphicDumperClientListenerProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IGraphicDumperClientListener>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicDumperClientListenerProxy::OnConfigChange(const std::string &tag, const std::string &val)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFI("%{public}s -> %{public}s", tag.c_str(), val.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(tag);
|
||||
arg.WriteString(val);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_CONFIG_CHANGE, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void GraphicDumperClientListenerProxy::OnDump(const std::string &tag)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFI("%{public}s", tag.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(tag);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_DUMP, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_client_listener_stub.h"
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperClientListenerStub" };
|
||||
}
|
||||
|
||||
int32_t GraphicDumperClientListenerStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (GetDescriptor() != remoteDescriptor) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_CONFIG_CHANGE: {
|
||||
std::string tag = data.ReadString();
|
||||
std::string val = data.ReadString();
|
||||
GDLOGI("%{public}s -> %{public}s", tag.c_str(), val.c_str());
|
||||
OnConfigChange(tag, val);
|
||||
reply.WriteInt32(GSERROR_OK);
|
||||
}
|
||||
break;
|
||||
case IGRAPHIC_DUMPER_CLIENT_LISTENER_ON_DUMP: {
|
||||
std::string val = data.ReadString();
|
||||
OnDump(val);
|
||||
reply.WriteInt32(GSERROR_OK);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
GDLOGFE("code %{public}d cannot process", code);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_command_proxy.h"
|
||||
|
||||
#include <message_option.h>
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperCommandProxy" };
|
||||
}
|
||||
|
||||
GraphicDumperCommandProxy::GraphicDumperCommandProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IGraphicDumperCommand>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandProxy::GetConfig(const std::string &k, std::string &v)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(k);
|
||||
arg.WriteString(v);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_COMMAND_GET_CONFIG, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_API_FAILED;
|
||||
}
|
||||
GSError retCode = static_cast<GSError>(ret.ReadInt32());
|
||||
if (retCode == GSERROR_OK) {
|
||||
v = ret.ReadString();
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandProxy::SetConfig(const std::string &k, const std::string &v)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(k);
|
||||
arg.WriteString(v);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_COMMAND_SET_CONFIG, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_API_FAILED;
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandProxy::Dump(const std::string &tag)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFE("%{public}s", tag.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(tag);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_COMMAND_DUMP, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_API_FAILED;
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandProxy::GetLog(const std::string &tag, std::string &log)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
GDLOGFE("%{public}s -> %{public}s", tag.c_str(), log.c_str());
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(tag);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_COMMAND_GET_LOG, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_API_FAILED;
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandProxy::AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
GDLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
arg.WriteString(tag);
|
||||
arg.WriteRemoteObject(listener->AsObject());
|
||||
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_COMMAND_ADD_INFO_LISTENER, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_BINDER;
|
||||
}
|
||||
|
||||
GSError err = (GSError)ret.ReadInt32();
|
||||
if (err != GSERROR_OK) {
|
||||
GDLOG_FAILURE_NO(err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_command_stub.h"
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_dumper_server.h"
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperCommandStub" };
|
||||
}
|
||||
|
||||
int32_t GraphicDumperCommandStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (GetDescriptor() != remoteDescriptor) {
|
||||
return 1;
|
||||
}
|
||||
switch (code) {
|
||||
case IGRAPHIC_DUMPER_COMMAND_GET_CONFIG: {
|
||||
std::string k = data.ReadString();
|
||||
std::string v = data.ReadString();
|
||||
GSError ret = GetConfig(k, v);
|
||||
reply.WriteInt32(ret);
|
||||
reply.WriteString(v);
|
||||
break;
|
||||
}
|
||||
|
||||
case IGRAPHIC_DUMPER_COMMAND_SET_CONFIG: {
|
||||
std::string k = data.ReadString();
|
||||
std::string v = data.ReadString();
|
||||
GSError ret = SetConfig(k, v);
|
||||
reply.WriteInt32(ret);
|
||||
break;
|
||||
}
|
||||
|
||||
case IGRAPHIC_DUMPER_COMMAND_DUMP: {
|
||||
std::string v = data.ReadString();
|
||||
GSError ret = Dump(v);
|
||||
reply.WriteInt32(ret);
|
||||
break;
|
||||
}
|
||||
|
||||
case IGRAPHIC_DUMPER_COMMAND_GET_LOG: {
|
||||
std::string tag = data.ReadString();
|
||||
std::string log = "";
|
||||
GSError ret = GetLog(tag, log);
|
||||
reply.WriteInt32(ret);
|
||||
break;
|
||||
}
|
||||
case IGRAPHIC_DUMPER_COMMAND_ADD_INFO_LISTENER: {
|
||||
auto tag = data.ReadString();
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
reply.WriteInt32(GSERROR_INVALID_ARGUMENTS);
|
||||
GDLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
||||
break;
|
||||
}
|
||||
|
||||
auto l = iface_cast<IGraphicDumperInfoListener>(remoteObject);
|
||||
GSError ret = AddInfoListener(tag, l);
|
||||
reply.WriteInt32(ret);
|
||||
if (ret != GSERROR_OK) {
|
||||
GDLOG_FAILURE_NO(ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandStub::GetConfig(const std::string &k, std::string &v)
|
||||
{
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
GraphicDumperServer::GetInstance()->GetConfig(k, v);
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandStub::SetConfig(const std::string &k, const std::string &v)
|
||||
{
|
||||
GDLOGFE("%{public}s -> %{public}s", k.c_str(), v.c_str());
|
||||
GraphicDumperServer::GetInstance()->SetConfig(k, v);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandStub::Dump(const std::string &tag)
|
||||
{
|
||||
GDLOGFE("%{public}s", tag.c_str());
|
||||
GraphicDumperServer::GetInstance()->Dump(tag);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandStub::GetLog(const std::string &tag, std::string &log)
|
||||
{
|
||||
GDLOGFE("%{public}s -> %{public}s", tag.c_str(), log.c_str());
|
||||
GraphicDumperServer::GetInstance()->GetLog(tag, log);
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError GraphicDumperCommandStub::AddInfoListener(const std::string &tag, sptr<IGraphicDumperInfoListener> &listener)
|
||||
{
|
||||
GDLOGFE("");
|
||||
if (listener == nullptr) {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
return GraphicDumperServer::GetInstance()->AddInfoListener(listener);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_info_listener_death_recipient.h"
|
||||
#include "graphic_dumper_server.h"
|
||||
#include "ipc/igraphic_dumper_command.h"
|
||||
#include "graphic_common.h"
|
||||
#include "graphic_dumper_hilog.h"
|
||||
namespace OHOS {
|
||||
void GraphicDumperInfoListenerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
return;
|
||||
}
|
||||
GraphicDumperServer::GetInstance()->RemoveInfoListener(object);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_info_listener_proxy.h"
|
||||
|
||||
#include <message_option.h>
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperInfoListenerProxy" };
|
||||
}
|
||||
|
||||
GraphicDumperInfoListenerProxy::GraphicDumperInfoListenerProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IGraphicDumperInfoListener>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicDumperInfoListenerProxy::OnInfoComing(const std::string &info)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
|
||||
arg.WriteString(info);
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_INFO_LISTENER_ON_INFO_COMING, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_info_listener_stub.h"
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperInfoListenerStub" };
|
||||
}
|
||||
|
||||
int32_t GraphicDumperInfoListenerStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (GetDescriptor() != remoteDescriptor) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case IGRAPHIC_DUMPER_INFO_LISTENER_ON_INFO_COMING: {
|
||||
std::string info = data.ReadString();
|
||||
OnInfoComing(info);
|
||||
reply.WriteInt32(GSERROR_OK);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
GDLOGFE("code %{public}d cannot process", code);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_service_proxy.h"
|
||||
|
||||
#include <message_option.h>
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperServiceProxy" };
|
||||
}
|
||||
|
||||
GraphicDumperServiceProxy::GraphicDumperServiceProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IGraphicDumperService>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
GSError GraphicDumperServiceProxy::AddClientListener(const std::string &tag,
|
||||
sptr<IGraphicDumperClientListener> &listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
GDLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
arg.WriteString(tag);
|
||||
arg.WriteRemoteObject(listener->AsObject());
|
||||
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_SERVICE_ADD_CLIENT_LISTENER, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_BINDER;
|
||||
}
|
||||
|
||||
GSError err = (GSError)ret.ReadInt32();
|
||||
if (err != GSERROR_OK) {
|
||||
GDLOG_FAILURE_NO(err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GSError GraphicDumperServiceProxy::SendInfo(const std::string &tag, const std::string &info)
|
||||
{
|
||||
MessageOption opt;
|
||||
MessageParcel arg;
|
||||
MessageParcel ret;
|
||||
|
||||
if (!arg.WriteInterfaceToken(GetDescriptor())) {
|
||||
GDLOGE("write interface token failed");
|
||||
}
|
||||
arg.WriteString(tag);
|
||||
arg.WriteString(info);
|
||||
GDLOGE("SendInfo SendRequest !!!!!");
|
||||
int result = Remote()->SendRequest(IGRAPHIC_DUMPER_SERVICE_SEND_INFO, arg, ret, opt);
|
||||
if (result) {
|
||||
GDLOG_ERROR_API(result, SendRequest);
|
||||
return GSERROR_BINDER;
|
||||
}
|
||||
return GSERROR_OK;
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "ipc/graphic_dumper_service_stub.h"
|
||||
|
||||
#include "graphic_dumper_hilog.h"
|
||||
#include "graphic_dumper_server.h"
|
||||
|
||||
#define REMOTE_RETURN(reply, gs_error) \
|
||||
do { \
|
||||
(reply).WriteInt32(gs_error); \
|
||||
if ((gs_error) != GSERROR_OK) { \
|
||||
GDLOG_FAILURE_NO(gs_error); \
|
||||
} \
|
||||
} while (0); \
|
||||
break
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "GraphicDumperServiceStub" };
|
||||
}
|
||||
|
||||
int32_t GraphicDumperServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (GetDescriptor() != remoteDescriptor) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case IGRAPHIC_DUMPER_SERVICE_ADD_CLIENT_LISTENER: {
|
||||
auto tag = data.ReadString();
|
||||
GDLOGFE("%{public}s", tag.c_str());
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
reply.WriteInt32(GSERROR_INVALID_ARGUMENTS);
|
||||
GDLOG_FAILURE_NO(GSERROR_INVALID_ARGUMENTS);
|
||||
break;
|
||||
}
|
||||
auto l = iface_cast<IGraphicDumperClientListener>(remoteObject);
|
||||
GSError ret = AddClientListener(tag, l);
|
||||
reply.WriteInt32(ret);
|
||||
if (ret != GSERROR_OK) {
|
||||
GDLOG_FAILURE_NO(ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IGRAPHIC_DUMPER_SERVICE_SEND_INFO: {
|
||||
std::string tag = data.ReadString();
|
||||
std::string info = data.ReadString();
|
||||
GSError ret = SendInfo(tag, info);
|
||||
reply.WriteInt32(ret);
|
||||
if (ret != GSERROR_OK) {
|
||||
GDLOG_FAILURE_NO(ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
GDLOGFE("code %{public}d cannot process", code);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
GSError GraphicDumperServiceStub::AddClientListener(const std::string &tag,
|
||||
sptr<IGraphicDumperClientListener> &listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
return GSERROR_INVALID_ARGUMENTS;
|
||||
}
|
||||
return GraphicDumperServer::GetInstance()->AddConfigListener(tag, listener);
|
||||
}
|
||||
GSError GraphicDumperServiceStub::SendInfo(const std::string &tag, const std::string &info)
|
||||
{
|
||||
return GraphicDumperServer::GetInstance()->InfoHandle(tag, info);
|
||||
}
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user