zeroconf/server/src/CBaseHandler.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 // cbasehandler.cpp
       
    15 // 
       
    16 //
       
    17 /**
       
    18 @file
       
    19 @internalTechnology
       
    20 */
       
    21 
       
    22 //System include 
       
    23 #include <mdns/ccacheentry.h>
       
    24 #include <mdns/cdnsmessage.h>
       
    25 
       
    26 //User Include 
       
    27 #include "cbasehandler.h"
       
    28 __FLOG_STMT(_LIT8(KComponent,"MDNSServer");)
       
    29 /*
       
    30  * Two phase constructor
       
    31  * @param aDnsMessage pointer to DnsMessage which should be sent to the network.
       
    32  * @param  aTransactionId transaction id
       
    33  * @param  aTime time at which this message should be scheduled.
       
    34  * @Param  aSockAddr address to which this should be sent.
       
    35  */
       
    36 COutStandingQuery* COutStandingQuery::NewL(CDnsMessage* aDnsMessage,TInt aTransactionId,TTime aTime, TSockAddr aAddr)
       
    37 	{
       
    38 	COutStandingQuery* self = new (ELeave) COutStandingQuery(aDnsMessage,aTransactionId, aTime, aAddr);	
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop();
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 /*
       
    46  * Destructor
       
    47  */
       
    48 COutStandingQuery::~COutStandingQuery()
       
    49 	{
       
    50 	__FLOG(_L8("COutStandingQuery::~COutStandingQuery- Entry"));
       
    51 	delete iDnsMessage;
       
    52 	__FLOG(_L8("COutStandingQuery::~COutStandingQuery- Exit"));
       
    53 	__FLOG_CLOSE;
       
    54 	}
       
    55 
       
    56 /*
       
    57  * @return iReviewTime returns the time data is added to queue.
       
    58  */
       
    59  TTime COutStandingQuery::GetAddTime() const
       
    60 	{
       
    61 	__FLOG(_L8("COutStandingQuery::GetAddTime- Entry"));
       
    62 	__FLOG(_L8("COutStandingQuery::GetAddTime- Exit"));
       
    63 	return iReviewTime;
       
    64 	}
       
    65 	
       
    66  /*
       
    67   *Sets the clienhandle (session) which request for the query.
       
    68   *@param aHandle Sessionid of the client. 
       
    69   */
       
    70 void COutStandingQuery::SetClientHandle(TInt aHandle)
       
    71 	{
       
    72 	__FLOG(_L8("COutStandingQuery::SetClientHandle- Entry"));
       
    73 	iClientHandle = aHandle;
       
    74 	__FLOG(_L8("COutStandingQuery::SetClientHandle- Exit"));
       
    75 	}
       
    76 	
       
    77 /*
       
    78  * @return returns ths transaction id
       
    79  */
       
    80 TInt COutStandingQuery::TransactionId()const 
       
    81 	{
       
    82 	__FLOG(_L8("COutStandingQuery::TransactionId- Entry"));
       
    83 	return iTransactionID;	
       
    84 	}
       
    85 
       
    86 /*
       
    87  * @return returns the socket address
       
    88  */
       
    89 TSockAddr COutStandingQuery::SocketAddress()const
       
    90 	{
       
    91 	__FLOG(_L8("COutStandingQuery::SocketAddress- Entry"));
       
    92 	return iSockAddress;	
       
    93 	}
       
    94 
       
    95 /*
       
    96  * @return iDnsMessage returns the reference to dns message.
       
    97  */
       
    98 CDnsMessage& COutStandingQuery::DnsMessage()const
       
    99 	{
       
   100 	__FLOG(_L8("COutStandingQuery::DnsMessage- Entry"));
       
   101 	return *iDnsMessage;	
       
   102 	}
       
   103 
       
   104 /*
       
   105  * Two phase constructor
       
   106  */
       
   107 void COutStandingQuery::ConstructL()
       
   108 	{
       
   109 	__FLOG_OPEN(KMDNSSubsystem, KComponent);
       
   110 	}
       
   111 
       
   112 /*
       
   113  * Constructor
       
   114  * @param aDnsMessage pointer to DnsMessage which should be sent to the network.
       
   115  * @param  aTransactionId transaction id
       
   116  * @param  aTime time at which this message should be scheduled.
       
   117  * @Param  aSockAddr address to which this should be sent.
       
   118  */
       
   119 COutStandingQuery::COutStandingQuery(CDnsMessage* aDnsMessage,TInt aTransactionId,TTime aTime, TSockAddr aAddr): iDnsMessage(aDnsMessage) , iTransactionID(aTransactionId) ,iReviewTime(aTime), iSockAddress(aAddr)
       
   120 	{
       
   121 	iClientHandle = 0;
       
   122 	}
       
   123 
       
   124 /*
       
   125  * @return iClientHandle clinethandle to which request is handled.
       
   126  */
       
   127 TInt  COutStandingQuery::ClientHandle() const
       
   128 	{
       
   129 	__FLOG(_L8("COutStandingQuery::ClientHandle- Entry"));
       
   130 	return iClientHandle;	
       
   131 	}
       
   132 
       
   133 /**
       
   134 Two phase constructor
       
   135 @param aMessageHandler refernce to messagehandler
       
   136 @return void
       
   137 */
       
   138 CBaseHandler* CBaseHandler::NewL(CMessageHandler& aMessageHandler)
       
   139 	{
       
   140 	CBaseHandler* self = new (ELeave)CBaseHandler(aMessageHandler);
       
   141 	CleanupStack::PushL(self);
       
   142 	self->ConstructL();
       
   143 	CleanupStack::Pop();
       
   144 	return self;	
       
   145 	}
       
   146 /**
       
   147 Destructor
       
   148 */	
       
   149 CBaseHandler::~CBaseHandler()
       
   150 	{
       
   151 	__FLOG(_L8("CBaseHandler::~CBaseHandler - Entry"));
       
   152 	Cancel();
       
   153 	iOutStandingQueryArray.ResetAndDestroy();
       
   154 	iOutStandingQueryArray.Close();
       
   155 	__FLOG(_L8("CBaseHandler::~CBaseHandler - Exit"));
       
   156 	__FLOG_CLOSE;
       
   157 	}
       
   158 
       
   159 /**
       
   160 Constructor
       
   161 */	 
       
   162 CBaseHandler::CBaseHandler(CMessageHandler& aMessageHandler): CTimer(EPriorityStandard),iMessageHandler(aMessageHandler)
       
   163 	{
       
   164 	
       
   165 	CActiveScheduler::Add(this);	
       
   166 	
       
   167 	}
       
   168 /**
       
   169 Two phase constructor
       
   170 */
       
   171 void CBaseHandler::ConstructL()
       
   172 	{
       
   173 	__FLOG_OPEN(KMDNSSubsystem, KComponent);
       
   174 	__FLOG(_L8("CBaseHandler::Open - Entry"));
       
   175 	CTimer::ConstructL();
       
   176 	__FLOG(_L8("CBaseHandler::Open - Exit"));
       
   177 	}
       
   178 /**
       
   179 Constant function returns a reference to messagehandler
       
   180 */
       
   181 CMessageHandler& CBaseHandler::MessageHandler()const
       
   182 	{
       
   183 	__FLOG(_L8("CBaseHandler::MessageHandler - Entry Exit"));
       
   184 	return iMessageHandler;	
       
   185 	}
       
   186 	
       
   187 /**
       
   188 Handles any incoming packet
       
   189 @param aMessage packet recieved form mdns port
       
   190 */
       
   191 void CBaseHandler::HandleIncomingPacketL(CDnsMessage& /*aMessage*/, const TSockAddr& /*aAddr*/)
       
   192 	{
       
   193 	__FLOG(_L8("CBaseHandler::HandleIncomingPacketL - Entry"));
       
   194 	//Nothing  To do ...........	
       
   195 	__FLOG(_L8("CBaseHandler::HandleIncomingPacketL - Exit"));
       
   196 	}
       
   197 
       
   198 /*
       
   199  * Wait for 120ms after the query is sent to the network.
       
   200  * After 120ms asynchronous request gets complete and will hit this runl
       
   201  * server will be notified with the same and it will take care of sending the 
       
   202  * response back to client.
       
   203  */
       
   204 void CBaseHandler::RunL()
       
   205 	{
       
   206 	__FLOG(_L8("CBaseHandler::RunL - Entry"));
       
   207 	COutStandingQuery* query = iOutStandingQueryArray[0];
       
   208 	if(0 != query->ClientHandle())
       
   209 		{
       
   210 		MessageHandler().NotifyClientQuery(query->ClientHandle());	
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		IsLastTruncated = EFalse;	
       
   215 		}	
       
   216 	iOutStandingQueryArray.Remove(0);
       
   217 	if(iOutStandingQueryArray.Count())
       
   218 		{
       
   219 		SetActive();
       
   220 		const TTime outTime = iOutStandingQueryArray[0]->GetAddTime();
       
   221 		At(outTime);
       
   222 		}
       
   223 	__FLOG(_L8("CBaseHandler::Open - Exit"));
       
   224 	delete query;	
       
   225 	}
       
   226 	
       
   227 /*
       
   228  * Nothing to do.
       
   229  */	
       
   230 void CBaseHandler::DoCancel()
       
   231 	{
       
   232 	__FLOG(_L8("CBaseHandler::RunL - Exit"));	
       
   233 	}
       
   234 
       
   235 
       
   236 
       
   237