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 32 static inline unsigned char* convertToUnibyteStringAndReplaceLastChar(unsigned short* input, 33 unsigned char* output, const unsigned int length, unsigned char c) { 34 int i = 0; 35 for (; i <= length && input[i] != 0; ++i) 36 output[i] = input[i] & 0xFF; 37 output[i-1] = c; 38 output[i] = 0; 39 return output; 40 } 41 42 static inline void LOGI_S16(unsigned short* string, const unsigned int length) { 43 unsigned char tmp_buffer[length]; 44 convertToUnibyteString(string, tmp_buffer, length); 45 LOGI(">> %s", tmp_buffer); 46 // The log facility is throwing out log that comes too fast. The following 47 // is a dirty way of slowing down processing so that we can see all log. 48 // TODO : refactor this in a blocking log or something. 49 // usleep(10); 50 } 51 52 static inline void LOGI_S16_PLUS(unsigned short* string, const unsigned int length, 53 unsigned char c) { 54 unsigned char tmp_buffer[length+1]; 55 convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c); 56 LOGI(">> %s", tmp_buffer); 57 // Likewise 58 // usleep(10); 59 } 60 61 static inline void printDebug(const char* tag, int* codes, int codesSize, int MAX_PROXIMITY_CHARS) { 62 unsigned char *buf = (unsigned char*)malloc((1 + codesSize) * sizeof(*buf)); 63 64 buf[codesSize] = 0; 65 while (--codesSize >= 0) 66 buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS]; 67 LOGI("%s, WORD = %s", tag, buf); 68 69 free(buf); 70 } 71 72 #endif // LATINIME_DEBUG_H 73