bluetooth/btlogger/btsnoophcilogger/src/hciloggerimpl.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-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 "hciloggerbtsnoop.h"
       
    17 
       
    18 EXPORT_C MHCIFrameLogger* CHCILoggerBtSnoop::GetInstanceL()
       
    19 	{
       
    20 	CHCILoggerBtSnoop* self = static_cast<CHCILoggerBtSnoop*>(Dll::Tls());
       
    21 	if (!self)
       
    22 		{
       
    23 		self = NewLC();
       
    24 		User::LeaveIfError(Dll::SetTls(self));
       
    25 		CleanupStack::Pop(self);
       
    26 		}
       
    27 	++(self->iRefCount);
       
    28 	return self;		
       
    29 	}
       
    30 
       
    31 void CHCILoggerBtSnoop::SetLibrary(RLibrary& aLib)
       
    32 	{
       
    33 	if(iRefCount > 1)
       
    34 		{
       
    35 		__ASSERT_DEBUG(iMyLib.Handle(), User::Panic(_L("BtSnoopLogger"), EBtSnoopLoggerPanicNoMyLibHandle));
       
    36 		return;
       
    37 		}
       
    38 	__ASSERT_DEBUG(!iMyLib.Handle(), User::Panic(_L("BtSnoopLogger"), EBtSnoopLoggerPanicHandleAlreadyExists));
       
    39 	iMyLib.SetHandle(aLib.Handle());
       
    40 	aLib.SetHandleNC(iMyLib.Handle());
       
    41 	}
       
    42 
       
    43 void CHCILoggerBtSnoop::GetLibrary(RLibrary& aLib)
       
    44 	{
       
    45 	if(iRefCount > 1)
       
    46 		{
       
    47 		aLib.SetHandleNC(iMyLib.Handle());
       
    48 		}
       
    49 	else // Give final client full control of the handle!
       
    50 		{
       
    51 		aLib.SetHandle(iMyLib.Handle());
       
    52 		}
       
    53 	}
       
    54 
       
    55 void CHCILoggerBtSnoop::Release()
       
    56 	{
       
    57 	__ASSERT_DEBUG((iRefCount > 0), User::Panic(_L("BtSnoopLogger"), EBtSnoopLoggerPanicRefCountTooLow));
       
    58 	--iRefCount;
       
    59 	if(iRefCount == 0)
       
    60 		{
       
    61 		delete this;
       
    62 		Dll::SetTls(0);
       
    63 		}
       
    64 	}
       
    65 
       
    66 void CHCILoggerBtSnoop::Initialise(TInt aType)
       
    67 	{
       
    68 	if (iRefCount > 1)
       
    69 		{
       
    70 		__ASSERT_DEBUG(iInitialised, User::Panic(_L("BtSnoopLogger"), EBtSnoopLoggerPanicHasntBeenInitialised));
       
    71 		return;
       
    72 		}
       
    73 	__ASSERT_DEBUG(!iInitialised, User::Panic(_L("BtSnoopLogger"), EBtSnoopLoggerPanicShouldNotBeInitialised));
       
    74 	DoInitialise(aType);
       
    75 	iInitialised = ETrue;	// this flag implies the DoInitialise() function has
       
    76 							// been called, but not that it was necessarily
       
    77 							// successful.
       
    78 	}
       
    79