Coding idoms applied. isActive functional added.
[framework/osp/vision.git] / src / FUixVisionImageFeatureManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FUixVisionImageFeatureManager.h>
19 #include "FUixVision_ImageFeatureManagerImpl.h"
20 #include <FMedia.h>
21 #include <FGraphics.h>
22 #include <FText.h>
23 #include <FBaseSysLog.h>
24
25 namespace Tizen { namespace Uix { namespace Vision
26 {
27
28 ImageFeatureManager::ImageFeatureManager(void)
29     : __pImageFeatureManagerImpl(0)
30 {
31 }
32
33 ImageFeatureManager::~ImageFeatureManager(void)
34 {
35 }
36
37 result
38 ImageFeatureManager::Construct(void)
39 {
40     SysAssertf(__pImageFeatureManagerImpl == null, "Already constructed! ",
41             "Calling Construct() twice or more on a same instance is not allowed for this class.");
42
43     std::unique_ptr<_ImageFeatureManagerImpl> pImageFeatureManagerImpl (new (std::nothrow) _ImageFeatureManagerImpl());
44     SysTryReturn(NID_UIX, pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45
46     __pImageFeatureManagerImpl = pImageFeatureManagerImpl.release();
47     __pImageFeatureManagerImpl->InitDB();
48     return E_SUCCESS;
49 }
50
51 result
52 ImageFeatureManager::DeleteFeature(int featureIndex)
53 {
54     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
55
56     SysTryReturn(NID_UIX, featureIndex >= 0, E_FAILURE, E_INVALID_ARG,
57             "index should be greater than 0. [E_INVALID_ARG]");
58
59     return __pImageFeatureManagerImpl->DeleteFeature(featureIndex) ? E_SUCCESS : E_FAILURE;
60 }
61
62 int
63 ImageFeatureManager::GetTotalNumberOfFeatures(void)
64 {
65     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
66     return __pImageFeatureManagerImpl->GetTotalNumberOfFeatures();
67 }
68
69 result
70 ImageFeatureManager::DeleteAllFeatures(void)
71 {
72     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
73     SysTryReturnResult(NID_UIX, __pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
74     __pImageFeatureManagerImpl->ReleaseDB();
75     __pImageFeatureManagerImpl->InitDB();
76     return E_SUCCESS;
77 }
78
79 int
80 ImageFeatureManager::AddFeature(const Tizen::Base::ByteBuffer& imageBuffer, int width, int height, const Tizen::Base::String& descr)
81 {
82
83     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
84
85     SysTryReturn(NID_UIX, width > 0 && height > 0, -1, E_INVALID_ARG,
86             "Width and height must me more than 0. [E_INVALID_ARG]");
87
88     const unsigned char* image = (unsigned char*) imageBuffer.GetPointer();
89
90     SysTryReturn(NID_UIX, image != null, -1, E_INVALID_ARG,
91             "image pointer must not be null. [E_INVALID_ARG]");
92
93     return (int) __pImageFeatureManagerImpl->AddFeature(image, width, height, descr);
94 }
95
96 int
97 ImageFeatureManager::AddFeature(const Tizen::Base::String& imagePath)
98 {
99     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
100
101     SysTryReturnResult(NID_UIX, !imagePath.IsEmpty(), E_INVALID_ARG,
102             "image path must not be empty. [E_INVALID_ARG]");
103
104     return (int) __pImageFeatureManagerImpl->AddFeature(imagePath);
105 }
106
107 result
108 ImageFeatureManager::Flush(const Tizen::Base::String* featureSetFilePath)
109 {
110     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
111
112     return __pImageFeatureManagerImpl->SaveDB(true, featureSetFilePath);
113 }
114
115 result
116 ImageFeatureManager::Load(const Tizen::Base::String& featureSetFilePath)
117 {
118     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
119
120     SysTryReturnResult(NID_UIX, !featureSetFilePath.IsEmpty(), E_INVALID_ARG,
121             "database path must not be empty. [E_INVALID_ARG]");
122
123     return __pImageFeatureManagerImpl->OpenDB(featureSetFilePath) ? E_SUCCESS : E_FAILURE;
124 }
125
126 Tizen::Base::Collection::IListT<Tizen::Media::ImageFormat>*
127 ImageFeatureManager::GetSupportedImageFileFormatsListN(void)
128 {
129     Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat>* formatList = new Tizen::Base::Collection::ArrayListT<Tizen::Media::ImageFormat>;
130     formatList->Add(Tizen::Media::IMG_FORMAT_BMP);
131     formatList->Add(Tizen::Media::IMG_FORMAT_JPG);
132     formatList->Add(Tizen::Media::IMG_FORMAT_PNG);
133     return formatList;
134 }
135
136 const Tizen::Uix::Vision::ImageFeatureInfo*
137 ImageFeatureManager::GetImageFeatureInfo(int index) const
138 {
139     SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use.");
140     return __pImageFeatureManagerImpl->GetImageFeatureInfo(index);
141 }
142
143 } } } //Tizen::Uix::Vision