localconnectivityservice/dun/utils/src/DunDataPusher.cpp
branchRCL_3
changeset 38 3dcb815346df
parent 15 c47ebe2ac36c
equal deleted inserted replaced
37:7e0ecb5b116a 38:3dcb815346df
    97 
    97 
    98 // ---------------------------------------------------------------------------
    98 // ---------------------------------------------------------------------------
    99 // Adds event notification to queue
    99 // Adds event notification to queue
   100 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   101 //
   101 //
   102 TInt CDunDataPusher::AddToEventQueue( const TDesC8 *aPushedData,
   102 TInt CDunDataPusher::AddToEventQueue( const TDesC8* aDataToPush,
   103                                       MDunCompletionReporter* aCallback )
   103                                       MDunCompletionReporter* aCallback )
   104     {
   104     {
   105     FTRACE(FPrint( _L("CDunDataPusher::AddToQueue()" )));
   105     FTRACE(FPrint( _L("CDunDataPusher::AddToQueue()" )));
   106     if ( !aPushedData || aPushedData->Length()<0 )
   106     if ( !aDataToPush || aDataToPush->Length()<0 )
   107         {
   107         {
   108         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (unknown data) complete" )));
   108         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (unknown data) complete" )));
   109         return KErrGeneral;
   109         return KErrGeneral;
   110         }
   110         }
   111     // Check if identical pointer to data already exists
   111     // Check if identical pointer to data already exists
   112     TInt foundIndex = FindEventFromQueue( aPushedData );
   112     TInt foundIndex = FindEventFromQueue( aDataToPush );
   113     if ( foundIndex >= 0 )
   113     if ( foundIndex >= 0 )
   114         {
   114         {
   115         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (already exists) complete" )));
   115         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (already exists) complete" )));
   116         return KErrAlreadyExists;
   116         return KErrAlreadyExists;
   117         }
   117         }
   118     // Unique pointer -> add to event queue
   118     // Unique pointer -> add to event queue
   119     TDunDataPush dataPush;
   119     TDunDataPush dataPush;
   120     dataPush.iPushedData = aPushedData;
   120     dataPush.iDataToPush = aDataToPush;
   121     dataPush.iCallback = aCallback;
   121     dataPush.iCallback = aCallback;
   122     TInt retTemp = iEventQueue.Append( dataPush );
   122     TInt retTemp = iEventQueue.Append( dataPush );
   123     if ( retTemp != KErrNone )
   123     if ( retTemp != KErrNone )
   124         {
   124         {
   125         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (append failed!) complete" )));
   125         FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() (append failed!) complete" )));
   126         return retTemp;
   126         return retTemp;
   127         }
   127         }
   128     FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() complete (%d)" ), iEventQueue.Count() ));
   128     FTRACE(FPrint( _L("CDunDataPusher::AddToQueue() complete (count=%d)" ), iEventQueue.Count() ));
   129     return KErrNone;
   129     return KErrNone;
   130     }
   130     }
   131 
   131 
   132 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   133 // Finds an event from queue
   133 // Finds an event from queue
   134 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   135 //
   135 //
   136 TInt CDunDataPusher::FindEventFromQueue( const TDesC8 *aPushedData )
   136 TInt CDunDataPusher::FindEventFromQueue( const TDesC8* aDataToPush )
   137     {
   137     {
   138     FTRACE(FPrint( _L("CDunDataPusher::FindEventFromQueue()" )));
   138     FTRACE(FPrint( _L("CDunDataPusher::FindEventFromQueue()" )));
   139     TInt i;
   139     TInt i;
   140     TInt count = iEventQueue.Count();
   140     TInt count = iEventQueue.Count();
   141     for ( i=0; i<count; i++ )
   141     for ( i=0; i<count; i++ )
   142         {
   142         {
   143         if ( iEventQueue[i].iPushedData == aPushedData )
   143         if ( iEventQueue[i].iDataToPush == aDataToPush )
   144             {
   144             {
   145             FTRACE(FPrint( _L("CDunDataPusher::FindEventFromQueue() complete" )));
   145             FTRACE(FPrint( _L("CDunDataPusher::FindEventFromQueue() complete" )));
   146             return i;
   146             return i;
   147             }
   147             }
   148         }
   148         }
   152 
   152 
   153 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   154 // Stops one event in the event queue
   154 // Stops one event in the event queue
   155 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   156 //
   156 //
   157 TInt CDunDataPusher::StopOneEvent( const TDesC8 *aPushedData )
   157 TInt CDunDataPusher::StopOneEvent( const TDesC8* aDataToPush )
   158     {
   158     {
   159     FTRACE(FPrint( _L("CDunDataPusher::StopOneEvent()" )));
   159     FTRACE(FPrint( _L("CDunDataPusher::StopOneEvent()" )));
   160     if ( !aPushedData )
   160     if ( !aDataToPush )
   161         {
   161         {
   162         FTRACE(FPrint( _L("CDunDataPusher::StopOneEvent() (unknown data) complete" )));
   162         FTRACE(FPrint( _L("CDunDataPusher::StopOneEvent() (unknown data) complete" )));
   163         return KErrGeneral;
   163         return KErrGeneral;
   164         }
   164         }
   165     TInt foundIndex = FindEventFromQueue( aPushedData );
   165     TInt foundIndex = FindEventFromQueue( aDataToPush );
   166     if ( foundIndex >= 0 )
   166     if ( foundIndex >= 0 )
   167         {
   167         {
   168         if ( iEventIndex == foundIndex )
   168         if ( iEventIndex == foundIndex )
   169             {
   169             {
   170             Stop();
   170             Stop();
   332          iEventIndex >= iEventQueue.Count() )
   332          iEventIndex >= iEventQueue.Count() )
   333         {
   333         {
   334         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() (buffer mismatch) complete" )));
   334         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() (buffer mismatch) complete" )));
   335         return KErrGeneral;
   335         return KErrGeneral;
   336         }
   336         }
   337     iStatus = KRequestPending;
   337     const TDesC8* dataToPush = iEventQueue[iEventIndex].iDataToPush;
   338     const TDesC8 *pushedData = iEventQueue[iEventIndex].iPushedData;
       
   339     if ( iComm )
   338     if ( iComm )
   340         {
   339         {
   341         iComm->Write( iStatus, *pushedData );
   340         iStatus = KRequestPending;
   342         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() RComm Write() requested" ) ));
   341         iComm->Write( iStatus, *dataToPush );
       
   342         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() RComm Write() requested (buffer=0x%08X)" ), dataToPush ));
   343         }
   343         }
   344     else if ( iSocket )
   344     else if ( iSocket )
   345         {
   345         {
   346         iSocket->Send( *pushedData, 0, iStatus );
   346         iStatus = KRequestPending;
   347         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() RSocket Send() requested" ) ));
   347         iSocket->Send( *dataToPush, 0, iStatus );
       
   348         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() RSocket Send() requested (buffer=0x%08X)" ), dataToPush ));
   348         }
   349         }
   349     else
   350     else
   350         {
   351         {
   351         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() (ERROR) complete" )));
   352         FTRACE(FPrint( _L("CDunDataPusher::ManageOneEvent() (ERROR) complete" )));
   352         return KErrGeneral;
   353         return KErrGeneral;
   383 // Gets called when endpoint data write complete
   384 // Gets called when endpoint data write complete
   384 // ---------------------------------------------------------------------------
   385 // ---------------------------------------------------------------------------
   385 //
   386 //
   386 void CDunDataPusher::RunL()
   387 void CDunDataPusher::RunL()
   387     {
   388     {
   388     FTRACE(FPrint( _L("CDunDataPusher::RunL()" )));
   389     FTRACE(FPrint( _L("CDunDataPusher::RunL() (buffer=0x%08X)" ), iEventQueue[iEventIndex].iDataToPush ));
   389 
   390 
   390     TBool isError;
   391     TBool isError;
   391     TInt retTemp = iStatus.Int();
   392     TInt retTemp = iStatus.Int();
   392     TInt stop = ProcessErrorCondition( retTemp, isError );
   393     TInt stop = ProcessErrorCondition( retTemp, isError );
   393 
   394