bluetooth/btstack/linkmgr/eirpublisherlocalname.cpp
branchRCL_3
changeset 23 32ba20339036
parent 0 29b1cd4cb562
equal deleted inserted replaced
22:9f17f914e828 23:32ba20339036
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "eirpublisherlocalname.h"
    16 #include "eirpublisherlocalname.h"
    17 #include "linkutil.h"
    17 #include "linkutil.h"
    18 #include <bluetooth/eirpublisherbase.h>
       
    19 #include <bluetooth/logger.h>
    18 #include <bluetooth/logger.h>
       
    19 
       
    20 #include "eirmanserver.h"
    20 
    21 
    21 #ifdef __FLOG_ACTIVE
    22 #ifdef __FLOG_ACTIVE
    22 _LIT8(KLogComponent, LOG_COMPONENT_EIRMANAGER);
    23 _LIT8(KLogComponent, LOG_COMPONENT_EIRMANAGER);
    23 #endif
    24 #endif
    24 
    25 
    27 // CEirPublisherLocalName
    28 // CEirPublisherLocalName
    28 //**********************************
    29 //**********************************
    29 /**
    30 /**
    30 Provides functionality to publish Local Name to EIR.
    31 Provides functionality to publish Local Name to EIR.
    31 **/
    32 **/
    32 CEirPublisherLocalName* CEirPublisherLocalName::NewL()
    33 CEirPublisherLocalName* CEirPublisherLocalName::NewL(CEirManServer& aServer)
    33 	{
    34 	{
    34 	LOG_STATIC_FUNC
    35 	LOG_STATIC_FUNC
    35 	CEirPublisherLocalName* self = new (ELeave) CEirPublisherLocalName();
    36 	CEirPublisherLocalName* self = new (ELeave) CEirPublisherLocalName();
    36 	CleanupStack::PushL(self);
    37 	CleanupStack::PushL(self);
    37 	self->ConstructL();
    38 	self->ConstructL(aServer);
    38 	CleanupStack::Pop();
    39 	CleanupStack::Pop();
    39 	return self;
    40 	return self;
    40 	}
    41 	}
    41 
    42 
    42 CEirPublisherLocalName::CEirPublisherLocalName()
    43 CEirPublisherLocalName::CEirPublisherLocalName()
    43 :	CEirPublisherBase(EEirTagName)
       
    44 	{
    44 	{
    45 	LOG_FUNC
    45 	LOG_FUNC
    46 	}
    46 	}
    47 
    47 
    48 CEirPublisherLocalName::~CEirPublisherLocalName()
    48 CEirPublisherLocalName::~CEirPublisherLocalName()
    49 	{
    49 	{
    50 	LOG_FUNC
    50 	LOG_FUNC
    51 	delete iPublishBuf;
    51 	delete iPublishBuf;
       
    52 	delete iSession;
    52 	}
    53 	}
    53 	
    54 	
    54 void CEirPublisherLocalName::ConstructL()
    55 void CEirPublisherLocalName::ConstructL(CEirManServer& aServer)
    55 	{
    56 	{
    56 	LOG_FUNC
    57 	LOG_FUNC
    57 	CEirPublisherBase::ConstructL();
    58 	iSession = aServer.NewInternalSessionL(*this);
       
    59 	iSession->RegisterTag(EEirTagName);
    58 	}
    60 	}
       
    61 
       
    62 void CEirPublisherLocalName::MeisnRegisterComplete(TInt aResult)
       
    63 	{
       
    64 	if (aResult == KErrNone)
       
    65 		{
       
    66 		iTagRegistered = ETrue;
       
    67 		if (iLocalName.Length() > 0)
       
    68 			{
       
    69 			iSession->NewData(iLocalName.Length());
       
    70 			}
       
    71 		}
       
    72 	}
       
    73 
       
    74 void CEirPublisherLocalName::MeisnSetDataError(TInt /* aError */)
       
    75 	{
    59 	
    76 	
       
    77 	}
       
    78 
       
    79 
    60 void CEirPublisherLocalName::UpdateName(const TDesC8& aName)
    80 void CEirPublisherLocalName::UpdateName(const TDesC8& aName)
    61 	{
    81 	{
    62 	LOG_FUNC
    82 	LOG_FUNC
    63 	// Check aName isn't longer than 248 characters
    83 	// Check aName isn't longer than 248 characters
    64 	__ASSERT_DEBUG(aName.Length() <= 248, Panic(EEIRPublisherUpdateNameTooLong));
    84 	__ASSERT_DEBUG(aName.Length() <= 248, Panic(EEIRPublisherUpdateNameTooLong));
    65 	iLocalName = aName;
    85 	iLocalName = aName;
    66 	iPublisher->PublishData(aName.Size());
    86 	if (iTagRegistered)
       
    87 		{
       
    88 		iSession->NewData(iLocalName.Size());
       
    89 		}
    67 	}
    90 	}
    68 	
    91 	
    69 
    92 
    70 // From MEirPublisherNotifier
    93 // From MEirPublisherNotifier
    71 void CEirPublisherLocalName::MepnSpaceAvailable(TUint aBytesAvailable)
    94 void CEirPublisherLocalName::MeisnSpaceAvailable(TUint aBytesAvailable)
    72 	{
    95 	{
    73 	LOG_FUNC
    96 	LOG_FUNC
    74 	// Delete memory from last time this was called
    97 	// Delete memory from last time this was called
    75 	delete iPublishBuf, iPublishBuf = NULL;
    98 	delete iPublishBuf, iPublishBuf = NULL;
    76 	
    99 	
    82 		{
   105 		{
    83 		// Truncate the device name to space available
   106 		// Truncate the device name to space available
    84 		iPublishBuf = iLocalName.Left(avail).Alloc();
   107 		iPublishBuf = iLocalName.Left(avail).Alloc();
    85 		if(iPublishBuf)
   108 		if(iPublishBuf)
    86 			{
   109 			{
    87 			iPublisher->SetData(*iPublishBuf, EEirDataPartial);
   110 			iSession->SetData(*iPublishBuf, EEirDataPartial);
    88 			}
   111 			}
    89 		}
   112 		}
    90 	else
   113 	else
    91 		{
   114 		{
    92 		// Zero-length device names will be published as "complete"
   115 		// Zero-length device names will be published as "complete"
    93 		// as defined in the specification, volume 3, part C, 8.1
   116 		// as defined in the specification, volume 3, part C, 8.1
    94 		iPublishBuf = iLocalName.Alloc();
   117 		iPublishBuf = iLocalName.Alloc();
    95 		if(iPublishBuf)
   118 		if(iPublishBuf)
    96 			{
   119 			{
    97 			iPublisher->SetData(*iPublishBuf, EEirDataComplete);
   120 			iSession->SetData(*iPublishBuf, EEirDataComplete);
    98 			}
   121 			}
    99 		}
   122 		}
   100 	// Final case to handle if OOM occurs.
   123 	// Final case to handle if OOM occurs.
   101 	if(!iPublishBuf)
   124 	if(!iPublishBuf)
   102 		{
   125 		{
   103 		iPublisher->SetData(KNullDesC8(), EEirDataPartial);
   126 		iSession->SetData(KNullDesC8(), EEirDataPartial);
   104 		}
   127 		}
   105 	}
   128 	}
   106 	
   129 
   107 void CEirPublisherLocalName::MepnSetDataError(TInt /*aResult*/)
   130 
   108 	{
       
   109 	LOG_FUNC
       
   110 	}