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