examples/ForumNokia/Symbian_OS_End-to-End_Sockets_API_Example/SocketTaskManager/engine/TaskManagerEngineReader.cpp

00001 /*
00002  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 
00031 // INCLUDE FILES
00032 #include "TaskManager.pan"
00033 #include "TaskManagerEngineReader.h"
00034 
00035 #include <securesocket.h>
00036 
00037 // ================= MEMBER FUNCTIONS =======================
00038 
00039 // Constructor
00040 CTaskManagerEngineReader::CTaskManagerEngineReader( MEngineNotifier& aNotifier )
00041 : CActive( EPriorityStandard ), iSocket( NULL ), iNotifier( aNotifier )
00042         {
00043         }
00044 
00045 // Destructor
00046 CTaskManagerEngineReader::~CTaskManagerEngineReader()
00047         {
00048         Cancel();
00049         }
00050 
00051 // ----------------------------------------------------
00052 // CTaskManagerEngineReader::ConstructL()
00053 // Second-phase constructor
00054 // ----------------------------------------------------
00055 //
00056 void CTaskManagerEngineReader::ConstructL()
00057         {
00058         CActiveScheduler::Add( this );
00059         }
00060 
00061 // ----------------------------------------------------
00062 // CTaskManagerEngineReader::NewL()
00063 // Two-phased construction.
00064 // ----------------------------------------------------
00065 //
00066 CTaskManagerEngineReader* CTaskManagerEngineReader::NewL( MEngineNotifier& aNotifier )
00067         {
00068         CTaskManagerEngineReader* self = CTaskManagerEngineReader::NewLC( aNotifier );
00069         CleanupStack::Pop( self );
00070         return self;
00071         }
00072 
00073 // ----------------------------------------------------
00074 // CTaskManagerEngineReader::NewLC()
00075 // Two-phased construction.
00076 // ----------------------------------------------------
00077 //
00078 CTaskManagerEngineReader* CTaskManagerEngineReader::NewLC( MEngineNotifier& aNotifier )
00079         {
00080         CTaskManagerEngineReader* self = new (ELeave) CTaskManagerEngineReader( aNotifier );
00081         CleanupStack::PushL( self );
00082         self->ConstructL();
00083         return self;
00084         }
00085 
00086 // ----------------------------------------------------
00087 // CTaskManagerEngineReader::Start()
00088 // Initiates the reader.
00089 // ----------------------------------------------------
00090 //
00091 void CTaskManagerEngineReader::Start()
00092         {
00093         // Initiate a new read from socket into iBuffer
00094     if (!IsActive())
00095         {
00096         IssueRead();
00097         }
00098         }
00099 
00100 // ----------------------------------------------------
00101 // CTaskManagerEngineReader::DoCancel()
00102 // Cancels an outstanding request.
00103 // ----------------------------------------------------
00104 //
00105 void CTaskManagerEngineReader::DoCancel()
00106         {
00107         iSocket->CancelRecv();
00108         }
00109 
00110 // ----------------------------------------------------
00111 // CTaskManagerEngineReader::RunL()
00112 // Handles an active objectís request completion event.
00113 // ----------------------------------------------------
00114 //
00115 void CTaskManagerEngineReader::RunL()
00116         {
00117         switch( iStatus.Int() )
00118                 {
00119                 case KErrNone:
00120                         {
00121                         // Something was read from socket. Pass it to upper levels
00122                 if( iNotifier.PackageReceivedL( iBuffer ) )
00123                     {
00124                     IssueRead(); // Immediately start another read
00125                     }
00126             
00127                         break;
00128                         }
00129                 default:
00130                     {
00131                     Panic( ETaskManagerInvalidState );
00132                     break;
00133                     }
00134                 }
00135         }
00136 
00137 // ----------------------------------------------------
00138 // CTaskManagerEngineReader::IssueRead()
00139 // Initiate a single new read from socket.
00140 // ----------------------------------------------------
00141 //
00142 void CTaskManagerEngineReader::IssueRead()
00143         {
00144         // This deletion is needed for some reason in S60 3rd Edition (at least for the emulator).
00145         // Otherwise the data in iBuffer will not get replaced on successive read operations to
00146         // the secure socket.
00147         iBuffer.Delete(0, iBuffer.Length());
00148     iSocket->RecvOneOrMore(iBuffer, iStatus, iDummyLength);
00149     SetActive();
00150     }
00151 
00152 // ----------------------------------------------------
00153 // CTaskManagerEngineReader::SetSecureSocket()
00154 // Sets a new socket from which to read.
00155 // ----------------------------------------------------
00156 //
00157 void CTaskManagerEngineReader::SetSecureSocket( CSecureSocket* aSocket )
00158     {
00159     iSocket = aSocket;
00160     }
00161     
00162 // End of file

Generated by  doxygen 1.6.2