1 /*
2  * Copyright (C) 2021 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_INCLUDE_GLOBAL_H
17 #define SERVICES_INCLUDE_GLOBAL_H
18 
19 #include <sys/time.h>
20 
21 #include <cerrno>
22 #include <ctime>
23 
24 #include "hilog/log.h"
25 #include "ipc_object_stub.h"
26 #include "iremote_broker.h"
27 #include "peer_holder.h"
28 #include "refbase.h"
29 
30 namespace OHOS {
31 namespace MiscServices {
32 using BRemoteObject = IPCObjectStub;
33 
34 #define LOG_INFO(fmt, args...) \
35     LogTimeStamp();            \
36     printf("I %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
37 
38 #define LOG_ERROR(fmt, args...) \
39     LogTimeStamp();             \
40     printf("E %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
41 
42 #define LOG_WARNING(fmt, args...) \
43     LogTimeStamp();               \
44     printf("W %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
45 
46 #if DEBUG
47 #define LOG_DEBUG(fmt, args...) \
48     LogTimeStamp();             \
49     printf("D %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
50 #else
51 #define LOG_DEBUG(fmt, args...)
52 #endif
53 
54 void LogTimeStamp();
55 
56 // Error Code
57 namespace ErrorCode {
58 // Error Code definition in the input method management system
59 constexpr int32_t NO_ERROR = 0;
60 
61 // system service error
62 constexpr int32_t ERROR_NULL_POINTER = 1;
63 constexpr int32_t ERROR_KEYWORD_NOT_FOUND = 26;
64 constexpr int32_t ERROR_ENABLE_IME = 27;
65 
66 constexpr int32_t ERROR_ENABLE_SECURITY_MODE = 32;
67 }; // namespace ErrorCode
68 
69 constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { LOG_CORE, 0xD001C10, "ImsaKit" };
70 
71 #define IMSA_HILOGD(fmt, ...)                                                                                    \
72     (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
73         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
74         __FUNCTION__, ##__VA_ARGS__)
75 #define IMSA_HILOGE(fmt, ...)                                                                                    \
76     (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
77         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
78         __FUNCTION__, ##__VA_ARGS__)
79 #define IMSA_HILOGF(fmt, ...)                                                                                    \
80     (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
81         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
82         __FUNCTION__, ##__VA_ARGS__)
83 #define IMSA_HILOGI(fmt, ...)                                                                                    \
84     (void)HILOG_IMPL(LOG_CORE, LOG_INFO, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
85         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
86         __FUNCTION__, ##__VA_ARGS__)
87 #define IMSA_HILOGW(fmt, ...)                                                                                    \
88     (void)HILOG_IMPL(LOG_CORE, LOG_WARN, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
89         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
90         __FUNCTION__, ##__VA_ARGS__)
91 } // namespace MiscServices
92 } // namespace OHOS
93 #endif // SERVICES_INCLUDE_GLOBAL_H
94