Install KM_log.h
authorCarl Hetherington <cth@carlh.net>
Fri, 7 Sep 2018 12:01:36 +0000 (13:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 3 Dec 2019 16:01:32 +0000 (17:01 +0100)
32 files changed:
src/AS_02_internal.h
src/AS_DCP_AES.cpp
src/AS_DCP_internal.h
src/AtmosSyncChannel_Mixer.cpp
src/Dict.cpp
src/JP2K.cpp
src/JP2K_Codestream_Parser.cpp
src/JP2K_Sequence_Parser.cpp
src/KLV.cpp
src/KM_fileio.cpp
src/KM_log.cpp
src/KM_log.h [deleted file]
src/KM_mutex.h [deleted file]
src/KM_prng.cpp
src/KM_util.cpp
src/KM_xml.cpp
src/MPEG.cpp
src/MPEG2_Parser.cpp
src/MXF.cpp
src/MXFTypes.cpp
src/Metadata.cpp
src/PCMDataProviders.cpp
src/PCMParserList.cpp
src/PCM_Parser.cpp
src/PHDR_Sequence_Parser.cpp
src/Wav.cpp
src/WavFileWriter.h
src/asdcp/KM_log.h [new file with mode: 0755]
src/asdcp/KM_mutex.h [new file with mode: 0755]
src/klvsplit.cpp
src/klvwalk.cpp
src/wscript

index 33726ee5e97d5f7c520079e75ea945b62e6781a1..add87330f4a448c57d67e024f29b0b61fba43828 100644 (file)
@@ -34,7 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #ifndef _AS_02_INTERNAL_H_
 #define _AS_02_INTERNAL_H_
 
-#include "KM_log.h"
+#include "asdcp/KM_log.h"
 #include "AS_DCP_internal.h"
 #include "asdcp/AS_02.h"
 
index a320fb0b25fb05332bb673f998743b36b894f231..9f8914098183e92e06d194fff3a73d708e644af6 100755 (executable)
@@ -32,7 +32,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <assert.h>
 #include <asdcp/AS_DCP.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <asdcp/KM_prng.h>
 using Kumu::DefaultLogSink;
 
index 7a525b8848804a02e4988800459092985dc31355..41820a890bbbac0eca013cc26b0b5ef56fa91441 100755 (executable)
@@ -34,7 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <asdcp/KM_platform.h>
 #include <asdcp/KM_util.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <asdcp/Metadata.h>
 
 using Kumu::DefaultLogSink;
index b0353414cbbc786e9480939fb4e4548fdbaae124..db2401abb2b16ce8a0ee8409642c993bd36dc720 100644 (file)
@@ -34,7 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <algorithm>
 
 #include <AS_DCP.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <PCMDataProviders.h>
 
 using namespace ASDCP;
index 9747b9d6087670eff2e713abf5b18b5f3dd25431..42b21f8ab2ff45e790f02221c499f2cdea0f7380 100755 (executable)
@@ -30,8 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 
-#include "KM_mutex.h"
-#include "KM_log.h"
+#include <asdcp/KM_mutex.h>
+#include <asdcp/KM_log.h>
 #include <asdcp/KLV.h>
 #include "MDD.cpp"
 
index a0f2a8a124757cf59bcd2b7c6b59aa3343b558d7..592cfb77076328fe935d3e7043002a5ba57f0bbb 100755 (executable)
@@ -33,7 +33,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include <JP2K.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 
index 3213f3084a03e3d932cec6af4a2509ac13a8a0ad..4de4f0bc95fbca003df47ef7fee1e1d88523b783 100755 (executable)
@@ -33,7 +33,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <asdcp/AS_DCP.h>
 #include <JP2K.h>
 #include <assert.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 //------------------------------------------------------------------------------------------
index dcdea8554b19bdfae8e29e4ee364b2b2267585ae..93359a6e7522d561b1d654de027c7f17f201ee6a 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <asdcp/AS_DCP.h>
 #include <asdcp/KM_fileio.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <list>
 #include <string>
 #include <algorithm>
index acf28bbfba070796d58aacc92e707892e82a402b..e3b5b436c1363fea9a4f1f6dcf30d526b70f21c8 100755 (executable)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include <asdcp/KLV.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 
index 9720c799ad032f003fcec6a5d6f0889f708e3451..374f11cac9a8186aba3caa8297bbae96ab992f7a 100644 (file)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
 
 #include <asdcp/KM_fileio.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <fcntl.h>
 #include <iomanip>
 
index 2ebd0581bd476b8849c301cbfb06ec22bd250c9d..f1c572d2ca33388bd1a2dc239102d7fd5bee86c7 100755 (executable)
@@ -30,8 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
 
 #include <asdcp/KM_util.h>
-#include <KM_log.h>
-#include <KM_mutex.h>
+#include <asdcp/KM_log.h>
+#include <asdcp/KM_mutex.h>
 #include <sys/types.h>
 #include <string.h>
 #include <stdarg.h>
diff --git a/src/KM_log.h b/src/KM_log.h
deleted file mode 100755 (executable)
index c604fc5..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
-Copyright (c) 2004-2009, John Hurst
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. The name of the author may not be used to endorse or promote products
-   derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-  /*! \file    KM_log.h
-    \version $Id$
-    \brief   message logging API
-  */
-
-
-#ifndef _KM_LOG_H_
-#define _KM_LOG_H_
-
-#include <asdcp/KM_platform.h>
-#include <KM_mutex.h>
-#include <asdcp/KM_util.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <iosfwd>
-#include <set>
-
-#define LOG_MSG_IMPL(t) \
-  va_list args; \
-  va_start(args, fmt); \
-  vLogf((t), fmt, &args); \
-  va_end(args)
-
-// Returns RESULT_PTR if the given argument is NULL.
-# define KM_TEST_NULL_L(p) \
-  if ( (p) == 0  ) { \
-    DefaultLogSink().Error("NULL pointer in file %s, line %d\n", __FILE__, __LINE__); \
-    return Kumu::RESULT_PTR; \
-  }
-
-// Returns RESULT_PTR if the given argument is NULL. It then
-// assumes that the argument is a pointer to a string and returns
-// RESULT_NULL_STR if the first character is '\0'.
-//
-# define KM_TEST_NULL_STR_L(p) \
-  KM_TEST_NULL_L(p); \
-  if ( (p)[0] == '\0' ) { \
-    DefaultLogSink().Error("Empty string in file %s, line %d\n", __FILE__, __LINE__); \
-    return Kumu::RESULT_NULL_STR; \
-  }
-
-
-namespace Kumu
-{
-  // no log message will exceed this length
-  const ui32_t MaxLogLength = 512;
-
-  //---------------------------------------------------------------------------------
-  // message logging
-
-  // Log messages are recorded by objects which implement the interface given
-  // in the class ILogSink below. The library maintains a pointer to a default
-  // log sink which is used by the library to report messages.
-  //
-
-  // types of log messages
-  enum LogType_t {
-    LOG_DEBUG,    // detailed developer info
-    LOG_INFO,     // developer info
-    LOG_WARN,     // library non-fatal or near-miss error
-    LOG_ERROR,    // library fatal error
-    LOG_NOTICE,   // application user info
-    LOG_ALERT,    // application non-fatal or near-miss error
-    LOG_CRIT,     // application fatal error
-    LOG_MAX
-  };
-
-
-  // OR these values together to come up with sink filter flags.
-  // The default mask is LOG_ALLOW_ALL (all messages).
-  const i32_t LOG_ALLOW_DEBUG      = 0x00000001;
-  const i32_t LOG_ALLOW_INFO       = 0x00000002;
-  const i32_t LOG_ALLOW_WARN       = 0x00000004;
-  const i32_t LOG_ALLOW_ERROR      = 0x00000008;
-  const i32_t LOG_ALLOW_NOTICE     = 0x00000010;
-  const i32_t LOG_ALLOW_ALERT      = 0x00000020;
-  const i32_t LOG_ALLOW_CRIT       = 0x00000040;
-  const i32_t LOG_ALLOW_NONE       = 0x00000000;
-  const i32_t LOG_ALLOW_ALL        = 0x000fffff;
-
-  // options are used to control display format default is 0.
-  const i32_t LOG_OPTION_TYPE      = 0x01000000;
-  const i32_t LOG_OPTION_TIMESTAMP = 0x02000000;
-  const i32_t LOG_OPTION_PID       = 0x04000000;
-  const i32_t LOG_OPTION_NONE      = 0x00000000;
-  const i32_t LOG_OPTION_ALL       = 0xfff00000;
-
-  // A log message with environmental metadata
- class LogEntry : public IArchive
-  {
-  public:
-    ui32_t      PID;
-    Timestamp   EventTime;
-    LogType_t   Type;
-    std::string Msg;
-
-    LogEntry() {}
-    LogEntry(ui32_t pid, LogType_t t, const char* m) : PID(pid), Type(t), Msg(m) { assert(m); }
-    virtual ~LogEntry() {}
-
-    // returns true if the message Type is present in the mask
-    bool   TestFilter(i32_t mask_value) const;
-
-    // renders the message into outstr using the given dispaly options
-    // returns outstr&
-    std::string& CreateStringWithOptions(std::string& outstr, i32_t mask_value) const;
-
-    // IArchive
-    bool   HasValue() const { return ! Msg.empty(); }
-    ui32_t ArchiveLength() const;
-    bool   Archive(MemIOWriter* Writer) const;
-    bool   Unarchive(MemIOReader* Reader);
-  };
-
-  //
-  std::basic_ostream<char, std::char_traits<char> >&
-    operator<<(std::basic_ostream<char, std::char_traits<char> >& strm, LogEntry const& Entry);
-
-
-  typedef ArchivableList<LogEntry> LogEntryList;
-
-  //
-  class ILogSink
-    {
-    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) {}
-      virtual ~ILogSink() {}
-
-      void  SetFilterFlag(i32_t f) { m_filter |= f; }
-      void  UnsetFilterFlag(i32_t f) { m_filter &= ~f; }
-      bool  TestFilterFlag(i32_t f) const  { return ((m_filter & f) == f); }
-
-      void  SetOptionFlag(i32_t o) { m_options |= o; }
-      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);  }
-      void Info(const char* fmt, ...)     { LOG_MSG_IMPL(LOG_INFO);  }
-      void Debug(const char* fmt, ...)    { LOG_MSG_IMPL(LOG_DEBUG); }
-
-      // application messages
-      void Critical(const char* fmt, ...) { LOG_MSG_IMPL(LOG_CRIT); }
-      void Alert(const char* fmt, ...)    { LOG_MSG_IMPL(LOG_ALERT); }
-      void Notice(const char* fmt, ...)   { LOG_MSG_IMPL(LOG_NOTICE); }
-
-      // message with type
-      void Logf(LogType_t type, const char* fmt, ...) { LOG_MSG_IMPL(type); }
-
-      // actual log sink input
-      virtual void vLogf(LogType_t, const char*, va_list*);
-      virtual void WriteEntry(const LogEntry&) = 0;
-    };
-
-
-  // Sets the internal default sink to the given receiver. If the given value
-  // is zero, sets the default sink to the internally allocated stderr sink.
-  void SetDefaultLogSink(ILogSink* = 0);
-
-  // Returns the internal default sink.
-  ILogSink& DefaultLogSink();
-
-
-  // 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);
-       }
-    };
-
-
-  //------------------------------------------------------------------------------------------
-  //
-
-  // collect log messages into the given list, does not test filter
-  class EntryListLogSink : public ILogSink
-  {
-    LogEntryList& m_Target;
-    KM_NO_COPY_CONSTRUCT(EntryListLogSink);
-    EntryListLogSink();
-
-  public:
-    EntryListLogSink(LogEntryList& target) : m_Target(target) {}
-    virtual ~EntryListLogSink() {}
-
-    void WriteEntry(const LogEntry& Entry);
-  };
-
-
-  // write messages to a POSIX stdio stream
-  class StdioLogSink : public ILogSink
-    {
-      FILE* m_stream;
-      KM_NO_COPY_CONSTRUCT(StdioLogSink);
-
-    public:
-    StdioLogSink() : m_stream(stderr) {}
-    StdioLogSink(FILE* stream) : m_stream(stream) {}
-      virtual ~StdioLogSink() {}
-
-    void WriteEntry(const LogEntry&);
-    };
-
-#ifdef KM_WIN32
-  // write messages to the Win32 debug stream
-  class WinDbgLogSink : public ILogSink
-    {
-      KM_NO_COPY_CONSTRUCT(WinDbgLogSink);
-
-    public:
-      WinDbgLogSink() {}
-      virtual ~WinDbgLogSink() {}
-
-      void WriteEntry(const LogEntry&);
-    };
-#endif
-
-#ifndef KM_WIN32
-  // write messages to a POSIX file descriptor
-  class StreamLogSink : public ILogSink
-    {
-      int   m_fd;
-      KM_NO_COPY_CONSTRUCT(StreamLogSink);
-      StreamLogSink();
-
-    public:
-      StreamLogSink(int fd) : m_fd(fd) {}
-      virtual ~StreamLogSink() {}
-
-      void WriteEntry(const LogEntry&);
-    };
-
-  // write messages to the syslog facility
-  class SyslogLogSink : public ILogSink
-    {
-      KM_NO_COPY_CONSTRUCT(SyslogLogSink);
-      SyslogLogSink();
-
-    public:
-      SyslogLogSink(const std::string& source_name, int facility);
-      virtual ~SyslogLogSink();
-      void WriteEntry(const LogEntry&);
-    };
-
-  // convert a string into the appropriate syslog facility id
-  int SyslogNameToFacility(const std::string& facility_name);
-
-#endif
-
-
-} // namespace Kumu
-
-#endif // _KM_LOG_H_
-
-//
-// end KM_log.h
-//
diff --git a/src/KM_mutex.h b/src/KM_mutex.h
deleted file mode 100755 (executable)
index b44c4f2..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
-Copyright (c) 2004-2009, John Hurst
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-3. The name of the author may not be used to endorse or promote products
-   derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-  /*! \file    KM_mutex.h
-    \version $Id$
-    \brief   platform portability
-  */
-
-#ifndef _KM_MUTEX_H_
-#define _KM_MUTEX_H_
-
-#include <asdcp/KM_platform.h>
-
-#ifndef KM_WIN32
-# include <pthread.h>
-#endif
-
-namespace Kumu
-{
-#ifdef KM_WIN32
-  class Mutex
-    {
-      CRITICAL_SECTION m_Mutex;
-      KM_NO_COPY_CONSTRUCT(Mutex);
-
-    public:
-      inline Mutex()       { ::InitializeCriticalSection(&m_Mutex); }
-      inline ~Mutex()      { ::DeleteCriticalSection(&m_Mutex); }
-      inline void Lock()   { ::EnterCriticalSection(&m_Mutex); }
-      inline void Unlock() { ::LeaveCriticalSection(&m_Mutex); }
-    };
-#else // KM_WIN32
-  class Mutex
-    {
-      pthread_mutex_t m_Mutex;
-      KM_NO_COPY_CONSTRUCT(Mutex);
-
-    public:
-      inline Mutex()       { pthread_mutex_init(&m_Mutex, 0); }
-      inline ~Mutex()      { pthread_mutex_destroy(&m_Mutex); }
-      inline void Lock()   { pthread_mutex_lock(&m_Mutex); }
-      inline void Unlock() { pthread_mutex_unlock(&m_Mutex); }
-    };
-#endif // KM_WIN32
-
-  // automatic Mutex management within a block -
-  // the mutex is created by the constructor and
-  // released by the destructor
-  class AutoMutex
-    {
-      Mutex& m_Mutex;
-      AutoMutex();
-      KM_NO_COPY_CONSTRUCT(AutoMutex);
-
-    public:
-      AutoMutex(Mutex& Mtx) : m_Mutex(Mtx) { m_Mutex.Lock(); }
-      ~AutoMutex() { m_Mutex.Unlock(); }
-    };
-
-} // namespace Kumu
-
-#endif // _KM_MUTEX_H_
-
-//
-// end KM_mutex.h
-//
index 336bfcac4134e5f5223c9449bfb55af25a19db33..a650eb84222692a4b78807650655780cab9de52f 100755 (executable)
@@ -30,8 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
 
 #include <asdcp/KM_prng.h>
