122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#ifndef SERVICES_INCLUDE_GLOBAL_H
1722736c2fSopenharmony_ci#define SERVICES_INCLUDE_GLOBAL_H
1822736c2fSopenharmony_ci
1922736c2fSopenharmony_ci#include <errno.h>
2022736c2fSopenharmony_ci#include <functional>
2122736c2fSopenharmony_ci#include <sys/time.h>
2222736c2fSopenharmony_ci#include <time.h>
2322736c2fSopenharmony_ci
2422736c2fSopenharmony_ci#include "hilog/log.h"
2522736c2fSopenharmony_ci
2622736c2fSopenharmony_cinamespace OHOS {
2722736c2fSopenharmony_cinamespace MiscServices {
2822736c2fSopenharmony_ci
2922736c2fSopenharmony_ci#define LOG_INFO(fmt, args...) \
3022736c2fSopenharmony_ci    LogTimeStamp();            \
3122736c2fSopenharmony_ci    printf("I %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
3222736c2fSopenharmony_ci
3322736c2fSopenharmony_ci#define LOG_ERROR(fmt, args...) \
3422736c2fSopenharmony_ci    LogTimeStamp();             \
3522736c2fSopenharmony_ci    printf("E %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
3622736c2fSopenharmony_ci
3722736c2fSopenharmony_ci#define LOG_WARNING(fmt, args...) \
3822736c2fSopenharmony_ci    LogTimeStamp();               \
3922736c2fSopenharmony_ci    printf("W %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
4022736c2fSopenharmony_ci
4122736c2fSopenharmony_ci#if DEBUG
4222736c2fSopenharmony_ci#define LOG_DEBUG(fmt, args...) \
4322736c2fSopenharmony_ci    LogTimeStamp();             \
4422736c2fSopenharmony_ci    printf("D %s:%d  %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
4522736c2fSopenharmony_ci#else
4622736c2fSopenharmony_ci#define LOG_DEBUG(fmt, args...)
4722736c2fSopenharmony_ci#endif
4822736c2fSopenharmony_ci
4922736c2fSopenharmony_civoid LogTimeStamp();
5022736c2fSopenharmony_ci
5122736c2fSopenharmony_ci// Error Code
5222736c2fSopenharmony_cinamespace ErrorCode {
5322736c2fSopenharmony_ci// Error Code definition in the input method management system
5422736c2fSopenharmony_cienum {
5522736c2fSopenharmony_ci    ERROR_STATUS_PERMISSION_DENIED = -EPERM,     // permission denied
5622736c2fSopenharmony_ci    ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, // unknown transaction
5722736c2fSopenharmony_ci
5822736c2fSopenharmony_ci    // binder exception error code from Status.h
5922736c2fSopenharmony_ci    ERROR_EX_ILLEGAL_ARGUMENT = -3,      // illegal argument exception
6022736c2fSopenharmony_ci    ERROR_EX_NULL_POINTER = -4,          // null pointer exception
6122736c2fSopenharmony_ci    ERROR_EX_ILLEGAL_STATE = -5,         // illegal state exception
6222736c2fSopenharmony_ci    ERROR_EX_PARCELABLE = -6,            // parcelable exception
6322736c2fSopenharmony_ci    ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception
6422736c2fSopenharmony_ci    ERROR_EX_SERVICE_SPECIFIC = -8,      // service specific exception
6522736c2fSopenharmony_ci    // no error
6622736c2fSopenharmony_ci    NO_ERROR = 0, // no error
6722736c2fSopenharmony_ci
6822736c2fSopenharmony_ci    // system service error
6922736c2fSopenharmony_ci    ERROR_NULL_POINTER = 1,   // null pointer
7022736c2fSopenharmony_ci    ERROR_BAD_PARAMETERS = 2, // bad parameters
7122736c2fSopenharmony_ci    ERROR_CLIENT_NOT_FOUND = 3,
7222736c2fSopenharmony_ci    ERROR_CLIENT_NULL_POINTER = 4,
7322736c2fSopenharmony_ci    ERROR_SUBSCRIBE_KEYBOARD_EVENT = 5,
7422736c2fSopenharmony_ci    ERROR_IME_NOT_STARTED = 6,
7522736c2fSopenharmony_ci    ERROR_SERVICE_START_FAILED = 7,
7622736c2fSopenharmony_ci
7722736c2fSopenharmony_ci    ERROR_CONTROLLER_INVOKING_FAILED = 8,
7822736c2fSopenharmony_ci    ERROR_PERSIST_CONFIG = 9,
7922736c2fSopenharmony_ci    ERROR_KBD_HIDE_FAILED = 10,
8022736c2fSopenharmony_ci    ERROR_SWITCH_IME = 11,
8122736c2fSopenharmony_ci    ERROR_PACKAGE_MANAGER = 12,
8222736c2fSopenharmony_ci    ERROR_REMOTE_CLIENT_DIED = 13,
8322736c2fSopenharmony_ci    ERROR_IME_START_FAILED = 14, // failed to start IME service
8422736c2fSopenharmony_ci    ERROR_KBD_SHOW_FAILED = 15,  // failed to show keyboard
8522736c2fSopenharmony_ci    ERROR_CLIENT_NOT_BOUND = 16,
8622736c2fSopenharmony_ci    ERROR_CLIENT_NOT_EDITABLE = 17,
8722736c2fSopenharmony_ci    ERROR_CLIENT_NOT_FOCUSED = 18,
8822736c2fSopenharmony_ci    ERROR_CLIENT_ADD_FAILED = 19,
8922736c2fSopenharmony_ci    ERROR_OPERATE_PANEL = 20,
9022736c2fSopenharmony_ci    ERROR_NOT_CURRENT_IME = 21,
9122736c2fSopenharmony_ci    ERROR_NOT_IME = 22,
9222736c2fSopenharmony_ci    ERROR_ADD_DEATH_RECIPIENT_FAILED = 23,
9322736c2fSopenharmony_ci    ERROR_STATUS_SYSTEM_PERMISSION = 24, // not system application
9422736c2fSopenharmony_ci    ERROR_IME = 25,
9522736c2fSopenharmony_ci    ERROR_PARAMETER_CHECK_FAILED = 26,
9622736c2fSopenharmony_ci    ERROR_IME_START_INPUT_FAILED = 27,
9722736c2fSopenharmony_ci    ERROR_KEYWORD_NOT_FOUND = 28,
9822736c2fSopenharmony_ci    ERROR_ENABLE_IME = 29,
9922736c2fSopenharmony_ci    ERROR_PARSE_CONFIG_FILE = 30,
10022736c2fSopenharmony_ci    ERROR_NOT_DEFAULT_IME = 31,
10122736c2fSopenharmony_ci    ERROR_ENABLE_SECURITY_MODE = 32,
10222736c2fSopenharmony_ci    ERROR_DISPATCH_KEY_EVENT = 33,
10322736c2fSopenharmony_ci    ERROR_INVALID_PRIVATE_COMMAND_SIZE = 34,
10422736c2fSopenharmony_ci    ERROR_TEXT_LISTENER_ERROR = 35,
10522736c2fSopenharmony_ci    ERROR_PANEL_NOT_FOUND = 36,
10622736c2fSopenharmony_ci    ERROR_WINDOW_MANAGER = 37,
10722736c2fSopenharmony_ci    ERROR_GET_TEXT_CONFIG = 38,
10822736c2fSopenharmony_ci    ERROR_TEXT_PREVIEW_NOT_SUPPORTED = 39,
10922736c2fSopenharmony_ci    ERROR_INVALID_RANGE = 40,
11022736c2fSopenharmony_ci    ERROR_CMD_LISTENER_ERROR = 41,
11122736c2fSopenharmony_ci    ERROR_SYSTEM_CMD_CHANNEL_ERROR = 42,
11222736c2fSopenharmony_ci    ERROR_INVALID_PRIVATE_COMMAND = 43,
11322736c2fSopenharmony_ci    ERROR_OS_ACCOUNT = 44,
11422736c2fSopenharmony_ci    ERROR_TASK_MANAGER_PEND_FAILED = 45,
11522736c2fSopenharmony_ci    ERROR_RES_ERROR = 46,
11622736c2fSopenharmony_ci};
11722736c2fSopenharmony_ci}; // namespace ErrorCode
11822736c2fSopenharmony_ci
11922736c2fSopenharmony_cistatic constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { LOG_CORE, 0xD001C10, "ImsaKit" };
12022736c2fSopenharmony_ci
12122736c2fSopenharmony_ci#define IMSA_HILOGD(fmt, ...)                                                                                    \
12222736c2fSopenharmony_ci    (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
12322736c2fSopenharmony_ci        OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
12422736c2fSopenharmony_ci        __FUNCTION__, ##__VA_ARGS__)
12522736c2fSopenharmony_ci#define IMSA_HILOGE(fmt, ...)                                                                                    \
12622736c2fSopenharmony_ci    (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
12722736c2fSopenharmony_ci        OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
12822736c2fSopenharmony_ci        __FUNCTION__, ##__VA_ARGS__)
12922736c2fSopenharmony_ci#define IMSA_HILOGF(fmt, ...)                                                                                    \
13022736c2fSopenharmony_ci    (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                     \
13122736c2fSopenharmony_ci        OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
13222736c2fSopenharmony_ci        __FUNCTION__, ##__VA_ARGS__)
13322736c2fSopenharmony_ci#define IMSA_HILOGI(fmt, ...)                                                                                    \
13422736c2fSopenharmony_ci    (void)HILOG_IMPL(LOG_CORE, LOG_INFO, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
13522736c2fSopenharmony_ci        OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
13622736c2fSopenharmony_ci        __FUNCTION__, ##__VA_ARGS__)
13722736c2fSopenharmony_ci#define IMSA_HILOGW(fmt, ...)                                                                                    \
13822736c2fSopenharmony_ci    (void)HILOG_IMPL(LOG_CORE, LOG_WARN, OHOS::MiscServices::g_SMALL_SERVICES_LABEL.domain,                      \
13922736c2fSopenharmony_ci        OHOS::MiscServices::g_SMALL_SERVICES_LABEL.tag, "line: %{public}d, function: %{public}s," fmt, __LINE__, \
14022736c2fSopenharmony_ci        __FUNCTION__, ##__VA_ARGS__)
14122736c2fSopenharmony_ciusing Function = std::function<bool()>;
14222736c2fSopenharmony_cibool BlockRetry(uint32_t interval, uint32_t maxRetryTimes, Function func);
14322736c2fSopenharmony_ci} // namespace MiscServices
14422736c2fSopenharmony_ci} // namespace OHOS
14522736c2fSopenharmony_ci#endif // SERVICES_INCLUDE_GLOBAL_H
146