SysTry -> SysSecureTry
[platform/framework/native/vision.git] / src / FUixVisionImageFeatureInfo.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 languae governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FUixVisionImageFeatureInfo.h>
19 #include "FUixVision_ImageFeatureInfoImpl.h"
20 #include <FText.h>
21 #include <FBaseSysLog.h>
22
23 namespace Tizen { namespace Uix { namespace Vision
24 {
25
26 ImageFeatureInfo::ImageFeatureInfo()
27     : __pImageFeatureInfoImpl(0)
28 {
29     std::unique_ptr<_ImageFeatureInfoImpl> pImageFeatureInfoImpl (new (std::nothrow) _ImageFeatureInfoImpl());
30     __pImageFeatureInfoImpl = pImageFeatureInfoImpl.release();
31 }
32
33 ImageFeatureInfo::~ImageFeatureInfo()
34 {
35     if (__pImageFeatureInfoImpl != null)
36     {
37         delete __pImageFeatureInfoImpl;
38         __pImageFeatureInfoImpl = null;
39     }
40 }
41
42 Tizen::Base::String
43 ImageFeatureInfo::GetDescription() const
44 {
45     ClearLastResult();
46
47     char ch;
48     int length = -1;
49
50     //get true length of path to allocate memory
51     length = __pImageFeatureInfoImpl->GetDescription(&ch, 1);
52     if (!length)
53     {
54         return Tizen::Base::String("");
55     }
56
57     std::unique_ptr<char[]> pName(new (std::nothrow) char[length + 1]);
58     SysSecureTryReturn(NID_UIX, pName != null, Tizen::Base::String(""), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY))
59
60     //set data to char pointer, with allocated memory
61     __pImageFeatureInfoImpl->GetDescription(pName.get(), length + 1);
62
63     Tizen::Base::String description(pName.get());
64     return description;
65 }
66
67 int
68 ImageFeatureInfo::GetThumbnailWidth(void) const
69 {
70     return __pImageFeatureInfoImpl->GetThumbnailWidth();
71 }
72
73 int
74 ImageFeatureInfo::GetThumbnailHeight(void) const
75 {
76     return __pImageFeatureInfoImpl->GetThumbnailHeight();
77 }
78
79 Tizen::Base::ByteBuffer*
80 ImageFeatureInfo::GetThumbnailN(void) const
81 {
82     int bufWidth  = __pImageFeatureInfoImpl->GetThumbnailWidth();
83     SysSecureTryReturn(NID_UIX, bufWidth > 0, null, E_FAILURE, "[%s] Failed to get thumbnail width.", GetErrorMessage(E_FAILURE));
84
85     int bufHeight = __pImageFeatureInfoImpl->GetThumbnailHeight();
86     SysSecureTryReturn(NID_UIX, bufHeight > 0, null, E_FAILURE, "[%s] Failed to get thumbnail height.", GetErrorMessage(E_FAILURE));
87
88     std::unique_ptr<Tizen::Base::ByteBuffer> pOutBuffer(new (std::nothrow) Tizen::Base::ByteBuffer());
89     SysSecureTryReturn(NID_UIX, pOutBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
90
91     result res = pOutBuffer->Construct(bufWidth * bufHeight);
92     SysSecureTryReturn(NID_UIX, res == E_SUCCESS, null, res, "[%s] Failed to construct ByteBuffer.", GetErrorMessage(res));
93
94     bool success = __pImageFeatureInfoImpl->GetThumbnail((char*)pOutBuffer->GetPointer(), bufWidth, bufHeight, false);
95     SysSecureTryReturn(NID_UIX, success == true, null, E_FAILURE, "[%s] Failed to get thumbnail.", GetErrorMessage(E_FAILURE));
96
97     return pOutBuffer.release();
98 }
99
100 bool
101 ImageFeatureInfo::Equals(const Object& obj) const
102 {
103     return (static_cast<const Object*>(this) == &obj);
104 }
105
106 int
107 ImageFeatureInfo::GetHashCode(void) const
108 {
109     return (int)__pImageFeatureInfoImpl;
110 }
111
112 } } } //Tizen::Uix::Vision
113