idlefw/tsrc/devicestatusplugin/mt_devstaplg/contentobserver.cpp
branchRCL_3
changeset 28 053c6c7c14f3
child 31 8baec10861af
equal deleted inserted replaced
27:2c7f27287390 28:053c6c7c14f3
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <e32svr.h>
       
    18 #include "contentobserver.h"
       
    19 
       
    20 
       
    21 CContentObserver& CContentObserver::InstanceL()
       
    22 	{
       
    23 	CContentObserver* self = static_cast<CContentObserver*>( Dll::Tls() );
       
    24 	if( self )
       
    25 		{
       
    26 		return *self;
       
    27 		}
       
    28 
       
    29 	self = new( ELeave )CContentObserver;
       
    30 	CleanupStack::PushL( self );
       
    31 	User::LeaveIfError( Dll::SetTls( self ) );
       
    32 	CleanupStack::Pop( self );
       
    33 	return *self;
       
    34 	}
       
    35 
       
    36 
       
    37 void CContentObserver::Release()
       
    38 	{
       
    39 	CContentObserver* self = static_cast<CContentObserver*>( Dll::Tls() );
       
    40 	delete self;
       
    41 	Dll::SetTls( NULL );
       
    42 	}
       
    43 
       
    44 
       
    45 void CContentObserver::Reset()
       
    46 	{
       
    47 	CContentObserver* self = static_cast<CContentObserver*>( Dll::Tls() );
       
    48 	if( self )
       
    49 		{
       
    50 		self->iCache.ResetAndDestroy();
       
    51 		}
       
    52 	}
       
    53 
       
    54 
       
    55 CContentCache* CContentObserver::GetContent( TInt aContentId, TBool aClean )
       
    56 	{
       
    57 	const TInt count( iCache.Count() );
       
    58 	for( TInt i( 0 ); i < count; i++ )
       
    59 		{
       
    60 		if( iCache[i]->iId == aContentId )
       
    61 			{
       
    62 			if( !aClean && iCache[i]->iClean)
       
    63 				{
       
    64 				continue;
       
    65 				}
       
    66 			return iCache[i];
       
    67 			}
       
    68 		}
       
    69 
       
    70 	return NULL;
       
    71 	}
       
    72 
       
    73 
       
    74 CContentCache* CContentObserver::GetLastContent( TInt aContentId, TBool aClean )
       
    75 	{
       
    76 	const TInt count( iCache.Count() );
       
    77 	for( TInt i( count - 1 ); i >= 0; i-- )
       
    78 		{
       
    79 		if( iCache[i]->iId != aContentId )
       
    80 			{
       
    81 			return NULL;
       
    82 			}
       
    83 		if( !aClean && iCache[i]->iClean)
       
    84 			{
       
    85 			continue;
       
    86 			}
       
    87 		return iCache[i];
       
    88 		}
       
    89 	return NULL;
       
    90 	}
       
    91 
       
    92 
       
    93 CContentObserver::~CContentObserver()
       
    94 	{
       
    95 	iCache.ResetAndDestroy();
       
    96 	}
       
    97 
       
    98 
       
    99 TInt CContentObserver::StartTransaction(TInt aTxId)
       
   100 	{
       
   101 	return 0;
       
   102 	}
       
   103 
       
   104 
       
   105 TInt CContentObserver::Commit(TInt aTxId)
       
   106 	{
       
   107 	return 0;
       
   108 	}
       
   109 
       
   110 
       
   111 TInt CContentObserver::CancelTransaction(TInt aTxId)
       
   112 	{
       
   113 	return 0;
       
   114 	}
       
   115 	
       
   116 
       
   117 TBool CContentObserver::CanPublish(CHsContentPublisher& /*aPlugin*/, TInt /*aContent*/, TInt /*aIndex*/ )
       
   118     {
       
   119     return EFalse;
       
   120     }
       
   121 
       
   122 
       
   123 TInt CContentObserver::Publish(CHsContentPublisher& aPlugin, TInt aContent, TInt aResource, TInt aIndex )
       
   124 	{
       
   125 	RDebug::Print( _L("Publish(%d, %d, %d)"), aContent, aResource, aIndex );
       
   126 	CContentCache* cache = new( ELeave )CContentCache;
       
   127 	CleanupStack::PushL( cache );
       
   128 	cache->iId = aContent;
       
   129 	cache->iResource = aResource;
       
   130 	cache->iIndex = aIndex;
       
   131 	User::LeaveIfError( iCache.Append( cache ) );
       
   132 	CleanupStack::Pop( cache );
       
   133 	return 0;
       
   134 	}
       
   135 
       
   136 TInt CContentObserver::Publish(CHsContentPublisher& aPlugin, TInt aContent, const TDesC16& aText, TInt aIndex )
       
   137 	{
       
   138 	RDebug::Print( _L("Publish(%d, \"%S\", %d)"), aContent, &aText, aIndex );
       
   139 	CContentCache* cache = new( ELeave )CContentCache;
       
   140 	CleanupStack::PushL( cache );
       
   141 	cache->iId = aContent;
       
   142 	cache->iText = aText.AllocL();
       
   143 	cache->iIndex = aIndex;
       
   144 	User::LeaveIfError( iCache.Append( cache ) );
       
   145 	CleanupStack::Pop( cache );
       
   146 	return 0;
       
   147 	}
       
   148 
       
   149 
       
   150 TInt CContentObserver::Publish(CHsContentPublisher& aPlugin, TInt aContent, const TDesC8& aBuf, TInt aIndex )
       
   151 	{
       
   152 	RDebug::Print( _L("Publish(%d, Buf.Len=%d, %d)"), aContent, aBuf.Length(), aIndex );
       
   153 	CContentCache* cache = new( ELeave )CContentCache;
       
   154 	CleanupStack::PushL( cache );
       
   155 	cache->iId = aContent;
       
   156 	cache->iData = aBuf.AllocL();
       
   157 	cache->iIndex = aIndex;
       
   158 	User::LeaveIfError( iCache.Append( cache ) );
       
   159 	CleanupStack::Pop( cache );
       
   160 	return 0;
       
   161 	}
       
   162 
       
   163 
       
   164 TInt CContentObserver::Publish(CHsContentPublisher& aPlugin, TInt aContent, RFile& aFile, TInt aIndex )
       
   165 	{
       
   166 	CContentCache* cache = new( ELeave )CContentCache;
       
   167 	CleanupStack::PushL( cache );
       
   168 	cache->iId = aContent;
       
   169 	cache->iIndex = aIndex;
       
   170 	User::LeaveIfError( iCache.Append( cache ) );
       
   171 	CleanupStack::Pop( cache );
       
   172 	return 0;
       
   173 	}
       
   174 
       
   175 
       
   176 TInt CContentObserver::Clean(CHsContentPublisher& aPlugin, TInt aContent, TInt aIndex)
       
   177 	{
       
   178 	RDebug::Print( _L("Clean(%d, %d)"), aContent, aIndex );
       
   179 	CContentCache* cache = new( ELeave )CContentCache;
       
   180 	CleanupStack::PushL( cache );
       
   181 	cache->iId = aContent;
       
   182 	cache->iIndex = aIndex;
       
   183 	cache->iClean = ETrue;
       
   184 	User::LeaveIfError( iCache.Append( cache ) );
       
   185 	CleanupStack::Pop( cache );
       
   186 	return 0;
       
   187 	}
       
   188 
       
   189 
       
   190 TAny* CContentObserver::Extension(TUid aUid)
       
   191 	{
       
   192 	return NULL;
       
   193 	}
       
   194 
       
   195 TBool CContentObserver::RequiresSubscription( const THsPublisherInfo& aPublisherInfo ) const
       
   196     {
       
   197     return EFalse;
       
   198     }
       
   199     
       
   200 // ---------------------------------------------------------------------------
       
   201 // SetProperty
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 TInt CContentObserver::SetProperty( CHsContentPublisher& /*aPlugin*/,
       
   205 									          const TDesC8& /*aElementId*/,
       
   206 									          const TDesC8& /*aPropertyName*/,
       
   207 									          const TDesC8& /*aPropertyValue*/ )
       
   208 {
       
   209 	return KErrNone;
       
   210 }				
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // SetProperty
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TInt CContentObserver::SetProperty( CHsContentPublisher& /*aPlugin*/,
       
   217 									          const TDesC8& /*aElementId*/,
       
   218 									          const TDesC8& /*aPropertyName*/,
       
   219 									          const TDesC8& /*aPropertyValue*/,
       
   220 									          MAiContentObserver::TValueType /*aValueType*/ )
       
   221 {
       
   222 	return KErrNone;
       
   223 }				    
       
   224 
       
   225 //  END OF FILE