|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExSocketReader.cpp 00004 * Part of : SIPExSocketEngine 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #include "SIPExSocketReader.h" 00017 #include "SIPExReaderNotifier.h" 00018 #include <in_sock.h> 00019 #include <e32svr.h> 00020 00021 // ----------------------------------------------------------------------------- 00022 // CSIPExSocketReader::NewL 00023 // Static constructor 00024 // ----------------------------------------------------------------------------- 00025 // 00026 CSIPExSocketReader* CSIPExSocketReader::NewL( 00027 RSocket& aSocket, 00028 MSIPExReaderNotifier& aNotifier ) 00029 { 00030 CSIPExSocketReader* self = NewLC( aSocket, aNotifier ); 00031 CleanupStack::Pop(self); 00032 return self; 00033 } 00034 00035 // ----------------------------------------------------------------------------- 00036 // CSIPExSocketReader::NewLC 00037 // Static constructor 00038 // ----------------------------------------------------------------------------- 00039 // 00040 CSIPExSocketReader* CSIPExSocketReader::NewLC( 00041 RSocket& aSocket, 00042 MSIPExReaderNotifier& aNotifier ) 00043 { 00044 CSIPExSocketReader* self = new (ELeave) CSIPExSocketReader( aSocket, aNotifier ); 00045 CleanupStack::PushL(self); 00046 self->ConstructL(); 00047 return self; 00048 } 00049 00050 // ----------------------------------------------------------------------------- 00051 // CSIPExSocketReader::CSIPExSocketReader 00052 // Constructor 00053 // ----------------------------------------------------------------------------- 00054 // 00055 CSIPExSocketReader::CSIPExSocketReader( 00056 RSocket& aSocket, 00057 MSIPExReaderNotifier& aNotifier ) 00058 : CActive(CActive::EPriorityStandard), 00059 iNotifier( aNotifier ), 00060 iSocket( aSocket ) 00061 { 00062 CActiveScheduler::Add(this); 00063 } 00064 00065 // ----------------------------------------------------------------------------- 00066 // CSIPExSocketReader::~CSIPExSocketReader 00067 // Destructor 00068 // ----------------------------------------------------------------------------- 00069 // 00070 CSIPExSocketReader::~CSIPExSocketReader() 00071 { 00072 Cancel(); 00073 } 00074 00075 // ----------------------------------------------------------------------------- 00076 // CSIPExSocketReader::ConstructL 00077 // 2nd phase constructor 00078 // ----------------------------------------------------------------------------- 00079 // 00080 void CSIPExSocketReader::ConstructL() 00081 { 00082 } 00083 00084 // ----------------------------------------------------------------------------- 00085 // CSIPExSocketReader::DoCancel 00086 // Cancels outstanding request. 00087 // ----------------------------------------------------------------------------- 00088 // 00089 void CSIPExSocketReader::DoCancel() 00090 { 00091 iSocket.CancelRead(); 00092 } 00093 00094 // ----------------------------------------------------------------------------- 00095 // CSIPExSocketReader::RunL 00096 // Buffers the characters read from socket and notifies the observer when buffer 00097 // if full. If error notifies the observer. 00098 // ----------------------------------------------------------------------------- 00099 // 00100 void CSIPExSocketReader::RunL() 00101 { 00102 if( iStatus.Int() == KErrNone ) 00103 { 00104 iMessage.Append( iBuffer ); 00105 iBuffer.Zero(); 00106 if( iMessage.Length() == 4 ) 00107 { 00108 iNotifier.MessageReceived( iMessage ); 00109 iMessage.Zero(); 00110 } 00111 Read(); 00112 } 00113 else 00114 { 00115 iMessage.FillZ(); 00116 iMessage.Zero(); 00117 iNotifier.ErrorInReading( iStatus.Int() ); 00118 } 00119 } 00120 00121 // ----------------------------------------------------------------------------- 00122 // CSIPExSocketReader::Read 00123 // Asynchronous 00124 // Starts the asynchoronous reading if not already active. 00125 // ----------------------------------------------------------------------------- 00126 // 00127 void CSIPExSocketReader::Read() 00128 { 00129 if( !IsActive() ) 00130 { 00131 iSocket.Read( iBuffer, iStatus ); 00132 SetActive(); 00133 } 00134 } 00135 00136 // End of file
|
© Nokia 2006 |