1 /** @file |
|
2 * Copyright (c) 2005-2006 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: CUpnpAVCPEngineSession |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpavcpenginesession.h" |
|
21 #include "upnpavcpmanager.h" |
|
22 #include "upnpavcontrolpoint.h" |
|
23 #include "upnpcommand.h" |
|
24 |
|
25 |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CUpnpAVCPEngineSession::CContentControlSession |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CUpnpAVCPEngineSession::CUpnpAVCPEngineSession( const RThread& /*aClient*/, |
|
36 CUpnpAVCPEngine& aAVCPEngine, |
|
37 CUpnpAVCPManager& aManager) |
|
38 : CSession2(), |
|
39 iAVCPEngine( aAVCPEngine ), |
|
40 iAVCPManager( aManager ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CUpnpAVCPEngineSession::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CUpnpAVCPEngineSession::ConstructL() |
|
50 { |
|
51 iAVCPEngine.IncrementSessions(this); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CUpnpAVCPEngineSession::~CUpnpAVCPEngineSession |
|
56 // Destructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CUpnpAVCPEngineSession::~CUpnpAVCPEngineSession() |
|
60 { |
|
61 iAVCPEngine.DecrementSessions(this); |
|
62 iCommandList.ResetAndDestroy(); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CUpnpAVCPEngineSession::ServiceL |
|
67 // Handle client requests. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CUpnpAVCPEngineSession::ServiceL( const RMessage2& aMessage ) |
|
71 { |
|
72 TInt index = KErrNotFound; |
|
73 switch ( aMessage.Function() ) |
|
74 { |
|
75 // getting result from previous invoked command |
|
76 case EDownloadDeviceList: |
|
77 case EDownloadDirList: |
|
78 case EDownloadMetadata: |
|
79 DEBUGSTRING(("Command for results with id %d", aMessage.Int0())); |
|
80 index = CommandById(aMessage.Int0()); |
|
81 |
|
82 if (index != KErrNotFound) |
|
83 { |
|
84 CUpnpCommand* resultCommand = iCommandList[index]; |
|
85 CleanupStack::PushL(resultCommand); |
|
86 resultCommand->SetResultL(aMessage); |
|
87 CleanupStack::PopAndDestroy(resultCommand); |
|
88 aMessage.Complete(KErrNone); |
|
89 } |
|
90 else |
|
91 { |
|
92 DEBUGSTRING(("Results not found %d", aMessage.Int0())); |
|
93 aMessage.Complete(KErrNotFound); |
|
94 } |
|
95 break; |
|
96 // all else commands |
|
97 default: |
|
98 CUpnpCommand* command = CUpnpCommand::NewL(iAVCPManager, *this, aMessage); |
|
99 if (command) |
|
100 { |
|
101 iCommandList.AppendL(command); |
|
102 CleanupStack::PushL(command); |
|
103 command->ExecuteL(); |
|
104 CleanupStack::Pop(command); // it will be destroyed after completion |
|
105 } |
|
106 else |
|
107 { |
|
108 PanicClient( aMessage, EAVCPEngineBadRequest ); |
|
109 } |
|
110 break; |
|
111 } |
|
112 |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CUpnpAVCPEngineSession::RemoveCommand |
|
117 // remove command |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CUpnpAVCPEngineSession::RemoveCommand(CUpnpCommand* aCommand) |
|
121 { |
|
122 TInt index = iCommandList.Find(aCommand); |
|
123 if (index != KErrNotFound) |
|
124 { |
|
125 DEBUGSTRING8(("CUpnpAVCPEngineSession::RemoveCommand with index %d", index)); |
|
126 iCommandList.Remove(index); |
|
127 } |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CUpnpAVCPEngineSession::CommandById |
|
132 // Index of command with given id |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 TInt CUpnpAVCPEngineSession::CommandById(TInt aId) |
|
136 { |
|
137 TInt i = KErrNotFound; |
|
138 |
|
139 for ( i=0; i < iCommandList.Count() && iCommandList[i]->Id() != aId; i++ ) |
|
140 {} |
|
141 |
|
142 if ( i != iCommandList.Count() ) |
|
143 { |
|
144 return i; |
|
145 } |
|
146 return KErrNotFound; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CUpnpAVCPEngineSession::PanicClient |
|
151 // Panic client |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CUpnpAVCPEngineSession::PanicClient( const RMessage2 &aMessage, TInt aPanic ) const |
|
155 { |
|
156 aMessage.Panic( KAVCPEngine, aPanic ) ; // Note: this panics the client thread, not server |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CUpnpAVCPEngineSession::NewL |
|
161 // Two-phased constructor. |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 CUpnpAVCPEngineSession* CUpnpAVCPEngineSession::NewL( |
|
165 const RThread& aClient, |
|
166 CUpnpAVCPEngine& aServer, |
|
167 CUpnpAVCPManager& aManager ) |
|
168 { |
|
169 CUpnpAVCPEngineSession* self = new (ELeave) CUpnpAVCPEngineSession( |
|
170 aClient, aServer, aManager); |
|
171 CleanupStack::PushL( self ); |
|
172 self->ConstructL() ; |
|
173 CleanupStack::Pop( self ) ; |
|
174 return self ; |
|
175 } |
|
176 |
|
177 |
|
178 // End of File |
|