blob: 8f6b69d772e840a33dbe4f0704df27558a20eab4 [file] [log] [blame]
Jean Chalarda5d58492011-02-18 17:50:58 +09001/*
Ken Wakasa5460ea32012-07-30 16:27:44 +09002 * Copyright (C) 2011, The Android Open Source Project
Ken Wakasa0bbb9172012-07-25 17:51:43 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jean Chalarda5d58492011-02-18 17:50:58 +090016
17#ifndef LATINIME_DEBUG_H
18#define LATINIME_DEBUG_H
19
20#include "defines.h"
21
Ken Wakasa0bbb9172012-07-25 17:51:43 +090022static inline unsigned char *convertToUnibyteString(unsigned short *input, unsigned char *output,
Jean Chalarda5d58492011-02-18 17:50:58 +090023 const unsigned int length) {
Jean Chalard1ff8dc42012-05-02 16:00:24 +090024 unsigned int i = 0;
Jean Chalardcc1062c2012-08-17 09:24:45 +090025 for (; i < length && input[i] != 0; ++i)
Jean Chalarda5d58492011-02-18 17:50:58 +090026 output[i] = input[i] & 0xFF;
27 output[i] = 0;
28 return output;
29}
Ken Wakasace9e52a2011-06-18 13:09:55 +090030
Ken Wakasa0bbb9172012-07-25 17:51:43 +090031static inline unsigned char *convertToUnibyteStringAndReplaceLastChar(unsigned short *input,
32 unsigned char *output, const unsigned int length, unsigned char c) {
Jean Chalard1ff8dc42012-05-02 16:00:24 +090033 unsigned int i = 0;
Jean Chalardcc1062c2012-08-17 09:24:45 +090034 for (; i < length && input[i] != 0; ++i)
Jean Chalarda5d58492011-02-18 17:50:58 +090035 output[i] = input[i] & 0xFF;
Jean Chalard1ff8dc42012-05-02 16:00:24 +090036 if (i > 0) output[i-1] = c;
Jean Chalarda5d58492011-02-18 17:50:58 +090037 output[i] = 0;
38 return output;
39}
Ken Wakasace9e52a2011-06-18 13:09:55 +090040
Ken Wakasa0bbb9172012-07-25 17:51:43 +090041static inline void LOGI_S16(unsigned short *string, const unsigned int length) {
Jean Chalarda5d58492011-02-18 17:50:58 +090042 unsigned char tmp_buffer[length];
43 convertToUnibyteString(string, tmp_buffer, length);
satok9fb6f472012-01-13 18:01:22 +090044 AKLOGI(">> %s", tmp_buffer);
Jean Chalarda5d58492011-02-18 17:50:58 +090045 // The log facility is throwing out log that comes too fast. The following
46 // is a dirty way of slowing down processing so that we can see all log.
47 // TODO : refactor this in a blocking log or something.
48 // usleep(10);
49}
Ken Wakasace9e52a2011-06-18 13:09:55 +090050
Ken Wakasa0bbb9172012-07-25 17:51:43 +090051static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int length,
Jean Chalarda5d58492011-02-18 17:50:58 +090052 unsigned char c) {
53 unsigned char tmp_buffer[length+1];
54 convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c);
satok9fb6f472012-01-13 18:01:22 +090055 AKLOGI(">> %s", tmp_buffer);
Jean Chalarda5d58492011-02-18 17:50:58 +090056 // Likewise
57 // usleep(10);
58}
59
Ken Wakasa0bbb9172012-07-25 17:51:43 +090060static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
Ken Wakasa267030d2012-08-14 18:54:13 +090061 unsigned char *buf = static_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf)));
Jean Chalardc2bbc6a2011-02-25 17:56:53 +090062
63 buf[codesSize] = 0;
Ken Wakasabcec82d2012-08-12 11:10:48 +090064 while (--codesSize >= 0) {
65 buf[codesSize] = static_cast<unsigned char>(codes[codesSize * MAX_PROXIMITY_CHARS]);
66 }
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