RAII applied. Memory leak fixed.
authorOleksandr Kaspruk <a.kaspruk@samsung.com>
Wed, 3 Apr 2013 16:35:55 +0000 (01:35 +0900)
committerKyusung Cho <ks0128.cho@samsung.com>
Fri, 5 Apr 2013 10:32:43 +0000 (19:32 +0900)
Change-Id: Iac895e8b54b203344a1e130fa7728d7bc8e2e92c
Signed-off-by: Oleksandr Kaspruk <a.kaspruk@samsung.com>
15 files changed:
inc/FUixVisionImageFeatureManager.h
src/FUixVisionImageFeatureInfo.cpp
src/FUixVisionImageFeatureManager.cpp
src/FUixVisionImageObject.cpp
src/FUixVisionImageRecognizer.cpp
src/FUixVisionQrCodeGenerator.cpp
src/FUixVisionQrCodeObject.cpp
src/FUixVisionQrCodeRecognizer.cpp
src/FUixVision_ImageFeatureManagerImpl.cpp
src/FUixVision_ImageFeatureManagerImpl.h
src/FUixVision_QrCodeObjectImpl.cpp
src/FUixVision_QrCodeObjectImpl.h
src/FUixVision_QrCodeRecognizerImpl.cpp
src/ImageFeatureInfo.h
src/ImageFeatureManager.h

index 2e22c4e..ed105be 100644 (file)
@@ -48,10 +48,10 @@ namespace Tizen { namespace Uix { namespace Vision
  * {
  *     Tizen::Uix::Vision::ImageFeatureManager imageFeatureManager;
  *     imageFeatureManager.Construct();
- *     imageFeatureManager.Load("/mnt/ums/Images/testFeatureSet.xdb");
- *     imageFeatureManager.AddFeature("/mnt/ums/Images/image1.jpg");
- *     imageFeatureManager.AddFeature("/mnt/ums/Images/image2.jpg");
- *     imageFeatureManager.AddFeature("/mnt/ums/Images/image3.jpg");
+ *     imageFeatureManager.Load("/opt/usr/media/Images/testFeatureSet.xdb");
+ *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image1.jpg");
+ *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image2.jpg");
+ *     imageFeatureManager.AddFeature("/opt/usr/media/Images/image3.jpg");
  *     imageFeatureManager.Flush();
  * }
  */
@@ -110,7 +110,7 @@ public:
      * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
      *
      * @remarks     if feature set file exists, it will be updated.
-     *              if feature set file does not exist, it will be newly created.
+     *              if feature set file does not exist, it will return E_INVALID_ARG exception.
      * @see
      */
     result Load(const Tizen::Base::String& featureSetFilePath);
@@ -130,8 +130,7 @@ public:
      *
      * @since       2.1
      *
-     * @return      Feature index of newly created feature on success.
-     *              If the specified input image file path is invalid, it returns -1.
+     * @return      Feature index of newly created feature on success, otherwise returns -1.
      *
      * @param[in]   imagePath            Input image file path
      *
@@ -151,8 +150,7 @@ public:
      *
      * @since       2.1
      *
-     * @return      Feature index of newly created feature on success.
-     *              If A specified input image file path is invalid, it returns -1.
+     * @return      Feature index of newly created feature on success, otherwise returns -1.
      *
      * @param[in]   imageBuffer              Image buffer of grayscale image data of specified width and height
      * @param[in]   width                    Width of input image
@@ -228,7 +226,8 @@ public:
      * @remarks     All changes in feature set file by 'AddFeature' or 'DeleteFeature' or 'DeleteAllFeatures' are updated by calling this Flush() method.
      *              If featureSetFilePath is not decided or is same to file path used in Load(), the loaded feature set file will be updated.
      *              If featureSetFilePath is not same to file path used in Load(), the loaded feature set file is remained and new feature set file will be created.
-     * @remarks     If featureSetFilePath is null, the feature set file loaded by Load() method will be overwritten.
+     *              If featureSetFilePath is null, the feature set file loaded by Load() method will be overwritten.
+        *                      If featureSetFilePath is not decided or is same to file path used in Load() and the loaded feature set file is read-only E_INVALID_ARG exception will be  returned.
      *
      * @see
      */
index c7e39ff..8f6e5bb 100644 (file)
@@ -32,6 +32,11 @@ ImageFeatureInfo::ImageFeatureInfo()
 
 ImageFeatureInfo::~ImageFeatureInfo()
 {
+    if (__pImageFeatureInfoImpl != null)
+    {
+        delete __pImageFeatureInfoImpl;
+        __pImageFeatureInfoImpl = null;
+    }
 }
 
 Tizen::Base::String
index 8ef65b8..072ce4b 100755 (executable)
@@ -32,6 +32,11 @@ ImageFeatureManager::ImageFeatureManager(void)
 
 ImageFeatureManager::~ImageFeatureManager(void)
 {
+    if (__pImageFeatureManagerImpl != null)
+    {
+        delete __pImageFeatureManagerImpl;
+        __pImageFeatureManagerImpl = null;
+    }
 }
 
 result
@@ -118,7 +123,10 @@ ImageFeatureManager::Load(const Tizen::Base::String& featureSetFilePath)
     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
 
     SysTryReturnResult(NID_UIX, !featureSetFilePath.IsEmpty(), E_INVALID_ARG,
-            "database path must not be empty. [E_INVALID_ARG]");
+            "feature set path must not be empty. [E_INVALID_ARG]");
+
+    SysTryReturnResult(NID_UIX, Tizen::Io::File::IsFileExist(featureSetFilePath), E_INVALID_ARG,
+            "feature set file must exist. [E_INVALID_ARG]");
 
     return __pImageFeatureManagerImpl->OpenDB(featureSetFilePath) ? E_SUCCESS : E_FAILURE;
 }
