• 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_ADD_CLIENT_FAILED: {
85                     return "failed fo add client";
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_NOT_IME_PACKAGE: {
103                     return "not an input method engine package";
104                 }
105                 case ERROR_IME_PACKAGE_DUPLICATED: {
106                     return "duplicated input method engine package";
107                 }
108                 case ERROR_SETTING_SAME_VALUE: {
109                     return "same setting value";
110                 }
111                 case ERROR_REMOTE_IME_DIED: {
112                     return "input method service died";
113                 }
114                 case ERROR_REMOTE_CLIENT_DIED: {
115                     return "input client died";
116                 }
117                 case ERROR_CLIENT_NOT_FOUND: {
118                     return "client is not found";
119                 }
120                 case ERROR_STATUS_UNKNOWN_ERROR: {
121                     return "unknown error";
122                 }
123                 case ERROR_STATUS_NO_MEMORY: {
124                     return "no memory";
125                 }
126                 case ERROR_STATUS_INVALID_OPERATION: {
127                     return "invalid operation";
128                 }
129                 case ERROR_STATUS_BAD_VALUE: {
130                     return "bad value";
131                 }
132                 case ERROR_STATUS_BAD_TYPE: {
133                     return "bad type";
134                 }
135                 case ERROR_STATUS_NAME_NOT_FOUND: {
136                     return "name not found";
137                 }
138                 case ERROR_STATUS_PERMISSION_DENIED: {
139                     return "permission denied";
140                 }
141                 case ERROR_STATUS_NO_INIT: {
142                     return "no init";
143                 }
144                 case ERROR_STATUS_ALREADY_EXISTS: {
145                     return "already exists";
146                 }
147                 case ERROR_STATUS_DEAD_OBJECT: {
148                     return "dead object";
149                 }
150                 case ERROR_STATUS_FAILED_TRANSACTION: {
151                     return "failed transaction";
152                 }
153                 case ERROR_STATUS_BAD_INDEX: {
154                     return "bad index";
155                 }
156                 case ERROR_STATUS_NOT_ENOUGH_DATA: {
157                     return "not enough data";
158                 }
159                 case ERROR_STATUS_WOULD_BLOCK: {
160                     return "would block";
161                 }
162                 case ERROR_STATUS_TIMED_OUT: {
163                     return "time out";
164                 }
165                 case ERROR_STATUS_UNKNOWN_TRANSACTION: {
166                     return "unknown transaction";
167                 }
168                 case ERROR_STATUS_FDS_NOT_ALLOWED: {
169                     return "fds not allowed";
170                 }
171                 case ERROR_STATUS_UNEXPECTED_NULL: {
172                     return "unexpected null";
173                 }
174                 case ERROR_EX_ILLEGAL_ARGUMENT: {
175                     return "illegal argument exception";
176                 }
177                 case ERROR_EX_NULL_POINTER: {
178                     return "null pointer exception";
179                 }
180                 case ERROR_EX_ILLEGAL_STATE: {
181                     return "illegal state exception";
182                 }
183                 case ERROR_EX_NETWORK_MAIN_THREAD: {
184                     return "network main thread exception";
185                 }
186                 case ERROR_EX_UNSUPPORTED_OPERATION: {
187                     return "unsupported operation exception";
188                 }
189                 case ERROR_EX_SERVICE_SPECIFIC: {
190                     return "service specific exception";
191                 }
192                 case ERROR_EX_PARCELABLE: {
193                     return "parcelable exception";
194                 }
195                 default: {
196                     return "error is out of definition";
197                 }
198             }
199             return "error is out of definition";
200         };
201     } // namespace ErrorCode
202 } // namespace MiscServices
203 } // namespace OHOS
204