-#include <KM_log.h>
-#include <KM_mutex.h>
+#include <asdcp/KM_log.h>
+#include <asdcp/KM_mutex.h>
 #include <string.h>
 #include <assert.h>
 #include <openssl/aes.h>
index 5409eae751b34ed4d743d78f9851bd665f5e078c..210e7ac8df71d1d1ec86d8a23c3992357de1efd1 100755 (executable)
@@ -33,8 +33,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <asdcp/KM_prng.h>
 #include <asdcp/KM_memio.h>
 #include <asdcp/KM_fileio.h>
-#include <KM_log.h>
-#include <KM_mutex.h>
+#include <asdcp/KM_log.h>
+#include <asdcp/KM_mutex.h>
 #include <ctype.h>
 #include <list>
 #include <map>
index ff5b72885fac006b1bde193737be661feb984881..36fbc28fa0a2a22bbfdeb6c185a5c85d4d8c0318 100644 (file)
@@ -30,8 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include <KM_xml.h>
-#include <KM_log.h>
-#include <KM_mutex.h>
+#include <asdcp/KM_log.h>
+#include <asdcp/KM_mutex.h>
 #include <stack>
 #include <map>
 
@@ -59,7 +59,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <xercesc/framework/XMLPScanToken.hpp>
 
 
-XERCES_CPP_NAMESPACE_USE 
+XERCES_CPP_NAMESPACE_USE
 
 extern "C"
 {
@@ -437,7 +437,7 @@ public:
 };
 
 // expat wrapper functions
