os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServViewWindowFetcher.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServViewWindowFetcher.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,204 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "LogServViewWindowFetcher.h"
1.20 +#include <s32mem.h>
1.21 +#include "LOGGET.H"
1.22 +#include "logservpanic.h"
1.23 +#include "LogServView.h"
1.24 +
1.25 +// Constants
1.26 +const TInt KLogViewWindowTransferBufferGranularity = 500;
1.27 +
1.28 +
1.29 +/////////////////////////////////////////////////////////////////////////////////////////
1.30 +// -----> CLogServViewWindowFetcher (source)
1.31 +/////////////////////////////////////////////////////////////////////////////////////////
1.32 +
1.33 +CLogServViewWindowFetcher::CLogServViewWindowFetcher(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
1.34 +: CLogActive(aPriority), iDatabase(aDatabase)
1.35 + {
1.36 + }
1.37 +
1.38 +CLogServViewWindowFetcher::~CLogServViewWindowFetcher()
1.39 + {
1.40 + Cancel();
1.41 + delete iBuffer;
1.42 + delete iGetEvent;
1.43 + delete iEvent;
1.44 + }
1.45 +
1.46 +void CLogServViewWindowFetcher::ConstructL()
1.47 + {
1.48 + iBuffer = CBufFlat::NewL(KLogViewWindowTransferBufferGranularity);
1.49 + iEvent = CLogEvent::NewL();
1.50 + iGetEvent = CLogGetEvent::NewL(iDatabase, Priority());
1.51 + }
1.52 +
1.53 +CLogServViewWindowFetcher* CLogServViewWindowFetcher::NewL(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
1.54 + {
1.55 + CLogServViewWindowFetcher* self = new(ELeave) CLogServViewWindowFetcher(aDatabase, aPriority);
1.56 + CleanupStack::PushL(self);
1.57 + self->ConstructL();
1.58 + CleanupStack::Pop(self);
1.59 + return self;
1.60 + }
1.61 +
1.62 +/////////////////////////////////////////////////////////////////////////////////////////
1.63 +/////////////////////////////////////////////////////////////////////////////////////////
1.64 +/////////////////////////////////////////////////////////////////////////////////////////
1.65 +
1.66 +void CLogServViewWindowFetcher::StartL(TRequestStatus& aStatus, const CLogServViewBase& aView, const TLogTransferWindow& aWindow, const RMessage2& aMessage)
1.67 + {
1.68 + __ASSERT_ALWAYS(iState == EStateIdle, Panic(ELogViewWindowFetcherBadState));
1.69 + //
1.70 + Queue(aStatus);
1.71 + //
1.72 + iView = &aView;
1.73 + iWindow = aWindow;
1.74 + iMessage = &aMessage;
1.75 + iBuffer->Reset();
1.76 + iWindowIndex = 0;
1.77 + iState = EStateStarting;
1.78 + //
1.79 + CompleteRequest();
1.80 + }
1.81 +
1.82 +/////////////////////////////////////////////////////////////////////////////////////////
1.83 +/////////////////////////////////////////////////////////////////////////////////////////
1.84 +/////////////////////////////////////////////////////////////////////////////////////////
1.85 +
1.86 +void CLogServViewWindowFetcher::DoRunL()
1.87 + {
1.88 + const TInt error = iStatus.Int();
1.89 + User::LeaveIfError(error);
1.90 +
1.91 + switch(iState)
1.92 + {
1.93 + case EStateStarting:
1.94 + GetNextEventL(iWindowIndex);
1.95 + iState = EStateContinuing;
1.96 + break;
1.97 + case EStateContinuing:
1.98 + ProcessEventL();
1.99 + break;
1.100 + default:
1.101 + __ASSERT_ALWAYS(0, Panic(ELogViewWindowFetcherBadState2));
1.102 + break;
1.103 + }
1.104 + }
1.105 +
1.106 +void CLogServViewWindowFetcher::ProcessEventL()
1.107 + {
1.108 + // Try and write the event to the buffer
1.109 + const TInt sizeBefore = iBuffer->Size();
1.110 + RBufWriteStream stream(*iBuffer, iBuffer->Size());
1.111 + stream << *iEvent;
1.112 + const TInt sizeAfter = iBuffer->Size();
1.113 + //
1.114 + TBool moreToFetch = EFalse;
1.115 +
1.116 + const TInt numberToFetch = iWindow.Range();
1.117 + if (sizeAfter > iWindow.iBufferSize)
1.118 + {
1.119 + //The client buffer size is too small. It should be increased, if the client wants
1.120 + //to get the server data.
1.121 + //The server sets iServerDataSize data member with the minimal size which the client
1.122 + //side buffer should have - sizeAfter.
1.123 + TPtrC8 ptr(reinterpret_cast <TUint8*> (&iWindow), sizeof(iWindow));
1.124 + iWindow.iServerDataSize = sizeAfter;
1.125 + iMessage->WriteL(2, ptr);
1.126 +
1.127 + iBuffer->ResizeL(sizeBefore);
1.128 + iWindowIndex -= 1; // we didn't get this event
1.129 + }
1.130 + else if (iWindowIndex+1 < numberToFetch)
1.131 + {
1.132 + GetNextEventL(iWindowIndex+1);
1.133 + moreToFetch = ETrue;
1.134 + }
1.135 +
1.136 + if (!moreToFetch)
1.137 + {
1.138 + // Write whatever we have back to the client's address space
1.139 + TPtr8 pBuffer(iBuffer->Ptr(0));
1.140 + iMessage->WriteL(3, pBuffer);
1.141 + iState = EStateIdle;
1.142 + }
1.143 + }
1.144 +
1.145 +void CLogServViewWindowFetcher::DoCancel()
1.146 + {
1.147 + switch(iState)
1.148 + {
1.149 + case EStateStarting:
1.150 + // Nothing to do, completed our own request status
1.151 + break;
1.152 + case EStateContinuing:
1.153 + iGetEvent->Cancel();
1.154 + break;
1.155 + default:
1.156 + __ASSERT_ALWAYS(0, Panic(ELogViewWindowFetcherBadState3));
1.157 + break;
1.158 + }
1.159 + CLogActive::DoCancel();
1.160 + }
1.161 +
1.162 +void CLogServViewWindowFetcher::DoComplete(TInt& aCompletionCode)
1.163 + {
1.164 + // Indicates to the client side how many records we retrieved.
1.165 + if (aCompletionCode == KErrNone)
1.166 + aCompletionCode = iWindowIndex+1;
1.167 + else
1.168 + iState = EStateIdle;
1.169 + }
1.170 +
1.171 +/////////////////////////////////////////////////////////////////////////////////////////
1.172 +/////////////////////////////////////////////////////////////////////////////////////////
1.173 +/////////////////////////////////////////////////////////////////////////////////////////
1.174 +
1.175 +void CLogServViewWindowFetcher::GetNextEventL(TInt aWindowIndex)
1.176 + {
1.177 + const TInt index = iWindow.iLower + aWindowIndex;
1.178 + const TInt viewCount = iView->Count();
1.179 + if (index < 0)
1.180 + {
1.181 + ::PanicClientL(*iMessage, ELogViewBadWindow);
1.182 + }
1.183 + else if (index >= viewCount)
1.184 + {
1.185 + // View is still catching up with changes which have been made in the server?
1.186 + CLogEvent* event = CLogEvent::NewL();
1.187 + delete iEvent;
1.188 + iEvent = event;
1.189 + CompleteRequest();
1.190 + iWindowIndex = aWindowIndex;
1.191 + }
1.192 + else
1.193 + {
1.194 + const TLogId id = iView->At(index);
1.195 + iEvent->SetId(id);
1.196 + iGetEvent->StartL(*iEvent, iStatus, *iMessage);
1.197 + iWindowIndex = aWindowIndex;
1.198 + SetActive();
1.199 + }
1.200 + }
1.201 +
1.202 +void CLogServViewWindowFetcher::CompleteRequest()
1.203 + {
1.204 + TRequestStatus* status = &iStatus;
1.205 + User::RequestComplete(status, KErrNone);
1.206 + SetActive();
1.207 + }