Remove dependency from CPlaybackView to CPlaybackController.
[profile/tv/apps/native/musicplayer.git] / src / playback / music-controller.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <string.h>
18 #include <stdlib.h>
19 #include <AppCommon.h>
20 #include "song_info.h"
21 #include "common.h"
22 #include "music-controller.h"
23 #include "MusicControllerImpl.h"
24
25
26 struct SMusicController {
27         static CMusicControllerImpl ref;
28         static int refCnt;
29 };
30
31
32 CMusicControllerImpl SMusicController::ref;
33 int SMusicController::refCnt = 0;
34
35
36 bool CMusicController::Create(void)
37 {
38         ASSERT(!m);
39
40         m = new SMusicController;
41         if (!m)
42                 return false;
43
44         if (m->refCnt == 0) {
45                 if (!m->ref.Create()) {
46                         delete m;
47                         m = NULL;
48                         return false;
49                 }
50         }
51         m->refCnt++;
52
53         return true;
54 }
55
56
57 void CMusicController::Destroy(void)
58 {
59         ASSERT(m);
60
61         m->refCnt--;
62         if (m->refCnt == 0) {
63                 m->ref.Destroy();
64         }
65         delete m;
66         m = NULL;
67 }
68
69
70 bool CMusicController::Start(void)
71 {
72         ASSERT(m);
73
74         return m->ref.Start();
75 }
76
77
78 bool CMusicController::Stop(void)
79 {
80         ASSERT(m);
81
82         return m->ref.Stop();
83 }
84
85
86 bool CMusicController::Resume(void)
87 {
88         ASSERT(m);
89
90         return m->ref.Resume();
91 }
92
93
94 bool CMusicController::Pause(void)
95 {
96         ASSERT(m);
97
98         return m->ref.Pause();
99 }
100
101
102 bool CMusicController::AddListener(IMusicControllerListener *listener)
103 {
104         ASSERT(m);
105
106         return m->ref.AddListener(listener);
107 }
108
109
110 bool CMusicController::RemoveListener(IMusicControllerListener *listener)
111 {
112         ASSERT(m);
113
114         return m->ref.RemoveListener(listener);
115 }
116
117
118 bool CMusicController::GetCurrentSongIndex(int *ind)
119 {
120         ASSERT(m);
121
122         return m->ref.GetCurrentSongIndex(ind);
123 }
124
125
126 bool CMusicController::GetTotalSongs(int *ts)
127 {
128         ASSERT(m);
129
130         return m->ref.GetTotalSongs(ts);
131 }
132
133
134 bool CMusicController::GetSonginfoFromIndex(int index, CSongInfo **const csinfo)
135 {
136         ASSERT(m);
137
138         return m->ref.GetSonginfoFromIndex(index, csinfo);
139 }
140
141
142 bool CMusicController::SetPosition(int milsec)
143 {
144         ASSERT(m);
145
146         return m->ref.SetPosition(milsec);
147 }
148
149
150 bool CMusicController::GetPosition(int *const milseconds)
151 {
152         ASSERT(m);
153
154         return m->ref.GetPosition(milseconds);
155 }
156
157
158 bool CMusicController::SetCurrentSong(char *mediaid)
159 {
160         ASSERT(m);
161
162         return m->ref.SetCurrentSong(mediaid);
163 }
164
165
166 bool CMusicController::GetCurrentSong(CSongInfo **const sinfo)
167 {
168         ASSERT(m);
169
170         return m->ref.GetCurrentSong(sinfo);
171 }
172
173
174 bool CMusicController::UpdatePlaylist(Eina_List *slist, int addmode)
175 {
176         ASSERT(m);
177
178         return m->ref.UpdatePlaylist(slist, addmode);
179 }
180
181
182 bool CMusicController::EmptyPlaylist(void)
183 {
184         ASSERT(m);
185
186         return m->ref.EmptyPlaylist();
187 }
188
189
190 bool CMusicController::PlayPreviousSong(void)
191 {
192         ASSERT(m);
193
194         return m->ref.PlayPreviousSong();
195 }
196
197
198 bool CMusicController::PlayNextSong(void)
199 {
200         ASSERT(m);
201
202         return m->ref.PlayNextSong();
203 }
204
205
206 bool CMusicController::PlayIndexSong(int index)
207 {
208         ASSERT(m);
209
210         return m->ref.PlayIndexSong(index);
211 }
212
213
214 bool CMusicController::RemoveSong(CSongInfo *sinfo, int index)
215 {
216         ASSERT(m);
217
218         return m->ref.RemoveSong(sinfo, index);
219 }
220
221
222 bool CMusicController::MediaGetList(int EListType, void *info, Eina_List **list)
223 {
224         ASSERT(m);
225
226         return m->ref.MediaGetList(EListType, info, list);
227 }
228
229
230 bool CMusicController::MediaInsertPlaylist(const char *name, Eina_List *idlist)
231 {
232         ASSERT(m);
233
234         return m->ref.MediaInsertPlaylist(name, idlist);
235 }
236
237
238 bool CMusicController::MediaExistPlaylist(const char *name)
239 {
240         ASSERT(m);
241
242         return m->ref.MediaExistPlaylist(name);
243 }
244
245
246 bool CMusicController::MediaDeletePlaylist(int id)
247 {
248         ASSERT(m);
249
250         return m->ref.MediaDeletePlaylist(id);
251 }
252
253
254 bool CMusicController::MediaRenamePlaylist(int id, const char *name)
255 {
256         ASSERT(m);
257
258         return m->ref.MediaRenamePlaylist(id, name);
259 }
260
261
262 bool CMusicController::MediaAddmediaPlaylist(int id, Eina_List *idlist)
263 {
264         ASSERT(m);
265
266         return m->ref.MediaAddmediaPlaylist(id, idlist);
267 }
268
269
270 bool CMusicController::MediaRemovemediaPlaylist(int id, Eina_List *idlist)
271 {
272         ASSERT(m);
273
274         return m->ref.MediaRemovemediaPlaylist(id, idlist);
275 }
276
277
278 bool CMusicController::MediaAddsongsPlaylist(int lid, Eina_List *list)
279 {
280         ASSERT(m);
281
282         return m->ref.MediaAddsongsPlaylist(lid, list);
283 }
284
285
286 CSongInfo *CMusicController::MediaSongByUri(char *uri)
287 {
288         ASSERT(m);
289
290         return m->ref.MediaSongByUri(uri);
291 }
292
293
294 bool CMusicController::SetPlayState(EPlayStatus state)
295 {
296         ASSERT(m);
297
298         return m->ref.SetPlayState(state);
299 }
300
301
302 EPlayStatus CMusicController::PlayState(void)
303 {
304         ASSERT(m);
305
306         return m->ref.PlayState();
307 }
308
309
310 bool CMusicController::SetShuffleState(EShuffleStatus state)
311 {
312         ASSERT(m);
313
314         return m->ref.SetShuffleState(state);
315 }
316
317
318 EShuffleStatus CMusicController::ShuffleState(void)
319 {
320         ASSERT(m);
321
322         return m->ref.ShuffleState();
323 }
324
325
326 bool CMusicController::SetRepeatState(ERepeatStatus state)
327 {
328         ASSERT(m);
329
330         return m->ref.SetRepeatState(state);
331 }
332
333
334 ERepeatStatus CMusicController::RepeatState(void)
335 {
336         ASSERT(m);
337
338         return m->ref.RepeatState();
339 }
340
341
342 void CMusicController::ChangePlayerMode(EPlayerMode mode)
343 {
344         ASSERT(m);
345
346         m->ref.ChangePlayerMode(mode);
347 }
348
349
350 void CMusicController::HandlePlaylistEditButtons(EPlayerEditBtns editBtn)
351 {
352         ASSERT(m);
353
354         m->ref.HandlePlaylistEditButtons(editBtn);
355 }
356
357
358 void CMusicController::HandleRemoteButtons(Evas_Object *eoBtn, EPlayerBtnsEvent ev)
359 {
360         ASSERT(m);
361
362         m->ref.HandleRemoteButtons(eoBtn, ev);
363 }
364
365
366 void CMusicController::UpdatePlayerUI(void)
367 {
368         ASSERT(m);
369
370         m->ref.UpdatePlayerUI();
371 }