• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 SERVICES_MECHBODY_CONTROLLER_LOG_H_
17 #define SERVICES_MECHBODY_CONTROLLER_LOG_H_
18 
19 #include "errors.h"
20 #include "hilog/log.h"
21 #include <cinttypes>
22 #include <cstdint>
23 
24 namespace OHOS {
25 namespace MechBodyController {
26 #undef LOG_DOMAIN
27 #define LOG_DOMAIN 0xD004170
28 
29 #undef LOG_TAG
30 #define LOG_TAG "MechBodyController"
31 
32 #ifdef HILOGD
33 #undef HILOGD
34 #endif
35 
36 #ifdef HILOGF
37 #undef HILOGF
38 #endif
39 
40 #ifdef HILOGE
41 #undef HILOGE
42 #endif
43 
44 #ifdef HILOGW
45 #undef HILOGW
46 #endif
47 
48 #ifdef HILOGI
49 #undef HILOGI
50 #endif
51 
52 #define HILOGF(fmt, ...) HILOG_FATAL(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
53 #define HILOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
54 #define HILOGW(fmt, ...) HILOG_WARN(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
55 #define HILOGI(fmt, ...) HILOG_INFO(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
56 #define HILOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
57 
58 
59 #define CHECK_POINTER_RETURN(object, log)                       \
60     do {                                                        \
61         if ((object) == nullptr) {                              \
62             HILOGE("%{public}s nullptr", (log));                \
63             return;                                             \
64         }                                                       \
65     } while (0)
66 
67 #define CHECK_POINTER_RETURN_VALUE(object, value, log)          \
68     do {                                                        \
69         if ((object) == nullptr) {                              \
70             HILOGE("%{public}s nullptr", (log));                \
71             return (value);                                     \
72         }                                                       \
73     } while (0)
74 
75 #define CHECK_ERR_RETURN_VALUE(errNo, value, log)                               \
76     do {                                                                        \
77         auto result = (errNo);                                                  \
78         if (result != ERR_OK) {                                                 \
79             HILOGE("%{public}s err, code %{public}d", (log), result);           \
80         }                                                                       \
81     } while (0)
82 
83 #define CHECK_ERR_RETURN(errNo, log)                                            \
84     do {                                                                        \
85         auto result = (errNo);                                                  \
86         if (result != ERR_OK) {                                                 \
87             HILOGE("%{public}s err, code %{public}d", (log), result);           \
88         }                                                                       \
89     } while (0)
90 
91 
92 enum {
93     /**
94      * Module type: Mechbody service core
95      */
96     MC_MODULE_TYPE_SERVICE = 0,
97 };
98 
99 // offset of EB error, only be used in this file.
100 constexpr ErrCode MC_SERVICE_ERR_OFFSET = ErrCodeOffset(SUBSYS_DISTRIBUTEDHARDWARE, MC_MODULE_TYPE_SERVICE);
101 
102 enum {
103     /**
104      * Result(96468992) for invalid parameters.
105      */
106     INVALID_PARAMETERS_ERR = MC_SERVICE_ERR_OFFSET,
107 
108     /**
109      * Result(96468993) for get sa manager failed.
110      */
111     MECH_GET_SAMGR_EXCEPTION,
112 
113     /**
114      * Result(96468994) for start mechbody service failed.
115      */
116     START_MECH_BODY_SERVICE_FAILED,
117 
118     /**
119      * Result(96468995) for napi send data to service by ipc failed.
120      */
121     NAPI_SEND_DATA_FAIL,
122 
123     /**
124      * Result(96468996) for napi receive data to service by ipc failed.
125      */
126     NAPI_RECV_DATA_FAIL,
127 
128     /**
129      * Result(96468997) for The IPC token does not match.
130      */
131     IPC_TOKEN_DOES_NOT_MATCH,
132 
133     /**
134      * Result(96468998) for The No matching service implementation is found.
135      */
136     NO_MATCHING_SERVICE_IMPL,
137 
138     /**
139      * Result(96468999) for invalid pid.
140      */
141     INVALID_PID,
142 
143     /**
144      * Result(96469000) for invalid mech id.
145      */
146     INVALID_MECH_ID,
147 
148     /**
149      * Result(96469001) for invalid remote object.
150      */
151     INVALID_REMOTE_OBJECT,
152 
153     /**
154      * Result(96469002) for invalid tracking layout.
155      */
156     INVALID_TRACKING_LAYOUT,
157 
158     /**
159      * Result(96469003) for invalid rotate parameters.
160      */
161     INVALID_ROTATE_PARAM,
162 
163     /**
164      * Result(96469004) for register callback failed.
165      */
166     REGISTER_CALLBACK_FAILED,
167 
168     /**
169      * Result(96469005) for unregister callback failed.
170      */
171     UNREGISTER_CALLBACK_FAILED,
172 
173     /**
174      * Result(96469006) for send callback info failed.
175      */
176     SEND_CALLBACK_INFO_FAILED,
177 
178     /**
179      * Result(96469007) for query device list failed.
180      */
181     QUERY_DEVICE_LIST_FAILED,
182 
183     /**
184      * Result(96469008) for unRegist failed.
185      */
186     UNREGISTER_FAILED_ERR,
187 
188     /**
189      * Result(96469009) for notify failed.
190      */
191     NOTIFICATION_FAILED_ERR,
192 
193     /**
194      * Result(96469010) for device not placed on mech.
195      */
196     DEVICE_NOT_PLACED_ON_MECH,
197 };
198 
199 enum MechNapiErrorCode {
200     /**
201      * Result(202) for permission denied.
202      */
203     PERMISSION_DENIED = 202,
204 
205     /**
206      * Result(401) for parameter check failed.
207      */
208     PARAMETER_CHECK_FAILED = 401,
209 
210     /**
211      * Result(33300001) for the system ability work abnormally.
212      */
213     SYSTEM_WORK_ABNORMALLY = 33300001,
214 
215     /**
216      * Result(33300002) for device not connected.
217      */
218     DEVICE_NOT_CONNECTED = 33300002,
219 
220     /**
221      * Result(33300003) for device not supported.
222      */
223     DEVICE_NOT_SUPPORTED = 33300003,
224 };
225 } // namespace MechBodyController
226 } // namespace OHOS
227 #endif // SERVICES_MECHBODY_CONTROLLER_LOG_H_
228