00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __UAPI__LOGGER
00021 #define __UAPI__LOGGER
00022
00023 #if defined (ANDROID)
00024 #define LOG_TAG "Uapi"
00025 #include <utils/Log.h>
00026 #endif
00027 #include "ReturnCode.h"
00028 #include "exports.h"
00029 #include "SmartProxy.h"
00030
00031 #define UAPI_LOG_FUNCTION_SCOPE
00032
00033 namespace android
00034 {
00035 namespace speech
00036 {
00037 namespace recognition
00038 {
00039 #ifdef UAPI_LOGGING_ENABLED
00040
00041 class LoggerProxy;
00050 class Logger
00051 {
00052 public:
00053 enum UAPI_EXPORT LogLevel
00054 {
00058 LEVEL_NONE,
00062 LEVEL_ERROR,
00066 LEVEL_WARN,
00071 LEVEL_INFO,
00076 LEVEL_TRACE
00077 };
00078
00085 UAPI_EXPORT static LoggerProxy getInstance(ReturnCode::Type& returnCode);
00086
00092 UAPI_EXPORT static Logger* getExistingInstance();
00093
00101 virtual void setLoggingLevel(LogLevel level, ReturnCode::Type& returnCode) = 0;
00102
00108 virtual LogLevel getLoggingLevel() const = 0;
00109
00119 virtual void setPath(const char* path, ReturnCode::Type& returnCode) = 0;
00120
00126 virtual void error(const char* fn, const char* lpszFormat, ...) = 0;
00127
00133 virtual void warn(const char* fn, const char* lpszFormat, ...) = 0;
00134
00140 virtual void info(const char* fn, const char* lpszFormat, ...) = 0;
00141
00147 virtual void trace(const char* fn, const char* lpszFormat, ...) = 0;
00148 protected:
00152 Logger();
00156 virtual ~Logger();
00157 private:
00158
00159
00160 friend class SmartProxy;
00161 friend class LoggerProxy;
00162 };
00163
00164
00165
00166
00167
00168
00169 DECLARE_SMARTPROXY(UAPI_EXPORT, LoggerProxy, SmartProxy, Logger)
00170 #else
00171 inline void UAPILog(const char *, const char* , ...)
00172 {
00173 }
00174 class Logger
00175 {
00176 public:
00177 enum UAPI_EXPORT LogLevel
00178 {
00179 LEVEL_NONE,
00180 LEVEL_ERROR,
00181 LEVEL_WARN,
00182 LEVEL_INFO,
00183 LEVEL_TRACE
00184 };
00185 };
00186 #endif
00187 }
00188 }
00189 }
00195 #ifdef UAPI_LOGGING_ENABLED
00196 #define UAPI_ERROR if(android::speech::recognition::Logger::getExistingInstance()) android::speech::recognition::Logger::getExistingInstance()->error
00197 #else
00198 # define UAPI_ERROR if (false) UAPILog
00199 #endif
00200
00206 #ifdef UAPI_LOGGING_ENABLED
00207 # define UAPI_WARN if(android::speech::recognition::Logger::getExistingInstance()) android::speech::recognition::Logger::getExistingInstance()->warn
00208 #else
00209 # define UAPI_WARN if (false) UAPILog
00210 #endif
00211
00216 #ifdef UAPI_LOGGING_ENABLED
00217 # define UAPI_INFO if(android::speech::recognition::Logger::getExistingInstance()) android::speech::recognition::Logger::getExistingInstance()->info
00218 #else
00219 # define UAPI_INFO if (false) UAPILog
00220 #endif
00221
00225 #ifdef UAPI_LOGGING_ENABLED
00226 # define UAPI_TRACE if(android::speech::recognition::Logger::getExistingInstance()) android::speech::recognition::Logger::getExistingInstance()->trace
00227 #else
00228 # define UAPI_TRACE if (false) UAPILog
00229 #endif
00230
00231
00232 # define UAPI_FN_NAME(name) const char* const fn = name;
00233
00234 #if defined(UAPI_LOGGING_ENABLED) && defined(UAPI_LOG_FUNCTION_SCOPE)
00235
00239 namespace android
00240 {
00241 namespace speech
00242 {
00243 namespace recognition
00244 {
00245 class TraceScope
00246 {
00247 public:
00248 TraceScope(const char* fn)
00249 : functionName(fn)
00250 { UAPI_TRACE(functionName, "ENTER\n"); }
00251 ~TraceScope()
00252 { UAPI_TRACE(functionName, "EXIT\n"); }
00253
00254 private:
00255 const char * functionName;
00256 };
00257 }
00258 }
00259 }
00260 # define UAPI_FN_SCOPE(name) const char* const fn = name; \
00261 android::speech::recognition::TraceScope traceScope(fn);
00262 #else
00263 inline void RemoveCompilerWarning(const char *) {}
00264 # define UAPI_FN_SCOPE(name) const char* const fn = name; RemoveCompilerWarning(fn);
00265 #endif
00266
00267
00268 #endif