|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * This file provides the implementation of System Tone Service used |
|
16 * by the STS Server. |
|
17 */ |
|
18 |
|
19 #include "sts.h" |
|
20 |
|
21 /*static*/CSts* CSts::Create() |
|
22 { |
|
23 CSts* self = new CSts(); |
|
24 if (self != 0) |
|
25 { |
|
26 bool successful = self->Init(); |
|
27 if (!successful) |
|
28 { |
|
29 delete self; |
|
30 self = 0; |
|
31 } |
|
32 } |
|
33 return self; |
|
34 } |
|
35 |
|
36 /*static*/void CSts::Delete(CSts* aSts) |
|
37 { |
|
38 delete aSts; |
|
39 } |
|
40 |
|
41 CSts::CSts() : |
|
42 iNextContext(1) |
|
43 { |
|
44 } |
|
45 |
|
46 bool CSts::Init() |
|
47 { |
|
48 return true; |
|
49 } |
|
50 |
|
51 CSts::~CSts() |
|
52 { |
|
53 CleanUpPlayers(); |
|
54 } |
|
55 |
|
56 void CSts::PlayTone(CSystemToneService::TToneType aToneType, |
|
57 unsigned int& aPlayToneContext) |
|
58 { |
|
59 CStsPlayer* player = CStsPlayer::Create(*this, aToneType, iNextContext); |
|
60 if (player != 0) |
|
61 { |
|
62 iMap[iNextContext] = player; |
|
63 aPlayToneContext = iNextContext; |
|
64 iNextContext++; |
|
65 player->Play(); |
|
66 } |
|
67 else |
|
68 { |
|
69 aPlayToneContext = 0; |
|
70 } |
|
71 } |
|
72 |
|
73 void CSts::StopTone(unsigned int aPlayToneContext) |
|
74 { |
|
75 CStsPlayer* player = iMap[aPlayToneContext]; |
|
76 if (player) |
|
77 { |
|
78 player->Stop(); |
|
79 PlayToneComplete(aPlayToneContext); |
|
80 } |
|
81 } |
|
82 |
|
83 void CSts::CleanUpPlayers() |
|
84 { |
|
85 for (TPlayerMap::iterator i = iMap.begin(); i != iMap.end(); i++) |
|
86 { |
|
87 StopTone(i->first); |
|
88 } |
|
89 } |
|
90 |
|
91 void CSts::PlayToneComplete(unsigned int aPlayToneContext) |
|
92 { |
|
93 CStsPlayer* player = iMap[aPlayToneContext]; |
|
94 iMap[aPlayToneContext] = 0; |
|
95 if (player) |
|
96 { |
|
97 delete player; |
|
98 } |
|
99 } |