1bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *
3bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * Redistribution and use in source and binary forms, with or without
4bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * modification, are permitted provided that the following conditions are
5bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * met:
6bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Redistributions of source code must retain the above copyright
7bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       notice, this list of conditions and the following disclaimer.
8bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Redistributions in binary form must reproduce the above
9bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       copyright notice, this list of conditions and the following
10bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       disclaimer in the documentation and/or other materials provided
11bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       with the distribution.
12bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *     * Neither the name of The Linux Foundation nor the names of its
13bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       contributors may be used to endorse or promote products derived
14bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *       from this software without specific prior written permission.
15bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo *
16bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo */
28bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
29bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifndef __PLATFORM_LIB_MACROS_H__
30bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define __PLATFORM_LIB_MACROS_H__
31bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
32bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#include <sys/time.h>
33bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
34bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define TS_PRINTF(format, x...)                                \
35bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo{                                                              \
36bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  struct timeval tv;                                           \
37bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  struct timezone tz;                                          \
38bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  int hh, mm, ss;                                              \
39bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  gettimeofday(&tv, &tz);                                      \
40bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  hh = tv.tv_sec/3600%24;                                      \
41bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  mm = (tv.tv_sec%3600)/60;                                    \
42bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  ss = tv.tv_sec%60;                                           \
43bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo  fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec,##x);    \
44bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
45bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
46bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
47bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifdef USE_GLIB
48bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
49bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define strlcat g_strlcat
50bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define strlcpy g_strlcpy
51bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
52bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x)
53bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ALOGW(format, x...) TS_PRINTF("W/%s (%d): " format , LOG_TAG, getpid(), ##x)
54bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ALOGI(format, x...) TS_PRINTF("I/%s (%d): " format , LOG_TAG, getpid(), ##x)
55bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ALOGD(format, x...) TS_PRINTF("D/%s (%d): " format , LOG_TAG, getpid(), ##x)
56bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ALOGV(format, x...) TS_PRINTF("V/%s (%d): " format , LOG_TAG, getpid(), ##x)
57bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
58bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define GETTID_PLATFORM_LIB_ABSTRACTION (syscall(SYS_gettid))
59bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
60bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION createPthread
61bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (elapsedMillisSinceBoot())
62bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
63bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
64bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#else
65bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
66bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifdef __cplusplus
67bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russoextern "C" {
68bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
69bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russopid_t gettid(void);
70bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
71bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#ifdef __cplusplus
72bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo}
73bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
74bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
75bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define GETTID_PLATFORM_LIB_ABSTRACTION (gettid())
76bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION android::AndroidRuntime::createJavaThread
77bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION  (android::elapsedRealtime())
78bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
79bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
80bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo
81bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#endif
82