bluetoothengine/bteng/btengconnman/src/btengconnhandler.cpp
branchRCL_3
changeset 55 613943a21004
parent 0 f63038272f30
child 56 9386f31cc85b
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
    81 //
    81 //
    82 CBTEngConnHandler::~CBTEngConnHandler()
    82 CBTEngConnHandler::~CBTEngConnHandler()
    83     {
    83     {
    84     TRACE_FUNC_ENTRY
    84     TRACE_FUNC_ENTRY
    85     CancelNotifyConnectionEvents();
    85     CancelNotifyConnectionEvents();
    86     CancelPairing();
       
    87     iBTEng.Close();
    86     iBTEng.Close();
    88     }
    87     }
    89 
    88 
    90 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    91 // Gets the connected device addresses; If a profile is defined, only 
    90 // Gets the connected device addresses; If a profile is defined, only 
   144 
   143 
   145 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   146 // ?implementation_description
   145 // ?implementation_description
   147 // ---------------------------------------------------------------------------
   146 // ---------------------------------------------------------------------------
   148 //
   147 //
   149 TInt CBTEngConnHandler::CancelNotifyConnectionEvents()
   148 void CBTEngConnHandler::CancelNotifyConnectionEvents()
   150     {
   149     {
   151     TRACE_FUNC_ENTRY
   150     TRACE_FUNC_ENTRY
   152     TInt err = KErrNone;
       
   153     if( iConnEventActive && iConnEventActive->IsActive() )
       
   154         {
       
   155         err = iBTEng.CancelNotifyConnectionEvents();
       
   156         iConnEventActive->CancelRequest();
       
   157         }
       
   158     delete iConnEventActive;
   151     delete iConnEventActive;
   159     iConnEventActive = NULL;
   152     iConnEventActive = NULL;
   160     return err;
   153     }
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // Request server side to activate/deactivate a pair observer
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TInt CBTEngConnHandler::SetPairingObserver( const TBTDevAddr& aAddr, 
       
   168     TBool aActivate )
       
   169     {
       
   170     RBTEng bteng;
       
   171     TInt err = bteng.Connect();
       
   172     if ( !err )
       
   173         {
       
   174         err = bteng.SetPairingObserver( aAddr, aActivate );
       
   175         }
       
   176     bteng.Close();
       
   177     return err;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Request BTEng to pair the device
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 TInt CBTEngConnHandler::StartPairing( const TBTDevAddr& aAddr, 
       
   185     const TBTDeviceClass& aDeviceClass )
       
   186     {
       
   187     TRACE_FUNC_ENTRY
       
   188     TInt err( KErrNone );
       
   189     if( iPairActive && iPairActive->IsActive() )
       
   190         {
       
   191         err = KErrServerBusy;
       
   192         }
       
   193     
       
   194     if( !iPairActive )
       
   195         {
       
   196             // Use a higher prioritty than normal, because we want 
       
   197             // to be notified fast (e.g. to update the UI).
       
   198         TRAP( err, iPairActive = CBTEngActive::NewL( *this, EPairDeviceId, 
       
   199                                                   CActive::EPriorityUserInput ) );
       
   200         }
       
   201     if ( !err )
       
   202         {
       
   203         iPairAddr() = aAddr;
       
   204         iPairDevCod = aDeviceClass.DeviceClass();
       
   205         iBTEng.PairDevice( iPairAddr, iPairDevCod, iPairActive->RequestStatus() );
       
   206         iPairActive->GoActive();
       
   207         }
       
   208     TRACE_FUNC_EXIT
       
   209     return err;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Cancel any outstanding operation, free resources.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CBTEngConnHandler::CancelPairing()
       
   217     {
       
   218     TRACE_FUNC_ENTRY
       
   219     if( iPairActive && iPairActive->IsActive() )
       
   220         {
       
   221         iBTEng.CancelPairDevice();
       
   222         }
       
   223     delete iPairActive;
       
   224     iPairActive = NULL;
       
   225     TRACE_FUNC_EXIT
       
   226     }
       
   227 
       
   228 
   154 
   229 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   230 // From class MBTEngActiveObserver.
   156 // From class MBTEngActiveObserver.
   231 // Called by the active object when a change in connection status has occured.
   157 // Called by the active object when a change in connection status has occured.
   232 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   233 //
   159 //
   234 void CBTEngConnHandler::RequestCompletedL( CBTEngActive* aActive, TInt aId, 
   160 void CBTEngConnHandler::RequestCompletedL( CBTEngActive* aActive, 
   235     TInt aStatus )
   161     TInt aStatus )
   236     {
   162     {
   237     TRACE_FUNC_ARG( ( _L( "ID: %d status: %d" ), aId, aStatus ) )
   163     TRACE_FUNC_ARG( ( _L( "ID: %d status: %d" ), aActive->RequestId(), aStatus ) )
   238 
       
   239     (void) aActive;
   164     (void) aActive;
   240     switch ( aId )
   165     ASSERT( aActive->RequestId() == EConnectionEventId );
   241         {
   166     HandleConnectionEvent( aStatus );
   242         case EConnectionEventId:
       
   243             {
       
   244             HandleConnectionEvent( aStatus );
       
   245             break;
       
   246             }
       
   247         case EPairDeviceId:
       
   248             {
       
   249             if ( iObserver )
       
   250                 {
       
   251                 iObserver->PairingComplete( iPairAddr(), aStatus );
       
   252                 }
       
   253             }
       
   254         }
       
   255 
       
   256     TRACE_FUNC_EXIT
   167     TRACE_FUNC_EXIT
   257     }
   168     }
   258 
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // From class MBTEngActiveObserver.
       
   172 // Handles cancelation of an outstanding request
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CBTEngConnHandler::CancelRequest( TInt aRequestId )
       
   176     {
       
   177     TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) )
       
   178     ASSERT( aRequestId == EConnectionEventId );
       
   179     ( void ) aRequestId;
       
   180     iBTEng.CancelNotifyConnectionEvents();
       
   181     TRACE_FUNC_EXIT 
       
   182     }
   259 
   183 
   260 // ---------------------------------------------------------------------------
   184 // ---------------------------------------------------------------------------
   261 // From class MBTEngActiveObserver.
   185 // From class MBTEngActiveObserver.
   262 // Called when RequestCompletedL/RunL leaves.
   186 // Called when RequestCompletedL/RunL leaves.
   263 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   264 //
   188 //
   265 void CBTEngConnHandler::HandleError( CBTEngActive* aActive, TInt aId, TInt aError )
   189 void CBTEngConnHandler::HandleError( CBTEngActive* aActive, TInt aError )
   266     {
   190     {
   267     TRACE_FUNC_ARG( ( _L( "error: %d" ), aError ) )
   191     TRACE_FUNC_ARG( ( _L( "error: %d" ), aError ) )
   268         // Should any info be passed to the client??
   192         // Should any info be passed to the client??
   269     (void) aActive;
   193     (void) aActive;
   270     (void) aId;
       
   271     (void) aError;
   194     (void) aError;
   272     }
   195     }
   273 
   196 
   274 void CBTEngConnHandler::HandleConnectionEvent( TInt aStatus )
   197 void CBTEngConnHandler::HandleConnectionEvent( TInt aStatus )
   275     {
   198     {