cbsref/csyrefplugins/csy27010/src/CommReadWriteBaseAo.cpp
author hgs
Mon, 09 Aug 2010 17:35:42 +0100
changeset 58 980b3d0c4069
parent 44 8b72faa1200f
permissions -rw-r--r--
201027_10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     1
//
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     2
// * Copyright 2004 Neusoft America Inc.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     3
// * All rights reserved.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     4
// * This component and the accompanying materials are made available
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     5
// * under the terms of the Eclipse Public License v1.0
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     6
// * which accompanies this distribution, and is available
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     7
// * at the URL "http://www.eclipse.org/legal/epl-v10.html".
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     8
// *
8b72faa1200f 201024_02
hgs
parents:
diff changeset
     9
// * Contributors:
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    10
// * Keith Collins (Neusoft America Inc.)  original software development and additional code and modifications.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    11
// * Thomas Gahagen (Neusoft America Inc.)  additional code and modifications.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    12
// * Zhen Yuan (Neusoft America Inc.)  additional code and modifications.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    13
// *
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    14
// * Description:  This file has the implementation for the class MsgToBPCmdQueue
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    15
// *               for adding and removing the BasePort Command messages from the queue.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    16
//
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    17
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    18
// CommReadWriteBaseAo.cpp
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    19
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    20
/** @file CommReadWriteBaseAo.cpp
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    21
 *
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    22
 * 
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    23
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    24
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    25
#include "CommReadWriteBaseAo.h"
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    26
#include "Portfactory.h"
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    27
#include "CsyDebugLogger.h"
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    28
#include "CsyGlobals.h"
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    29
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    30
CCommReadWriteBaseAo::CCommReadWriteBaseAo(CPortFactory* aParent,
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    31
										   CMux0710Protocol* aMux0710Protocol,
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    32
										   TInt aPriority)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    33
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    34
 * Constructor.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    35
 * @param aParent - Pointer to the parent
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    36
 * @param aMux0710Protocol - Pointer to the mux protocol
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    37
 * @param aPriority - Priority to set for active object
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    38
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    39
 : CActive(aPriority),
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    40
   iBufSize(KDefaultTxRxBufSize),
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    41
   iRole(ECommRoleDTE),
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    42
   iParent(aParent),
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    43
   iMux0710Protocol(aMux0710Protocol)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    44
	{
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    45
	iCommPort = aParent->DTEPort();
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    46
	CActiveScheduler::Add(this);
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    47
	}
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    48
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    49
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    50
CCommReadWriteBaseAo::~CCommReadWriteBaseAo()
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    51
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    52
 * Destructor. Delete the memory allocated by this object.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    53
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    54
    {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    55
    delete iBuffer;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    56
    delete iBuf;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    57
    }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    58
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    59
TInt CCommReadWriteBaseAo::SetServerConfig(TCommServerConfig& aConfig)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    60
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    61
 * Set the port to use partial reads/writes or the bungee buffer.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    62
 *
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    63
 * @param aConfig Reference to the new Comm server configuration
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    64
 * @return TInt error code. KErrNone for sucess
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    65
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    66
    {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    67
    _LOG_L4C1(">>CCommReadWriteBaseAo::SetServerConfig");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    68
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    69
    TCommServerConfigV01& c = aConfig();
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    70
    TInt res = KErrNone;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    71
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    72
    if (c.iBufFlags & KCommBufferPartial)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    73
        {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    74
        TInt bufSave = iBufSize;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    75
        iBufSize = c.iBufSize;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    76
        TRAP(res, SetBuffersL();)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    77
        if (res==KErrNone)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    78
            iBufFlags = c.iBufFlags;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    79
        else
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    80
            iBufSize = bufSave;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    81
        }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    82
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    83
	_LOG_L4C2("<<CCommReadWriteBaseAo::SetServerConfig [res=%d]",res);
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    84
	return res;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    85
    }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    86
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    87
void CCommReadWriteBaseAo::GetServerConfig(TCommServerConfig& aConfig) const
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    88
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    89
 * This method reads the comm server buffer configuration.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    90
 *
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    91
 * @param aConfig Reference to location to write the Comm server configuration
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    92
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    93
    {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    94
    _LOG_L4C1("CCommReadWriteBaseAo::GetServerConfig");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    95
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    96
    aConfig().iBufFlags = iBufFlags;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    97
    aConfig().iBufSize  = iBufSize;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    98
    }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
    99
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   100
void CCommReadWriteBaseAo::FreeMemory()
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   101
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   102
 * Reduce memory allocation levels by order of the comm server.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   103
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   104
    {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   105
    _LOG_L4C1("CCommReadWriteBaseAo::FreeMemory");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   106
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   107
    TRAP_IGNORE(SetBuffersL();)
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   108
	// MAF the result is ignored?
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   109
    }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   110
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   111
void CCommReadWriteBaseAo::SetBuffersL()
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   112
/**
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   113
 * This method frees the buffer memory and then tries to allocate
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   114
 * a smaller piece of memory. Note that this function will leave if
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   115
 * the memory allocation fails.
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   116
 */
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   117
    {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   118
    _LOG_L4C1(">>CCommReadWriteBaseAo::SetBuffersL");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   119
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   120
    if (!IsActive())
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   121
        {
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   122
		_LOG_L3C1("Not active - allow alloc to happen");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   123
        TInt allocLen = Align4(iBufSize);
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   124
   
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   125
        delete iBuffer;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   126
        delete iBuf;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   127
        iBuf = NULL;   // set to NULL, in case new leaves
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   128
        iBuffer = NULL;
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   129
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   130
        iBuffer = HBufC8::NewMaxL(allocLen);
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   131
        iBuf = new (ELeave) TPtr8((TText8*)iBuffer->Des().Ptr(), allocLen, allocLen);
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   132
        }
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   133
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   134
	_LOG_L4C1("<<CCommReadWriteBaseAo::SetBuffersL");
8b72faa1200f 201024_02
hgs
parents:
diff changeset
   135
	}