pimprotocols/pbap/pbaplogeng/pbaplogeng.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "pbaplogeng.h"
       
    17 
       
    18 #include "btaccesshostlog.h"
       
    19 
       
    20 //
       
    21 // CPbapLogWrapper
       
    22 //
       
    23 
       
    24 /*static*/ EXPORT_C CPbapLogWrapper* CPbapLogWrapper::NewL(RFs& aFs)
       
    25 	{
       
    26 	LOG_STATIC_FUNC
       
    27 	CPbapLogWrapper* self = new(ELeave) CPbapLogWrapper;
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL(aFs);
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 CPbapLogWrapper::CPbapLogWrapper()
       
    35 	{
       
    36 	LOG_FUNC
       
    37 	}
       
    38 
       
    39 void CPbapLogWrapper::ConstructL(RFs& aFs)
       
    40 	{
       
    41 	LOG_FUNC
       
    42 	
       
    43 	// create the CLogWrapper to forward requests to.
       
    44 	iLogWrapper = CLogWrapper::NewL(aFs);
       
    45 
       
    46 	if (iLogWrapper->ClientAvailable())
       
    47 		{
       
    48 		iLogClient = static_cast<CLogClient*>(&iLogWrapper->Log());
       
    49 		}
       
    50 	else
       
    51 		{
       
    52 		// if no client is available then we have no access to the call history
       
    53 		// information. The PBAP server will continue anyway but only giving
       
    54 		// access to the contact information.
       
    55 		User::Leave(KErrNotSupported);
       
    56 		}
       
    57 	}
       
    58 
       
    59 EXPORT_C  CPbapLogWrapper::~CPbapLogWrapper()
       
    60 	{
       
    61 	LOG_FUNC
       
    62 	
       
    63 	iPbapObservers.Close();
       
    64 	
       
    65 	delete iLogWrapper;	
       
    66 	}
       
    67 
       
    68 EXPORT_C  TBool CPbapLogWrapper::ClientAvailable() const
       
    69 	{
       
    70 	LOG_FUNC	
       
    71 	return iLogWrapper->ClientAvailable();
       
    72 	}
       
    73 	
       
    74 EXPORT_C  TInt CPbapLogWrapper::GetString(TDes &aString, TInt aId) const
       
    75 	{
       
    76 	LOG_FUNC
       
    77 	return iLogClient->GetString(aString, aId);
       
    78 	}
       
    79 
       
    80 CLogClient& CPbapLogWrapper::LogClient()
       
    81 	{
       
    82 	LOG_FUNC
       
    83 	return  *iLogClient;
       
    84 	}
       
    85 
       
    86 TInt CPbapLogWrapper::AddPbapObserver(MPbapLogEngViewObserver& aObserver)
       
    87 	{
       
    88 	LOG_FUNC
       
    89 	TInt rerr = iPbapObservers.Append(&aObserver);
       
    90 	
       
    91 	if ((iPbapObservers.Count() == 1) && (rerr == KErrNone))
       
    92 		{
       
    93 		// first observer was just successfully added, register for global events
       
    94 		TRAP(rerr, iLogClient->SetGlobalChangeObserverL(this));
       
    95 		}
       
    96 		
       
    97 	return rerr;
       
    98 	}
       
    99 	
       
   100 void CPbapLogWrapper::RemovePbapObserver(MPbapLogEngViewObserver& aObserver)
       
   101 	{
       
   102 	LOG_FUNC
       
   103 	
       
   104 	for (TInt i = iPbapObservers.Count() - 1; i >= 0; i--)
       
   105 		{
       
   106 		if (iPbapObservers[i] == &aObserver)
       
   107 			{
       
   108 			iPbapObservers.Remove(i); // don't delete - it's not ours!
       
   109 			}
       
   110 		}
       
   111 
       
   112 	if (iPbapObservers.Count() == 0)
       
   113 		{
       
   114 		// no more observers, deregister for global events
       
   115 		TRAP_IGNORE(iLogClient->SetGlobalChangeObserverL(NULL));
       
   116 		}
       
   117 	}
       
   118 
       
   119 // from MLogClientChangeObserver
       
   120 void CPbapLogWrapper::HandleLogClientChangeEventL(TUid aChangeType, TInt aParam1, TInt aParam2, TInt aParam3)
       
   121 	{
       
   122 	LOG_FUNC
       
   123 	
       
   124 	// Notify all of the PBAP Observers and turn the LogEng Global events into PBAP view events
       
   125 	for (TInt i = iPbapObservers.Count() - 1; i >= 0; i--)
       
   126 		{
       
   127 		iPbapObservers[i]->PbapLogEngViewChangeEventL(aChangeType, aParam1, aParam2, aParam3);
       
   128 		}
       
   129 	}
       
   130 
       
   131 //
       
   132 // CPbapLogViewEvent
       
   133 //
       
   134 
       
   135 /*static*/ EXPORT_C CPbapLogViewEvent* CPbapLogViewEvent::NewL(CPbapLogWrapper& aLogWrap)
       
   136 	{
       
   137 	LOG_STATIC_FUNC
       
   138 	CPbapLogViewEvent* self = new(ELeave) CPbapLogViewEvent(aLogWrap);
       
   139 	CleanupStack::PushL(self);
       
   140 	self->ConstructL();
       
   141 	CleanupStack::Pop(self);
       
   142 	return self;
       
   143 	}
       
   144 
       
   145 /*static*/ EXPORT_C CPbapLogViewEvent* CPbapLogViewEvent::NewL(CPbapLogWrapper& aLogWrap, MPbapLogEngViewObserver& aObserver)
       
   146 	{
       
   147 	LOG_STATIC_FUNC
       
   148 	CPbapLogViewEvent* self = new(ELeave) CPbapLogViewEvent(aLogWrap);
       
   149 	CleanupStack::PushL(self);
       
   150 	self->ConstructL(&aObserver);
       
   151 	CleanupStack::Pop(self);
       
   152 	return self;
       
   153 	}
       
   154 
       
   155 CPbapLogViewEvent::CPbapLogViewEvent(CPbapLogWrapper& aLogWrap) : iWrapper(aLogWrap)
       
   156 	{
       
   157 	LOG_FUNC
       
   158 	}
       
   159 		
       
   160 void CPbapLogViewEvent::ConstructL(MPbapLogEngViewObserver* aObserver)
       
   161 	{
       
   162 	LOG_FUNC
       
   163 
       
   164 	// create the CLogViewEvent to forward requests to.
       
   165 	if (aObserver != NULL)
       
   166 		{
       
   167 		// store the observer and add it receive global logeng events
       
   168 		User::LeaveIfError(iWrapper.AddPbapObserver(*aObserver));
       
   169 		iPbapObserver = aObserver;
       
   170 
       
   171 		iViewEvent = CLogViewEvent::NewL(iWrapper.LogClient(), *this);
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		iViewEvent = CLogViewEvent::NewL(iWrapper.LogClient());
       
   176 		}
       
   177 	}
       
   178 
       
   179 EXPORT_C  CPbapLogViewEvent::~CPbapLogViewEvent()
       
   180 	{
       
   181 	LOG_FUNC
       
   182 	
       
   183 	if (iPbapObserver)
       
   184 		{
       
   185 		// remove observer from receiving global events
       
   186 		iWrapper.RemovePbapObserver(*iPbapObserver);
       
   187 		}
       
   188 
       
   189 	delete iViewEvent;
       
   190 	}
       
   191 
       
   192 EXPORT_C TBool CPbapLogViewEvent::SetFilterL(const CLogFilterList& aFilterList, TRequestStatus& aStatus)
       
   193 	{
       
   194 	LOG_FUNC
       
   195 	return iViewEvent->SetFilterL(aFilterList, aStatus);
       
   196 	}
       
   197 	
       
   198 EXPORT_C TBool CPbapLogViewEvent::SetFilterL(const CLogFilter& aFilter, TRequestStatus& aStatus)
       
   199 	{
       
   200 	LOG_FUNC
       
   201 	return iViewEvent->SetFilterL(aFilter, aStatus);
       
   202 	}
       
   203 	
       
   204 EXPORT_C const CLogEvent& CPbapLogViewEvent::Event() const
       
   205 	{
       
   206 	LOG_FUNC
       
   207 	return iViewEvent->Event();
       
   208 	}
       
   209 	
       
   210 EXPORT_C TBool CPbapLogViewEvent::FirstL(TRequestStatus& aStatus)
       
   211 	{
       
   212 	LOG_FUNC
       
   213 	return iViewEvent->FirstL(aStatus);	
       
   214 	}
       
   215 	
       
   216 EXPORT_C TBool CPbapLogViewEvent::NextL(TRequestStatus& aStatus)
       
   217 	{
       
   218 	LOG_FUNC
       
   219 	return iViewEvent->NextL(aStatus);	
       
   220 	}
       
   221 
       
   222 EXPORT_C TInt CPbapLogViewEvent::CountL()
       
   223 	{
       
   224 	LOG_FUNC
       
   225 	return iViewEvent->CountL();	
       
   226 	}
       
   227 
       
   228 EXPORT_C void CPbapLogViewEvent::Cancel()
       
   229 	{
       
   230 	LOG_FUNC
       
   231 	iViewEvent->Cancel();
       
   232 	}
       
   233 
       
   234 // from MLogViewChangeObserver, pass all events to the PBAP view event observer
       
   235 void CPbapLogViewEvent::HandleLogViewChangeEventAddedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount)
       
   236 	{
       
   237 	LOG_FUNC
       
   238 
       
   239 	iPbapObserver->PbapLogEngViewChangeEventAddedL(aId, aViewIndex, aChangeIndex, aTotalChangeCount);
       
   240 	}
       
   241 	
       
   242 void CPbapLogViewEvent::HandleLogViewChangeEventChangedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount)
       
   243 	{
       
   244 	LOG_FUNC
       
   245 
       
   246 	iPbapObserver->PbapLogEngViewChangeEventChangedL(aId, aViewIndex, aChangeIndex, aTotalChangeCount);
       
   247 	}
       
   248 	
       
   249 void CPbapLogViewEvent::HandleLogViewChangeEventDeletedL(TLogId aId, TInt aViewIndex, TInt aChangeIndex, TInt aTotalChangeCount)
       
   250 	{
       
   251 	LOG_FUNC
       
   252 
       
   253 	iPbapObserver->PbapLogEngViewChangeEventDeletedL(aId, aViewIndex, aChangeIndex, aTotalChangeCount);
       
   254 	}