dosservices/dosserver/src/SaeThread.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Thread creater for SAE
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "SaeThread.h"
       
    21 #include "sae_debug.h"
       
    22 #include <e32svr.h>
       
    23 #include <e32std.h>
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ===============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSaeThread::CSaeThread
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CSaeThread::CSaeThread()
       
    52     {
       
    53     COM_TRACE_( "[DosServer:SAE] CSaeThread::CSaeThread()" );
       
    54 
       
    55     COM_TRACE_( "[DosServer:SAE] CSaeThread::CSaeThread" );
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSaeThread::ConstructL
       
    60 // Symbian 2nd phase constructor can leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CSaeThread::ConstructL()
       
    64     {
       
    65     COM_TRACE_( "[DosServer:SAE] CSaeThread::ConstructL()" );
       
    66 
       
    67 
       
    68     COM_TRACE_( "[DosServer:SAE] CSaeThread::ConstructL - return void" );
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CSaeThread::NewL
       
    73 // Two-phased constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CSaeThread* CSaeThread::NewL()
       
    77     {
       
    78     COM_TRACE_( "[DosServer:SAE] CSaeThread::NewL()" );
       
    79 
       
    80     CSaeThread* self = new ( ELeave ) CSaeThread();
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop( self );
       
    84 
       
    85     COM_TRACE_1( "[DosServer:SAE] CSaeThread::NewL - return 0x%x", &self );
       
    86 
       
    87     return self;
       
    88     }
       
    89 
       
    90 // Destructor
       
    91 CSaeThread::~CSaeThread()
       
    92     {
       
    93     COM_TRACE_( "[DosServer:SAE] CSaeThread::~CSaeThread()" );
       
    94 
       
    95     // CActiveScheduler::Stop();
       
    96 
       
    97     COM_TRACE_( "[DosServer:SAE] CSaeThread::~CSaeThread" );
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CSaeThread::StartThreadL
       
   102 // Creates a new thread
       
   103 // (other items were commented in a header).
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CSaeThread::StartThreadL()
       
   107     {
       
   108     COM_TRACE_( "[DosServer:SAE] CSaeThread::StartThreadL()" );
       
   109     
       
   110     // Generate unique thread name
       
   111     HBufC* bufThreadName = HBufC::NewL( KSAEThreadName().Length() );
       
   112 
       
   113     CleanupStack::PushL( bufThreadName );
       
   114     TPtr ptrThreadName = bufThreadName->Des();
       
   115     ptrThreadName = KSAEThreadName;
       
   116 
       
   117     COM_TRACE_1( "[DosServer:SAE] CSaeThread::StartThreadL(%S)", &ptrThreadName );
       
   118  
       
   119     User::LeaveIfError( iThread.Create(
       
   120                         ptrThreadName,
       
   121                         ThreadEntryPoint,
       
   122                         KDefaultStackSize,
       
   123                         NULL,
       
   124                         NULL ) );
       
   125 
       
   126     CleanupStack::Pop ( bufThreadName );
       
   127     
       
   128     iThread.Resume();
       
   129 
       
   130     delete bufThreadName;
       
   131 
       
   132     COM_TRACE_( "[DosServer:SAE] CSaeThread::StartThreadL - return void" );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSaeThread::ThreadEntryPoint
       
   137 // Entry point of new thread
       
   138 // (other items were commented in a header).
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TInt CSaeThread::ThreadEntryPoint( TAny* /*aParameter*/ )
       
   142     {
       
   143     COM_TRACE_( "[DosServer:SAE] CSaeThread::ThreadEntryPoint()" );
       
   144 
       
   145     TInt err = KErrNone;
       
   146 
       
   147     //create cleanupstack
       
   148     CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
       
   149     if ( !cleanup )
       
   150         err = KErrNoMemory;
       
   151 
       
   152     if ( !err )
       
   153         {
       
   154         TRAP( err, DoStartThreadL() );
       
   155         }
       
   156     delete cleanup;
       
   157 
       
   158     COM_TRACE_1( "[DosServer:SAE] CSaeThread::ThreadEntryPoint - return %d", err );
       
   159 
       
   160     return err;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CSaeThread::DoStartThreadL
       
   165 // Starts new thread by creating and starting active scheduler
       
   166 // (other items were commented in a header).
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TInt CSaeThread::DoStartThreadL()
       
   170     {
       
   171     COM_TRACE_( "[DosServer:SAE] CSaeThread::DoStartThreadL()" );
       
   172 
       
   173     CActiveScheduler* actSched = new (ELeave) CActiveScheduler;
       
   174     CleanupStack::PushL( actSched );
       
   175     CActiveScheduler::Install( actSched );
       
   176 
       
   177     TInt res = CreateSaeLC();
       
   178 
       
   179     CActiveScheduler::Start();
       
   180 
       
   181     CleanupStack::PopAndDestroy( 2 ); // saeObj, actSched
       
   182 
       
   183     COM_TRACE_1( "[DosServer:SAE] CSaeThread::DoStartThreadL - return %d", res );
       
   184 
       
   185     return ( res );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSaeThread::CreateSaeLC
       
   190 // Creates a new instance of SAE
       
   191 // (other items were commented in a header).
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 TInt CSaeThread::CreateSaeLC()
       
   195     {
       
   196     COM_TRACE_( "[DosServer:SAE] CSaeThread::CreateSaeLC()" );
       
   197 
       
   198     TInt res( KErrNone );
       
   199 
       
   200     CSae* saeObj;
       
   201     saeObj = CSae::NewL();
       
   202     
       
   203     CleanupStack::PushL( saeObj );
       
   204 
       
   205     COM_TRACE_1( "[DosServer:SAE] CSaeThread::CreateSaeLC - return %d", res );
       
   206 
       
   207     return res;
       
   208     }
       
   209 
       
   210 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   211 
       
   212 // End of File