zeroconf/client/src/cmdnsquerypublishnotifier.cpp
changeset 14 da856f45b798
equal deleted inserted replaced
12:78fbd574edf4 14:da856f45b798
       
     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 // cmdnsquerypublishnotifier.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19 @file
       
    20 @internalTechnology
       
    21 */
       
    22 //User include 
       
    23 #include "cmdnsquerypublishnotifier.h"
       
    24 #include "cmdnsclient.h"
       
    25 
       
    26 //System include
       
    27 #include <pnp/mpnpobserver.h>
       
    28 #include <mdns/mdnsparamset.h>
       
    29 __FLOG_STMT(_LIT8(KComponent,"CMdnsQueryPublishNotifier");)
       
    30 /*
       
    31  * Two phase constructor.
       
    32  * @param aMdns a refernce to the mdns client .
       
    33  * @return returns  the instance .
       
    34  */
       
    35 CMdnsQueryPublishNotifier* CMdnsQueryPublishNotifier::NewL(RMdns& aMdns)
       
    36 	{
       
    37 	CMdnsQueryPublishNotifier* self = new (ELeave)CMdnsQueryPublishNotifier(aMdns);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 /*
       
    42  * Destructor 
       
    43  */
       
    44 CMdnsQueryPublishNotifier::~CMdnsQueryPublishNotifier()
       
    45 	{
       
    46 	__FLOG(_L8("CMdnsQueryPublishNotifier::~CMdnsQueryPublishNotifier - Entry"));
       
    47 	iObserver = NULL;
       
    48 	__FLOG(_L8("CMdnsQueryPublishNotifier::~CMdnsQueryPublishNotifier - Exit"));
       
    49 	__FLOG_CLOSE;
       
    50 	}
       
    51 /*
       
    52  * :)Function gets hit whenever a query or publish request gets completed.
       
    53  * On completeion iBufferlength contains the no of bytes to be allocated to read 
       
    54  * the response.
       
    55  */
       
    56 void CMdnsQueryPublishNotifier::RunL()
       
    57 	{
       
    58 	__FLOG(_L8("CMdnsQueryPublishNotifier::RunL - Entry"));
       
    59 	if(iStatus.Int() == KErrNone )
       
    60 	    {
       
    61 	    HBufC8* data = HBufC8::NewL(iBufferLength);
       
    62 	    CleanupStack::PushL(data);
       
    63 	    TPtr8 dataPointer(data->Des());
       
    64 	    RPnPParameterBundle responseBundle;
       
    65 	    responseBundle.CreateL();
       
    66 	    switch (iState)
       
    67 	    {
       
    68 	    case EMdnsServerQueryMessages :
       
    69 	        {
       
    70 	        iMdns.RecieveMessage(dataPointer);
       
    71             responseBundle.Load(dataPointer);
       
    72             iObserver->OnPnPEventL(responseBundle);
       
    73             
       
    74             
       
    75              break;
       
    76 	        }
       
    77 	    case EMndsServerPublishMessages:
       
    78 	        {
       
    79 	        iMdns.RecieveMessage(dataPointer);
       
    80             responseBundle.Load(dataPointer);
       
    81             iObserver->OnPnPEventL(responseBundle);
       
    82             break;	        
       
    83 	        
       
    84 	        }
       
    85 	    }
       
    86 	    responseBundle.Close();
       
    87 	    CleanupStack::PopAndDestroy();//data
       
    88 	    }
       
    89 	else
       
    90 	    {
       
    91 	    iObserver->OnPnPError(iStatus.Int());
       
    92 	    }
       
    93 	__FLOG(_L8("CMdnsQueryPublishNotifier::RunL - Exit"));
       
    94 	}
       
    95 
       
    96 
       
    97 void CMdnsQueryPublishNotifier::DoCancel()
       
    98 	{
       
    99 	__FLOG(_L8("CMdnsQueryPublishNotifier::DoCancel - Entry"));
       
   100 	iObserver = NULL;
       
   101 	__FLOG(_L8("CMdnsQueryPublishNotifier::DoCancel - Exit"));
       
   102 	}
       
   103 
       
   104 /*
       
   105  * Constructor
       
   106  * @param reference to RMdns 
       
   107  */
       
   108 CMdnsQueryPublishNotifier::CMdnsQueryPublishNotifier(RMdns& aMdns):CActive(EPriorityStandard),iMdns(aMdns),iPckgLength(iBufferLength)
       
   109 	{
       
   110 	__FLOG_OPEN(KMDNSSubsystem, KComponent);
       
   111 	__FLOG(_L8("CMdnsQueryPublishNotifier::CMdnsQueryPublishNotifier - Entry"));
       
   112 	CActiveScheduler::Add(this);
       
   113 	__FLOG(_L8("CMdnsQueryPublishNotifier::CMdnsQueryPublishNotifier - Exit"));
       
   114 	}
       
   115 
       
   116 /*
       
   117  * return reference to iBufferLength object .\\
       
   118  * Same will be used to set the size of the buffer client can expect on completion of 
       
   119  * query and publish.
       
   120  * @return iBufferlength areference to iBufferLength object
       
   121  */
       
   122 TPckg<TInt>& CMdnsQueryPublishNotifier::BufferLength()
       
   123 	{
       
   124 	__FLOG(_L8("CMdnsQueryPublishNotifier::BufferLength - Entry"));
       
   125 	return iPckgLength;
       
   126 	__FLOG(_L8("CMdnsQueryPublishNotifier::BufferLength - Exit"));
       
   127 	}
       
   128 
       
   129 /*
       
   130  * Cancel the asynchoronous request if it is already active.
       
   131  * Calls SetActive and sets the status to KRequestPending.
       
   132  */
       
   133 void CMdnsQueryPublishNotifier::SetEventNotifierActive()
       
   134 	{
       
   135 	__FLOG(_L8("CMdnsQueryPublishNotifier::SetEventNotifierActive - Entry"));
       
   136 	if(IsActive())
       
   137 	    {
       
   138 	    Cancel();
       
   139 	    }
       
   140 	SetActive();
       
   141 	iStatus = KRequestPending;
       
   142 	__FLOG(_L8("CMdnsQueryPublishNotifier::SetEventNotifierActive - Exit"));
       
   143 	}
       
   144 
       
   145 /*
       
   146  * Returns the refernce to iStatus of the active object
       
   147  * @return iStatus reference to status of the active object.
       
   148  */
       
   149 TRequestStatus& CMdnsQueryPublishNotifier::EventNotifierStatus()
       
   150 	{
       
   151 	__FLOG(_L8("CMdnsQueryPublishNotifier::EventNotifierStatus - Entry"));
       
   152 	return iStatus;
       
   153 	__FLOG(_L8("CMdnsQueryPublishNotifier::EventNotifierStatus - Exit"));
       
   154 	}
       
   155 
       
   156 /*
       
   157  * Function to keep a refernce to the observer of the client.
       
   158  * @param aObserver An observer to the client.
       
   159  */
       
   160 
       
   161 void CMdnsQueryPublishNotifier::SetPnpObserver(MPnPObserver* aObserver)
       
   162 	{
       
   163 	__FLOG(_L8("CMdnsQueryPublishNotifier::SetPnpObserver - Entry"));
       
   164 	iObserver = aObserver;
       
   165 	__FLOG(_L8("CMdnsQueryPublishNotifier::SetPnpObserver - Exit"));
       
   166 	}
       
   167 /*
       
   168  * Set the state to either query or publish based on the request.
       
   169  * @param aState either query or publish.
       
   170  */
       
   171 void CMdnsQueryPublishNotifier::SetState(TMdnsServerMessages aState)
       
   172     {
       
   173     __FLOG(_L8("CMdnsQueryPublishNotifier::SetState - Entry"));
       
   174     iState = aState;
       
   175     __FLOG(_L8("CMdnsQueryPublishNotifier::SetState - Exit"));
       
   176     }
       
   177 
       
   178 /*
       
   179  * Returns the service notifier is  in 
       
   180  * @return iState returns the state. 
       
   181  */
       
   182 TMdnsServerMessages CMdnsQueryPublishNotifier::State() const 
       
   183     {
       
   184     __FLOG(_L8("CMdnsQueryPublishNotifier::State - Entry"));
       
   185     return iState;
       
   186     __FLOG(_L8("CMdnsQueryPublishNotifier::State - Exit"));
       
   187     }