idlefw/tsrc/framework/mt_aifw/AiFwTestContentPlugin.cpp
branchRCL_3
changeset 27 2c7f27287390
equal deleted inserted replaced
25:9e077f9a342c 27:2c7f27287390
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // ========== INCLUDE FILES ===================================================
       
    20 
       
    21 #include "AiFwTestContentPlugin.h"
       
    22 #include "AiFwTestDefines.h"
       
    23 #include "AiFwTestContentModel.h"
       
    24 
       
    25 #include <aicontentobserver.h>
       
    26 #include <aipluginsettings.h>
       
    27 #include <aiutility.h>
       
    28 
       
    29 // ========== EXTERNAL DATA STRUCTURES ========================================
       
    30 
       
    31 // ========== EXTERNAL FUNCTION PROTOTYPES ====================================
       
    32 
       
    33 // ========== CONSTANTS =======================================================
       
    34 
       
    35 // ========== MACROS ==========================================================
       
    36 
       
    37 // ========== LOCAL CONSTANTS AND MACROS ======================================
       
    38 
       
    39 // ========== MODULE DATA STRUCTURES ==========================================
       
    40 
       
    41 // ========== LOCAL FUNCTION PROTOTYPES =======================================
       
    42 
       
    43 // ========== FORWARD DECLARATIONS ============================================
       
    44 
       
    45 // ========== LOCAL FUNCTIONS =================================================
       
    46 
       
    47 // ========== MEMBER FUNCTIONS ================================================
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 //
       
    52 //
       
    53 // ----------------------------------------------------------------------------
       
    54 //
       
    55 CAiFwTestContentPlugin::CAiFwTestContentPlugin()
       
    56 {}
       
    57 
       
    58 EXPORT_C CAiFwTestContentPlugin* CAiFwTestContentPlugin::Instance()
       
    59     {
       
    60     TAny* ptr = Dll::Tls();
       
    61 	
       
    62     if ( ptr )
       
    63 		{
       
    64     	TAiTestTLSStorage* tlsSet = static_cast<TAiTestTLSStorage*>( ptr );
       
    65     	return tlsSet->iContentPlugin;
       
    66 		}
       
    67 	return NULL;
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 //
       
    73 //
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 void CAiFwTestContentPlugin::ConstructL()
       
    77 {
       
    78     iText = HBufC8::NewL(128);
       
    79 
       
    80     iInfo = new (ELeave) TAiPublisherInfo;
       
    81 
       
    82     iContent   = AiUtility::CreateContentItemArrayIteratorL(KTestPluginContent);
       
    83     iResources = AiUtility::CreateContentItemArrayIteratorL(KTestPluginResources);
       
    84     iEvents    = AiUtility::CreateContentItemArrayIteratorL(KTestPluginEvents);
       
    85 
       
    86    	TAiTestTLSStorage* tlsSet = TAiTestTLSStorage::CreateInstanceL();
       
    87 	tlsSet->iContentPlugin = this;
       
    88 }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 //
       
    93 //
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 CAiFwTestContentPlugin* CAiFwTestContentPlugin::NewL()
       
    97 {
       
    98     CAiFwTestContentPlugin* self = new (ELeave) CAiFwTestContentPlugin;
       
    99 
       
   100     CleanupStack::PushL(self);
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop();
       
   103 
       
   104     return self;
       
   105 }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 //
       
   110 //
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 CAiFwTestContentPlugin::~CAiFwTestContentPlugin()
       
   114 {
       
   115    	TAiTestTLSStorage::DestroyInstance();
       
   116 	    
       
   117     delete iText;
       
   118     iObservers.Close();
       
   119 
       
   120     delete iInfo;
       
   121     Release( iContent );
       
   122     Release( iResources );
       
   123     Release( iEvents );
       
   124 
       
   125     if( iTicker )
       
   126         iTicker->Cancel();
       
   127     delete iTicker;
       
   128     
       
   129 }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 //
       
   134 //
       
   135 // ----------------------------------------------------------------------------
       
   136 //
       
   137 TInt CAiFwTestContentPlugin::Callback(TAny* aPtr)
       
   138 {
       
   139     CAiFwTestContentPlugin* plugin = reinterpret_cast<CAiFwTestContentPlugin*> (aPtr);
       
   140     plugin->iCounter++;
       
   141     plugin->iText->Des().Copy(_L8("Count:"));
       
   142     plugin->iText->Des().AppendNum(plugin->iCounter);
       
   143 
       
   144     // Notify
       
   145     for (TInt i = 0; i < plugin->iObservers.Count(); i++)
       
   146     {
       
   147         MAiContentObserver* observer = plugin->iObservers[i];
       
   148         observer->StartTransaction(0);
       
   149 
       
   150         HBufC* value = HBufC::NewLC(plugin->iText->Length());
       
   151         value->Des().Copy(*plugin->iText);
       
   152 
       
   153         observer->Publish((MAiPropertyExtension&) *plugin, KTestPluginContent[0].id, *value, 0);
       
   154 
       
   155         if (plugin->iCounter % 2 == 0)
       
   156         {
       
   157             observer->Publish((MAiPropertyExtension&) *plugin, KTestPluginContent[1].id, KTestPluginResources[0].id, 0);
       
   158         }
       
   159         else
       
   160         {
       
   161             observer->Publish((MAiPropertyExtension&) *plugin, KTestPluginContent[1].id, KTestPluginResources[1].id, 0);
       
   162         }
       
   163 
       
   164         observer->Commit(0);
       
   165 
       
   166         CleanupStack::PopAndDestroy(); // value
       
   167     }
       
   168 
       
   169     return KErrNone;
       
   170 }
       
   171 
       
   172 // ----------------------------------------------------------------------------
       
   173 //
       
   174 //
       
   175 //
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 void CAiFwTestContentPlugin::LoadEngineL(TAiTransitionReason /*aReason*/)
       
   179 {
       
   180     iPluginLoaded = ETrue;
       
   181     if( !iTicker )
       
   182         {
       
   183         iTicker = CPeriodic::NewL(CActive::EPriorityStandard);
       
   184         }
       
   185 }
       
   186 
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 //
       
   190 //
       
   191 // ----------------------------------------------------------------------------
       
   192 //
       
   193 void CAiFwTestContentPlugin::Resume(TAiTransitionReason aReason)
       
   194 {
       
   195     TRAP_IGNORE( LoadEngineL( aReason ) );
       
   196     iPluginResumed = ETrue;
       
   197     if( iTicker && !iTicker->IsActive() )
       
   198         {
       
   199         TCallBack cb(Callback, this);
       
   200         iTicker->Start(1000000, 1000000, cb);
       
   201         }
       
   202 }
       
   203 
       
   204 // ----------------------------------------------------------------------------
       
   205 //
       
   206 //
       
   207 //
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CAiFwTestContentPlugin::Suspend(TAiTransitionReason /*aReason*/)
       
   211 {
       
   212     if( iTicker && iTicker->IsActive() )
       
   213     {
       
   214         iTicker->Cancel();
       
   215     }
       
   216 }
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 //
       
   220 //
       
   221 //
       
   222 // ----------------------------------------------------------------------------
       
   223 //
       
   224 void CAiFwTestContentPlugin::Stop(TAiTransitionReason /*aReason*/)
       
   225 {
       
   226     if( iTicker )
       
   227         {
       
   228         iTicker->Cancel();
       
   229         delete iTicker;
       
   230         iTicker = NULL;
       
   231         }
       
   232 }
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 //
       
   236 //
       
   237 //
       
   238 // ----------------------------------------------------------------------------
       
   239 //
       
   240 void CAiFwTestContentPlugin::SubscribeL(MAiContentObserver& aObserver)
       
   241 {
       
   242     return iObservers.AppendL(&aObserver);
       
   243 }
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 //
       
   247 //
       
   248 //
       
   249 // ----------------------------------------------------------------------------
       
   250 //
       
   251 void CAiFwTestContentPlugin::ConfigureL(RAiSettingsItemArray& aSettings)
       
   252     {
       
   253     iSettingFound = ETrue;
       
   254     for( TInt i = 0; i < aSettings.Count(); ++i )
       
   255         {
       
   256         MAiPluginSettingsItem& item = aSettings[i]->AiPluginSettingsItem();
       
   257         if( item.Value().Compare( _L("DesValue") ) == 0 )
       
   258             {
       
   259             // pass
       
   260             if( item.Key() == 1 )
       
   261                 {
       
   262                 }
       
   263             item.PublisherId();
       
   264             }
       
   265         /*TRAP_IGNORE(
       
   266         item.UpdateFromCenRepL();
       
   267         item.SetKey( -1 );
       
   268         item.UpdateFromCenRepL();
       
   269         item.SetKey( 0 );
       
   270         item.SetPublisherId( TUid::Uid( 0 ) );
       
   271         item.UpdateFromCenRepL();
       
   272         );*/
       
   273         }
       
   274     aSettings.ResetAndDestroy();
       
   275     }
       
   276 
       
   277 // ----------------------------------------------------------------------------
       
   278 //
       
   279 //
       
   280 //
       
   281 // ----------------------------------------------------------------------------
       
   282 //
       
   283 TAny* CAiFwTestContentPlugin::Extension(TUid aUid)
       
   284 {
       
   285     if (aUid == KExtensionUidProperty)
       
   286     {
       
   287         return static_cast<MAiPropertyExtension*>(this);
       
   288     }
       
   289     else if (aUid == KExtensionUidEventHandler)
       
   290         {
       
   291         return static_cast<MAiEventHandlerExtension*>(this);
       
   292         }
       
   293 
       
   294     return NULL;
       
   295 }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 //
       
   300 //
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 TAny* CAiFwTestContentPlugin::GetPropertyL(TInt aProperty)
       
   304 {
       
   305     switch (aProperty)
       
   306     {
       
   307     case EAiPublisherInfo:
       
   308         return iInfo;
       
   309 
       
   310     case EAiPublisherContent:
       
   311         return static_cast<MAiContentItemIterator*>( iContent );
       
   312 
       
   313     case EAiPublisherResources:
       
   314         return static_cast<MAiContentItemIterator*>( iResources );
       
   315 
       
   316     case EAiPublisherEvents:
       
   317         return static_cast<MAiContentItemIterator*>( iEvents );
       
   318 
       
   319     case EAiContentRequest:
       
   320         return static_cast<MAiContentRequest*>(this);
       
   321 
       
   322     case EAiResourceRequest:
       
   323         return static_cast<MAiContentRequest*>(this);
       
   324     }
       
   325 
       
   326     User::Leave(KErrNotSupported);
       
   327     return NULL;
       
   328 }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 //
       
   333 //
       
   334 // ----------------------------------------------------------------------------
       
   335 //
       
   336 void CAiFwTestContentPlugin::SetPropertyL(TInt aProperty, TAny* aValue)
       
   337     {
       
   338     if( aValue )
       
   339         {
       
   340         switch( aProperty )
       
   341             {
       
   342             case EAiPublisherInfo:
       
   343                 {
       
   344                 const TAiPublisherInfo* info =
       
   345                     static_cast<const TAiPublisherInfo*>(aValue);
       
   346                 iInfo->iUid.iUid = info->iUid.iUid;
       
   347                 iInfo->iName.Copy( info->iName );
       
   348                 iInfo->iNamespace.Copy( info->iNamespace );
       
   349                 break;
       
   350                 }
       
   351             }
       
   352         }
       
   353     }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 //
       
   357 //
       
   358 //
       
   359 // ----------------------------------------------------------------------------
       
   360 //
       
   361 void CAiFwTestContentPlugin::HandleEvent(TInt aEvent, const TDesC& aParam)
       
   362     {
       
   363     if( i2ndEvent )
       
   364         {
       
   365         return;
       
   366         }
       
   367     if( aEvent == 3 && aParam.Length() == 0 )
       
   368         {
       
   369         iEventReceived = ETrue;
       
   370         }
       
   371     i2ndEvent = ETrue;
       
   372     }
       
   373 
       
   374 TBool CAiFwTestContentPlugin::RefreshContent( TInt aContentId )
       
   375     {
       
   376     iContentRefreshed = ETrue;
       
   377     return ETrue;
       
   378     }
       
   379 
       
   380 // ----------------------------------------------------------------------------
       
   381 //
       
   382 //
       
   383 //
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 
       
   387 EXPORT_C TBool CAiFwTestContentPlugin::ContentRefreshed()
       
   388     {
       
   389     return iContentRefreshed;
       
   390     }
       
   391 
       
   392 EXPORT_C RPointerArray<MAiContentObserver>& CAiFwTestContentPlugin::Observers()
       
   393     {
       
   394     return iObservers;
       
   395     }
       
   396     
       
   397 EXPORT_C TBool CAiFwTestContentPlugin::WasLoaded()
       
   398     {
       
   399     return iPluginLoaded;
       
   400     }
       
   401 
       
   402 EXPORT_C TBool CAiFwTestContentPlugin::WasResumed()
       
   403     {
       
   404     return iPluginResumed;
       
   405     }
       
   406     
       
   407 EXPORT_C TBool CAiFwTestContentPlugin::WasConfigured()
       
   408     {
       
   409     return iSettingFound;
       
   410     }
       
   411 
       
   412 EXPORT_C TBool CAiFwTestContentPlugin::EventReceived()
       
   413     {
       
   414     return iEventReceived;
       
   415     }
       
   416 
       
   417 // ========== OTHER EXPORTED FUNCTIONS ========================================
       
   418 
       
   419 // End of File.