Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCntPlayListManager.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                FCntPlayListManager.cpp
18  * @brief               This is the implementation file for the %PlayListManager class.
19  *
20  * This is the implementation file for %PlayListManager class.
21  */
22
23 #include <memory>
24 #include <pthread.h>
25 #include <stdlib.h>
26 #include <FBaseSysLog.h>
27 #include <FCntPlayListManager.h>
28 #include <FBaseColIList.h>
29 #include <FIoFile.h>
30 #include <FSysEnvironment.h>
31 #include <FCnt_PlayListManagerImpl.h>
32
33 using namespace Tizen::Io;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::System;
37
38 namespace Tizen { namespace Content
39 {
40
41 PlayListManager* PlayListManager::__pPlayListManager = NULL;
42
43 PlayListManager::PlayListManager(void)
44         : Object()
45         , __pImpl(null)
46 {
47 }
48
49 PlayListManager::~PlayListManager(void)
50 {
51         delete __pImpl;
52 }
53
54 PlayListManager*
55 PlayListManager::GetInstance(void)
56 {
57         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
58
59         if (!__pPlayListManager)
60         {
61                 ClearLastResult();
62                 pthread_once(&onceBlock, InitSingleton);
63                 result r = GetLastResult();
64                 if (IsFailed(r))
65                 {
66                      onceBlock = PTHREAD_ONCE_INIT;
67                 }
68         }
69         return __pPlayListManager;
70 }
71
72 void
73 PlayListManager::InitSingleton(void)
74 {
75         __pPlayListManager = new (std::nothrow) PlayListManager();
76         SysTryReturnVoidResult(NID_CNT, __pPlayListManager, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
77
78         result r = __pPlayListManager->Construct();
79         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating from PlayListManager Construct.", GetErrorMessage(r));
80
81         atexit(DestroySingleton);
82
83         return;
84
85 CATCH:
86         delete __pPlayListManager;
87 }
88
89 void
90 PlayListManager::DestroySingleton(void)
91 {
92         delete __pPlayListManager;
93 }
94
95 result
96 PlayListManager::Construct(void)
97 {
98         result r = E_SUCCESS;
99
100         SysAssertf(__pImpl == null,
101                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
102
103         _PlayListManagerImpl* pPlayListManagerImpl = new (std::nothrow) _PlayListManagerImpl();
104         SysTryReturn(NID_CNT, pPlayListManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
105
106         r = pPlayListManagerImpl->Construct();
107         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
108
109         __pImpl = pPlayListManagerImpl;
110
111         return E_SUCCESS;
112
113 CATCH:
114         delete pPlayListManagerImpl;
115         return r;
116 }
117
118 PlayList*
119 PlayListManager::GetPlayListN(const Tizen::Base::String& playListName) const
120 {
121         ClearLastResult();
122
123         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
124
125         SysTryReturn(NID_CNT, !playListName.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The playListName is empty.");
126
127         return __pImpl->GetPlayListN(playListName);
128 }
129
130 result
131 PlayListManager::RemovePlayList(const Tizen::Base::String& playListName)
132 {
133         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
134
135         SysTryReturn(NID_CNT, !playListName.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The playListName is empty.");
136
137         return __pImpl->RemovePlayList(playListName);
138 }
139
140 int
141 PlayListManager::GetAllPlayListCount(void) const
142 {
143         ClearLastResult();
144
145         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
146
147         return __pImpl->GetAllPlayListCount();
148 }
149
150 Tizen::Base::Collection::IList*
151 PlayListManager::GetAllPlayListNameN(void) const
152 {
153         ClearLastResult();
154
155         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
156
157         return __pImpl->GetAllPlayListNameN();
158 }
159
160 }}