index e2a1de3..2c8347f 100644 (file)
@@ -30,6 +30,11 @@ ImageObject::ImageObject()
 
 ImageObject::~ImageObject()
 {
+    if (__pImageObjectImpl != null)
+    {
+        delete __pImageObjectImpl;
+        __pImageObjectImpl = null;
+    }
 }
 
 int
index 9084d2e..e2785cf 100755 (executable)
@@ -31,6 +31,11 @@ ImageRecognizer::ImageRecognizer(void)
 
 ImageRecognizer::~ImageRecognizer(void)
 {
+    if (__pImageRecognizerImpl != null)
+    {
+        delete __pImageRecognizerImpl;
+        __pImageRecognizerImpl = null;
+    }
 }
 
 result
index 2ab8958..189e35c 100644 (file)
@@ -30,6 +30,11 @@ QrCodeGenerator::QrCodeGenerator(void)
 
 QrCodeGenerator::~QrCodeGenerator(void)
 {
+    if (__pQrCodeGeneratorImpl != null)
+    {
+        delete __pQrCodeGeneratorImpl;
+        __pQrCodeGeneratorImpl = null;
+    }
 }
 
 result
index 7d5b45b..973eedd 100644 (file)
@@ -30,6 +30,11 @@ QrCodeObject::QrCodeObject(void)
 
 QrCodeObject::~QrCodeObject(void)
 {
+    if (__pQrCodeObjectImpl != null)
+    {
+        delete __pQrCodeObjectImpl;
+        __pQrCodeObjectImpl = null;
+    }
 }
 
 int
index 29b42d9..be6a792 100644 (file)
@@ -29,6 +29,11 @@ QrCodeRecognizer::QrCodeRecognizer(void)
 
 QrCodeRecognizer::~QrCodeRecognizer(void)
 {
+    if (__pQrCodeRecognizerImpl != null)
+    {
+        delete __pQrCodeRecognizerImpl;
+        __pQrCodeRecognizerImpl = null;
+    }
 }
 
 result
