|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExSocketWriter.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 // INCLUDES 00017 #include "SIPExSocketWriter.h" 00018 #include "SIPExWriterNotifier.h" 00019 #include <in_sock.h> 00020 00021 // ----------------------------------------------------------------------------- 00022 // CSIPExSocketWriter::NewL 00023 // Static constructor 00024 // ----------------------------------------------------------------------------- 00025 // 00026 CSIPExSocketWriter* CSIPExSocketWriter::NewL( 00027 RSocket& aSocket, 00028 MSIPExWriterNotifier& aNotifier ) 00029 { 00030 CSIPExSocketWriter* self = NewLC( aSocket, aNotifier ); 00031 CleanupStack::Pop(self); 00032 return self; 00033 } 00034 00035 // ----------------------------------------------------------------------------- 00036 // CSIPExSocketWriter::NewLC 00037 // Static constructor 00038 // ----------------------------------------------------------------------------- 00039 // 00040 CSIPExSocketWriter* CSIPExSocketWriter::NewLC( 00041 RSocket& aSocket, 00042 MSIPExWriterNotifier& aNotifier ) 00043 { 00044 CSIPExSocketWriter* self = new (ELeave) CSIPExSocketWriter( aSocket, aNotifier ); 00045 CleanupStack::PushL(self); 00046 self->ConstructL(); 00047 return self; 00048 } 00049 00050 // ----------------------------------------------------------------------------- 00051 // CSIPExSocketWriter::CSIPExSocketWriter 00052 // Constructor 00053 // ----------------------------------------------------------------------------- 00054 // 00055 CSIPExSocketWriter::CSIPExSocketWriter( 00056 RSocket& aSocket, 00057 MSIPExWriterNotifier& aNotifier ) 00058 : CActive(CActive::EPriorityStandard), 00059 iNotifier( aNotifier ), 00060 iSocket( aSocket ) 00061 { 00062 CActiveScheduler::Add(this); 00063 } 00064 00065 // ----------------------------------------------------------------------------- 00066 // CSIPExSocketWriter::~CSIPExSocketWriter 00067 // Destructor 00068 // ----------------------------------------------------------------------------- 00069 // 00070 CSIPExSocketWriter::~CSIPExSocketWriter() 00071 { 00072 Cancel(); 00073 delete iBuffer; 00074 } 00075 00076 // ----------------------------------------------------------------------------- 00077 // CSIPExSocketWriter::ConstructL 00078 // 2nd phase constructor 00079 // ----------------------------------------------------------------------------- 00080 // 00081 void CSIPExSocketWriter::ConstructL() 00082 { 00083 } 00084 00085 // ----------------------------------------------------------------------------- 00086 // CSIPExSocketWriter::DoCancel 00087 // From CActive 00088 // ----------------------------------------------------------------------------- 00089 // 00090 void CSIPExSocketWriter::DoCancel() 00091 { 00092 iSocket.CancelWrite(); 00093 } 00094 00095 // ----------------------------------------------------------------------------- 00096 // CSIPExSocketWriter::RunL 00097 // From CActive 00098 // ----------------------------------------------------------------------------- 00099 // 00100 void CSIPExSocketWriter::RunL() 00101 { 00102 if( iBuffer ) 00103 { 00104 delete iBuffer; 00105 iBuffer = NULL; 00106 } 00107 00108 if( iStatus.Int() == KErrNone ) 00109 { 00110 iNotifier.WriteDone(); 00111 } 00112 else 00113 { 00114 iNotifier.ErrorInWriting( iStatus.Int() ); 00115 } 00116 } 00117 00118 // ----------------------------------------------------------------------------- 00119 // CSIPExSocketWriter::Write 00120 // Asynchronous 00121 // Copy the parameter to the member variable and start asynchronous writing. 00122 // ----------------------------------------------------------------------------- 00123 // 00124 void CSIPExSocketWriter::Write( const TDesC8& aBuffer ) 00125 { 00126 if( iBuffer ) 00127 { 00128 delete iBuffer; 00129 iBuffer = NULL; 00130 } 00131 00132 TRAPD( err, iBuffer = aBuffer.AllocL() ); 00133 00134 if( !IsActive() && err == KErrNone ) 00135 { 00136 iSocket.Write( *iBuffer, iStatus ); 00137 SetActive(); 00138 } 00139 } 00140 00141 // End of file
|
© Nokia 2006 |