localconnectivityservice/dun/utils/src/DunStream.cpp
author hgs
Tue, 28 Sep 2010 20:14:08 +0800
changeset 52 866b4af7ffbe
parent 29 3ae5cb0b4c02
child 54 4dc88a4ac6f4
permissions -rw-r--r--
201039_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     1
/*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     3
* All rights reserved.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     8
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     9
* Initial Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    11
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    12
* Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    13
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    14
* Description:  Definitions needed for common stream functionality
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    15
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    16
*/
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    17
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    18
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    19
/*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    20
 * TODO: When local media is of type RComm, listening on it is started with
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    21
 * RComm::NotifyDataAvailable() call. Check that USB ACM port and Irda RCOMM
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    22
 * (and any other new media in the future) behaves correctly so that when
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    23
 * RComm::ReadOneOrMore() is issued, the read is issued immediately without
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    24
 * checking for new data. If waiting for new data happens in this
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    25
 * NotifyDataAvailable/ReadOneOrMore combination, raise a defect to Symbian.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    26
 */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    27
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    28
#include "DunStream.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    29
#include "DunDebug.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    30
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    31
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    32
// Destructor.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    33
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    34
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    35
CDunStream::~CDunStream()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    36
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    37
    FTRACE(FPrint( _L("CDunStream::~CDunStream()" )));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    38
    ResetData();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    39
    FTRACE(FPrint( _L("CDunStream::~CDunStream() complete" )));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    40
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    41
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    43
// Resets data to initial values
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    44
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    45
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    46
void CDunStream::ResetData()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    47
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    48
    // APIs affecting this:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    49
    // AddConnMonCallback()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    50
    iCallbacksR.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    51
    iCallbacksW.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    52
    // AddSkippedError()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    53
    iOkErrorsR.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    54
    iOkErrorsW.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    55
    // Internal
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    56
    Initialize();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    57
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    58
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    59
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    60
// Adds error code to consider as "no error" to either endpoint
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    61
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    62
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    63
TInt CDunStream::AddSkippedError( TInt aError,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    64
                                  TDunOperationType aOperationType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    65
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    66
    FTRACE(FPrint( _L("CDunStream::AddSkippedError()" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    67
    RArray<TInt>* okErrors = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    68
    if ( aOperationType == EDunOperationTypeRead )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    69
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    70
        okErrors = &iOkErrorsR;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    71
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    72
    else if ( aOperationType == EDunOperationTypeWrite )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    73
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    74
        okErrors = &iOkErrorsW;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    75
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    76
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    77
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    78
        FTRACE(FPrint( _L("CDunStream::AddSkippedError() (ERROR) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    79
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    80
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    81
    if ( aError >= 0 )  // errors can't be >= 0
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    82
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    83
        FTRACE(FPrint( _L("CDunStream::AddSkippedError() (ERROR) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    84
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    85
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    86
    TInt retTemp = okErrors->Find( aError );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    87
    if ( retTemp != KErrNotFound )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    88
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    89
        FTRACE(FPrint( _L("CDunStream::AddSkippedError() (already exists) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    90
        return KErrAlreadyExists;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    91
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    92
    retTemp = okErrors->Append( aError );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    93
    if ( retTemp != KErrNone )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    94
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    95
        FTRACE(FPrint( _L("CDunStream::AddSkippedError() (append failed!) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    96
        return retTemp;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    97
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    98
    FTRACE(FPrint( _L("CDunStream::AddSkippedError() complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    99
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   100
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   101
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   102
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   103
// Adds callback for line status change controlling
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   104
// The callback will be called when serious read error is detected
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   105
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   106
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   107
TInt CDunStream::AddConnMonCallback( MDunConnMon* aCallback,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   108
                                     TDunOperationType aOperationType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   109
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   110
    FTRACE(FPrint( _L("CDunStream::AddConnMonCallback()" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   111
    RPointerArray<MDunConnMon>* callbacks = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   112
    if ( aOperationType == EDunOperationTypeRead )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   113
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   114
        callbacks = &iCallbacksR;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   115
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   116
    else if ( aOperationType == EDunOperationTypeWrite )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   117
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   118
        callbacks = &iCallbacksW;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   119
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   120
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   121
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   122
        FTRACE(FPrint( _L("CDunStream::AddConnMonCallback() (ERROR) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   123
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   124
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   125
    if ( !aCallback )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   126
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   127
        FTRACE(FPrint( _L("CDunStream::AddConnMonCallback() (aCallback) not initialized!" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   128
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   129
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   130
    TInt retTemp = callbacks->Find( aCallback );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   131
    if ( retTemp != KErrNotFound )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   132
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   133
        FTRACE(FPrint( _L("CDunStream::AddCallback() (already exists) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   134
        return KErrAlreadyExists;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   135
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   136
    retTemp = callbacks->Append( aCallback );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   137
    if ( retTemp != KErrNone )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   138
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   139
        FTRACE(FPrint( _L("CDunStream::AddCallback() (append failed!) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   140
        return retTemp;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   141
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   142
    FTRACE(FPrint( _L("CDunStream::AddCallback() complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   143
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   144
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   145
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   146
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   147
// Sets buffering for this stream
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   148
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   149
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   150
TInt CDunStream::SetBuffering( TPtr8* aBufferPtr )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   151
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   152
    FTRACE(FPrint( _L("CDunStream::SetBuffering()" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   153
    if ( !aBufferPtr )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   154
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   155
        FTRACE(FPrint( _L("CDunStream::SetBuffering() (aBufferPtr) not initialized!" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   156
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   157
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   158
    if ( iBufferPtr )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   159
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   160
        FTRACE(FPrint( _L("CDunStream::SetBuffering() (already exists) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   161
        return KErrAlreadyExists;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   162
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   163
    iBufferPtr = aBufferPtr;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   164
    FTRACE(FPrint( _L("CDunStream::SetBuffering() complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   165
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   166
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   167
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   168
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   169
// Sets media to use for this endpoint
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   170
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   171
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   172
TInt CDunStream::SetMedia( RComm* aComm, TDunMediaContext aMediaContext )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   173
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   174
    FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm)" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   175
    if ( !aComm )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   176
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   177
        FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) (aComm not initialized!) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   178
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   179
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   180
    if ( aMediaContext == EDunMediaContextNetwork )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   181
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   182
        iNetwork = aComm;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   183
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   184
    else if ( aMediaContext == EDunMediaContextLocal )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   185
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   186
        iComm = aComm;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   187
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   188
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   189
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   190
        FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) (ERROR) complete" )));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   191
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   192
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   193
    FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   194
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   195
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   196
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   197
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   198
// Sets media to use for this endpoint
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   199
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   200
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   201
TInt CDunStream::SetMedia( RSocket* aSocket,
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   202
                           TDunMediaContext aMediaContext )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   203
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   204
    FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket)" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   205
    if ( !aSocket )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   206
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   207
        FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) (aSocket not initialized!) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   208
        return KErrGeneral;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   209
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   210
    if ( aMediaContext == EDunMediaContextLocal )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   211
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   212
        iSocket = aSocket;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   213
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   214
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   215
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   216
        FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) (not supported) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   217
        return KErrNotSupported;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   218
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   219
    FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   220
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   221
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   222
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   223
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   224
// Gets media context
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   225
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   226
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   227
TDunMediaContext CDunStream::GetMediaContext( TDunStreamType aStreamType )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   228
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   229
    FTRACE(FPrint( _L("CDunStream::GetMediaContext()" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   230
    if ( aStreamType == EDunStreamTypeUpstream )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   231
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   232
        if ( iOperationType == EDunOperationTypeRead )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   233
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   234
            return EDunMediaContextLocal;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   235
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   236
        else if ( iOperationType == EDunOperationTypeWrite )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   237
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   238
            return EDunMediaContextNetwork;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   239
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   240
        else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   241
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   242
            return EDunMediaContextUndefined;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   243
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   244
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   245
    else if ( aStreamType == EDunStreamTypeDownstream )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   246
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   247
        if ( iOperationType == EDunOperationTypeRead )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   248
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   249
            return EDunMediaContextNetwork;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   250
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   251
        else if ( iOperationType == EDunOperationTypeWrite )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   252
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   253
            return EDunMediaContextLocal;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   254
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   255
        else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   256
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   257
            return EDunMediaContextUndefined;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   258
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   259
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   260
    FTRACE(FPrint( _L("CDunStream::GetMediaContext() complete" ) ));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   261
    return EDunMediaContextUndefined;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   262
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   263
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   264
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   265
// Check whether an error code is severe error or not
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   266
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   267
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   268
TInt CDunStream::ProcessErrorCondition( TInt aError, TBool& aIsError )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   269
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   270
    FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d)" ), iDirection));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   271
    aIsError = EFalse;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   272
    if ( aError != KErrNone )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   273
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   274
        aIsError = ETrue;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   275
        RArray<TInt>* okErrors = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   276
        if ( iOperationType == EDunOperationTypeRead )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   277
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   278
            okErrors = &iOkErrorsR;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   279
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   280
        else // iOperationType == EDunOperationTypeWrite
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   281
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   282
            okErrors = &iOkErrorsW;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   283
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   284
        TInt retTemp = okErrors->Find( aError );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   285
        if ( retTemp == KErrNotFound )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   286
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   287
            FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d) (%d=ETrue) complete" ), iDirection, aError));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   288
            return ETrue;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   289
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   290
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   291
    FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d) (%d=EFalse) complete" ), iDirection, aError));
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   292
    return EFalse;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   293
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   294
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   295
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   296
// CDunStream::CDunStream
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   297
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   298
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   299
CDunStream::CDunStream() : CActive( EPriorityHigh )
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   300
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   301
    Initialize();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   302
    CActiveScheduler::Add( this );
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   303
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   304
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   305
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   306
// Initializes this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   307
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   308
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   309
void CDunStream::Initialize()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   310
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   311
    // Don't initialize iUtility here (it is set through NewL)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   312
    iBufferPtr = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   313
    iReadLengthSocket = 0;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   314
    iOperationType = EDunOperationTypeUndefined;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   315
    iTransferState = EDunStateIdle;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   316
    iDirection = EDunDirectionUndefined;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   317
    iNetwork = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   318
    iSocket = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   319
    iComm = NULL;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   320
    }