• 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 #include <cstdio>
17 #include "global.h"
18 
19 namespace OHOS {
20 namespace MiscServices {
LogTimeStamp()21     void LogTimeStamp()
22     {
23         struct timeval tv;
24         gettimeofday(&tv, nullptr);
25         struct tm nowTime;
26         localtime_r(&tv.tv_sec, &nowTime);
27         int32_t millSec = 1000;
28         printf("%02d-%02d %02d:%02d:%02d.%03d\t", nowTime.tm_mon, nowTime.tm_mday,
29             nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, (int)tv.tv_usec / millSec);
30     }
31 
32     namespace ErrorCode {
ToString(int errorCode)33         const char *ToString(int errorCode)
34         {
35             switch (errorCode) {
36                 case NO_ERROR: {
37                     return "no error";
38                 }
39                 case ERROR_NULL_POINTER: {
40                     return "null pointer";
41                 }
42                 case ERROR_BAD_PARAMETERS: {
43                     return "bad parameters";
44                 }
45                 case ERROR_SERVICE_START_FAILED: {
46                     return "failed to start service";
47                 }
48                 case ERROR_USER_NOT_STARTED: {
49                     return "user has not started";
50                 }
51                 case ERROR_USER_ALREADY_STARTED: {
52                     return "user has already started";
53                 }
54                 case ERROR_USER_NOT_UNLOCKED: {
55                     return "user has not unlocked";
56                 }
57                 case ERROR_USER_ALREADY_UNLOCKED: {
58                     return "user has already unlocked";
59                 }
60                 case ERROR_USER_NOT_LOCKED: {
61                     return "user has not locked";
62                 }
63                 case ERROR_IME_NOT_AVAILABLE: {
64                     return "input method engine is not available";
65                 }
66                 case ERROR_SECURITY_IME_NOT_AVAILABLE: {
67                     return "security input method engine is not available";
68                 }
69                 case ERROR_TOKEN_CREATE_FAILED: {
70                     return "failed to create token";
71                 }
72                 case ERROR_TOKEN_DESTROY_FAILED: {
73                     return "failed to destroy token";
74                 }
75                 case ERROR_IME_BIND_FAILED: {
76                     return "failed to bind service";
77                 }
78                 case ERROR_IME_UNBIND_FAILED: {
79                     return "failed to unbind service";
80                 }
81                 case ERROR_IME_START_FAILED: {
82                     return "failed to start input";
83                 }
84                 case ERROR_IME_STOP_FAILED: {
85                     return "failed to stop input";
86                 }
87                 case ERROR_KBD_SHOW_FAILED: {
88                     return "failed to show keyboard";
89                 }
90                 case ERROR_KBD_HIDE_FAILED: {
91                     return "failed to hide keyboard";
92                 }
93                 case ERROR_IME_NOT_STARTED: {
94                     return "input method service has not started";
95                 }
96                 case ERROR_KBD_IS_OCCUPIED: {
97                     return "keyboard is showing by another client";
98                 }
99                 case ERROR_KBD_IS_NOT_SHOWING: {
100                     return "keyboard is not showing";
101                 }
102                 case ERROR_IME_ALREADY_STARTED: {
103                     return "input method service has already started";
104                 }
105                 case ERROR_NOT_IME_PACKAGE: {
106                     return "not an input method engine package";
107                 }
108                 case ERROR_IME_PACKAGE_DUPLICATED: {
109                     return "duplicated input method engine package";
110                 }
111                 case ERROR_SETTING_SAME_VALUE: {
112                     return "same setting value";
113                 }
114                 case ERROR_NO_NEXT_IME: {
115                     return "next input method engine is not available";
116                 }
117                 case ERROR_CLIENTWINDOW_NOT_FOCUSED: {
118                     return "input client window is not focused";
119                 }
120                 case ERROR_CLIENT_NOT_WINDOW: {
121                     return "input client is not from a valid window";
122                 }
123                 case ERROR_REMOTE_IME_DIED: {
124                     return "input method service died";
125                 }
126                 case ERROR_RESTART_IME_FAILED: {
127                     return "failed to restart input method service";
128                 }
129                 case ERROR_REMOTE_CLIENT_DIED: {
130                     return "input client died";
131                 }
132                 case ERROR_CLIENT_DUPLICATED: {
133                     return "duplicated client";
134                 }
135                 case ERROR_CLIENT_NOT_FOUND: {
136                     return "client is not found";
137                 }
138                 case ERROR_STATUS_UNKNOWN_ERROR: {
139                     return "unknown error";
140                 }
141                 case ERROR_STATUS_NO_MEMORY: {
142                     return "no memory";
143                 }
144                 case ERROR_STATUS_INVALID_OPERATION: {
145                     return "invalid operation";
146                 }
147                 case ERROR_STATUS_BAD_VALUE: {
148                     return "bad value";
149                 }
150                 case ERROR_STATUS_BAD_TYPE: {
151                     return "bad type";
152                 }
153                 case ERROR_STATUS_NAME_NOT_FOUND: {
154                     return "name not found";
155                 }
156                 case ERROR_STATUS_PERMISSION_DENIED: {
157                     return "permission denied";
158                 }
159                 case ERROR_STATUS_NO_INIT: {
160                     return "no init";
161                 }
162                 case ERROR_STATUS_ALREADY_EXISTS: {
163                     return "already exists";
164                 }
165                 case ERROR_STATUS_DEAD_OBJECT: {
166                     return "dead object";
167                 }
168                 case ERROR_STATUS_FAILED_TRANSACTION: {
169                     return "failed transaction";
170                 }
171                 case ERROR_STATUS_BAD_INDEX: {
172                     return "bad index";
173                 }
174                 case ERROR_STATUS_NOT_ENOUGH_DATA: {
175                     return "not enough data";
176                 }
177                 case ERROR_STATUS_WOULD_BLOCK: {
178                     return "would block";
179                 }
180                 case ERROR_STATUS_TIMED_OUT: {
181                     return "time out";
182                 }
183                 case ERROR_STATUS_UNKNOWN_TRANSACTION: {
184                     return "unknown transaction";
185                 }
186                 case ERROR_STATUS_FDS_NOT_ALLOWED: {
187                     return "fds not allowed";
188                 }
189                 case ERROR_STATUS_UNEXPECTED_NULL: {
190                     return "unexpected null";
191                 }
192                 case ERROR_EX_ILLEGAL_ARGUMENT: {
193                     return "illegal argument exception";
194                 }
195                 case ERROR_EX_NULL_POINTER: {
196                     return "null pointer exception";
197                 }
198                 case ERROR_EX_ILLEGAL_STATE: {
199                     return "illegal state exception";
200                 }
201                 case ERROR_EX_NETWORK_MAIN_THREAD: {
202                     return "network main thread exception";
203                 }
204                 case ERROR_EX_UNSUPPORTED_OPERATION: {
205                     return "unsupported operation exception";
206                 }
207                 case ERROR_EX_SERVICE_SPECIFIC: {
208                     return "service specific exception";
209                 }
210                 case ERROR_EX_PARCELABLE: {
211                     return "parcelable exception";
212                 }
213                 default: {
214                     return "error is out of definition";
215                 }
216             }
217             return "error is out of definition";
218         };
219     }
220 }
221 }
222 
223