Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame^] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2011, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef LATINIME_DEBUG_H |
| 19 | #define LATINIME_DEBUG_H |
| 20 | |
| 21 | #include "defines.h" |
| 22 | |
| 23 | static inline unsigned char* convertToUnibyteString(unsigned short* input, unsigned char* output, |
| 24 | const unsigned int length) { |
| 25 | int i = 0; |
| 26 | for (; i <= length && input[i] != 0; ++i) |
| 27 | output[i] = input[i] & 0xFF; |
| 28 | output[i] = 0; |
| 29 | return output; |
| 30 | } |
| 31 | static inline unsigned char* convertToUnibyteStringAndReplaceLastChar(unsigned short* input, |
| 32 | unsigned char* output, const unsigned int length, unsigned char c) { |
| 33 | int i = 0; |
| 34 | for (; i <= length && input[i] != 0; ++i) |
| 35 | output[i] = input[i] & 0xFF; |
| 36 | output[i-1] = c; |
| 37 | output[i] = 0; |
| 38 | return output; |
| 39 | } |
| 40 | static inline void LOGI_S16(unsigned short* string, const unsigned int length) { |
| 41 | unsigned char tmp_buffer[length]; |
| 42 | convertToUnibyteString(string, tmp_buffer, length); |
| 43 | LOGI(">> %s", tmp_buffer); |
| 44 | // The log facility is throwing out log that comes too fast. The following |
| 45 | // is a dirty way of slowing down processing so that we can see all log. |
| 46 | // TODO : refactor this in a blocking log or something. |
| 47 | // usleep(10); |
| 48 | } |
| 49 | static inline void LOGI_S16_PLUS(unsigned short* string, const unsigned int length, |
| 50 | unsigned char c) { |
| 51 | unsigned char tmp_buffer[length+1]; |
| 52 | convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c); |
| 53 | LOGI(">> %s", tmp_buffer); |
| 54 | // Likewise |
| 55 | // usleep(10); |
| 56 | } |
| 57 | |
| 58 | #endif // LATINIME_DEBUG_H |