localconnectivityservice/dun/utils/src/DunChanMan.cpp
branchRCL_3
changeset 43 4a793f564d72
parent 42 0aa8cc770c8a
child 45 74aa6861c87d
equal deleted inserted replaced
42:0aa8cc770c8a 43:4a793f564d72
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  RComm channel management related functionality (waiter)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "DunSignalWaiter.h"
       
    20 #include "DunDataWaiter.h"
       
    21 #include "DunUpstream.h"
       
    22 #include "DunDownstream.h"
       
    23 #include "DunSignalCopy.h"
       
    24 #include "DunChanMan.h"
       
    25 #include "DunUtils.h"
       
    26 #include "DunDebug.h"
       
    27 #include "DunPlugin.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Two-phased constructor.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CDunChanMan* CDunChanMan::NewL( CDunTransporter& aParent,
       
    34                                 MDunTransporterUtility* aUtility,
       
    35                                 MDunTransporterUtilityAux* aUtilityAux,
       
    36                                 MDunPluginManager* aPluginManager )
       
    37     {
       
    38     CDunChanMan* self = new (ELeave) CDunChanMan( aParent,
       
    39                                                   aUtility,
       
    40                                                   aUtilityAux,
       
    41                                                   aPluginManager );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Destructor.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CDunChanMan::~CDunChanMan()
       
    53     {
       
    54     FTRACE(FPrint( _L("CDunChanMan::~CDunChanMan()") ));
       
    55     ResetData();
       
    56     FTRACE(FPrint( _L("CDunChanMan::~CDunChanMan() complete") ));
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Resets data to initial values
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CDunChanMan::ResetData()
       
    64     {
       
    65     FTRACE(FPrint( _L("CDunChanMan::ResetData()") ));
       
    66     // APIs affecting this:
       
    67     // AddConnWaiterL()
       
    68     // IssueConnWaiterRequest()
       
    69     TInt i;
       
    70     TInt count = iWaiterData.Count();
       
    71     for ( i=0; i<count; i++ )
       
    72         {
       
    73         DeleteWaiters( i );
       
    74         }
       
    75     iWaiterData.Close();
       
    76     FTRACE(FPrint( _L("CDunChanMan::ResetData() complete") ));
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Number of waiters
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 TInt CDunChanMan::NumberOfWaiters()
       
    84     {
       
    85     FTRACE(FPrint( _L("CDunChanMan::NumberOfWaiters()" )));
       
    86     TInt waiters = iWaiterData.Count();
       
    87     FTRACE(FPrint( _L("CDunChanMan::NumberOfWaiters() complete" )));
       
    88     return waiters;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // Gets number of waiters by owner UID
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TInt CDunChanMan::GetNumberOfWaitersByUid( TUid aOwnerUid )
       
    96     {
       
    97     FTRACE(FPrint( _L("CDunChanMan::GetNumberOfWaitersByUid()" )));
       
    98     TInt i;
       
    99     TInt waiters = 0;
       
   100     TInt count = iWaiterData.Count();
       
   101     for ( i=0; i<count; i++ )
       
   102         {
       
   103         TDunWaiterData& waiterData = iWaiterData[i];
       
   104         if ( waiterData.iOwnerUid == aOwnerUid )
       
   105             {
       
   106             waiters++;
       
   107             }
       
   108         }
       
   109     FTRACE(FPrint( _L("CDunChanMan::GetNumberOfWaitersByUid() complete" )));
       
   110     return waiters;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Adds new connection waiter to connection waiter array
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CDunChanMan::AddConnWaiterL( RComm* aComm,
       
   118                                   TUid aOwnerUid,
       
   119                                   const TDesC8& aName,
       
   120                                   TBool aEnqueuedFail,
       
   121                                   MDunBufferCorrection* aCorrection )
       
   122     {
       
   123     FTRACE(FPrint( _L("CDunChanMan::AddConnWaiterL()" )));
       
   124     if ( !aComm )
       
   125         {
       
   126         FTRACE(FPrint( _L("CDunChanMan::AddConnWaiterL() (aComm not initialized!) complete" )));
       
   127         User::Leave( KErrGeneral );
       
   128         }
       
   129     CDunSignalWaiter* signalWaiter = CDunSignalWaiter::NewL( this );
       
   130     CleanupStack::PushL( signalWaiter );
       
   131     TInt retTemp = signalWaiter->SetMedia( aComm );
       
   132     if ( retTemp != KErrNone )
       
   133         {
       
   134         FTRACE(FPrint( _L("CDunChanMan::AddConnWaiterL() (ERROR) complete" )));
       
   135         User::Leave( retTemp );
       
   136         }
       
   137     CDunDataWaiter* dataWaiter = CDunDataWaiter::NewL( this );
       
   138     CleanupStack::PushL( dataWaiter );
       
   139     retTemp = dataWaiter->SetMedia( aComm );
       
   140     if ( retTemp != KErrNone )
       
   141         {
       
   142         FTRACE(FPrint( _L("CDunChanMan::AddConnWaiterL() (ERROR) complete" )));
       
   143         User::Leave( retTemp );
       
   144         }
       
   145     TDunWaiterData waiterData;
       
   146     waiterData.iComm = aComm;
       
   147     waiterData.iChannelName = HBufC8::NewMaxL( aName.Length() );
       
   148     TPtr8 chanNamePtr = waiterData.iChannelName->Des();
       
   149     chanNamePtr.Copy( aName );
       
   150     waiterData.iSignalWaiter = signalWaiter;
       
   151     waiterData.iDataWaiter = dataWaiter;
       
   152     waiterData.iCorrection = aCorrection;
       
   153     waiterData.iEnqueuedFail = aEnqueuedFail;
       
   154     waiterData.iOwnerUid = aOwnerUid;
       
   155     iWaiterData.AppendL( waiterData );
       
   156     CleanupStack::Pop( dataWaiter );
       
   157     CleanupStack::Pop( signalWaiter );
       
   158     FTRACE(FPrint( _L("CDunChanMan::AddConnWaiterL() complete" )));
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // Removes existing waiter from connection waiter array
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 TInt CDunChanMan::RemoveConnWaiter( RComm* aComm )
       
   166     {
       
   167     FTRACE(FPrint( _L("CDunChanMan::RemoveConnWaiter()" )));
       
   168     TInt i;
       
   169     for ( i=iWaiterData.Count()-1; i>=0; i-- )
       
   170         {
       
   171         TDunWaiterData& waiterData = iWaiterData[i];
       
   172         if ( waiterData.iComm == aComm )
       
   173             {
       
   174             DeleteWaiters( i );
       
   175             iWaiterData.Remove( i );
       
   176             FTRACE(FPrint( _L("CDunChanMan::RemoveConnWaiter() complete" )));
       
   177             return KErrNone;
       
   178             }
       
   179         }
       
   180     FTRACE(FPrint( _L("CDunChanMan::RemoveConnWaiter() (not found) complete" )));
       
   181     return KErrNotFound;
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Makes CDunConnWaiter ready to detect new data
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 TInt CDunChanMan::IssueConnWaiterRequest( RComm* aComm )
       
   189     {
       
   190     FTRACE(FPrint( _L("CDunChanMan::IssueConnWaiterRequest()" )));
       
   191     TInt i;
       
   192     TInt count = iWaiterData.Count();
       
   193     for ( i=0; i<count; i++ )
       
   194         {
       
   195         TDunWaiterData& waiterData = iWaiterData[i];
       
   196         if ( waiterData.iComm == aComm )
       
   197             {
       
   198             waiterData.iSignalWaiter->IssueRequest();
       
   199             waiterData.iDataWaiter->IssueRequest();
       
   200             FTRACE(FPrint( _L("CDunChanMan::IssueConnWaiterRequest() complete" )));
       
   201             return KErrNone;
       
   202             }
       
   203         }
       
   204     FTRACE(FPrint( _L("CDunChanMan::IssueConnWaiterRequest() (not found) complete" )));
       
   205     return KErrNotFound;
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Stops CDunConnWaiter to detect new data
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 TInt CDunChanMan::StopConnWaiter( RComm* aComm )
       
   213     {
       
   214     FTRACE(FPrint( _L("CDunChanMan::StopConnWaiter()" )));
       
   215     TInt i;
       
   216     TInt count = iWaiterData.Count();
       
   217     for ( i=0; i<count; i++ )
       
   218         {
       
   219         TDunWaiterData& waiterData = iWaiterData[i];
       
   220         if ( waiterData.iComm == aComm )
       
   221             {
       
   222             waiterData.iSignalWaiter->Stop();
       
   223             waiterData.iDataWaiter->Stop();
       
   224             FTRACE(FPrint( _L("CDunChanMan::StopConnWaiter() complete" )));
       
   225             return KErrNone;
       
   226             }
       
   227         }
       
   228     FTRACE(FPrint( _L("CDunChanMan::StopConnWaiter() (not found) complete" )));
       
   229     return KErrNotFound;
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // Saves waiter's connection monitor callback data
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 TInt CDunChanMan::SaveWaiterConnMonCallbackL( RComm* aComm,
       
   237                                               MDunConnMon* aCallback,
       
   238                                               TDunDirection aDirection )
       
   239     {
       
   240     FTRACE(FPrint( _L("CDunChanMan::SaveWaiterConnMonCallbackL()" )));
       
   241     TInt i;
       
   242     TInt count = iWaiterData.Count();
       
   243     for ( i=0; i<count; i++ )
       
   244         {
       
   245         TDunWaiterData& waiterData = iWaiterData[i];
       
   246         if ( waiterData.iComm != aComm )
       
   247             {
       
   248             continue;
       
   249             }
       
   250         TDunConnMonCallback connMon;
       
   251         connMon.iCallback = aCallback;
       
   252         connMon.iDirection = aDirection;
       
   253         if ( aDirection==EDunReaderUpstream ||
       
   254              aDirection==EDunWriterDownstream )
       
   255             {
       
   256             // Local media -> add to object
       
   257             // Add signal waiter's callback (for RunL error monitoring)
       
   258             if ( !waiterData.iSignalWaiter )
       
   259                 {
       
   260                 FTRACE(FPrint( _L("CDunTransUtils::SaveWaiterConnMonCallbackL() (ERROR) complete" )));
       
   261                 return KErrGeneral;
       
   262                 }
       
   263             waiterData.iSignalWaiter->AddCallback( aCallback );
       
   264             // Add data waiter's callback (for RunL error monitoring)
       
   265             if ( !waiterData.iDataWaiter )
       
   266                 {
       
   267                 FTRACE(FPrint( _L("CDunTransUtils::SaveWaiterConnMonCallbackL() (ERROR) complete" )));
       
   268                 return KErrGeneral;
       
   269                 }
       
   270             waiterData.iDataWaiter->AddCallback( aCallback );
       
   271             // Now just store information for R/W case
       
   272             waiterData.iConnMons.AppendL( connMon );
       
   273             FTRACE(FPrint( _L("CDunChanMan::SaveWaiterConnMonCallbackL() complete" )));
       
   274             return KErrNone;
       
   275             }
       
   276         else if ( aDirection==EDunWriterUpstream ||
       
   277                   aDirection==EDunReaderDownstream )
       
   278             {
       
   279             // Network -> just store information for R/W case
       
   280             waiterData.iConnMons.AppendL( connMon );
       
   281             FTRACE(FPrint( _L("CDunChanMan::SaveWaiterConnMonCallbackL() complete" )));
       
   282             return KErrNone;
       
   283             }
       
   284         else
       
   285             {
       
   286             FTRACE(FPrint( _L("CDunTransUtils::SaveWaiterConnMonCallbackL() (ERROR) complete" )));
       
   287             return KErrGeneral;
       
   288             }
       
   289         }
       
   290     FTRACE(FPrint( _L("CDunChanMan::SaveWaiterConnMonCallbackL() (not found) complete" )));
       
   291     return KErrNotFound;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // Saves waiter's skipped error data
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 TInt CDunChanMan::SaveWaiterSkippedErrorL( TInt aError,
       
   299                                            RComm* aComm,
       
   300                                            TDunDirection aDirection )
       
   301     {
       
   302     FTRACE(FPrint( _L("CDunChanMan::SaveWaiterSkippedErrorL()" )));
       
   303     TInt i;
       
   304     TInt count = iWaiterData.Count();
       
   305     for ( i=0; i<count; i++ )
       
   306         {
       
   307         TDunWaiterData& waiterData = iWaiterData[i];
       
   308         if ( waiterData.iComm == aComm )
       
   309             {
       
   310             TDunSkippedError skippedError;
       
   311             skippedError.iError = aError;
       
   312             skippedError.iDirection = aDirection;
       
   313             waiterData.iOkErrors.AppendL( skippedError );
       
   314             FTRACE(FPrint( _L("CDunChanMan::SaveWaiterSkippedErrorL() complete" )));
       
   315             return KErrNone;
       
   316             }
       
   317         }
       
   318     FTRACE(FPrint( _L("CDunChanMan::SaveWaiterSkippedErrorL() (not found) complete" )));
       
   319     return KErrNotFound;
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CDunChanMan::CDunChanMan
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 CDunChanMan::CDunChanMan( CDunTransporter& aParent,
       
   327                           MDunTransporterUtility* aUtility,
       
   328                           MDunTransporterUtilityAux* aUtilityAux,
       
   329                           MDunPluginManager* aPluginManager ) :
       
   330     iParent( aParent ),
       
   331     iUtility( aUtility ),
       
   332     iUtilityAux( aUtilityAux ),
       
   333     iPluginManager( aPluginManager )
       
   334     {
       
   335     Initialize();
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CDunChanMan::ConstructL
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CDunChanMan::ConstructL()
       
   343     {
       
   344     FTRACE(FPrint( _L("CDunChanMan::ConstructL()" ) ));
       
   345     if ( !iUtility || !iUtilityAux || !iPluginManager )
       
   346         {
       
   347         User::Leave( KErrGeneral );
       
   348         }
       
   349     FTRACE(FPrint( _L("CDunChanMan::ConstructL() complete" ) ));
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // Initializes this class
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void CDunChanMan::Initialize()
       
   357     {
       
   358     FTRACE(FPrint( _L("CDunChanMan::Initialize()" ) ));
       
   359     // Don't initialize iParent here (it is set through NewL)
       
   360     // Don't initialize iUtility here (it is set through NewL)
       
   361     // Don't initialize iUtilityAux here (it is set through NewL)
       
   362     // Don't initialize iPluginManager here (it is set through NewL)
       
   363     FTRACE(FPrint( _L("CDunChanMan::Initialize() complete" ) ));
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // From class MDunChannelAllocator.
       
   368 // Notifies when new channel is wanted
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 TInt CDunChanMan::NotifyNewChannelRequest( RComm* aComm )
       
   372     {
       
   373     FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest()" )));
       
   374     if ( !aComm->SubSessionHandle() )
       
   375         {
       
   376         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) (bad handle) complete" ) ));
       
   377         return KErrBadHandle;
       
   378         }
       
   379     // Get plugin UID for connection ID
       
   380     TInt i;
       
   381     TUid foundUid = TUid::Null();
       
   382     TInt count = iWaiterData.Count();
       
   383     for ( i=0; i<count; i++ )
       
   384         {
       
   385         if ( iWaiterData[i].iComm == aComm )
       
   386             {
       
   387             foundUid = iWaiterData[i].iOwnerUid;
       
   388             break;
       
   389             }
       
   390         }
       
   391     if ( i >= count )
       
   392         {
       
   393         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) (not found) complete" )));
       
   394         return KErrNotFound;
       
   395         }
       
   396     TDunWaiterData& waiterData = iWaiterData[i];
       
   397     // Try to stop if either one of the waiters are still runnig
       
   398     waiterData.iSignalWaiter->Stop();
       
   399     waiterData.iDataWaiter->Stop();
       
   400     // enqueued will be omitted (not needed to set to RComm)
       
   401     TInt firstFree = iUtility->InitializeFirstFreeChannel( aComm );
       
   402     if ( firstFree < 0 )
       
   403         {
       
   404         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) (firstfree failed!) complete" ) ));
       
   405         return firstFree;
       
   406         }
       
   407     if ( firstFree >= iParent.iChannelData.Count() )
       
   408         {
       
   409         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) (firstfree failed!) complete" )));
       
   410         return KErrGeneral;
       
   411         }
       
   412     TInt bufferLength = KErrNotFound;
       
   413     MDunBufferCorrection* correction = waiterData.iCorrection;
       
   414     TRAPD( retTrap,
       
   415         iUtility->DoAllocateChannelL(aComm, bufferLength, firstFree, correction) );
       
   416     if ( retTrap != KErrNone )
       
   417         {
       
   418         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() trapped!" ) ));
       
   419         iParent.UnInitializeOnDemand();  // remove unused initialized channel
       
   420         if ( retTrap == KErrTooBig )
       
   421             {
       
   422             if ( waiterData.iEnqueuedFail )
       
   423                 {
       
   424                 // Inform plugin enqueue request
       
   425                 iPluginManager->NotifyPluginEnqueueRequest( foundUid );
       
   426                 }
       
   427             FTRACE(FPrint( _L("CDunTransporter::AllocateChannel() (RSocket) complete" )));
       
   428             return KErrTooBig;
       
   429             }
       
   430         iPluginManager->NotifyPluginCloseRequest( foundUid, EFalse );
       
   431         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (ERROR) complete" )));
       
   432         return retTrap;
       
   433         }
       
   434     TInt retTemp = CDunUtils::SetRCommBufferLength( *aComm, bufferLength );
       
   435     if ( retTemp != KErrNone )
       
   436         {
       
   437         iParent.UnInitializeOnDemand();  // remove unused initialized channel
       
   438         iPluginManager->NotifyPluginCloseRequest( foundUid, EFalse );
       
   439         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (ERROR) complete" )));
       
   440         }
       
   441     // Next find aComm from iWaiterData and copy its contents to channel data
       
   442     retTemp = FillNewWaiterChannelData( aComm, firstFree );
       
   443     if ( retTemp != KErrNone )
       
   444         {
       
   445         iParent.UnInitializeOnDemand();  // remove unused initialized channel
       
   446         iPluginManager->NotifyPluginCloseRequest( foundUid, EFalse );
       
   447         FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) (not found) complete" )));
       
   448         }
       
   449     FTRACE(FPrint( _L("CDunChanMan::NotifyNewChannelRequest() (RComm) complete" )));
       
   450     return KErrNone;
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // Fills data for channel created by waiter
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 TInt CDunChanMan::FillNewWaiterChannelData( RComm* aComm,
       
   458                                             TInt aFirstFree )
       
   459     {
       
   460     FTRACE(FPrint( _L("CDunChanMan::FillNewWaiterChannelData()" )));
       
   461     TInt i;
       
   462     TInt count = iWaiterData.Count();
       
   463     for ( i=0; i<count; i++ )
       
   464         {
       
   465         if ( iWaiterData[i].iComm == aComm )
       
   466             {
       
   467             break;
       
   468             }
       
   469         }
       
   470     if ( i >= count ||
       
   471          aFirstFree < 0 ||
       
   472          aFirstFree >= iParent.iChannelData.Count() )
       
   473         {
       
   474         FTRACE(FPrint( _L("CDunChanMan::FillNewWaiterChannelData() (not found) complete" )));
       
   475         return KErrNotFound;
       
   476         }
       
   477     TUid thisUid = iWaiterData[i].iOwnerUid; // pick up before remove
       
   478     TDunChannelData& channelData = iParent.iChannelData[aFirstFree];
       
   479     TDunWaiterData& waiterData = iWaiterData[i];
       
   480     channelData.iComm = waiterData.iComm;
       
   481     channelData.iChannelName = waiterData.iChannelName;
       
   482     channelData.iUpstreamRW->SetMedia( aComm, EDunMediaContextLocal );
       
   483     channelData.iDownstreamRW->SetMedia( aComm, EDunMediaContextLocal );
       
   484     channelData.iOwnerUid = thisUid;
       
   485     // Channel now occupied
       
   486     channelData.iChannelInUse = ETrue;
       
   487     // Restore data from waiter to transfer objects
       
   488     RestoreWaiterData( i, aFirstFree );
       
   489     // Now delete waiters before request issuing
       
   490     DeleteWaiters( i, ETrue );
       
   491     iWaiterData.Remove( i );
       
   492     // Issue transfer requests
       
   493     iUtility->DoIssueTransferRequests( aFirstFree );
       
   494     // Clear the queue, just to be sure
       
   495     iPluginManager->NotifyPluginDequeueRequest( thisUid );
       
   496     FTRACE(FPrint( _L("CDunChanMan::FillNewWaiterChannelData() complete" )));
       
   497     return KErrNone;
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // Restores saved waiter data to connection data
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 TInt CDunChanMan::RestoreWaiterData( TInt aWaiterIndex,
       
   505                                      TInt aChannelIndex )
       
   506     {
       
   507     FTRACE(FPrint( _L("CDunChanMan::RestoreWaiterData()" )));
       
   508     if ( aWaiterIndex < 0 ||
       
   509          aWaiterIndex >= iWaiterData.Count() ||
       
   510          aChannelIndex < 0 ||
       
   511          aChannelIndex >= iParent.iChannelData.Count() )
       
   512         {
       
   513         FTRACE(FPrint( _L("CDunChanMan::RestoreWaiterData() (not found) complete" )));
       
   514         return KErrNotFound;
       
   515         }
       
   516     TInt i;
       
   517     TInt count = iWaiterData[aWaiterIndex].iConnMons.Count();
       
   518     for ( i=0; i<count; i++ )
       
   519         {
       
   520         TDunConnMonCallback& connMon = iWaiterData[aWaiterIndex].iConnMons[i];
       
   521         // Add connection monitor callbacks (ignore errors)
       
   522         // Errors are ignored because in this phase they cannot be reported to
       
   523         // plugins. Instead add error checking to
       
   524         // CDunTransporter::AddConnMonCallbackL() if needed
       
   525         iUtility->DoAddConnMonCallback( aChannelIndex,
       
   526                                         connMon.iCallback,
       
   527                                         connMon.iDirection,
       
   528                                         NULL );
       
   529         }
       
   530     count = iWaiterData[aWaiterIndex].iOkErrors.Count();
       
   531     for (i=0; i<count; i++)
       
   532         {
       
   533         TDunSkippedError& skippedError = iWaiterData[aWaiterIndex].iOkErrors[i];
       
   534         // Add skipped errors (ignore errors)
       
   535         // Errors are ignored because in this phase they cannot be reported to
       
   536         // plugins. Instead add error checking to
       
   537         // CDunTransporter::AddSkippedErrorL() if needed
       
   538         iUtility->DoAddSkippedError( aChannelIndex,
       
   539                                      skippedError.iError,
       
   540                                      skippedError.iDirection );
       
   541         }
       
   542     FTRACE(FPrint( _L("CDunChanMan::RestoreWaiterData() complete" )));
       
   543     return KErrNone;
       
   544     }
       
   545 
       
   546 // ---------------------------------------------------------------------------
       
   547 // Deletes waiter objects of aIndex:th waiters
       
   548 // ---------------------------------------------------------------------------
       
   549 //
       
   550 TInt CDunChanMan::DeleteWaiters( TInt aIndex, TBool aNewOwnership )
       
   551     {
       
   552     FTRACE(FPrint( _L("CDunChanMan::DeleteWaiters()" )));
       
   553 
       
   554     if ( aIndex < 0 ||
       
   555          aIndex >= iWaiterData.Count() )
       
   556         {
       
   557         FTRACE(FPrint( _L("CDunChanMan::DeleteWaiters() (not found) complete" )));
       
   558         return KErrNotFound;
       
   559         }
       
   560 
       
   561     TDunWaiterData& waiterData = iWaiterData[aIndex];
       
   562     if ( !aNewOwnership )
       
   563         {
       
   564         delete waiterData.iChannelName;
       
   565         }
       
   566     waiterData.iChannelName = NULL;
       
   567     delete waiterData.iSignalWaiter;
       
   568     waiterData.iSignalWaiter = NULL;
       
   569     delete waiterData.iDataWaiter;
       
   570     waiterData.iDataWaiter = NULL;
       
   571 
       
   572     waiterData.iConnMons.Close();
       
   573     waiterData.iOkErrors.Close();
       
   574 
       
   575     FTRACE(FPrint( _L("CDunChanMan::DeleteWaiters() complete" )));
       
   576     return KErrNone;
       
   577     }