1e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent/*
2a6451827d543eb00824bc95097e47d0aac51ae93Alexander Gutkin *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *
4e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  Use of this source code is governed by a BSD-style license
5e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  that can be found in the LICENSE file in the root of the source
6e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  tree. An additional intellectual property rights grant can be found
7e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  in the file PATENTS.  All contributing project authors may
8e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent *  be found in the AUTHORS file in the root of the source tree.
9e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent */
10e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
11e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent// System independant wrapper for logging runtime information to file.
12e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent// Note: All log messages will be written to the same trace file.
13e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent// Note: If to many messages are written to file there will be a build up of
14e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent//       messages. Apply filtering to avoid that.
15e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
16e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
17e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
18e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#include "common_types.h"
19e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#include "typedefs.h"
20e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
21c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_TRACE Trace::Add
22e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
23e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentnamespace webrtc {
24e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentclass Trace
25e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent{
26e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentpublic:
27e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
28e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Increments the reference count to the trace.
29e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static void CreateTrace();
30e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Decrements the reference count to the trace.
31e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static void ReturnTrace();
32e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Note: any instance that writes to the trace file should increment and
33e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // decrement the reference count on construction and destruction
34e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // respectively
35e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
36e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Specifies what type of messages should be written to the trace file. The
37e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // filter parameter is a bitmask where each message type is enumerated by
38e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // the TraceLevel enumerator. TODO (hellner) why is the
39e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // TraceLevel enumerator not defined in this file?
40e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static WebRtc_Word32 SetLevelFilter(const WebRtc_UWord32 filter);
41e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
42e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Returns what type of messages are written to the trace file.
43e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static WebRtc_Word32 LevelFilter(WebRtc_UWord32& filter);
44e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
45e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Sets the file name. If addFileCounter is false the same file will be
46e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // reused when it fills up. If it's true a new file with incremented name
47e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // will be used.
48a6451827d543eb00824bc95097e47d0aac51ae93Alexander Gutkin    static WebRtc_Word32 SetTraceFile(const char* fileName,
49e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent                                      const bool addFileCounter = false);
50e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
51e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Returns the name of the file that the trace is currently writing to.
52a6451827d543eb00824bc95097e47d0aac51ae93Alexander Gutkin    static WebRtc_Word32 TraceFile(char fileName[1024]);
53e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
54e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Registers callback to receive trace messages. TODO (hellner)
55e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // why not use OutStream instead? Why is TraceCallback not defined in this
56e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // file
57e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static WebRtc_Word32 SetTraceCallback(TraceCallback* callback);
58e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent
59e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // Adds a trace message for writing to file. The message is put in a queue
60e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // for writing to file whenever possible for performance reasons. I.e. there
61e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // is a crash it is possible that the last, vital logs are not logged yet.
62e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // level is the the type of message to log. If that type of messages is
63e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // filtered it will not be written to file. module is an identifier for what
64e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // part of the code the message is comming.
65e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // id is an identifier that should be unique for that set of classes that
66e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // are associated (e.g. all instances owned by an engine).
67e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // msg and the elipsis are the same as e.g. sprintf.
68e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    // TODO (hellner) Why is TraceModule not defined in this file?
69e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent    static void Add(const TraceLevel level,
70e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent                    const TraceModule module,
71e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent                    const WebRtc_Word32 id,
72e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent                    const char* msg, ...);
73e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent};
74e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent} // namespace webrtc
75e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_
76