commsfwutils/commsbufs/mbufgobblerlayer/src/mbufgobblerhelper.cpp
changeset 78 dd4909eb54cd
equal deleted inserted replaced
77:c9776eadbffd 78:dd4909eb54cd
       
     1 // Copyright (c) 2010 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 // Helper class supplying useful logging functions to the providers in the layer
       
    15 //
       
    16 //
       
    17 //  This is a 3-plane comms layer implementation example, which has been customised to be a test layer which gobbles and releases ESOCK MBUFs.
       
    18 //  The MBuf gobbling functionality can be disabled by undefining the macro SYMBIAN_COMMSFW_MBUF_GOBBLER which is specified in mbufgobblerproviders.mmp.
       
    19 //  When SYMBIAN_COMMSFW_MBUF_GOBBLER is undefined, the source code specified by mbufgobblerproviders.mmp becomes a pass through layer i.e. it passes the data
       
    20 //  through to the layer above or below without altering it. This makes it useful as a starting point for implementing your own layers / providers;
       
    21 //  useful documentation on how to customise your own passthrough layer can be found in ..\docs\MbufGobblerLayer.doc
       
    22 //
       
    23 /**
       
    24  @file
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 #include "mbufgobblerhelper.h"
       
    29 #include "mbufgobblerlog.h"
       
    30 #include <elements/mm_node.h>
       
    31 #include <comms-infras/ss_nodeinterfaces.h>
       
    32 
       
    33 
       
    34 void MbufGobblerHelper::LogCreateDestroy(const TDesC8& aSubTag, const TDesC8& aNodeName, TAny* aNodePtr, TBool aIsCreate)
       
    35 	{
       
    36 	// to eradicate warnings on builds for which the LOG macro does nothing (e.g. urel)
       
    37 	(void)(aSubTag); (void)(aNodeName); (void)(aNodePtr); (void)(aIsCreate);
       
    38 	
       
    39 	if(aIsCreate)
       
    40 		{
       
    41 		LOG(aSubTag,_L8("%S (0x%x) Created"), &aNodeName, aNodePtr);
       
    42 		}		
       
    43 	else
       
    44 		{
       
    45 		LOG(aSubTag,_L8("%S (0x%x) Destroyed"), &aNodeName, aNodePtr);
       
    46 		}		
       
    47 	}
       
    48 
       
    49 void MbufGobblerHelper::LogMessage(const TDesC8& aSubTag, const TDesC8& aNodeName, TAny* aNodePtr, const Messages::TRuntimeCtxId& aSender, const Messages::TNodeId& aRecipient, Messages::TSignatureBase& aMessage)
       
    50 	{
       
    51 	// to eradicate warnings on builds for which the LOG macro does nothing (e.g. urel)
       
    52 	(void)(aSubTag); (void)(aNodeName); (void)(aNodePtr);
       
    53 
       
    54 	TInt msgId = aMessage.MessageId().MessageId();
       
    55 	TInt realm = aMessage.MessageId().Realm();
       
    56 	
       
    57 	TUint32 threadid_of_sender = aSender.Thread();
       
    58 	Messages::TNodeId nid = Messages::address_cast<Messages::TNodeId>(aSender);
       
    59 	TAny* ptr = nid.Ptr(); //this seems to be the only hting that can be used to print out something to address the node
       
    60 	TAny* rptr = aRecipient.Ptr();
       
    61 	__CFLOG_VAR((KMbufGobblerComponentTag, aSubTag,_L8("Node %S(0x%x) message received (msgid=%d, realm=0x%x), sender(0x%x threadID=%d)"), &aNodeName, rptr, msgId, realm, ptr, threadid_of_sender));
       
    62 	}
       
    63 
       
    64 void MbufGobblerHelper::PrintClientNodes(const TDesC8& aSubTag, const TDesC8& aNodeName, MeshMachine::AMMNodeBase& aNode, TInt& aClientCount)
       
    65 	{
       
    66 	// to eradicate warnings on builds for which the LOG macro does nothing (e.g. urel)
       
    67 	(void)(aSubTag); (void)(aNodeName);
       
    68 
       
    69 	TUint type = ESock::TCFClientType::EData | ESock::TCFClientType::ECtrl | ESock::TCFClientType::EServProvider | ESock::TCFClientType::ECtrlProvider;
       
    70 	TInt totclients =  	aNode.CountClients<Messages::TDefaultClientMatchPolicy>(type);
       
    71 	//only print if count different than previous
       
    72 	if(aClientCount != totclients)
       
    73 		{
       
    74 		aClientCount = 	totclients;
       
    75 		LOG(aSubTag,_L8("Printing Node %S(0x%x) info..."), &aNodeName, aNode.Id().Ptr());
       
    76 		LOG(aSubTag, _L8("\tTotal Num clients = %d"), totclients);
       
    77 		
       
    78 		//enumerate through clients	
       
    79 		Messages::TClientIter<Messages::TDefaultClientMatchPolicy> clientIter(aNode.GetClientIter<Messages::TDefaultClientMatchPolicy>(type));
       
    80 		Messages::RNodeInterface* client = clientIter++;
       
    81 		while (client)
       
    82 			{
       
    83 			
       
    84 			Messages::TNodeId id = client->RecipientId();
       
    85 			//look up node type
       
    86 			TBuf8<20> typlu;
       
    87 			switch(client->Type())
       
    88 				{
       
    89 				case ESock::TCFClientType::EUnknown:
       
    90 					typlu = _L8("EUnknown");
       
    91 					break;
       
    92 				case ESock::TCFClientType::EData:
       
    93 					typlu = _L8("EData");
       
    94 					break;
       
    95 				case ESock::TCFClientType::ECtrl:
       
    96 					typlu = _L8("ECtrl");
       
    97 					break;
       
    98 				case ESock::TCFClientType::EServProvider:
       
    99 					typlu = _L8("EServProvider");
       
   100 					break;
       
   101 				case ESock::TCFClientType::ECtrlProvider:
       
   102 					typlu = _L8("ECtrlProvider");
       
   103 					break;
       
   104 				default:
       
   105 					typlu = _L8("Unknown");
       
   106 					break;
       
   107 				}
       
   108 			LOG(aSubTag, _L8("\t\tClientNode(0x%x) type=%d(%S), flags=%d"), id.Ptr(), client->Type(), &typlu, client->Flags());
       
   109 			client = clientIter++;
       
   110 			}
       
   111 		}
       
   112 		
       
   113 	}
       
   114