-// 
+//
 static void
 xph_start(void* p, const XML_Char* name, const XML_Char** attrs)
 {
@@ -467,7 +467,7 @@ xph_start(void* p, const XML_Char* name, const XML_Char** attrs)
   std::string key;
   if ( ns_root != name )
     key.assign(ns_root, name - ns_root - 1);
-  
+
   ns_map::iterator ni = Ctx->Namespaces->find(key);
   if ( ni != Ctx->Namespaces->end() )
     Element->SetNamespace(ni->second);
@@ -514,7 +514,7 @@ xph_namespace_start(void* p, const XML_Char* ns_prefix, const XML_Char* ns_name)
 {
   assert(p);  assert(ns_name);
   ExpatParseContext* Ctx = (ExpatParseContext*)p;
-  
+
   if ( ns_prefix == 0 )
     ns_prefix = "";
 
@@ -578,7 +578,7 @@ Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len)
 }
 
 // expat wrapper functions
-// 
+//
 static void
 xph_start_one_shot(void* p, const XML_Char* name, const XML_Char** attrs)
 {
@@ -639,7 +639,7 @@ Kumu::XMLElement::ParseFirstFromString(const char* document, ui32_t doc_len)
 
 static Mutex sg_xerces_init_lock; // protect the xerces initialized
 static bool  sg_xml_init = false; // signal initialization
-static Mutex sg_coder_lock;       // protect the transcoder context 
+static Mutex sg_coder_lock;       // protect the transcoder context
 static XMLTranscoder*   sg_coder = 0;
 static const int sg_coder_buf_len = 128 * 1024;
 static char sg_coder_buf[sg_coder_buf_len + 8];
@@ -647,7 +647,7 @@ static unsigned char sg_coder_counts[sg_coder_buf_len / sizeof(XMLCh)]; // see X
 
 static const XMLCh sg_LS[] = { chLatin_L, chLatin_S, chNull };
 static const XMLCh sg_label_UTF_8[] = { chLatin_U, chLatin_T, chLatin_F,
-                                       chDash, chDigit_8, chNull}; 
+                                       chDash, chDigit_8, chNull};
 
 //
 void
