Fix : The original content is restored again if CreateContent API fail
[platform/framework/native/content.git] / src / FCntImageContentInfo.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FCntImageContentInfo.cpp
18  * @brief               This is the implementation file for the %ImageContentInfo class.
19  *
20  * This file contains implementation of the %ImageContentInfo class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntImageContentInfo.h>
25 #include "FCnt_ImageContentInfoImpl.h"
26 #include "FCnt_ContentInfoHelper.h"
27
28 using namespace Tizen::Base;
29
30 namespace Tizen { namespace Content
31 {
32
33 ImageContentInfo::ImageContentInfo(void)
34         : __pImageContentData(null)
35         , __pImageContentInfoImpl(null)
36 {
37
38 }
39
40 ImageContentInfo::~ImageContentInfo(void)
41 {
42         delete __pImageContentInfoImpl;
43 }
44
45 result
46 ImageContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
47 {
48         result r = E_SUCCESS;
49
50         SysAssertf(__pImageContentInfoImpl == null || __pImageContentInfoImpl->IsReconstructable(),
51                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52
53         _ImageContentInfoImpl* pImageContentInfoImpl = new (std::nothrow) _ImageContentInfoImpl();
54         SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
55
56         r = pImageContentInfoImpl->Construct(contentPath, thumbnailPath, setGps);
57         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
58
59         _ContentInfoHelper::SetContentInfoImpl(this, pImageContentInfoImpl);
60
61         delete __pImageContentInfoImpl;
62         __pImageContentInfoImpl = pImageContentInfoImpl;
63
64         if (r == E_FILE_NOT_FOUND)
65         {
66                 __pImageContentInfoImpl->SetReconstructable(true);
67         }
68         else
69         {
70                 __pImageContentInfoImpl->SetReconstructable(false);
71         }
72
73         return r;
74
75 CATCH:
76         delete pImageContentInfoImpl;
77
78         return r;
79 }
80
81 result
82 ImageContentInfo::Construct(const String* pContentPath)
83 {
84         result r = E_SUCCESS;
85
86         SysAssertf(__pImageContentInfoImpl == null || __pImageContentInfoImpl->IsReconstructable(),
87                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
88
89         _ImageContentInfoImpl* pImageContentInfoImpl = new (std::nothrow) _ImageContentInfoImpl();
90         SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
91
92         r = pImageContentInfoImpl->Construct(pContentPath);
93         SysTryCatch(NID_CNT, r == E_SUCCESS || r == E_FILE_NOT_FOUND, , r, "[%s] Propagating.", GetErrorMessage(r));
94
95         _ContentInfoHelper::SetContentInfoImpl(this, pImageContentInfoImpl);
96
97         delete __pImageContentInfoImpl;
98         __pImageContentInfoImpl = pImageContentInfoImpl;
99
100         if (r == E_FILE_NOT_FOUND)
101         {
102                 __pImageContentInfoImpl->SetReconstructable(true);
103         }
104         else
105         {
106                 __pImageContentInfoImpl->SetReconstructable(false);
107         }
108
109         return r;
110
111 CATCH:
112         delete pImageContentInfoImpl;
113
114         return r;
115 }
116
117 int
118 ImageContentInfo::GetWidth(void) const
119 {
120         SysAssertf(__pImageContentInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
121
122         return __pImageContentInfoImpl->GetWidth();
123 }
124
125 int
126 ImageContentInfo::GetHeight(void) const
127 {
128         SysAssertf(__pImageContentInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
129
130         return __pImageContentInfoImpl->GetHeight();
131 }
132
133 ImageOrientationType
134 ImageContentInfo::GetOrientation(void) const
135 {
136         SysAssertf(__pImageContentInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
137
138         return __pImageContentInfoImpl->GetOrientation();
139 }
140
141 String
142 ImageContentInfo::GetTitle(void) const
143 {
144         SysAssertf(__pImageContentInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
145
146         return __pImageContentInfoImpl->GetTitle();
147 }
148
149 }}