os/persistentdata/loggingservices/eventlogger/LogServ/src/LogNotify.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "LogNotify.h"
sl@0
    17
#include "logservpanic.h"
sl@0
    18
#include "LogServBackupInterface.h"
sl@0
    19
#include "LogServDatabaseChangeInterface.h"
sl@0
    20
sl@0
    21
sl@0
    22
CLogNotify::CLogNotify(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
sl@0
    23
:	CTimer(aPriority), iBackupInterface(aBackupInterface), iChangeInterface(aChangeInterface), iCompleteClientMessage(ETrue)
sl@0
    24
	{
sl@0
    25
	CActiveScheduler::Add(this);
sl@0
    26
	}
sl@0
    27
sl@0
    28
CLogNotify::~CLogNotify()
sl@0
    29
	{
sl@0
    30
	LOGTEXT("CLogNotify::~CLogNotify()");
sl@0
    31
sl@0
    32
	// This will only complete the client-side request if its not already
sl@0
    33
	// been completed
sl@0
    34
	Cancel();
sl@0
    35
	//
sl@0
    36
	iChangeInterface.DCIRequestChangeNotificationsCancel(*this);
sl@0
    37
	iBackupInterface.BIObserverRemove(*this);
sl@0
    38
sl@0
    39
	LOGTEXT("CLogNotify::~CLogNotify() - end");
sl@0
    40
	}
sl@0
    41
sl@0
    42
void CLogNotify::ConstructL()
sl@0
    43
	{
sl@0
    44
	LOGTEXT("CLogNotify::ConstructL()");
sl@0
    45
sl@0
    46
	CTimer::ConstructL();
sl@0
    47
sl@0
    48
	// Register for change events
sl@0
    49
	iChangeInterface.DCIRequestChangeNotificationsL(*this);
sl@0
    50
sl@0
    51
	// Register for backup events
sl@0
    52
	iBackupInterface.BIObserverAddL(*this, MLogServBackupInterface::EObjectClientChangeNotifications);
sl@0
    53
sl@0
    54
	LOGTEXT("CLogNotify::ConstructL() - end");
sl@0
    55
	}
sl@0
    56
sl@0
    57
CLogNotify* CLogNotify::NewL(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
sl@0
    58
	{
sl@0
    59
	CLogNotify* self = new(ELeave)CLogNotify(aBackupInterface, aChangeInterface, aPriority);
sl@0
    60
	CleanupStack::PushL(self);
sl@0
    61
	self->ConstructL();
sl@0
    62
	CleanupStack::Pop(); // self
sl@0
    63
	return self;
sl@0
    64
	}
sl@0
    65
sl@0
    66
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    67
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    68
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    69
sl@0
    70
void CLogNotify::DCOHandleChangeEventsL(const CLogChangeDefinition& /*aChanges*/)
sl@0
    71
//
sl@0
    72
//	Handle changes within the log database
sl@0
    73
//
sl@0
    74
	{
sl@0
    75
	LOGTEXT2("CLogNotify::DCOHandleChangeEventsL() - client thread is: %S", &iClientThreadName);
sl@0
    76
sl@0
    77
	// Increment number of changes but only notify the client side request
sl@0
    78
	// if the delay timer isn't running.
sl@0
    79
	++iCommit;
sl@0
    80
	//
sl@0
    81
	if	(!IsActive())
sl@0
    82
		CheckForChanges();
sl@0
    83
sl@0
    84
	LOGTEXT("CLogNotify::DCOHandleChangeEventsL() - end");
sl@0
    85
	}
sl@0
    86
sl@0
    87
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    88
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    89
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
    90
sl@0
    91
void CLogNotify::BOHandleEventL(TLogServBackupEvent aEvent)
sl@0
    92
	{
sl@0
    93
	switch(aEvent)
sl@0
    94
		{
sl@0
    95
	case EBackupStarting:
sl@0
    96
		LOGTEXT("CLogNotify::BOHandleEventL(EBackupStarting)");
sl@0
    97
sl@0
    98
		// A rather inelegant fix but gets rid of one whole class
sl@0
    99
		iCompleteClientMessage = EFalse;
sl@0
   100
		Cancel();
sl@0
   101
		iCompleteClientMessage = ETrue;
sl@0
   102
		break;
sl@0
   103
sl@0
   104
	case EBackupEnded:
sl@0
   105
		LOGTEXT("CLogNotify::BOHandleEventL(EBackupEnded)");
sl@0
   106
		// Simulate a change
sl@0
   107
		++iCommit;
sl@0
   108
		if	(!IsActive())
sl@0
   109
			CheckForChanges();
sl@0
   110
		break;
sl@0
   111
		}
sl@0
   112
sl@0
   113
	LOGTEXT("CLogNotify::BOHandleEventL() - end");
sl@0
   114
	}
sl@0
   115
sl@0
   116
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   117
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   118
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   119
sl@0
   120
void CLogNotify::Notify(TTimeIntervalMicroSeconds32 aDelay, const RMessage2& aMessage)
sl@0
   121
sl@0
   122
	{
sl@0
   123
#ifdef LOGGING_ENABLED
sl@0
   124
	RThread t;
sl@0
   125
	aMessage.Client(t);
sl@0
   126
	iClientThreadName = t.Name();
sl@0
   127
	t.Close();
sl@0
   128
	LOGTEXT3("CLogNotify::Notify(%d, %S)", aDelay.Int(), &iClientThreadName);
sl@0
   129
#endif
sl@0
   130
sl@0
   131
	__ASSERT_DEBUG(!IsActive(), Panic(ELogAlreadyActive18));
sl@0
   132
	Cancel();
sl@0
   133
sl@0
   134
	// Reset our change counter
sl@0
   135
	if (iLastCommit == 0)
sl@0
   136
		iLastCommit = iCommit;
sl@0
   137
sl@0
   138
	// Save a message pointer to client request status
sl@0
   139
	iMessagePtr = aMessage;
sl@0
   140
sl@0
   141
	// Wait until the delay has passed before notifying clients of changes
sl@0
   142
	After(aDelay);
sl@0
   143
sl@0
   144
	LOGTEXT("CLogNotify::Notify() - end");
sl@0
   145
	}
sl@0
   146
sl@0
   147
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   148
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   149
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   150
sl@0
   151
void CLogNotify::Cancel()
sl@0
   152
	{
sl@0
   153
	LOGTEXT2("CLogNotify::Cancel() - client thread is: %S", &iClientThreadName);
sl@0
   154
sl@0
   155
	CActive::Cancel();
sl@0
   156
sl@0
   157
	// Reset
sl@0
   158
	iLastCommit = 0;
sl@0
   159
sl@0
   160
	// Complete the client-side observer
sl@0
   161
	if	(iCompleteClientMessage)
sl@0
   162
		CompleteClientRequest(KErrCancel);
sl@0
   163
sl@0
   164
	LOGTEXT("CLogNotify::Cancel() - end");
sl@0
   165
	}
sl@0
   166
sl@0
   167
void CLogNotify::RunL()
sl@0
   168
//
sl@0
   169
//	RunL is called if the timer has expired
sl@0
   170
//
sl@0
   171
	{
sl@0
   172
	LOGTEXT3("CLogNotify::RunL(%d) - client thread is: %S", iStatus.Int(), &iClientThreadName);
sl@0
   173
sl@0
   174
	CheckForChanges();
sl@0
   175
sl@0
   176
	LOGTEXT("CLogNotify::RunL() - end");
sl@0
   177
	}
sl@0
   178
sl@0
   179
void CLogNotify::DoCancel()
sl@0
   180
	{
sl@0
   181
	LOGTEXT2("CLogNotify::DoCancel() - client thread is: %S", &iClientThreadName);
sl@0
   182
sl@0
   183
	// This is what really cancel's us
sl@0
   184
	CTimer::DoCancel();
sl@0
   185
sl@0
   186
	LOGTEXT("CLogNotify::DoCancel() - end");
sl@0
   187
	}
sl@0
   188
sl@0
   189
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   190
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   191
/////////////////////////////////////////////////////////////////////////////////////////
sl@0
   192
sl@0
   193
void CLogNotify::CheckForChanges()
sl@0
   194
	{
sl@0
   195
	LOGTEXT4("CLogNotify::CheckForChanges() - iLastCommit = %d, iCommit = %d, client thread name: %S", iLastCommit, iCommit, &iClientThreadName);
sl@0
   196
sl@0
   197
	if	(iLastCommit != iCommit)
sl@0
   198
		{
sl@0
   199
		LOGTEXT("CLogNotify::CheckForChanges() - changes detected, attempting to notify client");
sl@0
   200
		iLastCommit = iCommit;
sl@0
   201
		CompleteClientRequest(RDbNotifier::ECommit);
sl@0
   202
		}
sl@0
   203
sl@0
   204
	LOGTEXT("CLogNotify::CheckForChanges() - end");
sl@0
   205
	}
sl@0
   206
sl@0
   207
void CLogNotify::CompleteClientRequest(TInt aCompletionCode)
sl@0
   208
	{
sl@0
   209
	LOGTEXT3("CLogNotify::CompleteClientRequest() - aCompletionCode = %d, thread: %S", aCompletionCode, &iClientThreadName);
sl@0
   210
sl@0
   211
	if	(!iMessagePtr.IsNull())
sl@0
   212
		{
sl@0
   213
		LOGTEXT2("CLogNotify::CompleteClientRequest() - completing outstanding client request status for thread: %S", &iClientThreadName);
sl@0
   214
		iMessagePtr.Complete(aCompletionCode);
sl@0
   215
		}
sl@0
   216
	else
sl@0
   217
		{
sl@0
   218
		LOGTEXT2("CLogNotify::CompleteClientRequest() - thread %S doesn't have an outstanding notification request", &iClientThreadName);
sl@0
   219
		}
sl@0
   220
sl@0
   221
	LOGTEXT("CLogNotify::CompleteClientRequest() - end");
sl@0
   222
	}