@@ -902,7 +902,7 @@ public:
     std::string key;
     if ( ns_root != name )
       key.assign(ns_root, name - ns_root - 1);
-  
+
     ns_map::iterator ni = m_Namespaces->find(key);
     if ( ni != m_Namespaces->end() )
       Element->SetNamespace(ni->second);
@@ -973,7 +973,7 @@ Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len)
       DefaultLogSink().Error("Unexpected XML parser error\n");
       errorCount++;
     }
-  
+
   if ( errorCount == 0 )
     m_NamespaceOwner = (void*)docHandler->TakeNamespaceMap();
 
@@ -993,7 +993,7 @@ Kumu::XMLElement::ParseFirstFromString(const char* document, ui32_t doc_len)
     }
 
   kumu_init_xml_dom();
-  
+
   int errorCount = 0;
   SAXParser* parser = new SAXParser();
 
@@ -1040,7 +1040,7 @@ Kumu::XMLElement::ParseFirstFromString(const char* document, ui32_t doc_len)
       DefaultLogSink().Error("Unexpected XML parser error\n");
       errorCount++;
     }
-  
+
   if ( errorCount == 0 )
     m_NamespaceOwner = (void*)docHandler->TakeNamespaceMap();
 
index 14fde6615798ba05700a19eb701cfc993e6a3a23..98453fb319a8fe0feb6631e31131bb1aa561b9f3 100755 (executable)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include <MPEG.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 // walk a buffer stopping at the end of the buffer or the end of a VES
@@ -216,7 +216,7 @@ ASDCP::MPEG2::VESParser::Parse(const byte_t* buf, ui32_t buf_len)
              // let the delegate handle the header
              switch( m_HBuf[3] )
                {
-               case PIC_START:   result = m_Delegate->Picture(this, m_HBuf, m_HBufLen);   break;         
+               case PIC_START:   result = m_Delegate->Picture(this, m_HBuf, m_HBufLen);   break;
                case EXT_START:   result = m_Delegate->Extension(this, m_HBuf, m_HBufLen); break;
                case SEQ_START:   result = m_Delegate->Sequence(this, m_HBuf, m_HBufLen);  break;
                case GOP_START:   result = m_Delegate->GOP(this, m_HBuf, m_HBufLen);       break;
@@ -233,7 +233,7 @@ ASDCP::MPEG2::VESParser::Parse(const byte_t* buf, ui32_t buf_len)
                  m_State->Goto_IDLE();
                  return result;
                }
