M4PSW_Trace.c revision f24e48bbbc93da7655aabe04adf42eff2efcf69e
1/*
2 * Copyright (C) 2004-2011 NXP Software
3 * Copyright (C) 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 ************************************************************************
19 * @file        M4PSW_Trace.c
20 * @brief        Trace function for trace macros
21 * @note        This file gives the implementation of the trace function used
22 *                in the trace instrumentation macros
23 ************************************************************************
24*/
25
26
27#include <stdio.h> /*for printf */
28#include <stdarg.h> /* ANSI C macros and defs for variable args */
29#include "utils/Log.h"
30
31#include "M4OSA_Types.h"
32#include "M4OSA_Debug.h"
33
34#define NO_FILE /* suppresses the file name print out */
35
36#define MAX_STRING_SIZE 1024
37
38/**
39 ************************************************************************
40 * void M4OSA_Trace(M4OSA_Int32 line, M4OSA_Char* file ,M4OSA_Int32 level,
41 *                                                      M4OSA_Char* format, ...)
42 * @brief    This function implements the trace for debug tests
43 * @note    This implementation uses printf. First the variables are retrieved using
44 *            ANSI C defs and macros which enable to access a variable number of arguments.
45 *            Then the printf is done (with some ornemental adds).
46 * @param    level (IN): the debug level
47 * @param    format (IN): the "printf" formated string
48 * @param    ... (IN): as many parameters as required ...
49 * @return    none
50 ************************************************************************
51*/
52
53M4OSAL_TRACE_EXPORT_TYPE void M4OSA_Trace(M4OSA_Int32 line, M4OSA_Char* file ,
54                                     M4OSA_Int32 level, M4OSA_Char* format, ...)
55{
56    M4OSA_Char message[MAX_STRING_SIZE];
57    M4OSA_Int32 i;
58    va_list marker; /* pointer to list of arguments */
59
60    /* get the var arguments into the string message to be able to print */
61    va_start(marker,format); /* set ptr to first argument in the list of arguments passed to the function */
62    vsprintf((char *)message, (const char *)format,marker );  /* formats and writes the data into message */
63    va_end(marker); /* reset pointer to NULL */
64
65    /* do the actual print */
66#ifdef NO_FILE
67    __android_log_print(ANDROID_LOG_INFO, "M4OSA_Trace", "%s", (char*)message);
68#else /* NO_FILE     */
69    __android_log_print(ANDROID_LOG_INFO, "M4OSA_Trace", "%s", "%s at %lu in %s",
70                                                   (char *)message, line, file);
71#endif /* NO_FILE     */
72
73}
74
75M4OSAL_TRACE_EXPORT_TYPE M4OSA_Void M4OSA_TRACE_traceFunction(M4OSA_UInt32 line,
76                                                              M4OSA_Char* fileName,
77                                                              M4OSA_CoreID coreID,
78                                                              M4OSA_UInt32 level,
79                                                              M4OSA_Char* stringMsg, ...)
80{
81    M4OSA_Char message[MAX_STRING_SIZE];
82    M4OSA_Int32 i;
83    va_list marker; /* pointer to list of arguments */
84
85    /* get the var arguments into the string message to be able to print */
86    va_start(marker,stringMsg); /* set ptr to first argument in the list of arguments passed to the function */
87    vsprintf((char *)message, (const char *)stringMsg,marker );  /* formats and writes the data into message */
88    va_end(marker); /* reset pointer to NULL */
89
90    /* do the actual print */
91#ifdef NO_FILE
92    __android_log_print(ANDROID_LOG_INFO, "M4OSA_TRACE_traceFunction", "%s", (char*)message);
93#else /* NO_FILE     */
94    __android_log_print(ANDROID_LOG_INFO, "M4OSA_TRACE_traceFunction", "%s", "%s at %lu in %s",
95                                            (char *)message, line, (char*)file);
96#endif /* NO_FILE     */
97
98}
99
100