repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / cortex / addons / LoggingConsumer / LogWriter.h
blob8150d12b51757d4216b6031ad5bdb73e53b079b5
1 /*
2 * Copyright 1991-1999, Be Incorporated.
3 * Copyright (c) 1999-2000, Eric Moon.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions, and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // LogWriter.h
35 #ifndef LogWriter_H
36 #define LogWriter_H 1
38 #include <kernel/OS.h>
39 //#include <storage/Entry.h>
40 //#include <storage/File.h>
41 #include <Entry.h>
42 #include <File.h>
43 #include <support/String.h>
44 #include <set>
46 // logging message data structure
47 struct log_message
49 bigtime_t tstamp; // time that LogWriter::Log() was called, in real time
50 bigtime_t now; // time that LogWriter::Log() was called, according to the time source
51 union // various bits of data for different kinds of logged actions
53 struct
55 bigtime_t start_time; // buffer's start time stamp
56 bigtime_t offset; // how late or early the buffer was handled
57 } buffer_data;
58 struct
60 int32 status;
61 } data_status;
62 struct
64 int32 id; // parameter ID
65 float value; // new value
66 } param;
67 struct
69 int32 what;
70 } unknown;
74 // logging message 'what' codes
75 enum log_what
77 LOG_QUIT = 'Quit', // time to quit; tear down the thread
79 // messages related to BMediaNode methods
80 LOG_SET_RUN_MODE = 'Rnmd',
81 LOG_PREROLL = 'Prll',
82 LOG_SET_TIME_SOURCE = 'TSrc',
83 LOG_REQUEST_COMPLETED = 'Rqcm',
85 // messages related to BControllable methods
86 LOG_GET_PARAM_VALUE = 'PVal',
87 LOG_SET_PARAM_VALUE = 'SVal',
89 // messages related to BBufferProducer methods
90 LOG_FORMAT_SUGG_REQ = 'FSRq',
91 LOG_FORMAT_PROPOSAL = 'FPro',
92 LOG_FORMAT_CHANGE_REQ = 'FCRq',
93 LOG_SET_BUFFER_GROUP = 'SBfG',
94 LOG_VIDEO_CLIP_CHANGED = 'VClp',
95 LOG_GET_LATENCY = 'GLat',
96 LOG_PREPARE_TO_CONNECT = 'PCon',
97 LOG_CONNECT = 'Cnct',
98 LOG_DISCONNECT = 'Dsct',
99 LOG_LATE_NOTICE_RECEIVED = 'LNRc',
100 LOG_ENABLE_OUTPUT = 'EnOP',
101 LOG_SET_PLAY_RATE = 'PlRt',
102 LOG_ADDITIONAL_BUFFER = 'AdBf',
103 LOG_LATENCY_CHANGED = 'LtCh',
105 // messages related to BBufferConsumer methods
106 LOG_HANDLE_MESSAGE = 'Mesg',
107 LOG_ACCEPT_FORMAT = 'Frmt',
108 LOG_BUFFER_RECEIVED = 'Bufr',
109 LOG_PRODUCER_DATA_STATUS = 'PDSt',
110 LOG_CONNECTED = 'Cntd',
111 LOG_DISCONNECTED = 'Dctd',
112 LOG_FORMAT_CHANGED = 'Fmtc',
113 LOG_SEEK_TAG = 'STrq',
115 // messages related to BMediaEventLooper methods
116 LOG_REGISTERED = 'Rgst',
117 LOG_START = 'Strt',
118 LOG_STOP = 'Stop',
119 LOG_SEEK = 'Seek',
120 LOG_TIMEWARP = 'Warp',
122 // messages about handling things in BMediaEventLooper::HandleEvent()
123 LOG_HANDLE_EVENT = 'HEvt',
124 LOG_HANDLE_UNKNOWN = 'Uknw', // unknown event code in HandleEvent()
125 LOG_BUFFER_HANDLED = 'Bfhd',
126 LOG_START_HANDLED = 'Sthd',
127 LOG_STOP_HANDLED = 'Sphd',
128 LOG_SEEK_HANDLED = 'Skhd',
129 LOG_WARP_HANDLED = 'Wphd',
130 LOG_DATA_STATUS_HANDLED = 'DShd',
131 LOG_SET_PARAM_HANDLED = 'SPrm',
132 LOG_INVALID_PARAM_HANDLED = 'BadP'
135 // LogWriter class
136 class LogWriter
138 public:
139 // Set: output for the log_what members is disabled
140 typedef std::set<log_what> FilterSet;
142 public:
143 LogWriter(const entry_ref& logRef);
144 ~LogWriter();
146 // write a message to the log
147 void Log(log_what what, const log_message& data);
149 // filtering control for logged messages
150 void SetEnabled(log_what what, bool enable);
151 void EnableAllMessages();
152 void DisableAllMessages();
154 private:
155 entry_ref mLogRef;
156 thread_id mLogThread;
157 port_id mPort;
158 BFile mLogFile;
159 BString mWriteBuf;
160 FilterSet mFilters;
162 // called by the LogWriter's thread
163 void HandleMessage(log_what what, const log_message& msg);
165 friend int32 LogWriterLoggingThread(void* arg);
168 #endif