• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <errno.h>
20 #include <functional>
21 #include <sys/time.h>
22 #include <time.h>
23 
24 #include "hilog/log.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28 
29 #define LOG_INFO(fmt, args...) \
30     LogTimeStamp();            \
31     printf("I %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
32 
33 #define LOG_ERROR(fmt, args...) \
34     LogTimeStamp();             \
35     printf("E %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
36 
37 #define LOG_WARNING(fmt, args...) \
38     LogTimeStamp();               \
39     printf("W %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
40 
41 #if DEBUG
42 #define LOG_DEBUG(fmt, args...) \
43     LogTimeStamp();             \
44     printf("D %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
45 #else
46 #define LOG_DEBUG(fmt, args...)
47 #endif
48 
49 void LogTimeStamp();
50 
51 // Error Code
52 namespace ErrorCode {
53 // Error Code definition in the input method management system
54 enum {
55     ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, // unknown transaction
56 
57     // binder exception error code from Status.h
58     ERROR_EX_ILLEGAL_ARGUMENT = -3,      // illegal argument exception
59     ERROR_EX_NULL_POINTER = -4,          // null pointer exception
60     ERROR_EX_ILLEGAL_STATE = -5,         // illegal state exception
61     ERROR_EX_PARCELABLE = -6,            // parcelable exception
62     ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception
63     ERROR_EX_SERVICE_SPECIFIC = -8,      // service specific exception
64     // no error
65     NO_ERROR = 0, // no error
66 
67     ERROR_NULL_POINTER,   // null pointer
68     ERROR_BAD_PARAMETERS, // bad parameters
69     ERROR_SUBSCRIBE_KEYBOARD_EVENT,
70 
71     ERROR_CONTROLLER_INVOKING_FAILED,
72     ERROR_PERSIST_CONFIG,
73     ERROR_KBD_HIDE_FAILED,
74     ERROR_PACKAGE_MANAGER,
75     ERROR_REMOTE_CLIENT_DIED,
76 
77     ERROR_NOT_CURRENT_IME,
78     ERROR_NOT_IME,
79     ERROR_ADD_DEATH_RECIPIENT_FAILED,
80     ERROR_STATUS_SYSTEM_PERMISSION, // not system application
81     ERROR_PARAMETER_CHECK_FAILED,
82     ERROR_KEYWORD_NOT_FOUND,
83     ERROR_ENABLE_IME,
84     ERROR_NOT_DEFAULT_IME,
85     ERROR_ENABLE_SECURITY_MODE,
86     ERROR_DISPATCH_KEY_EVENT,
87     ERROR_INVALID_PRIVATE_COMMAND_SIZE,
88     ERROR_PANEL_NOT_FOUND,
89     ERROR_WINDOW_MANAGER,
90     ERROR_GET_TEXT_CONFIG,
91     ERROR_SYSTEM_CMD_CHANNEL_ERROR,
92     ERROR_INVALID_PRIVATE_COMMAND,
93     ERROR_OS_ACCOUNT,
94     ERROR_TASK_MANAGER_PEND_FAILED,
95     ERROR_INVALID_PANEL_TYPE,
96     ERROR_INVALID_PANEL_FLAG,
97     ERROR_MSG_HANDLER_NOT_REGIST,
98     ERROR_SECURITY_MODE_OFF,
99     ERROR_MESSAGE_HANDLER,
100     ERROR_INVALID_ARRAY_BUFFER_SIZE,
101     ERROR_SERVICE_START_FAILED,
102     ERROR_JS_CB_NOT_REGISTER,       // only for hiSysEvent
103     ERROR_DEAL_TIMEOUT,              // only for hiSysEvent
104     ERROR_IPC_REMOTE_NULLPTR,
105 
106     ERROR_IMA_BEGIN,
107     ERROR_IME,
108     ERROR_OPERATE_PANEL,
109     ERROR_IMA_CHANNEL_NULLPTR,
110     ERROR_IMA_NULLPTR,
111     ERROR_IMA_END,
112 
113     ERROR_IMC_BEGIN,
114     ERROR_CLIENT_NOT_EDITABLE,
115     ERROR_TEXT_PREVIEW_NOT_SUPPORTED,
116     ERROR_TEXT_LISTENER_ERROR,
117     ERROR_INVALID_RANGE,
118     ERROR_CLIENT_NOT_BOUND,
119     ERROR_IMC_NULLPTR,
120     ERROR_IMC_END,
121 
122     ERROR_IMSA_BEGIN,
123     ERROR_PARSE_CONFIG_FILE,
124     ERROR_IME_START_INPUT_FAILED,
125     ERROR_STATUS_PERMISSION_DENIED,
126     ERROR_CLIENT_NOT_FOCUSED,
127     ERROR_CLIENT_NULL_POINTER,
128     ERROR_CLIENT_ADD_FAILED,
129     ERROR_CLIENT_NOT_FOUND,
130     ERROR_IME_NOT_STARTED,
131     ERROR_KBD_SHOW_FAILED,  // failed to show keyboard
132     ERROR_IMSA_INPUT_TYPE_NOT_FOUND,
133     ERROR_IMSA_DEFAULT_IME_NOT_FOUND,
134     ERROR_IMSA_CLIENT_INPUT_READY_FAILED,
135     ERROR_IMSA_MALLOC_FAILED,
136     ERROR_IMSA_NULLPTR,
137     ERROR_IMSA_USER_SESSION_NOT_FOUND,
138     ERROR_IMSA_GET_IME_INFO_FAILED,
139     ERROR_IMSA_IME_TO_START_NULLPTR,
140     ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP,
141     ERROR_IMSA_IME_EVENT_CONVERT_FAILED,
142     ERROR_IMSA_IME_CONNECT_FAILED,
143     ERROR_IMSA_IME_DISCONNECT_FAILED,
144     ERROR_IMSA_IME_START_TIMEOUT,
145     ERROR_IMSA_IME_START_MORE_THAN_EIGHT_SECOND,
146     ERROR_IMSA_FORCE_STOP_IME_TIMEOUT,
147     ERROR_DEVICE_UNSUPPORTED,
148     ERROR_IMSA_END,
149 };
150 }; // namespace ErrorCode
151 
152 static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { LOG_CORE, 0xD001C10, "ImsaKit" };
153 
154 #define IMSA_HILOGD(fmt, ...)                                                                                    \
155     (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
156         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
157         __FUNCTION__, ##__VA_ARGS__)
158 #define IMSA_HILOGE(fmt, ...)                                                                                    \
159     (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
160         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
161         __FUNCTION__, ##__VA_ARGS__)
162 #define IMSA_HILOGF(fmt, ...)                                                                                    \
163     (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
164         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
165         __FUNCTION__, ##__VA_ARGS__)
166 #define IMSA_HILOGI(fmt, ...)                                                                                    \
167     (void)HILOG_IMPL(LOG_CORE, LOG_INFO, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
168         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
169         __FUNCTION__, ##__VA_ARGS__)
170 #define IMSA_HILOGW(fmt, ...)                                                                                    \
171     (void)HILOG_IMPL(LOG_CORE, LOG_WARN, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
172         OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
173         __FUNCTION__, ##__VA_ARGS__)
174 using Function = std::function<bool()>;
175 bool BlockRetry(uint32_t interval, uint32_t maxRetryTimes, Function func);
176 } // namespace MiscServices
177 } // namespace OHOS
178 #endif // SERVICES_INCLUDE_GLOBAL_H
179