sensorservices/tiltcompensationssy/src/tcchannel.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CTCChannel class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sensrvchannel.h>
       
    20 #include <sensrvchannelfinder.h>
       
    21 #include <ssycallback.h>
       
    22 
       
    23 #include "tcchannel.h"
       
    24 #include "tcutil.h"
       
    25 #include "common.h"
       
    26 #include "trace.h"
       
    27 
       
    28 CTCChannel::~CTCChannel()
       
    29     {
       
    30     FUNC_LOG;
       
    31     
       
    32     Cancel();
       
    33     iStatePool.ResetAndDestroy();
       
    34     }
       
    35 
       
    36 CTCChannel::CTCChannel( MSsyCallback& aCallback ):
       
    37     CActive( EPriorityNormal ),
       
    38     iCallback( aCallback )
       
    39     {
       
    40     FUNC_LOG;
       
    41     
       
    42     // Check that we have an active scheduler in the current process
       
    43     ASSERT_ALWAYS_SSY( CActiveScheduler::Current() );
       
    44     
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // METHODS
       
    49 
       
    50 // ----------------------------------------------------------------------------------
       
    51 // CTCChannel::ChannelId
       
    52 // ----------------------------------------------------------------------------------
       
    53 //
       
    54 void CTCChannel::SetChannelId( TSensrvChannelId aId )
       
    55     {
       
    56     FUNC_LOG;
       
    57     
       
    58     INFO_1( "Set channel ID: [%d]", aId );
       
    59     
       
    60     iChannelInfo.iChannelId = aId;
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------------
       
    64 // CTCChannel::ChannelId
       
    65 // ----------------------------------------------------------------------------------
       
    66 //
       
    67 TSensrvChannelId CTCChannel::ChannelId() const
       
    68     {
       
    69     FUNC_LOG;
       
    70     
       
    71     return iChannelInfo.iChannelId;
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------------
       
    75 // CTCChannel::ChannelSupported
       
    76 // ----------------------------------------------------------------------------------
       
    77 //
       
    78 TBool CTCChannel::ChannelSupported( const TSensrvChannelInfo& aInfo )
       
    79     {
       
    80     FUNC_LOG;
       
    81     
       
    82     return iChannelInfo.IsMatch( aInfo );
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------------
       
    86 // CTCChannel::DoCancel
       
    87 // ----------------------------------------------------------------------------------
       
    88 //
       
    89 void CTCChannel::DoCancel()
       
    90     {
       
    91     FUNC_LOG;
       
    92     
       
    93     CompleteTransaction( KErrCancel );
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------------
       
    97 // CTCChannel::RunError
       
    98 // ----------------------------------------------------------------------------------
       
    99 //
       
   100 TInt CTCChannel::RunError( TInt aError )
       
   101     {
       
   102     FUNC_LOG;
       
   103     
       
   104     if( aError != KErrNone )
       
   105         {
       
   106         INFO_1( "RunError called with code [%d]", aError );
       
   107         }
       
   108     
       
   109     return KErrNone;
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------------
       
   113 // CTCChannel::CurrentState
       
   114 // ----------------------------------------------------------------------------------
       
   115 //
       
   116 CTCState* CTCChannel::CurrentState() const
       
   117     {
       
   118     FUNC_LOG;
       
   119     
       
   120     return iCurrentState;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------------
       
   124 // CTCChannel::ChangeState
       
   125 // ----------------------------------------------------------------------------------
       
   126 //
       
   127 void CTCChannel::ChangeStateL( TInt aStateId )
       
   128     {
       
   129     FUNC_LOG;
       
   130     
       
   131     ASSERT_DEBUG_TRACE( aStateId >= CTCState::ETCStateIdle &&
       
   132         aStateId < CTCState::ETCStateLast, EInvalidState );
       
   133     
       
   134     iPreviousState = iCurrentState;
       
   135     iCurrentState = iStatePool[aStateId];
       
   136     
       
   137     // Inform new current state about state entry
       
   138     iCurrentState->HandleStateEntryL();
       
   139     
       
   140     // Inform previous state about state exit
       
   141     if( iPreviousState )
       
   142         {
       
   143         iPreviousState->HandleStateExitL();
       
   144         }
       
   145     
       
   146     INFO_2( "Changing channel state [%S] -> [%S]",
       
   147         &TCUtil::StateIdAsDesC( iPreviousState ),
       
   148         &TCUtil::StateIdAsDesC( iCurrentState ) );
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------------
       
   152 // CTCChannel::DataBuffer
       
   153 // ----------------------------------------------------------------------------------
       
   154 //
       
   155 TUint8* CTCChannel::DataBuffer() const
       
   156     {
       
   157     FUNC_LOG;
       
   158     
       
   159     return iData;
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------------
       
   163 // CTCChannel::DataCount
       
   164 // ----------------------------------------------------------------------------------
       
   165 //
       
   166 TInt CTCChannel::DataCount() const
       
   167     {
       
   168     FUNC_LOG;
       
   169     
       
   170     return iCount;
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------------
       
   174 // CTCChannel::BaseConstructL
       
   175 // ----------------------------------------------------------------------------------
       
   176 //
       
   177 void CTCChannel::BaseConstructL()
       
   178     {
       
   179     FUNC_LOG;
       
   180     
       
   181     // Register states
       
   182     RegisterStateL( CTCState::ETCStateIdle, iStatePool );
       
   183     RegisterStateL( CTCState::ETCStateOpen, iStatePool );
       
   184     RegisterStateL( CTCState::ETCStateListenData, iStatePool );
       
   185     RegisterStateL( CTCState::ETCStateBufferFull, iStatePool );
       
   186     RegisterStateL( CTCState::ETCStateClosing, iStatePool );
       
   187     
       
   188     // Switch to idle
       
   189     ChangeStateL( CTCState::ETCStateIdle );
       
   190     }
       
   191 
       
   192 // ----------------------------------------------------------------------------------
       
   193 // CTCChannel::FindChannelL
       
   194 // ----------------------------------------------------------------------------------
       
   195 //
       
   196 TBool CTCChannel::FindChannelL( const TSensrvChannelTypeId& aChannelTypeId,
       
   197     const TDesC8& aLocation,
       
   198     const TDesC8& aVendorId,
       
   199     TSensrvChannelInfo& aChannelInfo )
       
   200     {
       
   201     FUNC_LOG;
       
   202 
       
   203     TBool found = EFalse;
       
   204 
       
   205     // Configure channel
       
   206     CSensrvChannelFinder* channelFinder = CSensrvChannelFinder::NewLC();
       
   207     RSensrvChannelInfoList channelInfoList;
       
   208     CleanupClosePushL( channelInfoList );
       
   209     
       
   210     // Find double tap channel
       
   211     aChannelInfo.iChannelId = 0;
       
   212     aChannelInfo.iContextType = ESensrvContextTypeNotDefined;
       
   213     aChannelInfo.iQuantity = ESensrvQuantityNotdefined;
       
   214     aChannelInfo.iChannelType = aChannelTypeId;
       
   215     aChannelInfo.iLocation = aLocation;
       
   216     aChannelInfo.iVendorId = aVendorId;
       
   217     aChannelInfo.iDataItemSize = 0;
       
   218     channelFinder->FindChannelsL( channelInfoList, aChannelInfo );
       
   219     if( channelInfoList.Count() > 0 )
       
   220         {
       
   221         INFO_2( "aChannelInfo size [%d] vs. channelInfoList[0] size [%d]",
       
   222             sizeof( aChannelInfo ),
       
   223             sizeof( channelInfoList[ 0 ] ) );
       
   224         
       
   225         // Take first match and assume it to be best one
       
   226         aChannelInfo = channelInfoList[ 0 ];
       
   227         found = ETrue;
       
   228         INFO_3( "Found sensor channel with parameters: ChannelTypeId: %x, Location: %S, Vendor: %S",
       
   229              aChannelTypeId, &aLocation, &aVendorId );
       
   230         }
       
   231     else
       
   232         {
       
   233         ERROR_GEN_3( "Did not found sensor channel: ChannelTypeId: %x, Location: %S, Vendor: %S",
       
   234              aChannelTypeId,
       
   235              &aLocation,
       
   236              &aVendorId );
       
   237         }
       
   238     
       
   239     // Cleanup
       
   240     CleanupStack::PopAndDestroy( &channelInfoList );
       
   241     CleanupStack::PopAndDestroy( channelFinder );
       
   242 
       
   243     return found;
       
   244     }
       
   245 
       
   246 // ----------------------------------------------------------------------------------
       
   247 // CTCChannel::CompleteTransaction
       
   248 // ----------------------------------------------------------------------------------
       
   249 //
       
   250 void CTCChannel::CompleteTransaction( TInt aCode )
       
   251     {
       
   252     FUNC_LOG;
       
   253     
       
   254     ASSERT_DEBUG_TRACE( IsActive(), ENotActive );
       
   255     
       
   256     TRequestStatus* status = &iStatus;
       
   257     User::RequestComplete( status, aCode );
       
   258     }
       
   259 
       
   260 // End of File