Internal issue Fixes
[apps/osp/Camera.git] / src / CmCameraStarterThread.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file                CmCameraStarterThread.cpp
19  * @brief               This is the implementation file for CameraStarterThread class.
20  */
21
22 #include <cstdlib>
23 #include <FApp.h>
24 #include <FContent.h>
25 #include "CmCameraPresentationModel.h"
26 #include "CmCameraStarterThread.h"
27 #include "CmTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33 CameraStarterThread* CameraStarterThread::__pCameraStarterThread = null;
34
35 CameraStarterThread::CameraStarterThread(void)
36         : __pBufferInfo(null)
37 {
38         AppLogDebug("ENTER");
39         AppLogDebug("EXIT");
40 }
41
42 CameraStarterThread::~CameraStarterThread(void)
43 {
44         AppLogDebug("ENTER");
45         if (__pBufferInfo != null)
46         {
47                 __pBufferInfo = null;
48         }
49         AppLogDebug("EXIT");
50 }
51
52 CameraStarterThread*
53 CameraStarterThread::GetInstance(void)
54 {
55         AppLogDebug("ENTER");
56         if (__pCameraStarterThread == null)
57         {
58                 CreateInstance();
59         }
60         AppLogDebug("EXIT");
61         return __pCameraStarterThread;
62 }
63
64 result
65 CameraStarterThread::CreateInstance(void)
66 {
67         AppLogDebug("ENTER");
68         __pCameraStarterThread = new (std::nothrow) CameraStarterThread();
69
70         result r = __pCameraStarterThread->Construct();
71         if (IsFailed(r))
72         {
73                 AppLogDebug("IsFailed");
74                 __pCameraStarterThread->Stop();
75                 __pCameraStarterThread->Join();
76                 delete __pCameraStarterThread;
77                 __pCameraStarterThread = null;
78                 return r;
79         }
80
81         //std::atexit(DestroyInstance);
82         AppLogDebug("EXIT");
83         return E_SUCCESS;
84 }
85
86 void
87 CameraStarterThread::DestroyInstance(void)
88 {
89         AppLogDebug("ENTER");
90
91         __pCameraStarterThread->Stop();
92         __pCameraStarterThread->Join();
93         delete __pCameraStarterThread;
94         __pCameraStarterThread = null;
95         AppLogDebug("EXIT");
96 }
97
98 void
99 CameraStarterThread::DestroyCameraStarterThreadInstance(void)
100 {
101         AppLogDebug("ENTER");
102         CameraStarterThread* pCameraStarterThread = CameraStarterThread::GetInstance();
103
104         if (pCameraStarterThread)
105         {
106                 delete pCameraStarterThread;
107         }
108         AppLogDebug("EXIT");
109 }
110
111 result
112 CameraStarterThread::Construct(void)
113 {
114         AppLogDebug("ENTER");
115         AppLogDebug("EXIT");
116         return Thread::Construct();
117 }
118
119 result
120 CameraStarterThread::SetBufferinfo(Tizen::Graphics::BufferInfo* bufferinfo)
121 {
122         AppLogDebug("ENTER");
123         __pBufferInfo = bufferinfo;
124
125         if (__pBufferInfo == null)
126         {
127                 AppLogDebug("SetBufferinfo is __pBufferInfo is null");
128                 return E_FAILURE;
129         }
130         AppLogDebug("EXIT");
131         return E_SUCCESS;
132 }
133
134 bool
135 CameraStarterThread::OnStart(void)
136 {
137         return true;
138 }
139
140 void
141 CameraStarterThread::OnStop(void)
142 {
143         //empty implementation
144 }
145
146 Object*
147 CameraStarterThread::Run(void)
148 {
149         AppLogDebug("ENTER");
150         if (__pBufferInfo)
151         {
152                 AppLogDebug("Run::StartPreview");
153                 CameraPresentationModel* pCameraPresentationModel = CameraPresentationModel::GetInstance();
154
155                 if (pCameraPresentationModel->IsCameraInstance())
156                 {
157                         pCameraPresentationModel->StartPreview(__pBufferInfo);
158                 }
159         }
160
161         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
162         return null;
163 }