bluetooth/btcomm/src/locker.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1997-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 // Locker.cpp - all the active connector code
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <cs_port.h>
       
    19 #include "btcomm.h"
       
    20 #include "btcommactive.h"
       
    21 
       
    22 CBTPortLocker *CBTPortLocker::NewL(CBTPortProxy *aParent)
       
    23 /**
       
    24 	Create new CBTPortLocker.
       
    25 	This function creates a new CBTPortLocker active object.
       
    26 **/
       
    27 	{
       
    28 	CBTPortLocker *cc;
       
    29 	cc=new (ELeave) CBTPortLocker();
       
    30 	CleanupStack::PushL(cc);
       
    31 	cc->InitL(aParent);
       
    32 	CleanupStack::Pop();
       
    33 	CActiveScheduler::Add(cc);
       
    34 	return cc;
       
    35 	}
       
    36 
       
    37 void CBTPortLocker::InitL(CBTPortProxy *aParent)
       
    38 	{
       
    39 	iPortProxy=aParent;
       
    40 	}
       
    41 
       
    42 CBTPortLocker::~CBTPortLocker()
       
    43 /**
       
    44 	CBTPortLocker destructor.	
       
    45 **/
       
    46 	{
       
    47 	Cancel();
       
    48 	}
       
    49 
       
    50 void CBTPortLocker::RunL()
       
    51 /**
       
    52 	CBTPortLocker RunL.
       
    53 	Active status cleared.  We can now call the DoLockedAction 
       
    54 	function on the corresponding port proxy object.
       
    55 **/
       
    56 	{
       
    57     if(iStatus==KErrNone)
       
    58         iPortProxy->DoLockedAction();
       
    59 	}
       
    60 
       
    61 void CBTPortLocker::LockSession()
       
    62 /**
       
    63 	CBTPortLocker LockSession.
       
    64 	This function initiates the process of making the session exclusive
       
    65 	on the socket server.
       
    66 **/
       
    67 	{
       
    68     if(!IsActive())
       
    69         {
       
    70 		// We need to complete this request either by actually getting a
       
    71 		// lock on ESock if we've got a handle, or by just completing the 
       
    72 		// request if we don't.  It's fine to do the DoLockedAction() 
       
    73 		// without a locker if we don't have an ESock handle, as we can't
       
    74 		// be making any requests to ESock.
       
    75 		if(iPortProxy->iSockServ.Handle())
       
    76 			{
       
    77 			iPortProxy->iSockServ.SetExclusiveMode(iStatus);
       
    78 			SetActive();
       
    79 			}
       
    80 		else
       
    81 			{
       
    82 			SetActive();
       
    83 			TRequestStatus* status = &iStatus;
       
    84 			User::RequestComplete(status, KErrNone);
       
    85 			}
       
    86 		}
       
    87 	iLockOn=ETrue;
       
    88 	}
       
    89 
       
    90 void CBTPortLocker::UnlockSession()
       
    91 /**
       
    92 	CBTPortLocker UnlockSession.
       
    93 **/
       
    94 	{
       
    95     if(iPortProxy->iSockServ.Handle())
       
    96         iPortProxy->iSockServ.ClearExclusiveMode();
       
    97 	iLockOn=EFalse;
       
    98 	}
       
    99 
       
   100 void CBTPortLocker::DoCancel()
       
   101 /**
       
   102 	CBTPortLocker DoCancel.
       
   103 	Nothing to cancel.
       
   104 **/
       
   105 	{
       
   106 	}
       
   107 
       
   108 CBTPortLocker::CBTPortLocker() 
       
   109 	: CActive (1020)
       
   110 /**
       
   111 	CBTPortLocker private c'tor.
       
   112 	Note that this active object is set with a priority
       
   113 	of 1020 which is higher than any other active object 
       
   114 	running on the c32 active scheduler (note IrCOMM locker
       
   115 	has a priority of 1000).  This means that this active 
       
   116 	object will always be first in the scheduler's
       
   117 	list of completed actions when it is completes.
       
   118 **/
       
   119 	{
       
   120 	}
       
   121 
       
   122 TBool CBTPortLocker::IsSessionLocked()
       
   123 	{
       
   124 	return iLockOn;
       
   125 	}