-             
+
              m_HBuf[0] = m_HBuf[1] = 0; m_HBuf[2] = 1; m_HBuf[3] = *p; // 001x
              run_len = 0;
 
index 59a6f3e3bfdab7ec89015534dc33fc12edfd3012..f3b6e5c1730409f4e3ce436b0acee548f1178da8 100755 (executable)
@@ -32,7 +32,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <asdcp/KM_fileio.h>
 #include <MPEG.h>
 
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 using namespace ASDCP;
index 6e0abe3958276416222573ce5f07bc1226813ce4..1f22319b0ed615e2ee9f92c8c130167fc58b6a78 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <asdcp/MXF.h>
 #include <asdcp/Metadata.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 
 using Kumu::DefaultLogSink;
 using Kumu::GenRandomValue;
index fd6978946123a4d39a15af4b4e713b318d80b947..1900b78d058a7016737ea3aaa4e0577d4638792e 100755 (executable)
@@ -32,7 +32,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <asdcp/KM_prng.h>
 #include <asdcp/KM_tai.h>
 #include <asdcp/MXFTypes.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 
 using Kumu::DefaultLogSink;
 
index 4c9a21525bca749d6cc447ff29ec93d47d6a6f61..88f19bb08137b97edd1f4b16b9463d8b9f8a4530 100755 (executable)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 
-#include <KM_mutex.h>
+#include <asdcp/KM_mutex.h>
 #include <asdcp/Metadata.h>
 
 using namespace ASDCP;
