bthci/hci2implementations/CommandsEvents/symbian/src/Command.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2006-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 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <bluetooth/hci/command.h>
       
    22 #include <bluetooth/hci/commandstatusevent.h>
       
    23 #include <bluetooth/hci/event.h>
       
    24 #include <bluetooth/hci/commandcompleteevent.h>
       
    25 #include <bluetooth/hci/hcievents.h>
       
    26 #include <bluetooth/hci/hciframe.h>
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_COMMANDSEVENTS_SYMBIAN);
       
    30 #endif
       
    31 
       
    32 
       
    33 /***************  CHCICommandBase *******************************************/
       
    34 
       
    35 EXPORT_C THCIOpcode CHCICommandBase::Opcode() const
       
    36 	{
       
    37 	return(iOpcode);	
       
    38 	}
       
    39 
       
    40 CHCICommandBase::CHCICommandBase(THCIOpcode aOpcode)
       
    41 	: iOpcode(aOpcode)
       
    42 	, iCreditsConsumed(1) // Default is 1 consumed credit.
       
    43 	, iExpectsCommandStatusEvent(ETrue) // Default is command status event is expected
       
    44 	, iExpectsCommandCompleteEvent(ETrue) //  Default is command complete event is expected
       
    45 	{
       
    46 	}
       
    47 
       
    48 /**
       
    49 Method to get the number of credits consumed by command.
       
    50 @return The number of credits consumed by issuing this command.
       
    51 */
       
    52 	
       
    53 EXPORT_C TUint CHCICommandBase::CreditsConsumed() const
       
    54 	{
       
    55 	return iCreditsConsumed;
       
    56 	}
       
    57 
       
    58 /**
       
    59 Method to say whether the command will normally result in a corresponding
       
    60 Command Status event in response.
       
    61 @return ETrue if a command status event is expected, otherwise EFalse.
       
    62 */
       
    63 	
       
    64 EXPORT_C TBool CHCICommandBase::ExpectsCommandStatusEvent() const
       
    65 	{
       
    66 	return iExpectsCommandStatusEvent;
       
    67 	}
       
    68 	
       
    69 /**
       
    70 Method to say whether the command will normally result in a corresponding
       
    71 Command Complete event in response.
       
    72 @return ETrue if a command complete event is expected, otherwise EFalse.
       
    73 */
       
    74 	
       
    75 EXPORT_C TBool CHCICommandBase::ExpectsCommandCompleteEvent() const
       
    76 	{
       
    77 	return iExpectsCommandCompleteEvent;
       
    78 	}
       
    79 
       
    80 /**
       
    81 Method to change the number of command credits consumed by the command.
       
    82 Note: This will typically only be called in a constructor as it is a static
       
    83 property of a command.
       
    84 @param aConsumedCredits The number of credits the command consumes.
       
    85 */
       
    86 void CHCICommandBase::SetCreditsConsumed(TUint aConsumedCredits)
       
    87 	{
       
    88 	iCreditsConsumed = aConsumedCredits;
       
    89 	}
       
    90 
       
    91 /**
       
    92 Method to change whether a command status event is expected by the command.
       
    93 Note: This will typically only be called in a constructor as it is a static
       
    94 property of a command.
       
    95 @param aExpectsCmdStatus ETrue if a command status event is expected, otherwise EFalse
       
    96 */
       
    97 void CHCICommandBase::SetExpectsCommandStatusEvent(TBool aExpectsCmdStatus)
       
    98 	{
       
    99     iExpectsCommandStatusEvent = aExpectsCmdStatus;
       
   100 	}
       
   101 
       
   102 /**
       
   103 Method to change whether a command complete event is expected by the command.
       
   104 Note: This will typically only be called in a constructor as it is a static
       
   105 property of a command.
       
   106 @param aExpectsCmdComplete ETrue if a command complete event is expected, otherwise EFalse
       
   107 */
       
   108 void CHCICommandBase::SetExpectsCommandCompleteEvent(TBool aExpectsCmdComplete)
       
   109 	{
       
   110 	iExpectsCommandCompleteEvent = aExpectsCmdComplete;
       
   111 	}
       
   112 
       
   113 /**
       
   114 Baseclass method to say whether the command is matched by the specified event. Can be called
       
   115 from the derived class method as a first attempt to establish a match before using more
       
   116 command-specific logic in the derived class.
       
   117 */
       
   118 
       
   119 /* virtual */ void CHCICommandBase::Match(const THCIEventBase& aEvent, TBool& aMatchesCmd, TBool& aConcludesCmd, TBool& aContinueMatching) const
       
   120 	{
       
   121 	THCIEventCode eventCode(aEvent.EventCode());
       
   122 
       
   123 	if (eventCode == ECommandCompleteEvent)
       
   124 		{
       
   125 		THCICommandCompleteEvent& event = THCICommandCompleteEvent::Cast(aEvent);
       
   126 		aMatchesCmd			= (event.CommandOpcode() == Opcode());
       
   127 		aConcludesCmd		= aMatchesCmd;
       
   128 		aContinueMatching	= !aMatchesCmd;
       
   129 		}
       
   130 	else if (eventCode == ECommandStatusEvent)
       
   131 		{
       
   132 		TCommandStatusEvent& event = TCommandStatusEvent::Cast(aEvent);
       
   133 		aMatchesCmd			= (event.CommandOpcode() == Opcode());
       
   134 		// If the status is an error then this event concludes the command
       
   135 		aConcludesCmd		= (aMatchesCmd && (event.ErrorCode() != EOK));
       
   136 		aContinueMatching	= !aMatchesCmd;
       
   137 		}
       
   138 	else
       
   139 		{
       
   140 		aMatchesCmd			= EFalse;
       
   141 		aConcludesCmd		= EFalse;
       
   142 		aContinueMatching	= EFalse;
       
   143 		}
       
   144 	}
       
   145 
       
   146 CHCICommandBase::~CHCICommandBase()
       
   147 	{
       
   148 	delete iCommandBaseExtension;
       
   149 	}
       
   150 
       
   151 /**
       
   152 Method to format the command into the format required by the HCTL. Delegates
       
   153 most of the work to the pure virtual Format implementation in the derived class
       
   154 */
       
   155 EXPORT_C void CHCICommandBase::FormatCommand(CHctlCommandFrame& aCommandFrame)
       
   156 	{
       
   157 	// Write the Command Op code into the string.
       
   158 	aCommandFrame.SetOpcode(iOpcode);
       
   159 
       
   160 	// Format the rest of the command.
       
   161 	Format(aCommandFrame);
       
   162 	aCommandFrame.FinaliseCommand();
       
   163 	}
       
   164 
       
   165 /**
       
   166 This function should be called to initialise the CHCICommandBase completely.
       
   167 As such it should always be called by the factory function (NewL) of any class
       
   168 that derives from CHCICommandBase.
       
   169 */
       
   170 void CHCICommandBase::BaseConstructL()
       
   171 	{
       
   172 	// gain access to completing event methods
       
   173 	iCommandBaseExtension = CHCICommandBaseExtension::NewL();
       
   174 	}
       
   175 
       
   176 /**
       
   177 Extension function.  Use this to retrieve any extension interfaces to CHCICommandBase.
       
   178 It is essential that any class that derives from this class overload and then call
       
   179 this function.
       
   180 */
       
   181 TInt CHCICommandBase::Extension_(TUint aExtensionId, TAny*& aInterface, TAny* aData)
       
   182 	{
       
   183 	if (aExtensionId == KCompletingEventExpectUid && iCommandBaseExtension)
       
   184 		{
       
   185 		if (iCommandBaseExtension->CompletingEventQueryHelper())
       
   186 			{
       
   187 			aInterface = static_cast<MHCICompletingEventQuery*>(iCommandBaseExtension->CompletingEventQueryHelper());
       
   188 			return KErrNone;
       
   189 			}
       
   190 		}
       
   191 		
       
   192 	return CBase::Extension_(aExtensionId, aInterface, aData);
       
   193 	}
       
   194