|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include <ss_glob.h> |
|
20 #include <ss_thread.h> |
|
21 |
|
22 #include "upnpflowfactory.h" |
|
23 #include "httpclientflow.h" |
|
24 #include "httpserverflow.h" |
|
25 #include "httpudpflow.h" |
|
26 #include "httpmudpflow.h" |
|
27 |
|
28 using namespace ESock; |
|
29 using namespace Messages; |
|
30 |
|
31 CUPnPFlowFactory* CUPnPFlowFactory::NewL(TAny* aConstructionParameters) |
|
32 { |
|
33 CUPnPFlowFactory* factory = new (ELeave) CUPnPFlowFactory(TUid::Uid(CUPnPFlowFactory::iUid), *(reinterpret_cast<CSubConnectionFlowFactoryContainer*>(aConstructionParameters))); |
|
34 CleanupStack::PushL(factory); |
|
35 factory->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return factory; |
|
38 } |
|
39 |
|
40 CUPnPFlowFactory::CUPnPFlowFactory(TUid aFactoryId, CSubConnectionFlowFactoryContainer& aParentContainer) |
|
41 : CSubConnectionFlowFactoryBase(aFactoryId, aParentContainer) |
|
42 { |
|
43 // LOG_NODE_CREATE(KESockDataFactTag, CUPnPFlowFactory) |
|
44 } |
|
45 |
|
46 void CUPnPFlowFactory::ConstructL() |
|
47 { |
|
48 // Register with comms transport to be able to receive our |
|
49 // custom Upnp messages |
|
50 TUpnpMessage::RegisterL(SockManGlobals::Get ()->SelfWorker ()); |
|
51 } |
|
52 |
|
53 CProtocolIntfFactoryBase* CUPnPFlowFactory::CreateProtocolIntfFactoryL(CProtocolIntfFactoryContainer& aParentContainer) |
|
54 { |
|
55 ESock::CProtocolIntfFactoryBase* factory = CUPnPProtocolIntfFactory::NewL(Uid(), aParentContainer); |
|
56 return factory; |
|
57 } |
|
58 |
|
59 CUPnPFlowFactory::~CUPnPFlowFactory() |
|
60 { |
|
61 // LOG_NODE_DESTROY(KESockDataFactTag, CUPnPFlowFactory) |
|
62 TUpnpMessage::DeRegister(); |
|
63 } |
|
64 |
|
65 CSubConnectionFlowBase* CUPnPFlowFactory::DoCreateFlowL(CProtocolIntfBase* aProtocolIntf, TFactoryQueryBase& aQuery) |
|
66 { |
|
67 CSubConnectionFlowBase * flow = NULL; |
|
68 const TUPnPFlowQuery& queryBase = static_cast<const TUPnPFlowQuery&>( aQuery ); |
|
69 CChunkManager* chunkMgr = reinterpret_cast<CChunkManager*>(queryBase.iChunkManager); |
|
70 |
|
71 if(chunkMgr != NULL) |
|
72 { |
|
73 static_cast<CUPnPProtocolIntfBase *>(aProtocolIntf)->SetChunkManager(chunkMgr); |
|
74 } |
|
75 |
|
76 switch( (static_cast < const TUPnPFlowQuery& >( aQuery )).iDataClientType) |
|
77 { |
|
78 case EHttpClientFlow: |
|
79 { |
|
80 const THttpClientFlowQuery& clientData = static_cast<const THttpClientFlowQuery&>( aQuery ); |
|
81 flow = CHttpClientFlow::NewL(*this, aProtocolIntf, queryBase.iSCPRId, clientData.iSockAddr); |
|
82 } |
|
83 break; |
|
84 |
|
85 case EHttpServerFlow: |
|
86 { |
|
87 const THttpServerFlowQuery& serverData = static_cast<const THttpServerFlowQuery&>( aQuery ); |
|
88 TPtr8 reqUri ( const_cast<TUint8*>( serverData.iUri ), serverData.iLength, serverData.iLength ); |
|
89 flow = CHttpServerFlow::NewL(*this, aProtocolIntf, reqUri, queryBase.iSCPRId ); |
|
90 } |
|
91 break; |
|
92 |
|
93 case EHttpUdpFlow: |
|
94 { |
|
95 flow = CHttpUdpFlow::NewL( *this, static_cast<CUPnPProtocolIntfBase *>(aProtocolIntf), queryBase.iSCPRId ); |
|
96 } |
|
97 break; |
|
98 |
|
99 case EHttpMUdpFlow: |
|
100 { |
|
101 flow = CHttpMUdpFlow::NewL( *this, static_cast<CUPnPProtocolIntfBase *>(aProtocolIntf), queryBase.iSCPRId ); |
|
102 } |
|
103 break; |
|
104 |
|
105 default: |
|
106 ASSERT (0); |
|
107 } |
|
108 return flow; |
|
109 } |
|
110 |
|
111 ACommsFactoryNodeId* CUPnPFlowFactory::DoFindOrCreateObjectL( TFactoryQueryBase& aQuery ) |
|
112 { |
|
113 //Find the flow first |
|
114 const TUPnPFlowQuery& query = static_cast<const TUPnPFlowQuery&> ( aQuery ); |
|
115 ACommsFactoryNodeId* flow = NULL; |
|
116 |
|
117 if ( query.iDataClientType == EHttpClientFlow ) |
|
118 { |
|
119 const THttpClientFlowQuery& clientData = static_cast<const THttpClientFlowQuery&> ( query ); |
|
120 |
|
121 if ( clientData.iClientFlags == THttpClientFlowQuery::ECreateNew ) |
|
122 { // For UPnP POST request, control plane always creates new flow for attaching it to CSocket. |
|
123 flow = CreateL ( aQuery ); |
|
124 } |
|
125 else if ( clientData.iClientFlags == THttpClientFlowQuery::EUseExisting ) // HOST should match |
|
126 { |
|
127 flow = Find ( aQuery ); |
|
128 if ( flow == NULL ) |
|
129 flow = CreateL ( aQuery ); |
|
130 } |
|
131 static_cast<CUPnPFlowBase*>(flow)->AddControlClientL ( query.iSCPRId ); |
|
132 } |
|
133 else if ( query.iDataClientType == EHttpServerFlow ) |
|
134 { |
|
135 flow = Find ( aQuery ); |
|
136 if ( flow != NULL ) |
|
137 User::Leave ( KErrAlreadyExists ); |
|
138 else |
|
139 flow = CreateL ( aQuery ); |
|
140 } |
|
141 else |
|
142 { |
|
143 //Could be either udp flow or mudp flow. |
|
144 flow = Find ( aQuery ); |
|
145 if ( flow == NULL ) |
|
146 flow = CreateL ( aQuery ); |
|
147 static_cast<CUPnPFlowBase*>(flow)->AddControlClientL ( query.iSCPRId ); |
|
148 } |
|
149 return flow; |
|
150 } |
|
151 |
|
152 CSubConnectionFlowBase* CUPnPFlowFactory::CreateL ( TFactoryQueryBase& aQuery ) |
|
153 { |
|
154 TDefaultProtocolIntfFactoryQuery pintfQuery ( TNodeId::NullId () ); /*flowQuery.iCprId*/ |
|
155 CProtocolIntfBase* proto = SockManGlobals::Get ()->iProtocolIntfFactories->FindOrCreateProtocolIntfL ( Uid (), pintfQuery ); |
|
156 |
|
157 if ( NULL == proto ) |
|
158 { |
|
159 User::Leave ( KErrNotFound ); |
|
160 } |
|
161 CSubConnectionFlowBase* flow = DoCreateFlowL ( proto, aQuery ); |
|
162 CleanupStack::PushL(flow); |
|
163 |
|
164 AddManagedObjectL(*flow); |
|
165 |
|
166 CleanupStack::Pop(flow); |
|
167 return flow; |
|
168 } |