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