• 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 <sys/time.h>
21 #include <time.h>
22 
23 #include "hilog/log.h"
24 #include "ipc_object_stub.h"
25 #include "iremote_broker.h"
26 #include "peer_holder.h"
27 #include "refbase.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
31 
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 enum {
60     ERROR_STATUS_PERMISSION_DENIED = -EPERM,                          // permission denied
61     ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG,                      // unknown transaction
62 
63     // binder exception error code from Status.h
64     ERROR_EX_ILLEGAL_ARGUMENT = -3,      // illegal argument exception
65     ERROR_EX_NULL_POINTER = -4,          // null pointer exception
66     ERROR_EX_ILLEGAL_STATE = -5,         // illegal state exception
67     ERROR_EX_PARCELABLE  = -6,           // parcelable exception
68     ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception
69     ERROR_EX_SERVICE_SPECIFIC = -8,      // service specific exception
70     // no error
71     NO_ERROR = 0, // no error
72 
73     // system service error
74     ERROR_NULL_POINTER = 1,          // null pointer
75     ERROR_BAD_PARAMETERS = 2,        // bad parameters
76     ERROR_CLIENT_NOT_FOUND = 3,
77     ERROR_CLIENT_NULL_POINTER = 4,
78     ERROR_SUBSCRIBE_KEYBOARD_EVENT = 5,
79     ERROR_IME_NOT_STARTED = 6,
80     ERROR_SERVICE_START_FAILED = 7,
81 
82     ERROR_CONTROLLER_INVOKING_FAILED = 8,
83     ERROR_PERSIST_CONFIG = 9,
84     ERROR_KBD_HIDE_FAILED = 10,
85     ERROR_SWITCH_IME = 11,
86     ERROR_PACKAGE_MANAGER = 12,
87     ERROR_REMOTE_CLIENT_DIED = 13,
88     ERROR_IME_START_FAILED = 14,          // failed to start IME service
89     ERROR_KBD_SHOW_FAILED = 15,           // failed to show keyboard
90     ERROR_CLIENT_NOT_BOUND = 16,
91     ERROR_CLIENT_NOT_EDITABLE = 17,
92     ERROR_CLIENT_NOT_FOCUSED = 18,
93     ERROR_CLIENT_ADD_FAILED = 19,
94     ERROR_OPERATE_PANEL = 20,
95     ERROR_NOT_CURRENT_IME = 21,
96     ERROR_NOT_IME = 22,
97     ERROR_ADD_DEATH_RECIPIENT_FAILED = 23,
98     ERROR_STATUS_SYSTEM_PERMISSION = 24, // not system application
99     ERROR_IME_NOT_READY = 25,
100     ERROR_IME = 26,
101 };
102 }; // namespace ErrorCode
103 
104 static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { LOG_CORE, 0xD001C00, "ImsaKit" };
105 
106 #define IMSA_HILOGD(fmt, ...)                                                       \
107     (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
108         "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
109 #define IMSA_HILOGE(fmt, ...)                                                       \
110     (void)OHOS::HiviewDFX::HiLog::Error(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
111         "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
112 #define IMSA_HILOGF(fmt, ...)                                                       \
113     (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
114         "line: %{public}d, function: %{public}s," fmt, __LINE__FILE__, __FUNCTION__, ##__VA_ARGS__)
115 #define IMSA_HILOGI(fmt, ...)                                                      \
116     (void)OHOS::HiviewDFX::HiLog::Info(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
117         "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
118 #define IMSA_HILOGW(fmt, ...)                                                      \
119     (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
120         "line: %{public}d, function: %{public}s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
121 using Function = std::function<bool()>;
122 bool BlockRetry(uint32_t interval, uint32_t maxRetryTimes, Function func);
123 } // namespace MiscServices
124 } // namespace OHOS
125 #endif // SERVICES_INCLUDE_GLOBAL_H
126