servicediscoveryandcontrol/pnp/test/upnp/upnpmessage/src/cupnpmessagecomposer.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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 //
       
    15 
       
    16 #include "cupnpmessagecomposer.h"
       
    17 #include <http/thttphdrfielditer.h>
       
    18 #include "mcomposerobserver.h"
       
    19 
       
    20 __FLOG_STMT(_LIT8(KSubsys,"UPnPComposer");)
       
    21 __FLOG_STMT(_LIT8(KComponent,"UPnPMessage");)
       
    22 
       
    23 CUPnPMessageComposer ::~CUPnPMessageComposer ()
       
    24 	{
       
    25 	Cancel ();
       
    26 	iMessageComposer.Close ();
       
    27 	iDataChain.Close();
       
    28 	__FLOG(_L8("-> Request composer destroyed"));
       
    29 	__FLOG_CLOSE;		
       
    30 	}
       
    31 CUPnPMessageComposer::CUPnPMessageComposer (MComposerObserver& aObserver)
       
    32 : CActive (EPriorityNormal),
       
    33 iObserver ( aObserver )
       
    34 	{
       
    35 	CActiveScheduler::Add(this);
       
    36 	}
       
    37 
       
    38 void CUPnPMessageComposer::ConstructL ()
       
    39 	{
       
    40 	iMessageComposer.OpenL(*this);
       
    41 	__FLOG_OPEN(KSubsys, KComponent);
       
    42 	__FLOG(_L8("-> Response composer created"));		
       
    43 	}
       
    44 
       
    45 EXPORT_C void CUPnPMessageComposer::NotifyNewBodyData()
       
    46 	{
       
    47 	if ( !IsActive () )
       
    48 		CompleteSelf();
       
    49 	else
       
    50 		return;
       
    51 	}
       
    52 
       
    53 // From MHttpMessageComposerObserver
       
    54 void CUPnPMessageComposer::MessageComplete()
       
    55 	{
       
    56 	__FLOG(_L8("-> Message complete\n"));
       
    57 	iFieldIterPos = 0;
       
    58 	iObserver.ComposingConcluded();
       
    59 	}
       
    60 
       
    61 void CUPnPMessageComposer::MessageDataReadyL()
       
    62 	{
       
    63 	__FLOG(_L8("-> Got composed request"));
       
    64 	TPtrC8 dataPtr;
       
    65 	iMessageComposer.GetMessageData(dataPtr);
       
    66 
       
    67 	__FLOG_1(_L8("%S"), &dataPtr);
       
    68 	
       
    69 	// Notify the observer that there is message data ready to send.
       
    70 	iDataChain.Close();
       
    71 	iDataChain.CreateL(dataPtr);
       
    72 	iObserver.MessageDataReadyL(iDataChain);
       
    73 	}
       
    74 
       
    75 TInt CUPnPMessageComposer::HandleComposeError(TInt aError)
       
    76 	{
       
    77 	// The Message Composer has found a problem. Report to error to the observer.
       
    78 	__FLOG_1(_L8("-> HTTP message composer received error: %d"), aError);
       
    79 	iFieldIterPos = 0;
       
    80 	iObserver.ComposerError(aError);
       
    81 	return KErrNone;
       
    82 	}
       
    83 
       
    84 //void CUPnPMessageComposer::StartLineL(TPtrC8& /*aVersion*/, TPtrC8& /*aStatusCode*/, TPtrC8& /*aStatusText*/)
       
    85 //	{
       
    86 //	ASSERT(0);		
       
    87 //	}
       
    88 
       
    89 //TInt CUPnPMessageComposer::NextHeaderL(TPtrC8& /*aHeaderName*/, TPtrC8& /*aHeaderValue*/)
       
    90 //	{
       
    91 //	ASSERT(0);	
       
    92 //	return KErrNone;	
       
    93 //	}
       
    94 
       
    95 //MHTTPDataSupplier* CUPnPMessageComposer::HasBodyL()	
       
    96 //	{
       
    97 //	ASSERT(0);	
       
    98 //	return NULL;	
       
    99 //	}
       
   100 
       
   101 //TInt CUPnPMessageComposer::NextTrailerL(TPtrC8& /*aHeaderName*/, TPtrC8& /*aHeaderValue*/)
       
   102 //	{
       
   103 //	ASSERT(0);	
       
   104 //	return 0;	
       
   105 //	}
       
   106 
       
   107 // From CActive
       
   108 void CUPnPMessageComposer::RunL ()
       
   109 	{
       
   110 	__FLOG_1(_L8("-> HTTP message composer RunL called: %d"), iStatus.Int());
       
   111 	User::LeaveIfError (iStatus.Int());
       
   112 	iMessageComposer.MessageInfoAvailable ();		
       
   113 	}
       
   114 
       
   115 TInt CUPnPMessageComposer::RunError ()
       
   116 	{
       
   117 	__FLOG_0(_L8("-> Composer called RunError"));
       
   118 	iFieldIterPos = 0;
       
   119 	iObserver.ComposerError(KErrUnknown);
       
   120 	return KErrNone;		
       
   121 	}
       
   122 
       
   123 void CUPnPMessageComposer::CompleteSelf ()
       
   124 	{
       
   125 	TRequestStatus* pStat = &iStatus;
       
   126 	User::RequestComplete(pStat, KErrNone);
       
   127 	SetActive();		
       
   128 	}