zeroconf/client/src/cmdnsregisternotifier.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 // cmdnsregisternotifier.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19 @file
       
    20 @internalTechnology
       
    21 */
       
    22 
       
    23 //System include
       
    24 #include <mdns/mdnsparamset.h>
       
    25 #include <pnp/mpnpobserver.h>
       
    26 
       
    27 //User include
       
    28 #include "cmdnsregisternotifier.h"
       
    29 #include "cmdnsclient.h"
       
    30 __FLOG_STMT(_LIT8(KComponent,"CMdnsRegisterNotifier");)
       
    31 /*
       
    32  * Two phase constructor
       
    33  * @param aMdns reference to RMdns client object
       
    34  */
       
    35 CMdnsRegisterNotifier* CMdnsRegisterNotifier::NewL(RMdns& aMdns)
       
    36     {
       
    37     CMdnsRegisterNotifier* self = new (ELeave) CMdnsRegisterNotifier(aMdns);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     return self ;
       
    42     }
       
    43 /*
       
    44  * Destructor
       
    45  */
       
    46 CMdnsRegisterNotifier::~CMdnsRegisterNotifier()
       
    47     {
       
    48     __FLOG(_L8("CMdnsRegisterNotifier:: - Entry"));
       
    49     //Cancel any pending asynchronous request.
       
    50     Cancel();
       
    51     delete iNotifyRcvdMessage;
       
    52     iNotifyRcvdMessage = NULL;
       
    53     __FLOG(_L8("CMdnsRegisterNotifier:: - Exit"));
       
    54     __FLOG_CLOSE;
       
    55     }
       
    56 
       
    57 /*
       
    58  * Constructor
       
    59  * @param aMdns reference to mdns object.
       
    60  */
       
    61 CMdnsRegisterNotifier::CMdnsRegisterNotifier(RMdns& aMdns):CActive(EPriorityStandard),iMdns(aMdns),iPtrNotifyRcvdMessage(NULL,0,0)
       
    62     {
       
    63     
       
    64     }
       
    65 
       
    66 /*
       
    67  * Two phase constructor
       
    68  * Construct a buffer to recieve a new record from the network.
       
    69  * and start listening to it.
       
    70  */
       
    71 void CMdnsRegisterNotifier::ConstructL()
       
    72     {
       
    73     __FLOG_OPEN(KMDNSSubsystem, KComponent);
       
    74     __FLOG(_L8("CMdnsRegisterNotifier::ConstructL - Entry"));
       
    75     CActiveScheduler::Add(this);
       
    76     iNotifyRcvdMessage = HBufC8::NewL(KMaxDNSNameLength);
       
    77     iPtrNotifyRcvdMessage.Set(iNotifyRcvdMessage->Des());
       
    78     Start();
       
    79     __FLOG(_L8("CMdnsRegisterNotifier::ConstructL - Exit"));
       
    80     }
       
    81 /*
       
    82  * Constructs a bundle and notifies the same to the client.
       
    83  *  
       
    84  */
       
    85 void CMdnsRegisterNotifier::RunL()
       
    86     {
       
    87     __FLOG(_L8("CMdnsRegisterNotifier::RunL - Entry"));
       
    88     if(iObserver != NULL)
       
    89         {
       
    90         if(iStatus.Int() == KErrNone)
       
    91             {
       
    92             RPnPParameterBundle pnpBundle;
       
    93             pnpBundle.CreateL();
       
    94             pnpBundle.Load(iPtrNotifyRcvdMessage);
       
    95             iObserver->OnPnPEventL(pnpBundle);
       
    96             pnpBundle.Close();
       
    97             }
       
    98         else 
       
    99             {
       
   100             iObserver->OnPnPError(iStatus.Int());
       
   101             }
       
   102         }
       
   103     Start();
       
   104     __FLOG(_L8("CMdnsRegisterNotifier::RunL - Exit"));
       
   105     }
       
   106 
       
   107 /*
       
   108  * Clears the buffer .
       
   109  */
       
   110 void CMdnsRegisterNotifier::DoCancel()
       
   111     {
       
   112     __FLOG(_L8("CMdnsRegisterNotifier::DoCancel - Entry"));
       
   113     TRequestStatus * status = &iStatus;
       
   114     User::RequestComplete(status,KErrCancel);
       
   115     delete iNotifyRcvdMessage;
       
   116     iNotifyRcvdMessage = NULL;
       
   117     __FLOG(_L8("CMdnsRegisterNotifier::DoCancel - Exit"));
       
   118     }
       
   119 
       
   120 /*
       
   121  * Returns the error to activeschedluler as the RunL is not expected to leave.
       
   122  * @param aError error with which RunL leaves.
       
   123  * @return aError returns the error back to activescheduler .
       
   124  */
       
   125 TInt CMdnsRegisterNotifier::RunError(TInt aError)
       
   126     {
       
   127     __FLOG(_L8("CMdnsRegisterNotifier::RunError - Entry"));
       
   128     return aError;
       
   129     __FLOG(_L8("CMdnsRegisterNotifier::RunError - Exit"));
       
   130     }
       
   131 
       
   132 /*
       
   133  * Start as Asynchoronous request and wait for this to be completed by the server .
       
   134  * Will be called internally whenever a client requests for the notification.
       
   135  * 
       
   136  */
       
   137 void CMdnsRegisterNotifier::Start()
       
   138     {
       
   139     __FLOG(_L8("CMdnsRegisterNotifier::Start - Entry"));
       
   140     iStatus = KRequestPending;
       
   141     iMdns.RecieveNotifyMessageL(iPtrNotifyRcvdMessage,iStatus);
       
   142     SetActive();
       
   143     __FLOG(_L8("CMdnsRegisterNotifier::Start - Exit"));
       
   144     }
       
   145 
       
   146 /*
       
   147  * Set the observer
       
   148  * @param aObserver a pointer to the observer sent by the client along with the bundle.
       
   149  */
       
   150 void CMdnsRegisterNotifier::SetPnpObserver(MPnPObserver* aObserver)
       
   151     {
       
   152     __FLOG(_L8("CMdnsRegisterNotifier::SetPnpObserver - Entry"));
       
   153     iObserver = aObserver;
       
   154     __FLOG(_L8("CMdnsRegisterNotifier::SetPnpObserver - Exit"));
       
   155     }