SysTry -> SysSecureTry
[platform/framework/native/vision.git] / src / FUixVisionImageRecognizer.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 <FUixVisionImageRecognizer.h>
19 #include "FUixVision_ImageRecognizerImpl.h"
20 #include <cstring>
21 #include <FText.h>
22 #include <FBaseSysLog.h>
23
24 namespace Tizen { namespace Uix { namespace Vision
25 {
26
27 ImageRecognizer::ImageRecognizer(void)
28     : __pImageRecognizerImpl(0)
29 {
30 }
31
32 ImageRecognizer::~ImageRecognizer(void)
33 {
34     if (__pImageRecognizerImpl != null)
35     {
36         delete __pImageRecognizerImpl;
37         __pImageRecognizerImpl = null;
38     }
39 }
40
41 result
42 ImageRecognizer::Construct(void)
43 {
44     SysAssertf(__pImageRecognizerImpl == null, "Already constructed! ",
45             "Calling Construct() twice or more on a same instance is not allowed for this class.");
46
47     std::unique_ptr<_ImageRecognizerImpl> pImageRecognizerImpl (new (std::nothrow) _ImageRecognizerImpl);
48     SysSecureTryReturn(NID_UIX, pImageRecognizerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
49     __pImageRecognizerImpl = pImageRecognizerImpl.release();
50
51     return E_SUCCESS;
52 }
53
54 void
55 ImageRecognizer::SetMultiTrackingEnabled(bool enable)
56 {
57     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
58     __pImageRecognizerImpl->SetMultiTracking(enable);
59 }
60
61 result
62 ImageRecognizer::SetImageSize(int width, int height)
63 {
64     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
65
66     SysSecureTryReturnResult(NID_UIX, width > 0 && height > 0, E_INVALID_ARG,
67             "Width and height must me more than 0. [E_INVALID_ARG]");
68
69     return __pImageRecognizerImpl->SetImageSize(width, height) ? E_SUCCESS : E_FAILURE;
70 }
71
72 result
73 ImageRecognizer::SetFeatureManager(ImageFeatureManager& imageFeatureManager)
74 {
75     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
76
77     return __pImageRecognizerImpl->SetImageDatabase(&imageFeatureManager) ? E_SUCCESS : E_FAILURE;
78 }
79
80 int
81 ImageRecognizer::GetRecognizedObjectCount(void)
82 {
83     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
84     __pImageRecognizerImpl->FillObjectStorage();
85     return __pImageRecognizerImpl->GetRecognizedObjectsCount();
86 }
87
88 const ImageObject*
89 ImageRecognizer::GetRecognizedObject(int index) const
90 {
91     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
92     return __pImageRecognizerImpl->GetRecognizedObject(index);
93 }
94
95 result
96 ImageRecognizer::ProcessImage(const Tizen::Base::ByteBuffer& imageBuffer)
97 {
98     SysAssertf(__pImageRecognizerImpl != null, "Not yet constructed! Consruct() should be called before use.");
99
100     SysSecureTryReturn(NID_UIX, imageBuffer.GetPointer(), -1, E_INVALID_ARG,
101             "imageBuffer must not be null. [E_INVALID_ARG]");
102
103     return __pImageRecognizerImpl->ProcessImage((unsigned char*) imageBuffer.GetPointer()) != -1 ? E_SUCCESS : E_FAILURE;
104 }
105
106 } } } //Tizen::Uix::Vision