int main() { LimitedCounter counterA(0, 5); RoundupCounter counterB(0, 5); UseCounter(&counterA, 8); UseCounter(&counterB, 8); cout << "Counter A: " << counterA << endl; // output should be 5 cout << "Counter B: " << counterB << endl; // output should be 2 return 0; }
// ----------------------------------------------------------------------------- // DIscDevice::CancelSending // Cancels sending of frames to Domestic OS // ( other items were commented in a header ). // ----------------------------------------------------------------------------- // EXPORT_C TInt DIscDevice::CancelSending( const TUint16 aChannelId, const TAny* aChannelPtr ) { C_TRACE( ( _T( "DIscDevice::CancelSending - Caller is channel: %d (0x%x)" ), aChannelId, aChannelPtr ) ); TInt error( KErrNotFound ); TInt irqLevel( 0 ); TInt counterA( 0 ); TInt counterB( 0 ); TIscSendFrameInfo* temp = NULL; TDes8* frame = NULL; irqLevel = DisableIrqs(); if ( KIscControlChannel == aChannelId ) { // empty control send queue while ( !iControlSendQueue->Empty() ) { temp = iControlSendQueue->GetFirstFrameInfo(); frame = ( TDes8* )iControlSendQueue->RemoveFirst(); if ( temp && frame ) { if ( temp->iChannelId == aChannelId && temp->iChannelPtr == ( DIscChannel* )aChannelPtr ) { // sender found, no need to store the frame counterB++; } else { iTempQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo ); } } else { // should never came here TRACE_ASSERT_ALWAYS; } counterA++; temp = NULL; frame = NULL; } while ( !iTempQueue->Empty() ) { temp = iTempQueue->GetFirstFrameInfo(); frame = ( TDes8* )iTempQueue->RemoveFirst(); if ( temp && frame ) { iControlSendQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo ); } else { // should never came here TRACE_ASSERT_ALWAYS; } temp = NULL; frame = NULL; } } else { // empty normal send queue while ( !iSendQueue->Empty() ) { temp = iSendQueue->GetFirstFrameInfo(); frame = ( TDes8* )iSendQueue->RemoveFirst(); if ( temp && frame ) { if ( temp->iChannelId == aChannelId && temp->iChannelPtr == ( DIscChannel* )aChannelPtr ) { // sender found, no need to store frame counterB++; } else { iTempQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo ); } } else { // should never came here TRACE_ASSERT_ALWAYS; } counterA++; temp = NULL; frame = NULL; } while ( !iTempQueue->Empty() ) { temp = iTempQueue->GetFirstFrameInfo(); frame = ( TDes8* )iTempQueue->RemoveFirst(); if ( temp && frame ) { iSendQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo ); } else { // should never came here TRACE_ASSERT_ALWAYS; } temp = NULL; frame = NULL; } } RestoreIrqs( irqLevel ); C_TRACE( ( _T( "DIscDevice::CancelSending() - Frames in queue: Before: %d, After: %d" ), counterA, ( counterA-counterB ) ) ); C_TRACE( ( _T( "DIscDevice::CancelSending() - So channel 0x%x 0x%x had %d pending messages!" ), aChannelId, aChannelPtr, counterB ) ); // if there weren't any frames that were cancelled return KErrNotFound, otherwise return KErrNone if ( counterB > 0 ) { error = KErrNone; } return error; }