21
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "zeroconfclient.h"
|
|
19 |
#include "e32math.h"
|
|
20 |
|
|
21 |
#include <in_sock.h>
|
|
22 |
#include <ecom/ecom.h>
|
|
23 |
const TUint KPublishTierId = 0x2001DC8A;
|
|
24 |
|
|
25 |
CZeroconfClient* CZeroconfClient::NewL(MPnPObserver* aObserver)
|
|
26 |
{
|
|
27 |
CZeroconfClient* self = CZeroconfClient::NewLC(aObserver);
|
|
28 |
CleanupStack::Pop(self);
|
|
29 |
return self;
|
|
30 |
}
|
|
31 |
|
|
32 |
|
|
33 |
CZeroconfClient* CZeroconfClient::NewLC(MPnPObserver* aObserver)
|
|
34 |
{
|
|
35 |
CZeroconfClient* self = new (ELeave) CZeroconfClient(aObserver);
|
|
36 |
CleanupStack::PushL(self);
|
|
37 |
self->ConstructL();
|
|
38 |
return self;
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
void CZeroconfClient::ConnectL()
|
|
44 |
{
|
|
45 |
|
|
46 |
GetBTName();
|
|
47 |
TInt openStatus1 = iServicePublish.Open(KPublishTierId);
|
|
48 |
const TUint KTestTierId = 536924288;
|
|
49 |
TInt openStatus = iControlPoint.Open(KTestTierId);
|
|
50 |
//
|
|
51 |
}
|
|
52 |
|
|
53 |
CZeroconfClient::~CZeroconfClient()
|
|
54 |
{
|
|
55 |
iServicePublish.Close();
|
|
56 |
iControlPoint.Close();
|
|
57 |
iBTName.Close();
|
|
58 |
REComSession::FinalClose();
|
|
59 |
}
|
|
60 |
|
|
61 |
CZeroconfClient::CZeroconfClient(MPnPObserver* aObserver)
|
|
62 |
{
|
|
63 |
iMdnsObserver = aObserver;
|
|
64 |
}
|
|
65 |
|
|
66 |
void CZeroconfClient::ConstructL()
|
|
67 |
{
|
|
68 |
|
|
69 |
}
|
|
70 |
|
|
71 |
void CZeroconfClient::GetBTName()
|
|
72 |
{
|
|
73 |
iBTName.CreateL(KMaxFileName);
|
|
74 |
TInt rand = Math::Random()%100;
|
|
75 |
iBTName.Num(rand);
|
|
76 |
|
|
77 |
}
|
|
78 |
|
|
79 |
void CZeroconfClient::PublishMyService(const TDesC8& aBaseUrl,const TDesC8& aFileList,const TDesC8& aIconName)
|
|
80 |
{
|
|
81 |
RPnPParameterBundle pnpBundle;
|
|
82 |
pnpBundle.Open ();
|
|
83 |
//CleanupClosePushL( pnpBundle );
|
|
84 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
85 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
86 |
RParameterFamily ptrFamily = pnpBundle.CreateFamilyL (EMdnsPtrParamset);
|
|
87 |
//Srv Record
|
|
88 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
89 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
90 |
//CleanupStack::PushL(srvParam);
|
|
91 |
RBuf8 serviceName;
|
|
92 |
serviceName.CreateL(KMaxFileName);
|
|
93 |
serviceName.Append(_L8("DeviceService"));
|
|
94 |
serviceName.Append(iBTName.Collapse());
|
|
95 |
serviceName.Append(_L8("._daap._tcp.local"));
|
|
96 |
srvParam->SetDomainNameL(serviceName);
|
|
97 |
srvParam->SetTargetL(_L8("2IND50001.Local"));
|
|
98 |
srvParam->SetPriority(2);
|
|
99 |
srvParam->SetWeight(100);
|
|
100 |
srvParam->SetPort(80);
|
|
101 |
|
|
102 |
CMDnsPtrParamSet* ptrParam = CMDnsPtrParamSet::NewL(ptrFamily);
|
|
103 |
ptrParam->SetInstanceNameL(_L8("_daap._tcp.local"));
|
|
104 |
ptrParam->SetDomainNameL(serviceName);
|
|
105 |
//Txt record
|
|
106 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
107 |
//CleanupStack::PushL(txtParam);
|
|
108 |
txtParam->SetDomainNameL(serviceName);
|
|
109 |
RBuf8 baseUrl,fileUrl,iconUrl;
|
|
110 |
|
|
111 |
//data3 contains the base ip addr
|
|
112 |
baseUrl.Create(KMaxPath);
|
|
113 |
fileUrl.Create(KMaxFileName);
|
|
114 |
iconUrl.Create(KMaxFileName);
|
|
115 |
|
|
116 |
//data4 contains the filelist name
|
|
117 |
baseUrl.Append(_L8("BaseUrl = "));
|
|
118 |
baseUrl.Append(aBaseUrl);
|
|
119 |
|
|
120 |
fileUrl.Append(_L8("FileUrl = "));
|
|
121 |
fileUrl.Append(aFileList);
|
|
122 |
|
|
123 |
iconUrl.Append(_L8("IconUrl = "));
|
|
124 |
iconUrl.Append(aIconName);
|
|
125 |
|
|
126 |
txtParam->AppendTxtData(baseUrl);
|
|
127 |
txtParam->AppendTxtData(fileUrl);
|
|
128 |
txtParam->AppendTxtData(iconUrl);
|
|
129 |
|
|
130 |
iServicePublish.Publish(pnpBundle);
|
|
131 |
pnpBundle.Close();
|
|
132 |
|
|
133 |
baseUrl.Close();
|
|
134 |
fileUrl.Close();
|
|
135 |
iconUrl.Close();
|
|
136 |
serviceName.Close();
|
|
137 |
}
|
|
138 |
|
|
139 |
void CZeroconfClient::PublishNowPlayingServiceL(TDes& aTitleBuf)
|
|
140 |
{
|
|
141 |
TInt openStatus1 = iMusicPublish.Open(KPublishTierId);
|
|
142 |
|
|
143 |
RPnPParameterBundle pnpBundle;
|
|
144 |
pnpBundle.Open ();
|
|
145 |
CleanupClosePushL( pnpBundle );
|
|
146 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
147 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
148 |
//Srv Record
|
|
149 |
|
|
150 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
151 |
|
|
152 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
153 |
//CleanupStack::PushL(srvParam);
|
|
154 |
RBuf8 serviceName;
|
|
155 |
serviceName.CreateL(KMaxFileName);
|
|
156 |
serviceName.Append(_L8("MusicService"));
|
|
157 |
serviceName.Append(iBTName.Collapse());
|
|
158 |
serviceName.Append(_L8("._daap._tcp.local"));
|
|
159 |
|
|
160 |
srvParam->SetDomainNameL(serviceName);
|
|
161 |
srvParam->SetTargetL(_L8("2IND04990.Local"));
|
|
162 |
srvParam->SetPriority(2);
|
|
163 |
srvParam->SetWeight(100);
|
|
164 |
srvParam->SetPort(80);
|
|
165 |
//Txt record
|
|
166 |
RBuf8 data;
|
|
167 |
TUint KMaxLength(255);
|
|
168 |
data.CreateL(_L8("Now playing = "),KMaxLength);
|
|
169 |
data.Append(aTitleBuf.Collapse());
|
|
170 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
171 |
//CleanupStack::PushL(txtParam);
|
|
172 |
txtParam->SetDomainNameL(serviceName);
|
|
173 |
txtParam->AppendTxtData(data);
|
|
174 |
iServicePublish.Publish(pnpBundle);
|
|
175 |
data.Close();
|
|
176 |
serviceName.Close();
|
|
177 |
CleanupStack::PopAndDestroy(1);//pnpBundle
|
|
178 |
|
|
179 |
}
|
|
180 |
|
|
181 |
void CZeroconfClient::UpdateNowPlayingServiceL(TDes& aTitleBuf)
|
|
182 |
{
|
|
183 |
RPnPParameterBundle pnpBundle;
|
|
184 |
pnpBundle.Open ();
|
|
185 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
186 |
|
|
187 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
188 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
189 |
//update Publish
|
|
190 |
//pnpBundle.ClearAllParameters(RParameterFamily::ERequested);
|
|
191 |
RParameterFamily publishFamily = pnpBundle.CreateFamilyL (EMdnsPublishParamset);
|
|
192 |
CMDnsPublishParamSet* publishParam = CMDnsPublishParamSet::NewL(publishFamily);
|
|
193 |
publishParam->SetPublishUpdate(ETrue);
|
|
194 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
195 |
//CleanupStack::PushL(srvParam);
|
|
196 |
RBuf8 serviceName;
|
|
197 |
serviceName.CreateL(KMaxFileName);
|
|
198 |
serviceName.Append(_L8("MusicService"));
|
|
199 |
serviceName.Append(iBTName.Collapse());
|
|
200 |
serviceName.Append(_L8("._daap._tcp.local"));
|
|
201 |
|
|
202 |
srvParam->SetDomainNameL(serviceName);
|
|
203 |
srvParam->SetTargetL(_L8("2IND04990.Local"));
|
|
204 |
srvParam->SetPriority(2);
|
|
205 |
srvParam->SetWeight(100);
|
|
206 |
srvParam->SetPort(80);
|
|
207 |
//Txt record
|
|
208 |
RBuf8 data;
|
|
209 |
TUint KMaxLength(255);
|
|
210 |
data.CreateL(_L8("Now playing = "),KMaxLength);
|
|
211 |
data.Append(aTitleBuf.Collapse());
|
|
212 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
213 |
//CleanupStack::PushL(txtParam);
|
|
214 |
txtParam->SetDomainNameL(serviceName);
|
|
215 |
txtParam->AppendTxtData(data);
|
|
216 |
iServicePublish.Publish(pnpBundle);
|
|
217 |
data.Close();
|
|
218 |
serviceName.Close();
|
|
219 |
pnpBundle.Close();
|
|
220 |
}
|
|
221 |
void CZeroconfClient::PublishCurrentStatusServiceL(const TDesC8& aStatus)
|
|
222 |
{
|
|
223 |
TInt openStatus1 = iStatusPublish.Open(KPublishTierId);
|
|
224 |
RPnPParameterBundle pnpBundle;
|
|
225 |
pnpBundle.Open ();
|
|
226 |
CleanupClosePushL( pnpBundle );
|
|
227 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
228 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
229 |
//Srv Record
|
|
230 |
|
|
231 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
232 |
|
|
233 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
234 |
//CleanupStack::PushL(srvParam);
|
|
235 |
|
|
236 |
RBuf8 serviceName;
|
|
237 |
serviceName.CreateL(KMaxFileName);
|
|
238 |
serviceName.Append(_L8("StatusService"));
|
|
239 |
serviceName.Append(iBTName.Collapse());
|
|
240 |
serviceName.Append(_L8("._daap._tcp.local"));
|
|
241 |
|
|
242 |
srvParam->SetDomainNameL(serviceName);
|
|
243 |
|
|
244 |
srvParam->SetTargetL(_L8("2IND04990.Local"));
|
|
245 |
srvParam->SetPriority(2);
|
|
246 |
srvParam->SetWeight(100);
|
|
247 |
srvParam->SetPort(80);
|
|
248 |
//Txt record
|
|
249 |
RBuf8 data;
|
|
250 |
TUint KMaxLength(255);
|
|
251 |
data.CreateL(_L8("Status = "),KMaxLength);
|
|
252 |
data.Append(aStatus);
|
|
253 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
254 |
//CleanupStack::PushL(txtParam);
|
|
255 |
txtParam->SetDomainNameL(serviceName);
|
|
256 |
txtParam->AppendTxtData(data);
|
|
257 |
iServicePublish.Publish(pnpBundle);
|
|
258 |
data.Close();
|
|
259 |
serviceName.Close();
|
|
260 |
CleanupStack::PopAndDestroy(1);//pnpBundle
|
|
261 |
|
|
262 |
}
|
|
263 |
|
|
264 |
void CZeroconfClient::UpdateCurrentStatusServiceL(const TDesC8& aStatus)
|
|
265 |
{
|
|
266 |
RPnPParameterBundle pnpBundle;
|
|
267 |
pnpBundle.Open ();
|
|
268 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
269 |
|
|
270 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
271 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
272 |
//update Publish
|
|
273 |
//pnpBundle.ClearAllParameters(RParameterFamily::ERequested);
|
|
274 |
RParameterFamily publishFamily = pnpBundle.CreateFamilyL (EMdnsPublishParamset);
|
|
275 |
CMDnsPublishParamSet* publishParam = CMDnsPublishParamSet::NewL(publishFamily);
|
|
276 |
publishParam->SetPublishUpdate(ETrue);
|
|
277 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
278 |
//CleanupStack::PushL(srvParam);
|
|
279 |
|
|
280 |
RBuf8 serviceName;
|
|
281 |
serviceName.CreateL(KMaxFileName);
|
|
282 |
serviceName.Append(_L8("StatusService"));
|
|
283 |
serviceName.Append(iBTName.Collapse());
|
|
284 |
serviceName.Append(_L8("._daap._tcp.local"));
|
|
285 |
|
|
286 |
srvParam->SetDomainNameL(serviceName);
|
|
287 |
srvParam->SetTargetL(_L8("2IND04990.Local"));
|
|
288 |
srvParam->SetPriority(2);
|
|
289 |
srvParam->SetWeight(100);
|
|
290 |
srvParam->SetPort(80);
|
|
291 |
//Txt record
|
|
292 |
RBuf8 data;
|
|
293 |
TUint KMaxLength(255);
|
|
294 |
data.CreateL(_L8("Status = "),KMaxLength);
|
|
295 |
data.Append(aStatus);
|
|
296 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
297 |
//CleanupStack::PushL(txtParam);
|
|
298 |
txtParam->SetDomainNameL(serviceName);
|
|
299 |
txtParam->AppendTxtData(data);
|
|
300 |
iServicePublish.Publish(pnpBundle);
|
|
301 |
data.Close();
|
|
302 |
serviceName.Close();
|
|
303 |
pnpBundle.Close();
|
|
304 |
}
|
|
305 |
void CZeroconfClient::PublishService()
|
|
306 |
{
|
|
307 |
RPnPParameterBundle pnpBundle;
|
|
308 |
pnpBundle.Open ();
|
|
309 |
//CleanupClosePushL( pnpBundle );
|
|
310 |
RParameterFamily srvFamily = pnpBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
311 |
RParameterFamily txtFamily = pnpBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
312 |
//Srv Record
|
|
313 |
|
|
314 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
315 |
|
|
316 |
CMDnsSrvParamSet* srvParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
317 |
//CleanupStack::PushL(srvParam);
|
|
318 |
srvParam->SetDomainNameL(_L8("xyz._daap._tcp.local"));
|
|
319 |
srvParam->SetTargetL(_L8("2IND04990.Local"));
|
|
320 |
srvParam->SetPriority(2);
|
|
321 |
srvParam->SetWeight(100);
|
|
322 |
srvParam->SetPort(80);
|
|
323 |
//Txt record
|
|
324 |
CMDnsTxtParamSet* txtParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
325 |
//CleanupStack::PushL(txtParam);
|
|
326 |
txtParam->SetDomainNameL(_L8("xyz._daap._tcp.local"));
|
|
327 |
RBuf8 data1,data2;
|
|
328 |
data1.Create(_L8("vadan = ct "));
|
|
329 |
data2.Create(_L8("prakash = sharma "));
|
|
330 |
txtParam->AppendTxtData(data1);
|
|
331 |
txtParam->AppendTxtData(data2);
|
|
332 |
iServicePublish.Publish(pnpBundle);
|
|
333 |
pnpBundle.Close();
|
|
334 |
data1.Close();
|
|
335 |
data2.Close();
|
|
336 |
}
|
|
337 |
|
|
338 |
void CZeroconfClient::WriteServices()
|
|
339 |
{
|
|
340 |
RPnPParameterBundle pnpBundle;
|
|
341 |
pnpBundle.Open ();
|
|
342 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
343 |
RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (EMdnsRegisterNotifyParamset);
|
|
344 |
CMDnsRegisterNotifyParamSet* registerParam = CMDnsRegisterNotifyParamSet::NewL(pnpFamily);
|
|
345 |
_LIT8(KInstance,"_daap._tcp.local");
|
|
346 |
registerParam->SetInstanceNameL(KInstance);
|
|
347 |
iControlPoint.RegisterNotify(pnpBundle);
|
|
348 |
pnpBundle.Close();
|
|
349 |
}
|
|
350 |
|
|
351 |
void CZeroconfClient::WriteServiceTypes()
|
|
352 |
{
|
|
353 |
|
|
354 |
_LIT8(KInstance,"");
|
|
355 |
_LIT8(KServiceType,"_daap.");
|
|
356 |
RPnPParameterBundle pnpBundle;
|
|
357 |
|
|
358 |
pnpBundle.Open ();
|
|
359 |
|
|
360 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
361 |
RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (EMDnsDiscoverRequestParamSet);
|
|
362 |
CMDnsQueryRequestParamSet* queryParam = CMDnsQueryRequestParamSet::NewL(pnpFamily);
|
|
363 |
|
|
364 |
queryParam->SetInstanceNameL(KInstance);
|
|
365 |
queryParam->SetQueryTypeL(EDnsQType_Any);
|
|
366 |
queryParam->SetProtocol(1);
|
|
367 |
queryParam->SetServiceTypeL(KServiceType);
|
|
368 |
|
|
369 |
User::After(5000000);
|
|
370 |
iControlPoint.Discover(pnpBundle);
|
|
371 |
pnpBundle.Close();
|
|
372 |
|
|
373 |
}
|
|
374 |
|
|
375 |
void CZeroconfClient::GetService(const TDesC8& aInstanceName,TDnsType aType)
|
|
376 |
{
|
|
377 |
_LIT8(KServiceType,"_daap.");
|
|
378 |
RPnPParameterBundle pnpBundle;
|
|
379 |
|
|
380 |
pnpBundle.Open ();
|
|
381 |
|
|
382 |
pnpBundle.SetPnPObserver((MPnPObserver*)iMdnsObserver);
|
|
383 |
RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (EMDnsDiscoverRequestParamSet);
|
|
384 |
CMDnsQueryRequestParamSet* queryParam = CMDnsQueryRequestParamSet::NewL(pnpFamily);
|
|
385 |
|
|
386 |
queryParam->SetInstanceNameL(aInstanceName);
|
|
387 |
queryParam->SetQueryTypeL(aType);
|
|
388 |
queryParam->SetProtocol(1);
|
|
389 |
queryParam->SetServiceTypeL(KServiceType);
|
|
390 |
|
|
391 |
|
|
392 |
iControlPoint.Discover(pnpBundle);
|
|
393 |
pnpBundle.Close();
|
|
394 |
}
|
|
395 |
|
|
396 |
|
|
397 |
void CZeroconfClient::SearchService()
|
|
398 |
{}
|
|
399 |
|
|
400 |
void CZeroconfClient::UnPublishServices()
|
|
401 |
{
|
|
402 |
iServicePublish.Close();
|
|
403 |
iMusicPublish.Close();
|
|
404 |
iStatusPublish.Close();
|
|
405 |
}
|