1 /*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef RS_HRP_SERVICE_H
17 #define RS_HRP_SERVICE_H
18
19 #include <cstdarg>
20 #include <cstddef>
21 #include <cstdint>
22 #include <string>
23
24 namespace OHOS::Rosen {
25
26 #define HRP_SERVICE_DIR "/data/local/shader_cache/local/system/RenderProfiler"
27
28 #define HRP_SERVICE_FILE_NAME_MAX_SIZE (255)
29 #define HRP_SERVICE_REQUEST_MAX_SIZE_BYTES (256*1024)
30
31 enum HrpServiceDir : uint32_t {
32 HRP_SERVICE_DIR_UNKNOWN = 0,
33 HRP_SERVICE_DIR_COMMON = 1,
34 HRP_SERVICE_DIR_RS = 2,
35 HRP_SERVICE_DIR_TRACE3D = 3,
36 };
37
38 enum RetCodeHrpService : int32_t {
39 RET_HRP_SERVICE_MORE_DATA_AVAILABLE = 1,
40 RET_HRP_SERVICE_SUCCESS = 0,
41 RET_HRP_SERVICE_ERR_UNKNOWN = -1,
42 RET_HRP_SERVICE_ERR_UNSUPPORTED = -2,
43 RET_HRP_SERVICE_ERR_INVALID_PARAM = -3,
44 RET_HRP_SERVICE_ERR_ACCESS_DENIED = -4,
45 RET_HRP_SERVICE_ERR_INVALID_FILE_DESCRIPTOR = -5,
46 // Proxy errors
47 RET_HRP_SERVICE_ERR_PROXY_GET_REMOTE = -101,
48 RET_HRP_SERVICE_ERR_PROXY_SEND_REQUEST = -102,
49 RET_HRP_SERVICE_ERR_PROXY_INVALID_RESULT = -103,
50 RET_HRP_SERVICE_ERR_PROXY_INVALID_RESULT_DATA = -104,
51 // Stub errors
52 RET_HRP_SERVICE_ERR_STUB_MAKE_DIR_ACCESS_DENIED = -201,
53 RET_HRP_SERVICE_ERR_STUB_OPEN_FILE_ACCESS_DENIED = -202,
54 RET_HRP_SERVICE_ERR_STUB_MAKE_DIR = -203,
55 RET_HRP_SERVICE_ERR_STUB_OPEN_FILE = -204,
56 RET_HRP_SERVICE_ERR_STUB_OPEN_DIR_ERROR = -205,
57 RET_HRP_SERVICE_ERR_STUB_FILE_READ_ERROR_NOT_EXISTS = -206,
58 RET_HRP_SERVICE_ERR_STUB_PATH_EXISTS_NOT_DIR = -207
59 };
60
61 struct HrpServiceDirInfo {
62 HrpServiceDir baseDirType{ HRP_SERVICE_DIR_UNKNOWN };
63 std::string subDir;
64 std::string subDir2;
65 };
66
67 struct HrpServiceBaseFileInfo {
68 struct TimeValue {
69 uint64_t sec { 0 }, nsec { 0 };
70 };
71 uint32_t size { 0 };
72 bool isDir { false };
73 uint32_t accessBits { 0 };
74 TimeValue accessTime {}, modifyTime {};
75 };
76
77 struct HrpServiceFileInfo : public HrpServiceBaseFileInfo {
78 std::string name;
79 };
80
HrpServiceValidDirOrFileName(const std::string & name)81 static inline bool HrpServiceValidDirOrFileName(const std::string& name)
82 {
83 return (name.length() <= HRP_SERVICE_FILE_NAME_MAX_SIZE &&
84 name.find("\\") == std::string::npos && name.find("/") == std::string::npos &&
85 name != "." && name != "..");
86 }
87
HrpServiceGetDirFull(HrpServiceDir type)88 static inline const char* HrpServiceGetDirFull(HrpServiceDir type)
89 {
90 switch (type) {
91 case HRP_SERVICE_DIR_COMMON:
92 return HRP_SERVICE_DIR "/common";
93 case HRP_SERVICE_DIR_RS:
94 return HRP_SERVICE_DIR "/rs";
95 case HRP_SERVICE_DIR_TRACE3D:
96 return HRP_SERVICE_DIR "/trace3d";
97 default:
98 return ""; // empty string for convenient subfolder construction
99 }
100 }
101
HrpServiceGetDirType(uint32_t val)102 static inline HrpServiceDir HrpServiceGetDirType(uint32_t val)
103 {
104 switch (val) {
105 case HRP_SERVICE_DIR_COMMON:
106 return HRP_SERVICE_DIR_COMMON;
107 case HRP_SERVICE_DIR_RS:
108 return HRP_SERVICE_DIR_RS;
109 case HRP_SERVICE_DIR_TRACE3D:
110 return HRP_SERVICE_DIR_TRACE3D;
111 default:
112 return HRP_SERVICE_DIR_UNKNOWN;
113 }
114 }
115
116 } // namespace OHOS::Rosen
117
118 #endif // RS_HRP_SERVICE_H
119