diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/KM_log.cpp | 15 | ||||
| -rwxr-xr-x | src/KM_log.h | 88 | ||||
| -rwxr-xr-x | src/KM_util.cpp | 14 | ||||
| -rwxr-xr-x | src/KM_util.h | 5 | ||||
| -rw-r--r-- | src/KM_xml.cpp | 2 | ||||
| -rw-r--r-- | src/Makefile.am | 22 | ||||
| -rwxr-xr-x | src/asdcp-util.cpp | 4 |
7 files changed, 80 insertions, 70 deletions
diff --git a/src/KM_log.cpp b/src/KM_log.cpp index 21c3df7..7ac0f90 100755 --- a/src/KM_log.cpp +++ b/src/KM_log.cpp @@ -90,7 +90,8 @@ Kumu::DefaultLogSink() void Kumu::EntryListLogSink::WriteEntry(const LogEntry& Entry) { - AutoMutex L(m_Lock); + AutoMutex L(m_lock); + WriteEntryToListeners(Entry); if ( Entry.TestFilter(m_filter) ) m_Target.push_back(Entry); @@ -102,8 +103,9 @@ Kumu::EntryListLogSink::WriteEntry(const LogEntry& Entry) void Kumu::StdioLogSink::WriteEntry(const LogEntry& Entry) { - AutoMutex L(m_Lock); std::string buf; + AutoMutex L(m_lock); + WriteEntryToListeners(Entry); if ( Entry.TestFilter(m_filter) ) { @@ -121,8 +123,9 @@ Kumu::StdioLogSink::WriteEntry(const LogEntry& Entry) void Kumu::WinDbgLogSink::WriteEntry(const LogEntry& Entry) { - AutoMutex L(m_Lock); std::string buf; + AutoMutex L(m_lock); + WriteEntryToListeners(Entry); if ( Entry.TestFilter(m_filter) ) { @@ -140,8 +143,9 @@ Kumu::WinDbgLogSink::WriteEntry(const LogEntry& Entry) void Kumu::StreamLogSink::WriteEntry(const LogEntry& Entry) { - AutoMutex L(m_Lock); std::string buf; + AutoMutex L(m_lock); + WriteEntryToListeners(Entry); if ( Entry.TestFilter(m_filter) ) { @@ -199,7 +203,8 @@ Kumu::SyslogLogSink::WriteEntry(const LogEntry& Entry) case Kumu::LOG_DEBUG: priority = SYSLOG_DEBUG; break; } - AutoMutex L(m_Lock); + AutoMutex L(m_lock); + WriteEntryToListeners(Entry); if ( Entry.TestFilter(m_filter) ) { diff --git a/src/KM_log.h b/src/KM_log.h index 0989706..bc99cd1 100755 --- a/src/KM_log.h +++ b/src/KM_log.h @@ -39,6 +39,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdarg.h> #include <errno.h> #include <iosfwd> +#include <set> #define LOG_MSG_IMPL(t) \ va_list args; \ @@ -149,6 +150,18 @@ namespace Kumu protected: i32_t m_filter; i32_t m_options; + Mutex m_lock; + std::set<ILogSink*> m_listeners; + + // you must obtain m_lock BEFORE calling this from your own WriteEntry + void WriteEntryToListeners(const LogEntry& entry) + { + std::set<ILogSink*>::iterator i; + for ( i = m_listeners.begin(); i != m_listeners.end(); ++i ) + (*i)->WriteEntry(entry); + } + + KM_NO_COPY_CONSTRUCT(ILogSink); public: ILogSink() : m_filter(LOG_ALLOW_ALL), m_options(LOG_OPTION_NONE) {} @@ -162,6 +175,19 @@ namespace Kumu void UnsetOptionFlag(i32_t o) { m_options &= ~o; } bool TestOptionFlag(i32_t o) const { return ((m_options & o) == o); } + void AddListener(ILogSink& s) { + if ( &s != this ) + { + AutoMutex l(m_lock); + m_listeners.insert(&s); + } + } + + void DelListener(ILogSink& s) { + AutoMutex l(m_lock); + m_listeners.erase(&s); + } + // library messages void Error(const char* fmt, ...) { LOG_MSG_IMPL(LOG_ERROR); } void Warn(const char* fmt, ...) { LOG_MSG_IMPL(LOG_WARN); } @@ -190,51 +216,35 @@ namespace Kumu ILogSink& DefaultLogSink(); - // Sets a log sink as the default until the object is destroyed. - // The original default sink is saved and then restored on delete. - class LogSinkContext - { - KM_NO_COPY_CONSTRUCT(LogSinkContext); - LogSinkContext(); - ILogSink* m_orig; + // attach a log sink as a listener until deleted + class LogSinkListenContext + { + ILogSink* m_log_source; + ILogSink* m_sink; + KM_NO_COPY_CONSTRUCT(LogSinkListenContext); + LogSinkListenContext(); + + public: + LogSinkListenContext(ILogSink& source, ILogSink& sink) + { + m_log_source = &source; + m_sink = &sink; + m_log_source->AddListener(*m_sink); + } + + ~LogSinkListenContext() + { + m_log_source->DelListener(*m_sink); + } + }; - public: - LogSinkContext(ILogSink& sink) { - m_orig = &DefaultLogSink(); - SetDefaultLogSink(&sink); - } - - ~LogSinkContext() { - SetDefaultLogSink(m_orig); - } - }; //------------------------------------------------------------------------------------------ // - // write messages to two subordinate log sinks - class TeeLogSink : public ILogSink - { - KM_NO_COPY_CONSTRUCT(TeeLogSink); - TeeLogSink(); - - ILogSink& m_a; - ILogSink& m_b; - - public: - TeeLogSink(ILogSink& a, ILogSink& b) : m_a(a), m_b(b) {} - virtual ~TeeLogSink() {} - - void WriteEntry(const LogEntry& Entry) { - m_a.WriteEntry(Entry); - m_b.WriteEntry(Entry); - } - }; - // collect log messages into the given list, does not test filter class EntryListLogSink : public ILogSink { - Mutex m_Lock; LogEntryList& m_Target; KM_NO_COPY_CONSTRUCT(EntryListLogSink); EntryListLogSink(); @@ -250,7 +260,6 @@ namespace Kumu // write messages to a POSIX stdio stream class StdioLogSink : public ILogSink { - Mutex m_Lock; FILE* m_stream; KM_NO_COPY_CONSTRUCT(StdioLogSink); @@ -266,7 +275,6 @@ namespace Kumu // write messages to the Win32 debug stream class WinDbgLogSink : public ILogSink { - Mutex m_Lock; KM_NO_COPY_CONSTRUCT(WinDbgLogSink); public: @@ -281,7 +289,6 @@ namespace Kumu // write messages to a POSIX file descriptor class StreamLogSink : public ILogSink { - Mutex m_Lock; int m_fd; KM_NO_COPY_CONSTRUCT(StreamLogSink); StreamLogSink(); @@ -296,7 +303,6 @@ namespace Kumu // write messages to the syslog facility class SyslogLogSink : public ILogSink { - Mutex m_Lock; KM_NO_COPY_CONSTRUCT(SyslogLogSink); SyslogLogSink(); diff --git a/src/KM_util.cpp b/src/KM_util.cpp index d585b32..803b0ed 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -812,7 +812,7 @@ Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const return str_buf; } -// +// ^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(?:([+-]\d{2}):(\d{2}))?)?$ bool Kumu::Timestamp::DecodeString(const char* datestr) { @@ -825,6 +825,9 @@ Kumu::Timestamp::DecodeString(const char* datestr) ui32_t char_count = 10; TAI::caltime YMDhms; + YMDhms.hour = 0; + YMDhms.minute = 0; + YMDhms.second = 0; YMDhms.offset = 0; YMDhms.date.year = atoi(datestr); YMDhms.date.month = atoi(datestr + 5); @@ -954,6 +957,15 @@ Kumu::Timestamp::GetCTime() const return m_Timestamp.x - ui64_C(4611686018427387914); } +// +void +Kumu::Timestamp::SetCTime(const ui64_t& ctime) +{ + m_Timestamp.x = ctime + ui64_C(4611686018427387914); +} + + + //------------------------------------------------------------------------------------------ diff --git a/src/KM_util.h b/src/KM_util.h index 177cff7..f4de54e 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -244,7 +244,7 @@ namespace Kumu virtual ~ArchivableString() {} bool HasValue() const { return ! this->empty(); } - ui32_t ArchiveLength() const { return static_cast<ui32_t>((sizeof(ui32_t) + this->size())|0xffffffff); } + ui32_t ArchiveLength() const { sizeof(ui32_t) + static_cast<ui32_t>(this->size()); } bool Archive(MemIOWriter* Writer) const { if ( Writer == 0 ) return false; @@ -453,6 +453,9 @@ namespace Kumu // Return the number of seconds since the Unix epoch UTC (1970-01-01T00:00:00+00:00) ui64_t GetCTime() const; + // Set internal time to the number of seconds since the Unix epoch UTC + void SetCTime(const ui64_t& ctime); + // Read and write the timestamp (always UTC) value as a byte string having // the following format: // | 16 bits int, big-endian | 8 bits | 8 bits | 8 bits | 8 bits | 8 bits | diff --git a/src/KM_xml.cpp b/src/KM_xml.cpp index 1148c53..8f41f9c 100644 --- a/src/KM_xml.cpp +++ b/src/KM_xml.cpp @@ -531,10 +531,10 @@ Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len) if ( ! XML_Parse(Parser, document, doc_len, 1) ) { - XML_ParserFree(Parser); DefaultLogSink().Error("XML Parse error on line %d: %s\n", XML_GetCurrentLineNumber(Parser), XML_ErrorString(XML_GetErrorCode(Parser))); + XML_ParserFree(Parser); return false; } diff --git a/src/Makefile.am b/src/Makefile.am index 77a4e69..5f3a728 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,8 @@ endif # list of all the header files that should be installed include_HEADERS = KM_error.h KM_fileio.h KM_log.h KM_memio.h KM_mutex.h \ - KM_platform.h KM_prng.h KM_util.h KM_tai.h KM_xml.h AS_DCP.h AS_02.h + KM_platform.h KM_prng.h KM_util.h KM_tai.h KM_xml.h AS_DCP.h + if DEV_HEADERS include_HEADERS += S12MTimecode.h MDD.h Metadata.h KLV.h MXFTypes.h MXF.h Wav.h \ PCMParserList.h @@ -49,7 +50,7 @@ endif # list of the libraries to build and install -lib_LTLIBRARIES = libkumu.la libasdcp.la libas02.la +lib_LTLIBRARIES = libkumu.la libasdcp.la # sources for kumu library libkumu_la_SOURCES = KM_error.h KM_fileio.cpp KM_fileio.h KM_log.cpp KM_log.h \ @@ -82,14 +83,6 @@ libasdcp_la_LIBADD = libkumu.la libasdcp_la_CPPFLAGS = -DASDCP_PLATFORM=\"@host@\" -# sources for as-02 library -libas02_la_SOURCES = \ - AS_02.h AS_02_MXF.cpp AS_02_JP2K.cpp AS_02_PCM.cpp h__02_Reader.cpp h__02_Writer.cpp AS_02_internal.h -libas02_la_LDFLAGS = -release @VERSION@ -libas02_la_LIBADD = libasdcp.la libkumu.la -libas02_la_CPPFLAGS = -DASDCP_PLATFORM=\"@host@\" - - # Python extension if PYTHON_USE lib_LTLIBRARIES += libpyasdcp.la @@ -131,20 +124,13 @@ endif # list of programs to be built and installed bin_PROGRAMS = \ asdcp-wrap asdcp-unwrap asdcp-util asdcp-info asdcp-test \ - as-02-wrap as-02-unwrap \ j2c-test blackwave klvwalk wavesplit \ - kmfilegen kmrandgen kmuuidgen + kmfilegen kmrandgen kmuuidgen # sources and linkage for CLI utilities asdcp_test_SOURCES = asdcp-test.cpp asdcp_test_LDADD = libasdcp.la -as_02_wrap_SOURCES = as-02-wrap.cpp -as_02_wrap_LDADD = libas02.la - -as_02_unwrap_SOURCES = as-02-unwrap.cpp -as_02_unwrap_LDADD = libas02.la - asdcp_wrap_SOURCES = asdcp-wrap.cpp asdcp_wrap_LDADD = libasdcp.la diff --git a/src/asdcp-util.cpp b/src/asdcp-util.cpp index be070ff..6be6c07 100755 --- a/src/asdcp-util.cpp +++ b/src/asdcp-util.cpp @@ -78,9 +78,7 @@ USAGE: %s [-h|-help] [-V]\n\ \n\ %s -d <input-file>\n\ \n\ - %s -g | -u\n\ -\n\ - %s -u\n\n", + %s -g | -u\n", PROGRAM_NAME, PROGRAM_NAME, PROGRAM_NAME, PROGRAM_NAME); fprintf(stream, "\ |