index 8eb968101dcfaa467d019079fe66ec360cdc4500..696a323b7b7c8f2ea66202bd2292311825680409 100644 (file)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <PCMDataProviders.h>
 
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 
 using namespace ASDCP;
 using namespace Kumu;
index f65aae60cabf82548feba81ea0ca4f888124d12e..1633b262fe48cd6bc3fee7cb6973eadeadd75ab1 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <PCMParserList.h>
 #include <asdcp/KM_fileio.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <assert.h>
 
 using namespace ASDCP;
index 2700aa4b8b409fdd57f908b0397c4b60d3caf045..967853463e257bf6ca3010d6a697722a96e9ac46 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <Wav.h>
 #include <assert.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 using namespace ASDCP;
index d7d86165194f1244173522238e90da35b78c1356..7dd106843d9291000f8a4707a649b11364027719 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <AS_02_PHDR.h>
 #include <KM_fileio.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <list>
 #include <string>
 #include <algorithm>
index 27a40837c0a6bb2410abc095c36302416c98233b..c8935cdf3f2f7b3749ef26ab1e8cd8dc5e7f993c 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "Wav.h"
 #include <assert.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 using Kumu::DefaultLogSink;
 
 
index 5d326f2d111a5cf0b53aa1d53f9a1383a9966dc6..b5300996ebcf6d449fa8e460a311457b947da393 100755 (executable)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include <KM_fileio.h>
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <Wav.h>
 #include <list>
 
