|
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: Push transport server |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef UPNPPUSHSERVER_H |
|
19 #define UPNPPUSHSERVER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <e32hashtab.h> |
|
24 |
|
25 #include <upnphttpservertransactioncreator.h> |
|
26 #include <upnphttpserverobserver.h> |
|
27 #include "upnpcontentdirectorydatafinder.h" |
|
28 |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CUpnpItem; |
|
32 class CUpnpHttpServerSession; |
|
33 class CUpnpElement; |
|
34 class CUpnpDlnaFilter; |
|
35 class CUpnpDlnaProtocolInfo; |
|
36 |
|
37 // CONSTANTS |
|
38 const TInt KPushServerPort = 58186; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 |
|
42 /** |
|
43 * Push controller server. A singleton class that instantiates itself whenever |
|
44 * something is shared using the static "ShareL" methods. And as the last item |
|
45 * is unshared, the singleton is destroyed. |
|
46 * |
|
47 * @lib pushtransportserver |
|
48 */ |
|
49 NONSHARABLE_CLASS( CUpnpPushServer) |
|
50 : public CBase |
|
51 , public MUpnpHttpServerTransactionCreator |
|
52 , public MUpnpHttpServerObserver |
|
53 , public MUpnpContentDirectoryDataFinder |
|
54 { |
|
55 |
|
56 public: // the api |
|
57 |
|
58 /** |
|
59 * Share an item to the push transport server. |
|
60 * All the resources within the item become shared. |
|
61 * The given hash should be unique within the process. |
|
62 * It can be used to unshare. |
|
63 * |
|
64 * @param aHash, TUint (usualy instance of the class using this functionality) |
|
65 * @param aItem, upnpitem |
|
66 */ |
|
67 IMPORT_C static void ShareL( |
|
68 TUint aHash, |
|
69 CUpnpItem& aItem ); |
|
70 |
|
71 /** |
|
72 * Unshare an item identified by the hash. |
|
73 * |
|
74 * @param aHash, TUint (usualy instance of the class using this functionality) |
|
75 */ |
|
76 IMPORT_C static void UnshareL( |
|
77 TUint aHash ); |
|
78 |
|
79 /** |
|
80 * Unshare all items |
|
81 */ |
|
82 IMPORT_C static void UnshareAllL(); |
|
83 |
|
84 /** |
|
85 * Returns true if server is running |
|
86 */ |
|
87 IMPORT_C static TBool IsRunning(); |
|
88 |
|
89 private: // internal construction/destruction |
|
90 |
|
91 /** |
|
92 * default constructor |
|
93 */ |
|
94 CUpnpPushServer(); |
|
95 |
|
96 /** |
|
97 * 2nd phase constructor |
|
98 */ |
|
99 void ConstructL(); |
|
100 |
|
101 /** |
|
102 * destructor |
|
103 */ |
|
104 ~CUpnpPushServer(); |
|
105 |
|
106 private: // MUpnpHttpServerTransactionCreator |
|
107 |
|
108 /** |
|
109 * see MUpnpHttpServerTransactionCreator |
|
110 */ |
|
111 void NewTransactionL( const TDesC8& aMethod, |
|
112 const TDesC8& aUri, const TInetAddr& aSender, |
|
113 CUpnpHttpServerTransaction*& aTrans ); |
|
114 |
|
115 private: // MUpnpHttpServerObserver |
|
116 |
|
117 /** |
|
118 * see MUpnpHttpServerObserver |
|
119 */ |
|
120 void HttpEventLD( CUpnpHttpMessage* aMessage ); |
|
121 |
|
122 private: // MUpnpContentDirectoryDataFinder |
|
123 |
|
124 /** |
|
125 * see MUpnpContentDirectoryDataFinder |
|
126 */ |
|
127 TInt CheckImportUriL( const TDesC8& aImportUri ); |
|
128 |
|
129 /** |
|
130 * see MUpnpContentDirectoryDataFinder |
|
131 */ |
|
132 void GetTitleForUriL( TInt aObjectId, TPtr& aValue ); |
|
133 |
|
134 /** |
|
135 * see MUpnpContentDirectoryDataFinder |
|
136 */ |
|
137 TInt GetProtocolInfoL( const TDesC8& aContentUri, |
|
138 CUpnpDlnaProtocolInfo*& aProtocolInfo ); |
|
139 |
|
140 /** |
|
141 * see MUpnpContentDirectoryDataFinder |
|
142 */ |
|
143 TInt FindSharedFolderL( const TDesC& aUrlPath, |
|
144 const TDesC& aFileName, HBufC*& aFolderPath ); |
|
145 |
|
146 /** |
|
147 * see MUpnpContentDirectoryDataFinder |
|
148 */ |
|
149 CUpnpDlnaProtocolInfo* GetProtocolInfoByImportUriL( |
|
150 const TDesC8& aImportUri); |
|
151 |
|
152 private: // internal methods |
|
153 |
|
154 /** |
|
155 * shares a resource by hash. |
|
156 * |
|
157 * @param aHash, TUint |
|
158 * @param aResource, upnpelement |
|
159 */ |
|
160 void ShareResourceL( |
|
161 TUint aHash, |
|
162 CUpnpElement& aResource ); |
|
163 |
|
164 /** |
|
165 * unshared an entry by hash. |
|
166 * |
|
167 * @param aHash, TUint |
|
168 */ |
|
169 void UnshareResource( |
|
170 TUint aHash ); |
|
171 |
|
172 /** |
|
173 * count of shared entries. |
|
174 * |
|
175 */ |
|
176 TInt EntryCount(); |
|
177 |
|
178 /** |
|
179 * constructs an URI by hashcode. |
|
180 * |
|
181 * @param aHash, TUint |
|
182 * @param aFileExt, file extension of the element |
|
183 * @param aUriBuf, uri output buffer. |
|
184 */ |
|
185 void HashToUri( TUint aHash, const TDesC& aFileExt, TDes8& aUriBuf ); |
|
186 |
|
187 /** |
|
188 * extracts hashcode from given uri. |
|
189 * |
|
190 * @param aUri, uri |
|
191 */ |
|
192 TUint HashFromUri( const TDesC8& aUri ); |
|
193 |
|
194 /** |
|
195 * extracts hashcode from given uri |
|
196 * |
|
197 * @param aUri, uri |
|
198 */ |
|
199 TUint HashFromUri( const TDesC16& aUri ); |
|
200 |
|
201 private: |
|
202 /** |
|
203 * An array entry that represents one resource that is being shared |
|
204 * within this push server. |
|
205 */ |
|
206 class TUpnpPushEntry |
|
207 { |
|
208 public: |
|
209 TUpnpPushEntry( TUint aHash, const TDesC& aPath, |
|
210 const TDesC8& aProtocolInfo ): iHash(aHash), |
|
211 iPath(aPath), iProtocolInfo(aProtocolInfo) {} |
|
212 TUint Hash() const {return iHash;} |
|
213 const TDesC& Path() const {return iPath;} |
|
214 const TDesC8& ProtocolInfo() const {return iProtocolInfo;} |
|
215 private: |
|
216 TUint iHash; |
|
217 const TDesC& iPath; |
|
218 const TDesC8& iProtocolInfo; |
|
219 }; |
|
220 |
|
221 private: // members |
|
222 |
|
223 // the http server |
|
224 CUpnpHttpServerSession* iHttpServer; |
|
225 |
|
226 // shared content |
|
227 RHashMap<TUint,TUpnpPushEntry> iEntries; |
|
228 |
|
229 CUpnpDlnaFilter* iFilter; //owned |
|
230 |
|
231 }; |
|
232 |
|
233 |
|
234 #endif // UPNPPUSHSERVER_H |
|
235 |
|
236 // End of File |