index 2096738..0f212d1 100644 (file)
@@ -27,6 +27,7 @@ namespace Tizen { namespace Uix { namespace Vision
 
 _ImageFeatureManagerImpl::_ImageFeatureManagerImpl(void)
     : __imageFeatureManager(0)
+       , __readOnly(false)
 {
 }
 
@@ -54,7 +55,7 @@ void
 _ImageFeatureManagerImpl::InitDB(void)
 {
     __indices.RemoveAll();
-    if(__imageFeatureManager)
+    if (__imageFeatureManager)
     {
         delete __imageFeatureManager;
     }
@@ -67,13 +68,13 @@ _ImageFeatureManagerImpl::AddFeature(const Tizen::Base::String& filepath)
 {
     Tizen::Media::ImageBuffer imBuf;
     result r = imBuf.Construct(filepath, null, false);
-    if(IsFailed(r))
+    if (IsFailed(r))
     {
         return -1;
     }
 
     Tizen::Base::ByteBuffer* yuvBuf = imBuf.GetByteBufferN(Tizen::Media::MEDIA_PIXEL_FORMAT_YUV420P);
-    if(yuvBuf == null)
+    if (yuvBuf == null)
     {
         return -1;
     }
@@ -87,9 +88,10 @@ _ImageFeatureManagerImpl::AddFeature(const Tizen::Base::String& filepath)
 int
 _ImageFeatureManagerImpl::AddFeature(const unsigned char* data, int width, int height, const Tizen::Base::String& info)
 {
-    if(!__imageFeatureManager)
+    if (!__imageFeatureManager)
+       {
         return -1;
-
+       }
     Tizen::Text::Utf8Encoding utf8;
     int index = (int) __imageFeatureManager->addImageToDB(data, width, height, (char*) utf8.GetBytesN(info)->GetPointer());
 
@@ -104,12 +106,14 @@ _ImageFeatureManagerImpl::AddFeature(const unsigned char* data, int width, int h
 bool
 _ImageFeatureManagerImpl::DeleteFeature(int index)
 {
-    if(!__imageFeatureManager)
+    if (!__imageFeatureManager)
+       {
         return false;
+       }
 
     int realIndex(0);
     __indices.GetAt(index,realIndex);
-    if(__imageFeatureManager->deleteImageFromDB(realIndex))
+    if (__imageFeatureManager->deleteImageFromDB(realIndex))
     {
         __indices.RemoveAt(index);
         return true;
@@ -134,8 +138,10 @@ _ImageFeatureManagerImpl::SaveDB(bool optimizeDatabase, const Tizen::Base::Strin
     __indices.RemoveAll();
     result result = E_FAILURE;
 
-    if(!__imageFeatureManager)
+    if (!__imageFeatureManager)
+       {
         return E_FAILURE;
+       }
 
 
     if (null != dbPath)
@@ -147,15 +153,18 @@ _ImageFeatureManagerImpl::SaveDB(bool optimizeDatabase, const Tizen::Base::Strin
     }
     else
     {
-        if(!__path.IsEmpty())
+        if (!__path.IsEmpty())
         {
             Tizen::Text::Utf8Encoding utf8;
             result = __imageFeatureManager->saveDB(optimizeDatabase, (const char*) utf8.GetBytesN(__path)->GetPointer()) ? E_SUCCESS : E_FAILURE;
+                       if (E_FAILURE == result && __readOnly)
+                       {
+                               result = E_INVALID_ARG;
+                       }
         }
     }
 
     return result;
-
 }
 
 bool
@@ -163,7 +172,7 @@ _ImageFeatureManagerImpl::UpdateDB()
 {
     __indices.RemoveAll();
 
-    if(__imageFeatureManager->updateDB())
+    if (__imageFeatureManager->updateDB())
     {
         UpdateFeatureIndices();
         return true;
@@ -177,44 +186,29 @@ _ImageFeatureManagerImpl::UpdateDB()
 bool
 _ImageFeatureManagerImpl::OpenDB(const Tizen::Base::String& dbpath)
 {
-    if(__imageFeatureManager)
+    if (__imageFeatureManager)
     {
         delete __imageFeatureManager;
     }
     __imageFeatureManager = new sari2::ImageFeatureManager();
     __imageFeatureManager->initDB();
 
-    if(!Tizen::Io::File::IsFileExist(dbpath))
-    {
-        result r;
-        Tizen::Io::File featureFile;
-        r = featureFile.Construct(dbpath, "w+");
-        //r = featureFile.Flush();
-
-        if (IsFailed(r))
-        {
-            __path = L"";
-            return false;
-        }
+    Tizen::Text::Utf8Encoding utf8;
+       switch (__imageFeatureManager->openDB((const char*) utf8.GetBytesN(dbpath)->GetPointer()))
+       {
+       case 0: //ok
         __path = dbpath;
-        __indices.RemoveAll();
-
-    }
-    else
-    {
-        Tizen::Text::Utf8Encoding utf8;
-        if(!__imageFeatureManager->openDB((const char*) utf8.GetBytesN(dbpath)->GetPointer()))
-        {
-            __path = L"";
-            __indices.RemoveAll();
-            return false;
-        }
-        else
-        {
-            __path = dbpath;
-            UpdateFeatureIndices();
-        }
-    }
+        UpdateFeatureIndices();
+               break;
+       case -2: //read only feature set file
+        __path = dbpath;
+        UpdateFeatureIndices();
+               __readOnly = true;
+               break;
+       default: //error
+        __path = dbpath;
+        UpdateFeatureIndices();
+       }
 
     return true;
 }
@@ -222,8 +216,10 @@ _ImageFeatureManagerImpl::OpenDB(const Tizen::Base::String& dbpath)
 void
 _ImageFeatureManagerImpl::ReleaseDB(void)
 {
-    if(!__imageFeatureManager)
+    if (!__imageFeatureManager)
+       {
         return;
+       }
 
     __imageFeatureManager->releaseDB();
     __indices.RemoveAll();
@@ -232,8 +228,10 @@ _ImageFeatureManagerImpl::ReleaseDB(void)
 const Tizen::Uix::Vision::ImageFeatureInfo*
 _ImageFeatureManagerImpl::GetImageFeatureInfo(int index)
 {
-    if(!__imageFeatureManager)
+    if (!__imageFeatureManager)
+       {
         return null;
+       }
 
     Tizen::Uix::Vision::ImageFeatureInfo* di = _ImageFeatureInfoImpl::CreateImageFeatureInfoN();
     int realIndex(0);
@@ -248,7 +246,9 @@ _ImageFeatureManagerImpl::UpdateFeatureIndices(void)
     __indices.RemoveAll();
 
     if (!__imageFeatureManager)
+       {
         return;
+       }
 
     int total = __imageFeatureManager->totalNumberOfImages();
     for (int i = 0; i < total; i++)
index b259255..42c905f 100644 (file)
@@ -60,6 +60,7 @@ private:
     sari2::ImageFeatureManager*              __imageFeatureManager;
     Tizen::Base::String                      __path;
     Tizen::Base::Collection::ArrayListT<int> __indices;
+       bool                                                                     __readOnly;
 };
 
 } } } //Tizen::Uix::Vision
index 622aafe..cf91159 100644 (file)
@@ -116,6 +116,18 @@ _QrCodeObjectImpl::GetInstance(const QrCodeObject* pQrObject)
     return pQrObject->__pQrCodeObjectImpl;
 }
 
+void
+_QrCodeObjectImpl::ReleaseQrCodeObject(QrCodeObject* pQrCodeObject)
+{
+    delete pQrCodeObject;
+}
+
+void
+_QrCodeObjectImpl::ReleaseQrCodeObjectArray(QrCodeObject* pQrCodeObject)
+{
+    delete[] pQrCodeObject;
+}
+
 Tizen::Uix::Vision::QrCodeObject*
 _QrCodeObjectImpl::CreateQRCodeObjectStorageN(const unsigned int size)
 {
index 988966a..9f5f770 100644 (file)
@@ -50,6 +50,8 @@ public:
 public:
     static Tizen::Uix::Vision::QrCodeObject* CreateQRCodeObjectStorageN(const unsigned int size);
     static Tizen::Uix::Vision::QrCodeObject* CreateQRCodeObjectN();
+    static void ReleaseQrCodeObject(QrCodeObject* pQrCodeObject);
+    static void ReleaseQrCodeObjectArray(QrCodeObject* pQrCodeObject);
     static _QrCodeObjectImpl* GetInstance(QrCodeObject* pQrObject);
     static const _QrCodeObjectImpl* GetInstance(const QrCodeObject* pQrObject);
 
index 6ae93ab..f8fb607 100644 (file)
@@ -29,6 +29,7 @@ _QrCodeRecognizerImpl::_QrCodeRecognizerImpl(void)
 
 _QrCodeRecognizerImpl::~_QrCodeRecognizerImpl(void)
 {
+       _QrCodeObjectImpl::ReleaseQrCodeObjectArray(__objectStorage);
 }
 
 bool
index 75752d1..40e7e7b 100755 (executable)
@@ -51,7 +51,6 @@ public:
     /// \return Path size.
     unsigned int imagePath(char* path, unsigned int length) const;
 
-
     /// \brief valuate if the object is available for query.
     /// \return true if object is available
     bool isActive(void) const;
index 38be9d1..0474776 100755 (executable)
@@ -67,8 +67,10 @@ public:
 
     /// \brief Loads database from input file.
     /// \param[in] dbPath Database file path.
-    /// \return 'true' on success.
-    bool openDB(const char* dbPath);
+    /// \return 0 on success.
+    /// \return -1 on failure.
+    /// \return -2 on readonly file.
+    int openDB(const char* dbPath);
 
     /// \brief Delete all objects from the database.
     void releaseDB(void);