|
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: Media Server event handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpmediaservereventhandler.h" |
|
21 #include "upnpmediaserversession.h" |
|
22 #include "upnpfiletransfereventlist.h" |
|
23 #include "upnpfiletransferevent.h" |
|
24 #include "upnpmediaserver.pan" |
|
25 #include <s32mem.h> |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CUpnpMediaServerEventHandler::NewL |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CUpnpMediaServerEventHandler* CUpnpMediaServerEventHandler::NewL(CUpnpMediaServer* aServer) |
|
33 { |
|
34 CUpnpMediaServerEventHandler* self = CUpnpMediaServerEventHandler::NewLC(aServer); |
|
35 CleanupStack::Pop( self ) ; |
|
36 return self ; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CUpnpMediaServerEventHandler::NewLC |
|
41 // Two-phased constructor. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CUpnpMediaServerEventHandler* CUpnpMediaServerEventHandler::NewLC(CUpnpMediaServer* aServer) |
|
45 { |
|
46 CUpnpMediaServerEventHandler* self = new (ELeave) CUpnpMediaServerEventHandler(aServer); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL() ; |
|
49 return self ; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CUpnpMediaServerEventHandler::EventMediaServerSubscribeEventsL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CUpnpMediaServerEventHandler::EventMediaServerSubscribeEvents( const RMessage2& aMessage ) |
|
58 { |
|
59 iMediaServer->SubscribeEvents(this); |
|
60 aMessage.Complete( KErrNone ); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CUpnpMediaServerEventHandler::EventMediaServerUnsubscribeEventsL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CUpnpMediaServerEventHandler::EventMediaServerUnsubscribeEvents( const RMessage2& aMessage ) |
|
69 { |
|
70 if ( iListenRequestPending ) |
|
71 { |
|
72 iCurrentMessage.Complete( KErrNone ); |
|
73 } |
|
74 iMediaServer->UnsubscribeEvents(this); |
|
75 aMessage.Complete( KErrNone ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CUpnpMediaServerEventHandler::EventMediaServerServerListenTransferEventL |
|
80 // Serves event listening request |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CUpnpMediaServerEventHandler::EventMediaServerServerListenTransferEventL( const RMessage2& aMessage ) |
|
84 { |
|
85 iCurrentMessage = aMessage; |
|
86 |
|
87 if ( iFileTransferEventList->GetPointerArray().Count() > 0 ) |
|
88 { |
|
89 ListenTransferEventCompleteL(); |
|
90 } |
|
91 else |
|
92 { |
|
93 iListenRequestPending = ETrue; |
|
94 } |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CUpnpMediaServerEventHandler::EventMediaServerGetTransferEventBodyL |
|
99 // Sends event list body to client |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CUpnpMediaServerEventHandler::EventMediaServerGetTransferEventBodyL( const RMessage2& aMessage ) |
|
103 { |
|
104 aMessage.WriteL(0, *iResponseBuffer); |
|
105 aMessage.Complete( KErrNone ); |
|
106 delete iResponseBuffer; |
|
107 iResponseBuffer = NULL; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CUpnpMediaServerEventHandler::CUpnpMediaServerEventHandler |
|
112 // Constructor. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CUpnpMediaServerEventHandler::CUpnpMediaServerEventHandler(CUpnpMediaServer* aServer) |
|
116 :iMediaServer(aServer), iRespLengthPkg(iRespLength) |
|
117 { |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CUpnpMediaServerEventHandler::~CUpnpMediaServerEventHandler() |
|
123 // Destructor. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CUpnpMediaServerEventHandler::~CUpnpMediaServerEventHandler() |
|
127 { |
|
128 if(iMediaServer) |
|
129 { |
|
130 iMediaServer->UnsubscribeEvents(this); |
|
131 } |
|
132 delete iResponseBuffer; |
|
133 delete iFileTransferEventList; |
|
134 } |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CUpnpMediaServerSession::ConstructL |
|
139 // Symbian 2nd phase constructor can leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CUpnpMediaServerEventHandler::ConstructL() |
|
143 { |
|
144 iFileTransferEventList = CUpnpFileTransferEventList::NewL(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CUpnpMediaServerEventHandler::FileTransferEvent |
|
149 // File transfer event callback method.(from MUpnpContentDirectoryObserver) |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CUpnpMediaServerEventHandler::FileTransferEvent( CUpnpFileTransferEvent *aEvent ) |
|
153 { |
|
154 TRAP_IGNORE( ServeEventL( aEvent ) ); |
|
155 } |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CUpnpMediaServerEventHandler::ServeEventL |
|
160 // Serves incoming transfer event |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CUpnpMediaServerEventHandler::ServeEventL(CUpnpFileTransferEvent *aEvent) |
|
164 { |
|
165 iFileTransferEventList->GetPointerArray().AppendL( aEvent->CloneL() ); |
|
166 if (iListenRequestPending) |
|
167 { |
|
168 ListenTransferEventCompleteL(); |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CUpnpMediaServerEventHandler::ListenTransferEventCompleteL |
|
174 // Serialize events queue and sends buffer length to client |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CUpnpMediaServerEventHandler::ListenTransferEventCompleteL() |
|
178 { |
|
179 iResponseBuffer = iFileTransferEventList->ToDes8L(); |
|
180 iFileTransferEventList->GetPointerArray().ResetAndDestroy(); |
|
181 iRespLength = iResponseBuffer->Des().Size(); |
|
182 iCurrentMessage.WriteL(0, iRespLengthPkg); |
|
183 iCurrentMessage.Complete( KErrNone ); |
|
184 iListenRequestPending = EFalse; |
|
185 } |
|
186 |
|
187 |
|
188 |
|
189 |