1 // LogWriter.h 2 3 #ifndef LogWriter_H 4 #define LogWriter_H 1 5 6 #include <kernel/OS.h> 7 //#include <storage/Entry.h> 8 //#include <storage/File.h> 9 #include <Entry.h> 10 #include <File.h> 11 #include <support/String.h> 12 #include <set> 13 14 // logging message data structure 15 struct log_message 16 { 17 bigtime_t tstamp; // time that LogWriter::Log() was called, in real time 18 bigtime_t now; // time that LogWriter::Log() was called, according to the time source 19 union // various bits of data for different kinds of logged actions 20 { 21 struct 22 { 23 bigtime_t start_time; // buffer's start time stamp 24 bigtime_t offset; // how late or early the buffer was handled 25 } buffer_data; 26 struct 27 { 28 int32 status; 29 } data_status; 30 struct 31 { 32 int32 id; // parameter ID 33 float value; // new value 34 } param; 35 struct 36 { 37 int32 what; 38 } unknown; 39 }; 40 }; 41 42 // logging message 'what' codes 43 enum log_what 44 { 45 LOG_QUIT = 'Quit', // time to quit; tear down the thread 46 47 // messages related to BMediaNode methods 48 LOG_SET_RUN_MODE = 'Rnmd', 49 LOG_PREROLL = 'Prll', 50 LOG_SET_TIME_SOURCE = 'TSrc', 51 LOG_REQUEST_COMPLETED = 'Rqcm', 52 53 // messages related to BControllable methods 54 LOG_GET_PARAM_VALUE = 'PVal', 55 LOG_SET_PARAM_VALUE = 'SVal', 56 57 // messages related to BBufferProducer methods 58 LOG_FORMAT_SUGG_REQ = 'FSRq', 59 LOG_FORMAT_PROPOSAL = 'FPro', 60 LOG_FORMAT_CHANGE_REQ = 'FCRq', 61 LOG_SET_BUFFER_GROUP = 'SBfG', 62 LOG_VIDEO_CLIP_CHANGED = 'VClp', 63 LOG_GET_LATENCY = 'GLat', 64 LOG_PREPARE_TO_CONNECT = 'PCon', 65 LOG_CONNECT = 'Cnct', 66 LOG_DISCONNECT = 'Dsct', 67 LOG_LATE_NOTICE_RECEIVED = 'LNRc', 68 LOG_ENABLE_OUTPUT = 'EnOP', 69 LOG_SET_PLAY_RATE = 'PlRt', 70 LOG_ADDITIONAL_BUFFER = 'AdBf', 71 LOG_LATENCY_CHANGED = 'LtCh', 72 73 // messages related to BBufferConsumer methods 74 LOG_HANDLE_MESSAGE = 'Mesg', 75 LOG_ACCEPT_FORMAT = 'Frmt', 76 LOG_BUFFER_RECEIVED = 'Bufr', 77 LOG_PRODUCER_DATA_STATUS = 'PDSt', 78 LOG_CONNECTED = 'Cntd', 79 LOG_DISCONNECTED = 'Dctd', 80 LOG_FORMAT_CHANGED = 'Fmtc', 81 LOG_SEEK_TAG = 'STrq', 82 83 // messages related to BMediaEventLooper methods 84 LOG_REGISTERED = 'Rgst', 85 LOG_START = 'Strt', 86 LOG_STOP = 'Stop', 87 LOG_SEEK = 'Seek', 88 LOG_TIMEWARP = 'Warp', 89 90 // messages about handling things in BMediaEventLooper::HandleEvent() 91 LOG_HANDLE_EVENT = 'HEvt', 92 LOG_HANDLE_UNKNOWN = 'Uknw', // unknown event code in HandleEvent() 93 LOG_BUFFER_HANDLED = 'Bfhd', 94 LOG_START_HANDLED = 'Sthd', 95 LOG_STOP_HANDLED = 'Sphd', 96 LOG_SEEK_HANDLED = 'Skhd', 97 LOG_WARP_HANDLED = 'Wphd', 98 LOG_DATA_STATUS_HANDLED = 'DShd', 99 LOG_SET_PARAM_HANDLED = 'SPrm', 100 LOG_INVALID_PARAM_HANDLED = 'BadP' 101 }; 102 103 // LogWriter class 104 class LogWriter 105 { 106 public: 107 // Set: output for the log_what members is disabled 108 typedef std::set<log_what> FilterSet; 109 110 public: 111 LogWriter(const entry_ref& logRef); 112 ~LogWriter(); 113 114 // write a message to the log 115 void Log(log_what what, const log_message& data); 116 117 // filtering control for logged messages 118 void SetEnabled(log_what what, bool enable); 119 void EnableAllMessages(); 120 void DisableAllMessages(); 121 122 private: 123 entry_ref mLogRef; 124 thread_id mLogThread; 125 port_id mPort; 126 BFile mLogFile; 127 BString mWriteBuf; 128 FilterSet mFilters; 129 130 // called by the LogWriter's thread 131 void HandleMessage(log_what what, const log_message& msg); 132 133 friend int32 LogWriterLoggingThread(void* arg); 134 }; 135 136 #endif 137