Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      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
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #ifndef PVLOGGER_ACCESSORIES_H_INCLUDED
     19 #define PVLOGGER_ACCESSORIES_H_INCLUDED
     20 
     21 #ifndef OSCL_BASE_H_INCLUDED
     22 #include "oscl_base.h"
     23 #endif
     24 
     25 #ifndef PVLOGGER_H_INCLUDED
     26 #include "pvlogger.h"
     27 #endif
     28 
     29 /**
     30  * Base class for all message formatters. This class defines the interface to
     31  * the message formatter. There are two kinds of msg formatting APIs, one to
     32  * format text messages, and other to format opaque message buffers.
     33  */
     34 class PVLoggerLayout
     35 {
     36     public:
     37         typedef PVLogger::message_id_type message_id_type;
     38 
     39         virtual ~PVLoggerLayout() {}
     40 
     41         /**
     42          * Formats the string and copies it to the given buffer.
     43          *
     44          * @return The length of the string not including the trailing '\0'
     45          */
     46         virtual int32 FormatString(char* formatBuf, int32 formatBufSize,
     47                                    message_id_type msgID, const char * fmt,
     48                                    va_list va) = 0;
     49 
     50         /**
     51          * Formats the data and copies it to the given buffer.
     52          *
     53          * @return The length of the buffer used.
     54          */
     55         virtual int32 FormatOpaqueMessage(char* formatBuf, int32 formatBufSize,
     56                                           message_id_type msgID, int32 numPairs,
     57                                           va_list va) = 0;
     58 };
     59 
     60 /**
     61  * Base class for all message filters. This class defines the interface to
     62  * the message filters. There are two kinds of msg filtering APIs, one to
     63  * filter text messages, and other to filter opaque message buffers.
     64  */
     65 class PVLoggerFilter
     66 {
     67     public:
     68         virtual ~PVLoggerFilter() {}
     69 
     70         typedef PVLogger::message_id_type message_id_type;
     71         typedef PVLogger::log_level_type log_level_type;
     72         typedef PVLogger::filter_status_type filter_status_type;
     73 
     74         virtual filter_status_type FilterString(char* tag, message_id_type msgID, log_level_type level) = 0;
     75         virtual filter_status_type FilterOpaqueMessge(char* tag, message_id_type msgID, log_level_type level) = 0;
     76 };
     77 
     78 const PVLoggerFilter::filter_status_type PVLOGGER_FILTER_ACCEPT = 1;
     79 const PVLoggerFilter::filter_status_type PVLOGGER_FILTER_REJECT = 2;
     80 const PVLoggerFilter::filter_status_type PVLOGGER_FILTER_NEUTRAL = 3;
     81 
     82 /**
     83  * Example filter that allows all messages to be logged.
     84  */
     85 class AllPassFilter : public PVLoggerFilter
     86 {
     87     public:
     88         typedef PVLoggerFilter::message_id_type message_id_type;
     89         typedef PVLoggerFilter::log_level_type log_level_type;
     90         typedef PVLoggerFilter::filter_status_type filter_status_type;
     91 
     92         AllPassFilter() {};
     93         virtual ~AllPassFilter() {};
     94 
     95         filter_status_type FilterString(char* tag, message_id_type msgID, log_level_type level)
     96         {
     97             OSCL_UNUSED_ARG(tag);
     98             OSCL_UNUSED_ARG(msgID);
     99             OSCL_UNUSED_ARG(level);
    100             return (PVLOGGER_FILTER_ACCEPT);
    101         };
    102         filter_status_type FilterOpaqueMessge(char* tag, message_id_type msgID, log_level_type level)
    103         {
    104             OSCL_UNUSED_ARG(tag);
    105             OSCL_UNUSED_ARG(msgID);
    106             OSCL_UNUSED_ARG(level);
    107             return (PVLOGGER_FILTER_ACCEPT);
    108         };
    109 };
    110 
    111 /**
    112  * Base class for all message appenders. This class defines the interface to
    113  * the message appenders. There are two kinds of msg appender APIs, one to
    114  * append text messages, and other to append opaque message buffers.
    115  */
    116 class PVLoggerAppender
    117 {
    118     public:
    119         typedef PVLogger::message_id_type message_id_type;
    120 
    121         virtual ~PVLoggerAppender() {}
    122 
    123         virtual void AppendString(message_id_type msgID, const char *fmt, va_list va) = 0;
    124         virtual void AppendBuffers(message_id_type msgID, int32 numPairs, va_list va) = 0;
    125 };
    126 
    127 
    128 #endif
    129 
    130