localconnectivityservice/dun/server/src/DunCloseWait.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     1 /*
       
     2 * Copyright (c) 2006-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:  Common waiter for closing self-destruct plugins
       
    15 *
       
    16 */
       
    17 
       
    18 #include "DunCloseWait.h"
       
    19 #include "DunDebug.h"
       
    20 
       
    21 // ---------------------------------------------------------------------------
       
    22 // Two-phased constructor.
       
    23 // ---------------------------------------------------------------------------
       
    24 //
       
    25 CDunCloseWait* CDunCloseWait::NewL( MDunCloseWait* aCallback )
       
    26     {
       
    27     CDunCloseWait* self = new (ELeave) CDunCloseWait( aCallback );
       
    28     CleanupStack::PushL( self );
       
    29     self->ConstructL();
       
    30     CleanupStack::Pop( self );
       
    31     return self;
       
    32     }
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Destructor.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CDunCloseWait::~CDunCloseWait()
       
    39     {
       
    40     FTRACE(FPrint( _L("CDunCloseWait::~CDunCloseWait()" )));
       
    41     ResetData();
       
    42     FTRACE(FPrint( _L("CDunCloseWait::~CDunCloseWait() complete" )));
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Resets data to initial values
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CDunCloseWait::ResetData()
       
    50     {
       
    51     // IssueRequest()
       
    52     Stop();
       
    53     // AddPluginToClose()
       
    54     iCloseList.Close();
       
    55     // Internal
       
    56     Initialize();
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Adds a new object to be destructed to the list
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 TInt CDunCloseWait::AddPluginToClose( MDunLocalMediaPlugin* aPluginToClose )
       
    64     {
       
    65     FTRACE(FPrint( _L("CDunCloseWait::AddPluginToClose()" ) ));
       
    66     if ( !aPluginToClose )
       
    67         {
       
    68         FTRACE(FPrint( _L("CDunCloseWait::AddPluginToClose() (ERROR) complete" ) ));
       
    69         return KErrGeneral;
       
    70         }
       
    71     TInt retTemp = iCloseList.Find( aPluginToClose );
       
    72     if ( retTemp != KErrNotFound )
       
    73         {
       
    74         FTRACE(FPrint( _L("CDunCloseWait::AddPluginToClose() (already exists) complete" ) ));
       
    75         return KErrAlreadyExists;
       
    76         }
       
    77     retTemp = iCloseList.Append( aPluginToClose );
       
    78     if ( retTemp != KErrNone )
       
    79         {
       
    80         FTRACE(FPrint( _L("CDunCloseWait::AddPluginToClose() (append failed!) complete" ) ));
       
    81         return retTemp;
       
    82         }
       
    83     FTRACE(FPrint( _L("CDunCloseWait::AddPluginToClose() complete" ) ));
       
    84     return KErrNone;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Issues request to start closing the objects in the close list
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TInt CDunCloseWait::IssueRequest()
       
    92     {
       
    93     FTRACE(FPrint( _L("CDunCloseWait::IssueRequest()" )));
       
    94     if ( IsActive() )
       
    95         {
       
    96         FTRACE(FPrint( _L("CDunCloseWait::IssueRequest() (not ready) complete" )));
       
    97         return KErrNotReady;
       
    98         }
       
    99     iStatus = KRequestPending;
       
   100     SetActive();
       
   101     TRequestStatus* requestStatus = &iStatus;
       
   102     User::RequestComplete( requestStatus, KErrNone );
       
   103     FTRACE(FPrint( _L("CDunCloseWait::IssueRequest() complete" )));
       
   104     return KErrNone;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Stops closing the objects in the close list
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 TInt CDunCloseWait::Stop()
       
   112     {
       
   113     FTRACE(FPrint( _L("CDunCloseWait::Stop()" )));
       
   114     if ( !IsActive() )
       
   115         {
       
   116         FTRACE(FPrint( _L("CDunCloseWait::Stop() (not ready) complete" )));
       
   117         return KErrNotReady;
       
   118         }
       
   119     Cancel();
       
   120     FTRACE(FPrint( _L("CDunCloseWait::Stop() complete" )));
       
   121     return KErrNone;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CDunCloseWait::CDunCloseWait
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CDunCloseWait::CDunCloseWait( MDunCloseWait* aCallback ) :
       
   129     CActive( EPriorityHigh ),
       
   130     iCallback( aCallback )
       
   131     {
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CDunCloseWait::ConstructL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CDunCloseWait::ConstructL()
       
   139     {
       
   140     FTRACE(FPrint( _L("CDunCloseWait::ConstructL()" ) ));
       
   141     if ( !iCallback )
       
   142         {
       
   143         User::Leave( KErrGeneral );
       
   144         }
       
   145     CActiveScheduler::Add( this );
       
   146     FTRACE(FPrint( _L("CDunCloseWait::ConstructL() complete" ) ));
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Initializes this class
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CDunCloseWait::Initialize()
       
   154     {
       
   155     // Don't initialize iCallback here (it is set through NewL)
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // From class CActive.
       
   160 // Gets called when closing of the plugins should be done
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CDunCloseWait::RunL()
       
   164     {
       
   165     FTRACE(FPrint( _L("CDunCloseWait::RunL()" )));
       
   166     iCallback->NotifyPluginCloseAfterWait( iCloseList );
       
   167     iCloseList.Reset();
       
   168     FTRACE(FPrint( _L("CDunCloseWait::RunL() complete" )));
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // From class CActive.
       
   173 // Gets called on cancel
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CDunCloseWait::DoCancel()
       
   177     {
       
   178     }