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