zeroconf/client/src/cmdnsclient.cpp
author guru.kini@nokia.com
Thu, 24 Jun 2010 19:09:47 +0530
changeset 14 da856f45b798
permissions -rw-r--r--
Committing ZeroConf for 10.1 to the FCL.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     2
// All rights reserved.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     3
// This component and the accompanying materials are made available
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     5
// which accompanies this distribution, and is available
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     7
//
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     8
// Initial Contributors:
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    10
//
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    11
// Contributors:
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    12
//
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    13
// Description:
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    14
// cmdnsclient.cpp
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    15
// 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    16
//
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    17
/**
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    18
@file
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    19
@PublishedAll
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    20
*/
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    21
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    22
//User include 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    23
#include "cmdnsclient.h"
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    24
#include "cmdnsserverconstants.h"
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    25
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    26
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    27
//System include
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    28
#include <mdns/dnsconstants.h>
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    29
#include <s32mem.h>
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    30
#include <in_sock.h>
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    31
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    32
__FLOG_STMT(_LIT8(KComponent,"MDNSClient");)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    33
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    34
 * Default constructor -Assigns the buffer pointer to Null 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    35
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    36
EXPORT_C RMdns::RMdns():iBufPointer(NULL,0)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    37
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    38
	__FLOG_OPEN(KMDNSSubsystem, KComponent);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    39
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    40
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    41
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    42
 * Interface to start the Mdns server .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    43
 * KMdnsServerName referes to the name of the Mdns server.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    44
 * @param aConnectionHandle handle to the RConnection object // TODO
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    45
 * @param aSocketServerHandle handler to the RSocketServ object //TODO 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    46
 * 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    47
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    48
EXPORT_C TInt RMdns::Open(TInt aConnectionHandle)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    49
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    50
	__FLOG(_L8("RMdns::Open - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    51
	TVersion serverVersion(0, 0, 0);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    52
	//creates a new session if the server exists and it is up and running .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    53
	//returns KErrNotFound if the server needs to be launched.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    54
	TInt err = CreateSession(KMdnsServerName, serverVersion, 2);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    55
	if (err == KErrNotFound)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    56
		{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    57
		// try starting the server, since create session didn't work
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    58
		//iap refers to the iap application wants to use.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    59
		TBuf<16> iap;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    60
		iap.AppendNum(aConnectionHandle);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    61
		RProcess server;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    62
		User::LeaveIfError(server.Create(KMdnsServerExe, iap));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    63
		server.Resume();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    64
		TRequestStatus status;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    65
		status = KRequestPending;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    66
		server.Rendezvous(status);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    67
		//waits for the server to construct all the required object.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    68
	 	User::WaitForRequest(status);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    69
		User::LeaveIfError(status.Int());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    70
		User::LeaveIfError(CreateSession(KMdnsServerName, serverVersion, 2));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    71
		server.Close();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    72
		}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    73
	else
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    74
		{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    75
		User::LeaveIfError(err);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    76
		}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    77
	iNotifierCount =0;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    78
	//creates a buffer object with buffer length KDnsBufferlength = 1000 this is the max application
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    79
	//could send stored in the bundle.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    80
	iBuffer = HBufC8::NewL(KDnsBufferlength);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    81
	//Set the pointer to point buffer.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    82
	iBufPointer.Set(iBuffer->Des());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    83
	//Create a notifier which will be used to catch all the publish and 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    84
	// query response . There will be only one eventobserver for the client.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    85
	//Will be destroyed when the client will be closed.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    86
	TRAPD(error,iEventNotifier = CMdnsQueryPublishNotifier::NewL(*this));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    87
	__FLOG(_L8("RMdns::Open - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    88
	return error;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    89
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    90
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    91
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    92
 * Hanldes any queries either the ptr ,srv txt and address record
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    93
 * IN case of PTR query will be send to the network . 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    94
 * For SRV and TXT if it exist in the cache ,request will be completed immediately .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    95
 * @param aQueryParams contains the query bundle.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    96
 * Leaves with KErrAlreadyExists if a request is pending.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    97
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    98
EXPORT_C void RMdns::QueryL( const RPnPParameterBundle& aQueryParams )
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
    99
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   100
	__FLOG(_L8("RMdns::QueryL - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   101
	//Get the status of the event notifies . If it is KRequestPending 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   102
	//there exists a query which needs to be completed . 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   103
	//Leaves with KErrAlreadyExist if there is query which is pending.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   104
	TRequestStatus &status =  iEventNotifier->EventNotifierStatus();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   105
	if( status.Int() == KRequestPending)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   106
        {
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   107
        User::Leave(KErrAlreadyExists);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   108
        }
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   109
	//Set the buffer pointer to zero and convert bundle in to buffer and store it in buffer.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   110
	iBufPointer.Zero();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   111
	TInt temp = aQueryParams.Length();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   112
	aQueryParams.Store(iBufPointer);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   113
	//TODO
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   114
	//Create a reference to buffer length and send it along the with the request.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   115
	//On completion contains the length of the buffer client should create to get the 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   116
	//response for the query.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   117
	//TPckg<TInt> len(iEventNotifier->BufferLength());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   118
	TIpcArgs args(&iBufPointer,&iEventNotifier->BufferLength());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   119
	//Set Event notifier active
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   120
	iEventNotifier->SetEventNotifierActive();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   121
	iEventNotifier->SetPnpObserver(aQueryParams.PnPObserver());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   122
	//Set the state as query message so that on response it can decide wheteher it is query or publish.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   123
	iEventNotifier->SetState(EMdnsServerQueryMessages);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   124
	TRAPD(error,SendReceive(EMdnsServerQueryMessages,args, status));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   125
	__FLOG(_L8("RMdns::QueryL - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   126
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   127
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   128
//TODO yet to decide wat to do with this 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   129
//as query itself can handle all the requests
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   130
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   131
EXPORT_C void RMdns::ResolveL( const RPnPParameterBundle& aResolveParams )
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   132
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   133
	__FLOG(_L8("RMdns::ResolveL - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   134
	QueryL(aResolveParams);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   135
	__FLOG(_L8("RMdns::ResolveL - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   136
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   137
	
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   138
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   139
 * Interferace for the applicaion to register for a particular service it serves
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   140
 * on the network , A copy of this will be kept in the cache .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   141
 * applicaion dont have to renew the service .Consistency Manager will take care of renewing the service.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   142
 * @param aPublishParam contains the srv record and the txt record if required need to be published.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   143
 * 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   144
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   145
EXPORT_C void RMdns::RegisterServiceL( const RPnPParameterBundle& aPublishParams ,TBool aIsUpdate)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   146
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   147
	__FLOG(_L8("RMdns::RegisterServiceL - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   148
	iBufPointer.Zero();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   149
	aPublishParams.Store(iBufPointer);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   150
	TIpcArgs args(&iBufPointer,&iEventNotifier->BufferLength(),aIsUpdate);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   151
	iEventNotifier->SetEventNotifierActive();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   152
	iEventNotifier->SetPnpObserver(aPublishParams.PnPObserver());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   153
	TRequestStatus &status =  iEventNotifier->EventNotifierStatus();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   154
	iEventNotifier->SetState(EMndsServerPublishMessages);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   155
	TRAPD(error,SendReceive(EMndsServerPublishMessages,args,status));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   156
	User::LeaveIfError(error);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   157
	__FLOG(_L8("RMdns::RegisterServiceL - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   158
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   159
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   160
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   161
 * An Asychronous request which tells the mdns about the service it is interested in .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   162
 * Internally it calls RecieveNotifyMessageL which is a private function, feasible only to CMDnsregisterNotifier
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   163
 * CMDnsRegisterNotifier is an active object running all the time waiting for any ptr enteries.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   164
 * @param aNotifyParam contains the ptr type the application is interrested in ;to be notified.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   165
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   166
EXPORT_C void RMdns::WaitForNotificationL( const RPnPParameterBundle& aNotifyParams )
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   167
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   168
	__FLOG(_L8("RMdns::WaitForNotificationL - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   169
	if(!iRegisterNotifier)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   170
        {
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   171
        iRegisterNotifier = CMdnsRegisterNotifier::NewL(*this);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   172
        }
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   173
	iRegisterNotifier->SetPnpObserver(aNotifyParams.PnPObserver());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   174
	HBufC8* buffer  = HBufC8::NewL(KDnsBufferlength);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   175
	TPtr8 aNotifyMessage(NULL,0,0);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   176
	aNotifyMessage.Set(buffer->Des());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   177
	aNotifyParams.Store(aNotifyMessage);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   178
	TIpcArgs args(&aNotifyMessage);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   179
	SendReceive(EMdnsServerStartNotifyMessages,args);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   180
	iNotifierCount++;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   181
	delete buffer;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   182
	__FLOG(_L8("RMdns::WaitForNotificationL - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   183
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   184
	
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   185
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   186
 *Interface to cancel any notification client requested for .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   187
 *@param aCancelParams contains the name of the ptr type client is not interested to be notified.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   188
 * 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   189
 */	
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   190
EXPORT_C TInt RMdns::Cancel( const RPnPParameterBundle& aCancelParams )
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   191
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   192
	__FLOG(_L8("RMdns::Cancel - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   193
	//notifier count keeps track of the number of entries requested for.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   194
	iNotifierCount--;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   195
	HBufC8* buffer  = HBufC8::NewL(KDnsBufferlength);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   196
	TPtr8 aNotifyMessage(NULL,0,0);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   197
	aNotifyMessage.Set(buffer->Des());
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   198
	aCancelParams.Store(aNotifyMessage);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   199
	TIpcArgs args(&aNotifyMessage);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   200
	SendReceive(EMdnsServerStopNotifyMessages,args);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   201
	//when notifier count is zero close the CMdnsRegisterNotifier active object.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   202
	//count =0 means the concerned client is not interested in any notification.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   203
	if(iNotifierCount == 0)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   204
	    {
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   205
	    iRegisterNotifier->Cancel();
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   206
	    }
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   207
	delete buffer;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   208
	__FLOG(_L8("RMdns::Cancel - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   209
	return KErrNone;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   210
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   211
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   212
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   213
 * Destructor 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   214
 */	
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   215
EXPORT_C TInt RMdns::Close()
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   216
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   217
	__FLOG(_L8("RMdns::Close - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   218
	RSessionBase::Close(); 
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   219
	delete iEventNotifier;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   220
	delete iRegisterNotifier;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   221
	delete iBuffer;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   222
	__FLOG(_L8("RMdns::Close - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   223
	__FLOG_CLOSE;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   224
	return KErrNone;
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   225
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   226
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   227
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   228
 * Private function used by the Query and publish notifier .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   229
 * Based on the size of the buffer recieved by the query and publish request.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   230
 * a new buffer is allocated and sent to recieve the response.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   231
 * @param aData contains the buffer allocated to recieve the response.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   232
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   233
void RMdns::RecieveMessage(TDes8& aData)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   234
	{
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   235
	__FLOG(_L8("RMdns::RecieveMessage - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   236
	TIpcArgs args(&aData);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   237
	TRAPD(error,SendReceive(EMdnsServerRecieveMessages,args));	
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   238
	__FLOG(_L8("RMdns::RecieveMessage - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   239
	}
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   240
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   241
/*
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   242
 * An synchronous request will be running all the time . whenever a waitfornotification been called.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   243
 * @param aData contains the buffer for which data to be set to .
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   244
 * @param aStatus used to complete the asynchronous request.
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   245
 */
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   246
void RMdns::RecieveNotifyMessageL(TDes8& aData,TRequestStatus& aStatus)
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   247
    {
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   248
    __FLOG(_L8("RMdns::RecieveNotifyMessageL - Entry"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   249
    TIpcArgs args(&aData);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   250
    SendReceive(EMdnsServerRecieveNotifyMessages,args,aStatus);
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   251
    __FLOG(_L8("RMdns::RecieveNotifyMessageL - Exit"));
da856f45b798 Committing ZeroConf for 10.1 to the FCL.
guru.kini@nokia.com
parents:
diff changeset
   252
    }