corrected test of Py bool
authorjhurst <jhurst@cinecert.com>
Tue, 10 Aug 2010 23:03:27 +0000 (23:03 +0000)
committerjhurst <>
Tue, 10 Aug 2010 23:03:27 +0000 (23:03 +0000)
configure.ac
src/AS_DCP.h
src/KM_error.h
src/KM_platform.h
src/KM_util.cpp

index 8952e2abb790b5a9c32f423ae70728db51e2c5fa..2af20e3a4cb4508c5876aec24a6bf8cdc30adf0e 100644 (file)
@@ -37,7 +37,7 @@ AC_PREREQ([2.59])
 # For example, if asdcplib version 1.0.0 were modified to accomodate changes
 # in file format, and if no changes were made to AS_DCP.h, the new version would be
 # 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1.
-AC_INIT([asdcplib], [1.6.37], [asdcplib@cinecert.com])
+AC_INIT([asdcplib], [1.7.38], [asdcplib@cinecert.com])
 
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_SRCDIR([src/KM_error.h])
index 383f270b6ca25b3e8f89722687db37be9868b495..cd411c247cd844bf8955970e6656ee31ce5518d4 100755 (executable)
@@ -180,21 +180,21 @@ namespace ASDCP {
   using Kumu::RESULT_ENDOFFILE;
   using Kumu::RESULT_CONFIG;
 
-  const Kumu::Result_t RESULT_FORMAT     (-101, "The file format is not proper OP-Atom/AS-DCP.");
-  const Kumu::Result_t RESULT_RAW_ESS    (-102, "Unknown raw essence file type.");
-  const Kumu::Result_t RESULT_RAW_FORMAT (-103, "Raw essence format invalid.");
-  const Kumu::Result_t RESULT_RANGE      (-104, "Frame number out of range.");
-  const Kumu::Result_t RESULT_CRYPT_CTX  (-105, "AESEncContext required when writing to encrypted file.");
-  const Kumu::Result_t RESULT_LARGE_PTO  (-106, "Plaintext offset exceeds frame buffer size.");
-  const Kumu::Result_t RESULT_CAPEXTMEM  (-107, "Cannot resize externally allocated memory.");
-  const Kumu::Result_t RESULT_CHECKFAIL  (-108, "The check value did not decrypt correctly.");
-  const Kumu::Result_t RESULT_HMACFAIL   (-109, "HMAC authentication failure.");
-  const Kumu::Result_t RESULT_HMAC_CTX   (-110, "HMAC context required.");
-  const Kumu::Result_t RESULT_CRYPT_INIT (-111, "Error initializing block cipher context.");
-  const Kumu::Result_t RESULT_EMPTY_FB   (-112, "Empty frame buffer.");
-  const Kumu::Result_t RESULT_KLV_CODING (-113, "KLV coding error.");
-  const Kumu::Result_t RESULT_SPHASE     (-114, "Stereoscopic phase mismatch.");
-  const Kumu::Result_t RESULT_SFORMAT    (-115, "Rate mismatch, file may contain stereoscopic essence.");
+  KM_DECLARE_RESULT(FORMAT,     -101, "The file format is not proper OP-Atom/AS-DCP.");
+  KM_DECLARE_RESULT(RAW_ESS,    -102, "Unknown raw essence file type.");
+  KM_DECLARE_RESULT(RAW_FORMAT, -103, "Raw essence format invalid.");
+  KM_DECLARE_RESULT(RANGE,      -104, "Frame number out of range.");
+  KM_DECLARE_RESULT(CRYPT_CTX,  -105, "AESEncContext required when writing to encrypted file.");
+  KM_DECLARE_RESULT(LARGE_PTO,  -106, "Plaintext offset exceeds frame buffer size.");
+  KM_DECLARE_RESULT(CAPEXTMEM,  -107, "Cannot resize externally allocated memory.");
+  KM_DECLARE_RESULT(CHECKFAIL,  -108, "The check value did not decrypt correctly.");
+  KM_DECLARE_RESULT(HMACFAIL,   -109, "HMAC authentication failure.");
+  KM_DECLARE_RESULT(HMAC_CTX,   -110, "HMAC context required.");
+  KM_DECLARE_RESULT(CRYPT_INIT, -111, "Error initializing block cipher context.");
+  KM_DECLARE_RESULT(EMPTY_FB,   -112, "Empty frame buffer.");
+  KM_DECLARE_RESULT(KLV_CODING, -113, "KLV coding error.");
+  KM_DECLARE_RESULT(SPHASE,     -114, "Stereoscopic phase mismatch.");
+  KM_DECLARE_RESULT(SFORMAT,    -115, "Rate mismatch, file may contain stereoscopic essence.");
 
   //---------------------------------------------------------------------------------
   // file identification
index 8c2f5fceb611e0584cdd99feb7df73be7de0f951..3a3880395c1c881977a5bfaa543a0f1284169150 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2009, John Hurst
+Copyright (c) 2004-2010, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #ifndef _KM_ERROR_H_
 #define _KM_ERROR_H_
 
+#define KM_DECLARE_RESULT(sym, i, l) const Result_t RESULT_##sym(i, #sym, l);
+
 namespace Kumu
 {
   // Result code container. Both a signed integer and a text string are stored in the object.
@@ -45,13 +47,25 @@ namespace Kumu
     {
       int value;
       const char* label;
+      const char* symbol;
       Result_t();
 
     public:
-      static const Result_t& Find(int);
-      static Result_t Delete(int);
+      // Return registered Result_t for the given "value" code.
+      static const Result_t& Find(int value);
+
+      // Unregister the Result_t matching the given "value" code. Returns
+      // RESULT_FALSE if "value" does not match a registered Result_t.
+      // Returns RESULT_FAIL if ( value < -99 || value > 99 ) (Kumu core
+      // codes may not be deleted).
+      static Result_t Delete(int value);
 
-      Result_t(int v, const char* l);
+      // Iteration through registered result codes, not thread safe.
+      // Get accepts contiguous values from 0 to End() - 1.
+      static unsigned int End();
+      static const Result_t& Get(unsigned int);
+
+      Result_t(int v, const char* s, const char* l);
       ~Result_t();
 
       inline bool        operator==(const Result_t& rhs) const { return value == rhs.value; }
@@ -64,31 +78,33 @@ namespace Kumu
 
       inline const char* Label() const { return label; }
       inline operator    const char*() const { return label; }
+
+      inline const char* Symbol() const { return symbol; }
     };
 
-  const Result_t RESULT_FALSE      ( 1,   "Successful but not true.");
-  const Result_t RESULT_OK         ( 0,   "Success.");
-  const Result_t RESULT_FAIL       (-1,   "An undefined error was detected.");
-  const Result_t RESULT_PTR        (-2,   "An unexpected NULL pointer was given.");
-  const Result_t RESULT_NULL_STR   (-3,   "An unexpected empty string was given.");
-  const Result_t RESULT_ALLOC      (-4,   "Error allocating memory.");
-  const Result_t RESULT_PARAM      (-5,   "Invalid parameter.");
-  const Result_t RESULT_NOTIMPL    (-6,   "Unimplemented Feature.");
-  const Result_t RESULT_SMALLBUF   (-7,   "The given buffer is too small.");
-  const Result_t RESULT_INIT       (-8,   "The object is not yet initialized.");
-  const Result_t RESULT_NOT_FOUND  (-9,   "The requested file does not exist on the system.");
-  const Result_t RESULT_NO_PERM    (-10,  "Insufficient privilege exists to perform the operation.");
-  const Result_t RESULT_STATE      (-11,  "Object state error.");
-  const Result_t RESULT_CONFIG     (-12,  "Invalid configuration option detected.");
-  const Result_t RESULT_FILEOPEN   (-13,  "File open failure.");
-  const Result_t RESULT_BADSEEK    (-14,  "An invalid file location was requested.");
-  const Result_t RESULT_READFAIL   (-15,  "File read error.");
-  const Result_t RESULT_WRITEFAIL  (-16,  "File write error.");
-  const Result_t RESULT_ENDOFFILE  (-17,  "Attempt to read past end of file.");
-  const Result_t RESULT_FILEEXISTS (-18,  "Filename already exists.");
-  const Result_t RESULT_NOTAFILE   (-19,  "Filename not found.");
-  const Result_t RESULT_UNKNOWN    (-20,  "Unknown result code.");
-  const Result_t RESULT_DIR_CREATE (-21,  "Unable to create directory.");
+  KM_DECLARE_RESULT(FALSE,       1,   "Successful but not true.");
+  KM_DECLARE_RESULT(OK,          0,   "Success.");
+  KM_DECLARE_RESULT(FAIL,       -1,   "An undefined error was detected.");
+  KM_DECLARE_RESULT(PTR,        -2,   "An unexpected NULL pointer was given.");
+  KM_DECLARE_RESULT(NULL_STR,   -3,   "An unexpected empty string was given.");
+  KM_DECLARE_RESULT(ALLOC,      -4,   "Error allocating memory.");
+  KM_DECLARE_RESULT(PARAM,      -5,   "Invalid parameter.");
+  KM_DECLARE_RESULT(NOTIMPL,    -6,   "Unimplemented Feature.");
+  KM_DECLARE_RESULT(SMALLBUF,   -7,   "The given buffer is too small.");
+  KM_DECLARE_RESULT(INIT,       -8,   "The object is not yet initialized.");
+  KM_DECLARE_RESULT(NOT_FOUND,  -9,   "The requested file does not exist on the system.");
+  KM_DECLARE_RESULT(NO_PERM,    -10,  "Insufficient privilege exists to perform the operation.");
+  KM_DECLARE_RESULT(STATE,      -11,  "Object state error.");
+  KM_DECLARE_RESULT(CONFIG,     -12,  "Invalid configuration option detected.");
+  KM_DECLARE_RESULT(FILEOPEN,   -13,  "File open failure.");
+  KM_DECLARE_RESULT(BADSEEK,    -14,  "An invalid file location was requested.");
+  KM_DECLARE_RESULT(READFAIL,   -15,  "File read error.");
+  KM_DECLARE_RESULT(WRITEFAIL,  -16,  "File write error.");
+  KM_DECLARE_RESULT(ENDOFFILE,  -17,  "Attempt to read past end of file.");
+  KM_DECLARE_RESULT(FILEEXISTS, -18,  "Filename already exists.");
+  KM_DECLARE_RESULT(NOTAFILE,   -19,  "Filename not found.");
+  KM_DECLARE_RESULT(UNKNOWN,    -20,  "Unknown result code.");
+  KM_DECLARE_RESULT(DIR_CREATE, -21,  "Unable to create directory.");
   // -22 is reserved
  
 } // namespace Kumu
index a0e6a8ca17164820d99c1bad76b0de7306d5e876..54d5f2789d0b70b4091c1326cb9817541e275cc5 100644 (file)
@@ -184,6 +184,54 @@ namespace Kumu
           T(const T&); \
           T& operator=(const T&)
 
+/*
+// Example
+  class foo
+    {
+      KM_NO_COPY_CONSTRUCT(foo); // accessing private mthods will cause compile time error
+    public:
+      // ...
+    };
+*/
+
+// Produces copy constructor boilerplate. Implements
+// copy and assignment, see example below
+# define KM_EXPLICIT_COPY_CONSTRUCT(T) \
+  T(const T&);                         \
+  const T& operator=(const T&)
+
+# define KM_EXPLICIT_COPY_CONSTRUCT_IMPL_START(N, T)   \
+  void T##_copy_impl(N::T& lhs, const N::T& rhs)       \
+  {
+
+#define KM_COPY_ITEM(I) lhs.I = rhs.I;
+
+# define KM_EXPLICIT_COPY_CONSTRUCT_IMPL_END(N, T)     \
+  }                                                    \
+  N::T::T(const N::T& rhs) { T##_copy_impl(*this, rhs); }              \
+  const N::T& N::T::operator=(const N::T& rhs) { T##_copy_impl(*this, rhs); return *this; }
+
+/*
+// Example
+namespace bar {
+  class foo
+    {
+    public:
+      std::string param_a;
+      int param_b;
+
+      KM_EXPLICIT_COPY_CONSTRUCT(foo);
+      // ...
+    };
+}
+
+//
+KM_EXPLICIT_COPY_CONSTRUCT_IMPL_START(bar, foo)
+KM_COPY_ITEM(param_a)
+KM_COPY_ITEM(param_b)
+KM_EXPLICIT_COPY_CONSTRUCT_IMPL_END(bar, foo)
+*/
+
 #endif // _KM_PLATFORM_H_
 
 //
index 2624f07fcb1bf6533153c787c9892360b07e9564..0a9d5890c60fba1f076de48b4de9f924cab18669 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2009, John Hurst
+Copyright (c) 2005-2010, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <KM_fileio.h>
 #include <KM_log.h>
 #include <KM_tai.h>
+#include <KM_mutex.h>
 #include <ctype.h>
 #include <list>
 #include <map>
@@ -53,14 +54,16 @@ Kumu::Version()
 
 struct map_entry_t
 {
-  int             rcode;
+  int rcode;
   Kumu::Result_t* result;
 };
 
-const ui32_t MapMax = 1024;
-const ui32_t MapSize = MapMax * (sizeof(struct map_entry_t));
-static bool s_MapInit = false;
-static struct map_entry_t s_ResultMap[MapSize];
+const ui32_t MapMax = 2048;
+
+static Kumu::Mutex s_MapLock;
+static ui32_t s_MapSize = 0;
+static struct map_entry_t s_ResultMap[MapMax];
+
 
 //
 const Kumu::Result_t&
@@ -69,7 +72,9 @@ Kumu::Result_t::Find(int v)
   if ( v == 0 )
     return RESULT_OK;
 
-  for ( ui32_t i = 0; s_ResultMap[i].result != 0 && i < MapMax; i++ )
+  AutoMutex L(s_MapLock);
+
+  for ( ui32_t i = 0; i < s_MapSize; ++i )
     {
       if ( s_ResultMap[i].rcode == v )
        return *s_ResultMap[i].result;
@@ -82,22 +87,22 @@ Kumu::Result_t::Find(int v)
 Kumu::Result_t
 Kumu::Result_t::Delete(int v)
 {
-  if ( v >= RESULT_NOTAFILE.Value() )
+  if ( v < -99 || v > 99 )
     {
       DefaultLogSink().Error("Cannot delete core result code: %ld\n", v);
       return RESULT_FAIL;
     }
 
-  for ( ui32_t i = 0; s_ResultMap[i].result != 0 && i < MapMax; i++ )
+  AutoMutex L(s_MapLock);
+
+  for ( ui32_t i = 0; i < s_MapSize; ++i )
     {
       if ( s_ResultMap[i].rcode == v )
        {
-         s_ResultMap[i].rcode = 0;
-         s_ResultMap[i++].result = 0;
-
-         for ( ; s_ResultMap[i].result != 0 && i < MapMax; i++ )
+         for ( ++i; i < s_MapSize; ++i )
            s_ResultMap[i-1] = s_ResultMap[i];
 
+         --s_MapSize;
          return RESULT_OK;
        }
     }
@@ -105,41 +110,43 @@ Kumu::Result_t::Delete(int v)
   return RESULT_FALSE;
 }
 
+//
+unsigned int
+Kumu::Result_t::End()
+{
+  return s_MapSize;
+}
+
+//
+const Kumu::Result_t&
+Kumu::Result_t::Get(unsigned int i)
+{
+  return *s_ResultMap[i].result;
+}
 
 //
-Kumu::Result_t::Result_t(int v, const char* l) : value(v), label(l)
+Kumu::Result_t::Result_t(int v, const char* s, const char* l) : value(v), symbol(s), label(l)
 {
   assert(l);
-  assert(value < (int)MapMax);
+  assert(s);
 
   if ( v == 0 )
     return;
 
-  if ( ! s_MapInit )
-    {
-      s_MapInit = true;
-      s_ResultMap[0].rcode = v;
-      s_ResultMap[0].result = this;
-      s_ResultMap[1].rcode = 0;
-      s_ResultMap[1].result = 0;
-      return;
-    }
+  AutoMutex L(s_MapLock);
 
-  ui32_t i = 0;
-  while ( s_ResultMap[i].result != 0 && i < MapMax )
+  for ( ui32_t i = 0; i < s_MapSize; ++i )
     {
-      if ( s_ResultMap[i].rcode == v && s_ResultMap[i].result != 0 )
+      if ( s_ResultMap[i].rcode == v )
        return;
-
-      i++;
     }
 
-  assert(i+2 < MapMax);
+  assert(s_MapSize+1 < MapMax);
+
+  s_ResultMap[s_MapSize].rcode = v;
+  s_ResultMap[s_MapSize].result = this;
+  ++s_MapSize;
 
-  s_ResultMap[i].rcode = v;
-  s_ResultMap[i].result = this;
-  s_ResultMap[i+1].rcode = 0;
-  s_ResultMap[i+1].result = 0;
   return;
 }