diff --git a/src/asdcp/KM_log.h b/src/asdcp/KM_log.h
new file mode 100755 (executable)
index 0000000..c15608a
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+Copyright (c) 2004-2009, John Hurst
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+  /*! \file    KM_log.h
+    \version $Id$
+    \brief   message logging API
+  */
+
+
+#ifndef _KM_LOG_H_
+#define _KM_LOG_H_
+
+#include <asdcp/KM_platform.h>
+#include <asdcp/KM_mutex.h>
+#include <asdcp/KM_util.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <iosfwd>
+#include <set>
+
+#define LOG_MSG_IMPL(t) \
+  va_list args; \
+  va_start(args, fmt); \
+  vLogf((t), fmt, &args); \
+  va_end(args)
+
+// Returns RESULT_PTR if the given argument is NULL.
+# define KM_TEST_NULL_L(p) \
+  if ( (p) == 0  ) { \
+    DefaultLogSink().Error("NULL pointer in file %s, line %d\n", __FILE__, __LINE__); \
+    return Kumu::RESULT_PTR; \
+  }
+
+// Returns RESULT_PTR if the given argument is NULL. It then
+// assumes that the argument is a pointer to a string and returns
+// RESULT_NULL_STR if the first character is '\0'.
+//
+# define KM_TEST_NULL_STR_L(p) \
+  KM_TEST_NULL_L(p); \
+  if ( (p)[0] == '\0' ) { \
+    DefaultLogSink().Error("Empty string in file %s, line %d\n", __FILE__, __LINE__); \
+    return Kumu::RESULT_NULL_STR; \
+  }
+
+
+namespace Kumu
+{
+  // no log message will exceed this length
+  const ui32_t MaxLogLength = 512;
+
+  //---------------------------------------------------------------------------------
+  // message logging
+
+  // Log messages are recorded by objects which implement the interface given
+  // in the class ILogSink below. The library maintains a pointer to a default
+  // log sink which is used by the library to report messages.
+  //
+
+  // types of log messages
+  enum LogType_t {
+    LOG_DEBUG,    // detailed developer info
+    LOG_INFO,     // developer info
+    LOG_WARN,     // library non-fatal or near-miss error
+    LOG_ERROR,    // library fatal error
+    LOG_NOTICE,   // application user info
+    LOG_ALERT,    // application non-fatal or near-miss error
+    LOG_CRIT,     // application fatal error
+    LOG_MAX
+  };
+
+
+  // OR these values together to come up with sink filter flags.
+  // The default mask is LOG_ALLOW_ALL (all messages).
+  const i32_t LOG_ALLOW_DEBUG      = 0x00000001;
+  const i32_t LOG_ALLOW_INFO       = 0x00000002;
+  const i32_t LOG_ALLOW_WARN       = 0x00000004;
+  const i32_t LOG_ALLOW_ERROR      = 0x00000008;
+  const i32_t LOG_ALLOW_NOTICE     = 0x00000010;
+  const i32_t LOG_ALLOW_ALERT      = 0x00000020;
+  const i32_t LOG_ALLOW_CRIT       = 0x00000040;
+  const i32_t LOG_ALLOW_NONE       = 0x00000000;
+  const i32_t LOG_ALLOW_ALL        = 0x000fffff;
+
+  // options are used to control display format default is 0.
+  const i32_t LOG_OPTION_TYPE      = 0x01000000;
+  const i32_t LOG_OPTION_TIMESTAMP = 0x02000000;
+  const i32_t LOG_OPTION_PID       = 0x04000000;
+  const i32_t LOG_OPTION_NONE      = 0x00000000;
+  const i32_t LOG_OPTION_ALL       = 0xfff00000;
+
+  // A log message with environmental metadata
+ class LogEntry : public IArchive
+  {
+  public:
+    ui32_t      PID;
+    Timestamp   EventTime;
+    LogType_t   Type;
+    std::string Msg;
+
+    LogEntry() {}
+    LogEntry(ui32_t pid, LogType_t t, const char* m) : PID(pid), Type(t), Msg(m) { assert(m); }
+    virtual ~LogEntry() {}
+
+    // returns true if the message Type is present in the mask
+    bool   TestFilter(i32_t mask_value) const;
+
+    // renders the message into outstr using the given dispaly options
+    // returns outstr&
+    std::string& CreateStringWithOptions(std::string& outstr, i32_t mask_value) const;
+
+    // IArchive
+    bool   HasValue() const { return ! Msg.empty(); }
+    ui32_t ArchiveLength() const;
+    bool   Archive(MemIOWriter* Writer) const;
+    bool   Unarchive(MemIOReader* Reader);
+  };
+
+  //
+  std::basic_ostream<char, std::char_traits<char> >&
+    operator<<(std::basic_ostream<char, std::char_traits<char> >& strm, LogEntry const& Entry);
+
+
+  typedef ArchivableList<LogEntry> LogEntryList;
+
+  //
+  class ILogSink
+    {
+    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) {}
+      virtual ~ILogSink() {}
+
+      void  SetFilterFlag(i32_t f) { m_filter |= f; }
+      void  UnsetFilterFlag(i32_t f) { m_filter &= ~f; }
+      bool  TestFilterFlag(i32_t f) const  { return ((m_filter & f) == f); }
+
+      void  SetOptionFlag(i32_t o) { m_options |= o; }
+      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);  }
+      void Info(const char* fmt, ...)     { LOG_MSG_IMPL(LOG_INFO);  }
+      void Debug(const char* fmt, ...)    { LOG_MSG_IMPL(LOG_DEBUG); }
+
+      // application messages
+      void Critical(const char* fmt, ...) { LOG_MSG_IMPL(LOG_CRIT); }
+      void Alert(const char* fmt, ...)    { LOG_MSG_IMPL(LOG_ALERT); }
+      void Notice(const char* fmt, ...)   { LOG_MSG_IMPL(LOG_NOTICE); }
+
+      // message with type
+      void Logf(LogType_t type, const char* fmt, ...) { LOG_MSG_IMPL(type); }
+
+      // actual log sink input
+      virtual void vLogf(LogType_t, const char*, va_list*);
+      virtual void WriteEntry(const LogEntry&) = 0;
+    };
+
+
+  // Sets the internal default sink to the given receiver. If the given value
+  // is zero, sets the default sink to the internally allocated stderr sink.
+  void SetDefaultLogSink(ILogSink* = 0);
+
+  // Returns the internal default sink.
+  ILogSink& DefaultLogSink();
+
+
+  // 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);
+       }
+    };
+
+
+  //------------------------------------------------------------------------------------------
+  //
+
+  // collect log messages into the given list, does not test filter
+  class EntryListLogSink : public ILogSink
+  {
+    LogEntryList& m_Target;
+    KM_NO_COPY_CONSTRUCT(EntryListLogSink);
+    EntryListLogSink();
+
+  public:
+    EntryListLogSink(LogEntryList& target) : m_Target(target) {}
+    virtual ~EntryListLogSink() {}
+
+    void WriteEntry(const LogEntry& Entry);
+  };
+
+
+  // write messages to a POSIX stdio stream
+  class StdioLogSink : public ILogSink
+    {
+      FILE* m_stream;
+      KM_NO_COPY_CONSTRUCT(StdioLogSink);
+
+    public:
+    StdioLogSink() : m_stream(stderr) {}
+    StdioLogSink(FILE* stream) : m_stream(stream) {}
+      virtual ~StdioLogSink() {}
+
+    void WriteEntry(const LogEntry&);
+    };
+
+#ifdef KM_WIN32
+  // write messages to the Win32 debug stream
+  class WinDbgLogSink : public ILogSink
+    {
+      KM_NO_COPY_CONSTRUCT(WinDbgLogSink);
+
+    public:
+      WinDbgLogSink() {}
+      virtual ~WinDbgLogSink() {}
+
+      void WriteEntry(const LogEntry&);
+    };
+#endif
+
+#ifndef KM_WIN32
+  // write messages to a POSIX file descriptor
+  class StreamLogSink : public ILogSink
+    {
+      int   m_fd;
+      KM_NO_COPY_CONSTRUCT(StreamLogSink);
+      StreamLogSink();
+
+    public:
+      StreamLogSink(int fd) : m_fd(fd) {}
+      virtual ~StreamLogSink() {}
+
+      void WriteEntry(const LogEntry&);
+    };
+
+  // write messages to the syslog facility
+  class SyslogLogSink : public ILogSink
+    {
+      KM_NO_COPY_CONSTRUCT(SyslogLogSink);
+      SyslogLogSink();
+
+    public:
+      SyslogLogSink(const std::string& source_name, int facility);
+      virtual ~SyslogLogSink();
+      void WriteEntry(const LogEntry&);
+    };
+
+  // convert a string into the appropriate syslog facility id
+  int SyslogNameToFacility(const std::string& facility_name);
+
+#endif
+
+
+} // namespace Kumu
+
+#endif // _KM_LOG_H_
+
+//
+// end KM_log.h
+//
diff --git a/src/asdcp/KM_mutex.h b/src/asdcp/KM_mutex.h
new file mode 100755 (executable)
index 0000000..b44c4f2
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+Copyright (c) 2004-2009, John Hurst
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+  /*! \file    KM_mutex.h
+    \version $Id$
+    \brief   platform portability
+  */
+
+#ifndef _KM_MUTEX_H_
+#define _KM_MUTEX_H_
+
+#include <asdcp/KM_platform.h>
+
+#ifndef KM_WIN32
+# include <pthread.h>
+#endif
+
+namespace Kumu
+{
+#ifdef KM_WIN32
+  class Mutex
+    {
+      CRITICAL_SECTION m_Mutex;
+      KM_NO_COPY_CONSTRUCT(Mutex);
+
+    public:
+      inline Mutex()       { ::InitializeCriticalSection(&m_Mutex); }
+      inline ~Mutex()      { ::DeleteCriticalSection(&m_Mutex); }
+      inline void Lock()   { ::EnterCriticalSection(&m_Mutex); }
+      inline void Unlock() { ::LeaveCriticalSection(&m_Mutex); }
+    };
+#else // KM_WIN32
+  class Mutex
+    {
+      pthread_mutex_t m_Mutex;
+      KM_NO_COPY_CONSTRUCT(Mutex);
+
+    public:
+      inline Mutex()       { pthread_mutex_init(&m_Mutex, 0); }
+      inline ~Mutex()      { pthread_mutex_destroy(&m_Mutex); }
+      inline void Lock()   { pthread_mutex_lock(&m_Mutex); }
+      inline void Unlock() { pthread_mutex_unlock(&m_Mutex); }
+    };
+#endif // KM_WIN32
+
+  // automatic Mutex management within a block -
+  // the mutex is created by the constructor and
+  // released by the destructor
+  class AutoMutex
+    {
+      Mutex& m_Mutex;
+      AutoMutex();
+      KM_NO_COPY_CONSTRUCT(AutoMutex);
+
+    public:
+      AutoMutex(Mutex& Mtx) : m_Mutex(Mtx) { m_Mutex.Lock(); }
+      ~AutoMutex() { m_Mutex.Unlock(); }
+    };
+
+} // namespace Kumu
+
+#endif // _KM_MUTEX_H_
+
+//
+// end KM_mutex.h
+//
index 20f9e571a95e62fbcf227257f3baf370e94841e7..9358d1cc3b845dc659de39cab76bf3c7dd7aace1 100755 (executable)
@@ -30,7 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include "MXF.h"
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 
 
 using namespace ASDCP;
index dc03dbe6acb1795b5256d405e35c8f532718eda5..6ecb99cb6800eddc770ab9d3c6ef0f361b962b85 100755 (executable)
@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "AS_DCP.h"
 #include "MXF.h"
-#include <KM_log.h>
+#include <asdcp/KM_log.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
index f03d80227b9436155e51a3264ae781915d32c161..638a89d4316a08481f0684d69576c77a84001c56 100644 (file)
@@ -87,6 +87,8 @@ def build(bld):
               asdcp/KM_tai.h
               asdcp/KM_fileio.h
               asdcp/KM_prng.h
+              asdcp/KM_log.h
+              asdcp/KM_mutex.h
               asdcp/AS_DCP.h
               asdcp/AS_02.h
               asdcp/Metadata.h