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