blob: 2fee6e83fe023cf6e384ccab9d9a7136eab7b3d0 [file] [log] [blame]
Jean Chalarda5d58492011-02-18 17:50:58 +09001/*
Ken Wakasa0bbb9172012-07-25 17:51:43 +09002 *
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 */
Jean Chalarda5d58492011-02-18 17:50:58 +090017
18#ifndef LATINIME_DEBUG_H
19#define LATINIME_DEBUG_H
20
21#include "defines.h"
22
Ken Wakasa0bbb9172012-07-25 17:51:43 +090023static inline unsigned char *convertToUnibyteString(unsigned short *input, unsigned char *output,
Jean Chalarda5d58492011-02-18 17:50:58 +090024 const unsigned int length) {
Jean Chalard1ff8dc42012-05-02 16:00:24 +090025 unsigned int i = 0;
Jean Chalarda5d58492011-02-18 17:50:58 +090026 for (; i <= length && input[i] != 0; ++i)
27 output[i] = input[i] & 0xFF;
28 output[i] = 0;
29 return output;
30}
Ken Wakasace9e52a2011-06-18 13:09:55 +090031
Ken Wakasa0bbb9172012-07-25 17:51:43 +090032static inline unsigned char *convertToUnibyteStringAndReplaceLastChar(unsigned short *input,
33 unsigned char *output, const unsigned int length, unsigned char c) {
Jean Chalard1ff8dc42012-05-02 16:00:24 +090034 unsigned int i = 0;
Jean Chalarda5d58492011-02-18 17:50:58 +090035 for (; i <= length && input[i] != 0; ++i)
36 output[i] = input[i] & 0xFF;
Jean Chalard1ff8dc42012-05-02 16:00:24 +090037 if (i > 0) output[i-1] = c;
Jean Chalarda5d58492011-02-18 17:50:58 +090038 output[i] = 0;
39 return output;
40}
Ken Wakasace9e52a2011-06-18 13:09:55 +090041
Ken Wakasa0bbb9172012-07-25 17:51:43 +090042static inline void LOGI_S16(unsigned short *string, const unsigned int length) {
Jean Chalarda5d58492011-02-18 17:50:58 +090043 unsigned char tmp_buffer[length];
44 convertToUnibyteString(string, tmp_buffer, length);
satok9fb6f472012-01-13 18:01:22 +090045 AKLOGI(">> %s", tmp_buffer);
Jean Chalarda5d58492011-02-18 17:50:58 +090046 // 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}
Ken Wakasace9e52a2011-06-18 13:09:55 +090051
Ken Wakasa0bbb9172012-07-25 17:51:43 +090052static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int length,
Jean Chalarda5d58492011-02-18 17:50:58 +090053 unsigned char c) {
54 unsigned char tmp_buffer[length+1];
55 convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c);
satok9fb6f472012-01-13 18:01:22 +090056 AKLOGI(">> %s", tmp_buffer);
Jean Chalarda5d58492011-02-18 17:50:58 +090057 // Likewise
58 // usleep(10);
59}
60
Ken Wakasa0bbb9172012-07-25 17:51:43 +090061static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
Jean Chalardc2bbc6a2011-02-25 17:56:53 +090062 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];
satok9fb6f472012-01-13 18:01:22 +090067 AKLOGI("%s, WORD = %s", tag, buf);
Jean Chalardc2bbc6a2011-02-25 17:56:53 +090068
69 free(buf);
70}
Jean Chalarda5d58492011-02-18 17:50:58 +090071#endif // LATINIME_DEBUG_H