|
1 /* |
|
2 * Copyright (c) 2002-2005,2007 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: Client interface of the phone ringing tone server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32std.h> |
|
22 #include <e32svr.h> |
|
23 |
|
24 #include "rphonetoneclient.h" |
|
25 #include "cphonetoneserver.h" |
|
26 #include "tphonecmdparamringtone.h" |
|
27 #include "phoneringingtonetrace.h" |
|
28 |
|
29 // LOCAL FUNCTION PROTOTYPES |
|
30 static TInt StartServer(); |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // RPhoneToneClient::RPhoneToneClient |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C RPhoneToneClient::RPhoneToneClient() : RSessionBase() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // RPhoneToneClient::~RPhoneToneClient |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C RPhoneToneClient::~RPhoneToneClient() |
|
45 { |
|
46 Close(); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // RPhoneToneClient::Connect |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C TInt RPhoneToneClient::Connect() |
|
54 { |
|
55 PHONERINGINGTONE_PRINT("RPhoneToneClient::Connect <"); |
|
56 |
|
57 TBool reConnect( EFalse ); |
|
58 |
|
59 TInt err = CreateSession( KRingingToneServerName, |
|
60 TVersion( KRingingToneSrvVersionMajor, |
|
61 KRingingToneSrvVersionMinor, |
|
62 KRingingToneSrvVersionBuild ) ); |
|
63 |
|
64 if ( KErrNotFound == err ) |
|
65 { |
|
66 err = StartServer(); |
|
67 |
|
68 if ( !err ) |
|
69 { |
|
70 reConnect = ETrue; |
|
71 } |
|
72 } |
|
73 |
|
74 if ( reConnect ) |
|
75 { |
|
76 err = CreateSession( KRingingToneServerName, |
|
77 TVersion( KRingingToneSrvVersionMajor, |
|
78 KRingingToneSrvVersionMinor, |
|
79 KRingingToneSrvVersionBuild ) ); |
|
80 } |
|
81 |
|
82 PHONERINGINGTONE_PRINTF("RPhoneToneClient::Connect - err(%d)", err); |
|
83 PHONERINGINGTONE_PRINT("RPhoneToneClient::Connect >"); |
|
84 return err; |
|
85 |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // StartServer |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt StartServer() |
|
93 { |
|
94 PHONERINGINGTONE_PRINT("RPhoneToneClient - StartServer <"); |
|
95 // Form thread name |
|
96 TTime time; |
|
97 time.UniversalTime(); |
|
98 |
|
99 TFullName threadName; |
|
100 threadName.Format( _L("PhoneRingingToneThread%Ld"), time.Int64() ); |
|
101 |
|
102 // Create thread |
|
103 RThread thread; |
|
104 TInt err = thread.Create( threadName, |
|
105 CPhoneToneServer::ThreadEntryFunc, |
|
106 0x8000, |
|
107 NULL, |
|
108 NULL ); |
|
109 |
|
110 PHONERINGINGTONE_PRINTF("RPhoneToneClient - StartServer - err(%d)", err); |
|
111 if ( err ) |
|
112 { |
|
113 thread.Close(); |
|
114 return err; |
|
115 } |
|
116 |
|
117 thread.SetPriority( EPriorityAbsoluteHigh ); |
|
118 TRequestStatus status; |
|
119 thread.Rendezvous( status ); |
|
120 |
|
121 thread.Resume(); |
|
122 |
|
123 // Wait for thread start or death |
|
124 User::WaitForRequest( status ); |
|
125 thread.Close(); |
|
126 PHONERINGINGTONE_PRINT("RPhoneToneClient - StartServer >"); |
|
127 return status.Int(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // RPhoneToneClient::PlayRingingToneL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C void RPhoneToneClient::PlayRingingToneL( TPhoneCommandParam *aCommandParam ) |
|
135 { |
|
136 PHONERINGINGTONE_PRINT("RPhoneToneClient::PlayRingingToneL <"); |
|
137 |
|
138 if ( aCommandParam->ParamId() == TPhoneCommandParam::EPhoneParamIdRingTone ) |
|
139 { |
|
140 TPhoneCmdParamRingTone* ringToneParam = |
|
141 static_cast<TPhoneCmdParamRingTone*>( aCommandParam ); |
|
142 |
|
143 TIpcArgs args( &( ringToneParam->RingTone() ), |
|
144 ringToneParam->Volume(), |
|
145 ringToneParam->RingingType() ); |
|
146 User::LeaveIfError( SendReceive( EPlayAudioRingTone, args ) ); |
|
147 } |
|
148 PHONERINGINGTONE_PRINT("RPhoneToneClient::PlayRingingToneL >"); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // RPhoneToneClient::StopPlaying |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void RPhoneToneClient::StopPlayingL() |
|
156 { |
|
157 PHONERINGINGTONE_PRINT("RPhoneToneClient::StopPlayingL <"); |
|
158 User::LeaveIfError( SendReceive( EStopPlaying ) ); |
|
159 PHONERINGINGTONE_PRINT("RPhoneToneClient::StopPlayingL >"); |
|
160 } |
|
161 |
|
162 // End of file |