|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: mp engine factory. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mpengine.h" |
|
19 #include "mpenginefactory.h" |
|
20 #include "mptrace.h" |
|
21 |
|
22 /*! |
|
23 \class MpEngineFactory |
|
24 \brief Music Player engine factory. |
|
25 |
|
26 MP Engine factory is responsible to create and mantain ownership of MP engines. |
|
27 */ |
|
28 |
|
29 /*! |
|
30 Constructs music player engine factory. |
|
31 */ |
|
32 MpEngineFactory::MpEngineFactory() |
|
33 : mSharedEngine( 0 ) |
|
34 { |
|
35 TX_LOG |
|
36 } |
|
37 |
|
38 /*! |
|
39 Destructs music player engine factory. |
|
40 */ |
|
41 MpEngineFactory::~MpEngineFactory() |
|
42 { |
|
43 } |
|
44 |
|
45 /*! |
|
46 Returns the singleton instance of music player engine factory. |
|
47 */ |
|
48 MpEngineFactory * MpEngineFactory::instance() |
|
49 { |
|
50 static MpEngineFactory instance; |
|
51 return &instance; |
|
52 } |
|
53 |
|
54 /*! |
|
55 Returns an instance to an engine with \a hostUid, and \a mode, if the shared engine is |
|
56 already created parameters are ignored. |
|
57 */ |
|
58 MpEngine *MpEngineFactory::createSharedEngine( TUid hostUid , MpEngine::EngineMode mode ) |
|
59 { |
|
60 if ( !instance()->mSharedEngine ) { |
|
61 instance()->mSharedEngine = new MpEngine(); |
|
62 instance()->mSharedEngine->initialize( hostUid, mode ); |
|
63 } |
|
64 return instance()->mSharedEngine; |
|
65 } |
|
66 |
|
67 /*! |
|
68 Returns an instance to an isolated engine with \a mode. |
|
69 */ |
|
70 MpEngine *MpEngineFactory::createIsolatedEngine( MpEngine::EngineMode mode ) |
|
71 { |
|
72 instance()->mEngines.append( new MpEngine() ); |
|
73 instance()->mEngines.last()->initialize( TUid::Uid( MpCommon::KMusicPlayerUid + instance()->mEngines.count() ), mode ); |
|
74 return instance()->mEngines.last(); |
|
75 } |
|
76 |
|
77 /*! |
|
78 Returns an instance to the current shared engine previously created with createEngine(). |
|
79 */ |
|
80 MpEngine *MpEngineFactory::sharedEngine() |
|
81 { |
|
82 return instance()->mSharedEngine; |
|
83 } |
|
84 |
|
85 /*! |
|
86 Closes all engines created on this process. |
|
87 */ |
|
88 void MpEngineFactory::close() |
|
89 { |
|
90 if ( instance()->mSharedEngine ) { |
|
91 delete instance()->mSharedEngine; |
|
92 instance()->mSharedEngine = 0; |
|
93 |
|
94 } |
|
95 MpEngine *ptr; |
|
96 foreach ( ptr, instance()->mEngines ) { |
|
97 delete ptr; |
|
98 ptr = 0; |
|
99 } |
|
100 } |