mediator/src/Server/MediatorServerObjects.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Domain, category, event & command object implementations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <e32base.h>
       
    21 
       
    22 #include    "MediatorServerObjects.h"
       
    23 #include    "MediatorCommon.h"
       
    24 #include    "MediatorServer.h"
       
    25 #include    "MediatorServiceDefs.h"
       
    26 #include    "Debug.h"
       
    27 
       
    28 // =============================================================================
       
    29 // ============================ DOMAIN FUNCTIONS ===============================
       
    30 // =============================================================================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CDomain::CDomain
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CDomain::CDomain()
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CDomain::ConstructL
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CDomain::ConstructL( TUid aDomain )
       
    45     {
       
    46     iDomain = aDomain;
       
    47     iSearchCategory = CCategory::NewL( TUid() ); // just assign some arbitrary domain, updated in search
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CDomain::NewL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CDomain* CDomain::NewL( TUid aDomain )
       
    55     {
       
    56     CDomain* self = new( ELeave ) CDomain;
       
    57     
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aDomain );
       
    60     CleanupStack::Pop( self );
       
    61 
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CDomain::~CDomain
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CDomain::~CDomain()
       
    70     {
       
    71     iCategoryList.ResetAndDestroy();
       
    72     delete iSearchCategory;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CDomain::DomainUid
       
    77 // (other items were commented in a header).
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 TUid CDomain::DomainUid() const
       
    81     {
       
    82     return iDomain;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CDomain::SetDomainUid
       
    87 // (other items were commented in a header).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CDomain::SetDomainUid( TUid aDomain )
       
    91     {
       
    92     iDomain = aDomain;
       
    93     }
       
    94     
       
    95 // -----------------------------------------------------------------------------
       
    96 // CDomain::AddCategoryL
       
    97 // (other items were commented in a header).
       
    98 // -----------------------------------------------------------------------------
       
    99 //     
       
   100 void CDomain::AddCategoryL( const CCategory* aNewCategory )
       
   101     {
       
   102     __ASSERT_DEBUG( aNewCategory, CMediatorServer::PanicServer( EMediatorServerIllegalParameter ) );
       
   103     TInt index = 0;     // not used here
       
   104     if ( FindCategory( aNewCategory->CategoryUid(), index ) )
       
   105         {
       
   106         ERROR_TRACE(Print(_L("CDomain::AddCategoryL: category %d already exists in domain %d\n"), aNewCategory->CategoryUid().iUid,
       
   107                                                                                                   iDomain.iUid ) );    
       
   108         User::Leave( KErrAlreadyExists );
       
   109         }
       
   110     iCategoryList.AppendL( aNewCategory );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CDomain::AddCategoryL
       
   115 // (other items were commented in a header).
       
   116 // -----------------------------------------------------------------------------
       
   117 //     
       
   118 CCategory* CDomain::AddCategoryL( const TUid aCategory )
       
   119     {
       
   120     CCategory* newCategory = CCategory::NewL( aCategory );
       
   121     CleanupStack::PushL( newCategory );
       
   122     
       
   123     TInt index = 0;
       
   124     if ( FindCategory( newCategory, index ) )
       
   125         {
       
   126         ERROR_TRACE(Print(_L("CDomain::AddCategoryL: category %d already exists in domain %d\n"), aCategory.iUid,
       
   127                                                                                                   iDomain.iUid ) );    
       
   128         User::Leave( KErrAlreadyExists );
       
   129         }
       
   130     iCategoryList.AppendL( newCategory );
       
   131     CleanupStack::Pop( newCategory );   // ownership is changed
       
   132     return newCategory;
       
   133     }
       
   134         
       
   135 // -----------------------------------------------------------------------------
       
   136 // CDomain::RemoveCategory
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 //       
       
   140 TInt CDomain::RemoveCategory( const TUid aCategory )
       
   141     {
       
   142     TInt error = KErrMediatorCategoryNotFound;
       
   143     // Find the category
       
   144     TInt index = 0;
       
   145     CCategory* category = FindCategory( aCategory, index );
       
   146     
       
   147     if ( category )
       
   148         {
       
   149         // Make temporary pointer to it, remove it from list and delete.
       
   150         CCategory* category = iCategoryList[ index ];
       
   151         iCategoryList.Remove( index );
       
   152         delete category;
       
   153         error = KErrNone;
       
   154         }
       
   155     return error;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CDomain::GetCategory
       
   160 // 
       
   161 // (other items were commented in a header).
       
   162 // -----------------------------------------------------------------------------
       
   163 //  
       
   164 const CCategory* CDomain::GetCategory( const TUid aCategory )
       
   165     {
       
   166     TInt index = 0;
       
   167     return FindCategory( aCategory, index );
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CDomain::GetCategory
       
   172 // 
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //      
       
   176 CCategory* CDomain::GetCategory( TInt aIndex )
       
   177     {
       
   178     CCategory* categoryPtr = NULL;
       
   179     if ( aIndex >= 0 && aIndex < CategoryCount() )
       
   180         {
       
   181         categoryPtr = iCategoryList[aIndex];
       
   182         }
       
   183     return categoryPtr;
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CDomain::CategoryCount
       
   188 // 
       
   189 // (other items were commented in a header).
       
   190 // -----------------------------------------------------------------------------
       
   191 //     
       
   192 TInt CDomain::CategoryCount()
       
   193     {
       
   194     return iCategoryList.Count();
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CDomain::FindCategory
       
   199 // 
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 //     
       
   203 CCategory* CDomain::FindCategory( const TUid aCategory, TInt& aIndex )
       
   204     {
       
   205     iSearchCategory->SetCategoryUid( aCategory );
       
   206     
       
   207     return FindCategory( iSearchCategory, aIndex );
       
   208     }    
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CDomain::FindCategory
       
   212 // 
       
   213 // (other items were commented in a header).
       
   214 // -----------------------------------------------------------------------------
       
   215 //     
       
   216 CCategory* CDomain::FindCategory( const CCategory* aCategory, TInt& aIndex )
       
   217     {
       
   218     // Create utilities to be used in find
       
   219     TIdentityRelation<CCategory> relation( CompareCategories );
       
   220 	
       
   221 	// Find the item from array
       
   222     aIndex = iCategoryList.Find( aCategory, relation );	
       
   223     // Then return it, if found. 
       
   224     CCategory* category = NULL;
       
   225     if ( aIndex != KErrNotFound )
       
   226         {
       
   227         category = iCategoryList[aIndex];
       
   228         }
       
   229 	return category;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CDomain::GetCategoriesL
       
   234 // 
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 //      
       
   238 void CDomain::GetCategoriesL( RCategoryList& aCategories )
       
   239     {
       
   240     // Loop through category list and append to return list.
       
   241     for ( TInt index = 0; index < iCategoryList.Count(); index++ )
       
   242         {
       
   243         aCategories.AppendL( iCategoryList[index]->CategoryUid() );
       
   244         }
       
   245     }
       
   246           
       
   247 // -----------------------------------------------------------------------------
       
   248 // CDomain::CompareCategories
       
   249 // Compares categories and returns boolean according to comparison
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //    
       
   253 TBool CDomain::CompareCategories( const CCategory& aLeftCategory, 
       
   254                                   const CCategory& aRightCategory )
       
   255     {
       
   256     return aLeftCategory.CategoryUid() == aRightCategory.CategoryUid();
       
   257     }
       
   258 
       
   259 // =============================================================================
       
   260 // ============================ CATEGORY FUNCTIONS =============================
       
   261 // =============================================================================
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CCategory::CCategory()
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 CCategory::CCategory()
       
   268     {
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCategory::ConstructL
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CCategory::ConstructL( TUid aCategory )
       
   276     {
       
   277     iCategory = aCategory;
       
   278     iSearchCommand = CCommand::NewL(0); // arbitrary id, updated in search
       
   279     iSearchEvent = CEvent::NewL(0); // arbitrary id, updated in search
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CCategory::NewL
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 CCategory* CCategory::NewL( TUid aCategory )
       
   287     {
       
   288     CCategory* self = new( ELeave ) CCategory;
       
   289     
       
   290     CleanupStack::PushL( self );
       
   291     self->ConstructL( aCategory );
       
   292     CleanupStack::Pop( self );
       
   293 
       
   294     return self;
       
   295     }
       
   296     
       
   297 // -----------------------------------------------------------------------------
       
   298 // CCategory::~CCategory
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 CCategory::~CCategory()
       
   302     {
       
   303     iEventList.ResetAndDestroy();
       
   304     iCommandList.ResetAndDestroy();
       
   305     delete iSearchCommand;
       
   306     delete iSearchEvent;
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CCategory::CategoryUid
       
   311 // 
       
   312 // (other items were commented in a header).
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 TUid CCategory::CategoryUid() const
       
   316     {
       
   317     return iCategory;
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CCategory::SetCategoryUid
       
   322 // 
       
   323 // (other items were commented in a header).
       
   324 // -----------------------------------------------------------------------------
       
   325 //    
       
   326 void CCategory::SetCategoryUid( TUid aCategory )
       
   327     {
       
   328     iCategory = aCategory;
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CCategory::AddEventL
       
   333 // Adds new event to eventlist
       
   334 // (other items were commented in a header).
       
   335 // -----------------------------------------------------------------------------
       
   336 //     
       
   337 TInt CCategory::AddEvent( const CEvent* aNewEvent )
       
   338     {
       
   339     __ASSERT_DEBUG( aNewEvent, CMediatorServer::PanicServer( EMediatorServerIllegalParameter ) );
       
   340     
       
   341     TInt error = FindEvent( *aNewEvent );
       
   342     if ( error == KErrNotFound )
       
   343         {
       
   344 #ifdef _DEBUG
       
   345         TRACE(Print(_L("[Mediator Server]\t CCategory::AddEvent id %d\n"), aNewEvent->Id() ));
       
   346         for ( TInt index = 0; index < ECapability_Limit; index ++ )
       
   347             {
       
   348             TCapabilitySet caps = aNewEvent->Policy();
       
   349             TBool required = caps.HasCapability( (TCapability) index );
       
   350             if ( required )
       
   351                 {
       
   352                 TRACE(Print(_L("[Mediator] CCategory::AddEvent: Capability %d required\n"), index ));
       
   353                 }
       
   354             }
       
   355 #endif // _DEBUG
       
   356         error = iEventList.Append( aNewEvent );
       
   357         }
       
   358     else
       
   359         {
       
   360         error = KErrMediatorEventAlreadyExists;
       
   361         }
       
   362     return error;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CCategory::AddCommandL
       
   367 // Adds new command to commandList
       
   368 // (other items were commented in a header).
       
   369 // -----------------------------------------------------------------------------
       
   370 //     
       
   371 TInt CCategory::AddCommand( const CCommand* aNewCommand )
       
   372     {
       
   373     __ASSERT_DEBUG( aNewCommand, CMediatorServer::PanicServer( EMediatorServerIllegalParameter ) );
       
   374     
       
   375     TInt error = FindCommand( *aNewCommand );
       
   376     if ( error == KErrNotFound )
       
   377         {
       
   378 #ifdef _DEBUG
       
   379         TRACE(Print(_L("[Mediator Server]\t CCategory::AddCommand id %d\n"), aNewCommand->Id() ));
       
   380         for ( TInt index = 0; index < ECapability_Limit; index ++ )
       
   381             {
       
   382             TCapabilitySet caps = aNewCommand->Policy();
       
   383             TBool required = caps.HasCapability( (TCapability) index );
       
   384             if ( required )
       
   385                 {
       
   386                 TRACE(Print(_L("[Mediator] CCategory::AddCommand: Capability %d required\n"), index ));
       
   387                 }
       
   388             }
       
   389 #endif // _DEBUG
       
   390         error = iCommandList.Append( aNewCommand );
       
   391         }
       
   392     else
       
   393         {
       
   394         error = KErrMediatorCommandAlreadyExists;
       
   395         }
       
   396     return error;
       
   397     }
       
   398         
       
   399 // -----------------------------------------------------------------------------
       
   400 // CCategory::RemoveEvent
       
   401 // Removes item from the category
       
   402 // (other items were commented in a header).
       
   403 // -----------------------------------------------------------------------------
       
   404 // 
       
   405 void CCategory::RemoveEvent( TInt aIndex )
       
   406     {
       
   407     if ( aIndex >= 0 && aIndex < iEventList.Count() )
       
   408         {
       
   409         iEventList.Remove( aIndex );
       
   410         }
       
   411     }
       
   412     
       
   413 // -----------------------------------------------------------------------------
       
   414 // CCategory::RemoveCommand
       
   415 // Removes item from the category
       
   416 // (other items were commented in a header).
       
   417 // -----------------------------------------------------------------------------
       
   418 // 
       
   419 void CCategory::RemoveCommand( TInt aIndex )
       
   420     {
       
   421     if ( aIndex >= 0 && aIndex < iCommandList.Count() )
       
   422         {
       
   423         iCommandList.Remove( aIndex );
       
   424         }
       
   425     }
       
   426     
       
   427 // -----------------------------------------------------------------------------
       
   428 // CCategory::FindEvent
       
   429 // Returns item specified by Id
       
   430 // (other items were commented in a header).
       
   431 // -----------------------------------------------------------------------------
       
   432 //         
       
   433 CEvent* CCategory::FindEvent( const TInt aId, TInt& aIndex )
       
   434     {
       
   435     iSearchEvent->SetId( aId );
       
   436 	
       
   437     aIndex = FindEvent( *iSearchEvent );
       
   438     
       
   439     // Then return it, if found. 
       
   440     CEvent* event = NULL;
       
   441     if ( aIndex != KErrNotFound )
       
   442         {
       
   443         event = iEventList[aIndex];
       
   444         }
       
   445     
       
   446 	return event;
       
   447     }    
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CCategory::GetEvent
       
   451 // Returns item specified by index
       
   452 // (other items were commented in a header).
       
   453 // -----------------------------------------------------------------------------
       
   454 //    
       
   455 CEvent* CCategory::GetEvent( TInt aIndex )
       
   456     {
       
   457     CEvent* eventPtr = NULL;
       
   458     if ( aIndex >= 0 && aIndex < EventCount() )
       
   459         {
       
   460         eventPtr = iEventList[aIndex];
       
   461         }
       
   462     return eventPtr;
       
   463     }
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CCategory::GetCommand
       
   467 // Returns item specified by index
       
   468 // (other items were commented in a header).
       
   469 // -----------------------------------------------------------------------------
       
   470 //    
       
   471 CCommand* CCategory::GetCommand( TInt aIndex )
       
   472     {
       
   473     CCommand* commandPtr = NULL;
       
   474     if ( aIndex >= 0 && aIndex < CommandCount() )
       
   475         {
       
   476         commandPtr = iCommandList[aIndex];
       
   477         }
       
   478     return commandPtr;
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CCategory::FindCommand
       
   483 // Returns item specified by Id
       
   484 // (other items were commented in a header).
       
   485 // -----------------------------------------------------------------------------
       
   486 //       
       
   487 CCommand* CCategory::FindCommand( const TInt aId, TInt& aIndex )
       
   488     {
       
   489     iSearchCommand->SetId( aId );
       
   490     
       
   491     aIndex = FindCommand( *iSearchCommand );
       
   492     
       
   493     // Then return it, if found. 
       
   494     CCommand* command = NULL;
       
   495     if ( aIndex != KErrNotFound )
       
   496         {
       
   497         command = iCommandList[aIndex];
       
   498         }
       
   499     
       
   500 	return command;
       
   501     }    
       
   502 
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CCategory::FindEvent
       
   506 // Finds event from the event list
       
   507 // (other items were commented in a header).
       
   508 // -----------------------------------------------------------------------------
       
   509 //    
       
   510 TInt CCategory::FindEvent( const CEvent& aEvent )
       
   511     {
       
   512     // Create utilities to be used in find
       
   513     TIdentityRelation<CEvent> relation( CompareEvents );
       
   514 
       
   515 	// Find the event from array	
       
   516 	return iEventList.Find( &aEvent, relation );
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CCategory::FindCommand
       
   521 // Finds item from the item list
       
   522 // (other items were commented in a header).
       
   523 // -----------------------------------------------------------------------------
       
   524 //    
       
   525 TInt CCategory::FindCommand( const CCommand& aCommand )
       
   526     {
       
   527     // Create utilities to be used in find
       
   528     TIdentityRelation<CCommand> relation( CompareCommands );
       
   529 
       
   530 	// Find the command from array	
       
   531 	return iCommandList.Find( &aCommand, relation );
       
   532     }
       
   533 
       
   534 // -----------------------------------------------------------------------------
       
   535 // CCategory::GetEventsL
       
   536 // 
       
   537 // (other items were commented in a header).
       
   538 // -----------------------------------------------------------------------------
       
   539 //      
       
   540 void CCategory::GetEventsL( REventList& aEvents )
       
   541     {
       
   542     // Loop thought category's event list and append those to returned 
       
   543     // event list.
       
   544     for ( TInt index = 0; index < iEventList.Count(); index++ )
       
   545         {
       
   546         CEvent* event = iEventList[index];
       
   547         if ( event )
       
   548             {
       
   549             aEvents.AppendL( event->Event() );
       
   550             }
       
   551         }
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CCategory::GetCommandsL
       
   556 // 
       
   557 // (other items were commented in a header).
       
   558 // -----------------------------------------------------------------------------
       
   559 //      
       
   560 void CCategory::GetCommandsL( RCommandList& aCommands )
       
   561     {
       
   562     // Loop thought category's event list and append those to returned 
       
   563     // event list.
       
   564     for ( TInt index = 0; index < iCommandList.Count(); index++ )
       
   565         {
       
   566         CCommand* command = iCommandList[index];
       
   567         if ( command )
       
   568             {
       
   569             aCommands.AppendL( command->Command() );
       
   570             }
       
   571         }
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CCategory::EventCount
       
   576 // 
       
   577 // (other items were commented in a header).
       
   578 // -----------------------------------------------------------------------------
       
   579 //       
       
   580 TInt CCategory::EventCount()
       
   581     {
       
   582     return iEventList.Count();
       
   583     }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // CCategory::CommandCount
       
   587 // 
       
   588 // (other items were commented in a header).
       
   589 // -----------------------------------------------------------------------------
       
   590 //       
       
   591 TInt CCategory::CommandCount()
       
   592     {
       
   593     return iCommandList.Count();
       
   594     }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // CCategory::CompareCommands
       
   598 // Compares two commands
       
   599 // (other items were commented in a header).
       
   600 // -----------------------------------------------------------------------------
       
   601 //       
       
   602 TBool CCategory::CompareCommands( const CCommand& aLeftCommand, 
       
   603                                   const CCommand& aRightCommand )
       
   604     { 
       
   605     return aLeftCommand.Id() == aRightCommand.Id();
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CCategory::CompareEvents
       
   610 // Compares two commands
       
   611 // (other items were commented in a header).
       
   612 // -----------------------------------------------------------------------------
       
   613 //       
       
   614 TBool CCategory::CompareEvents( const CEvent& aLeftEvent, 
       
   615                                 const CEvent& aRightEvent )
       
   616     { 
       
   617     return aLeftEvent.Id() == aRightEvent.Id();
       
   618     }
       
   619  
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CCategory::CommitCommands
       
   623 // 
       
   624 // (other items were commented in a header).
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CCategory::CommitCommands()
       
   628     {
       
   629     // iterate through command list
       
   630     CCommand* command;
       
   631     
       
   632     for ( TInt i = iCommandList.Count() - 1; i >= 0; i-- ) // iterage in reverse order because count may change
       
   633         {
       
   634         command = iCommandList[i];
       
   635         
       
   636         if ( command->CommitState() == CItem::EAdded )
       
   637             {
       
   638             // if item state is Added -> set to Committed
       
   639             command->SetCommitState( CItem::ECommitted );
       
   640             }
       
   641         else if ( command->CommitState() == CItem::ERemoved )
       
   642             {
       
   643             // if item state is Removed -> remove item and release reserved memory
       
   644             iCommandList.Remove( i );
       
   645             delete command;
       
   646             }
       
   647         }
       
   648     }
       
   649     
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // CCategory::RollbackCommands
       
   653 // 
       
   654 // (other items were commented in a header).
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 void CCategory::RollbackCommands()
       
   658     {
       
   659     CCommand* command;
       
   660 
       
   661     // iterate through command list
       
   662     for ( TInt i = iCommandList.Count() - 1; i >= 0; i-- ) // iterage in reverse order because count may change
       
   663         {
       
   664         command = iCommandList[i];
       
   665         
       
   666         if ( command->CommitState() == CItem::EAdded )
       
   667             {
       
   668             // if item state is Added -> remove item and release reserved memory
       
   669             iCommandList.Remove( i );
       
   670             delete command;
       
   671             }
       
   672         else if ( command->CommitState() == CItem::ERemoved )
       
   673             {
       
   674             // if item state is Removed -> set back to Committed
       
   675             command->SetCommitState( CItem::ECommitted );
       
   676             }
       
   677         }
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CCategory::CommitEvents
       
   682 // 
       
   683 // (other items were commented in a header).
       
   684 // -----------------------------------------------------------------------------
       
   685 //    
       
   686 void CCategory::CommitEvents()
       
   687     {
       
   688     CEvent* event;
       
   689     
       
   690     // iterate through event list
       
   691     for ( TInt i = iEventList.Count() - 1; i >= 0; i-- ) // iterage in reverse order because count may change
       
   692         {
       
   693         event = iEventList[i];
       
   694         
       
   695         if ( event->CommitState() == CItem::EAdded )
       
   696             {
       
   697             // if item state is Added -> set to Committed
       
   698             event->SetCommitState( CItem::ECommitted );
       
   699             }
       
   700         else if ( event->CommitState() == CItem::ERemoved )
       
   701             {
       
   702             // if item state is Removed -> remove item and release reserved memory
       
   703             iEventList.Remove( i );
       
   704             delete event;
       
   705             }
       
   706         }
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CCategory::RollbackEvents
       
   711 // 
       
   712 // (other items were commented in a header).
       
   713 // -----------------------------------------------------------------------------
       
   714 //    
       
   715 void CCategory::RollbackEvents()
       
   716     {
       
   717     CEvent* event;
       
   718 
       
   719     // iterate through command list
       
   720     for ( TInt i = iEventList.Count() - 1; i >= 0; i-- ) // iterage in reverse order because count may change
       
   721         {
       
   722         event = iEventList[i];
       
   723         
       
   724         if ( event->CommitState() == CItem::EAdded )
       
   725             {
       
   726             // if item state is Added -> remove item and release reserved memory
       
   727             iEventList.Remove( i );
       
   728             delete event;
       
   729             }
       
   730         else if ( event->CommitState() == CItem::ERemoved )
       
   731             {
       
   732             // if item state is Removed -> set back to Committed
       
   733             event->SetCommitState( CItem::ECommitted );
       
   734             }
       
   735         }
       
   736     }
       
   737     
       
   738 // =============================================================================
       
   739 // ============================ ITEM FUNCTIONS =================================
       
   740 // =============================================================================
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CItem::CItem
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 CItem::CItem()
       
   747     {
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CItem::~CItem
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 CItem::~CItem()
       
   755     {
       
   756     delete iData;
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CItem::Id
       
   761 // Returns id of the item
       
   762 // (other items were commented in a header).
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 TInt CItem::Id() const
       
   766     {
       
   767     return iId;
       
   768     }
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // CItem::SetId
       
   772 // 
       
   773 // (other items were commented in a header).
       
   774 // -----------------------------------------------------------------------------
       
   775 //    
       
   776 void CItem::SetId( TInt aId )
       
   777     {
       
   778     iId = aId;
       
   779     }
       
   780 
       
   781 // -----------------------------------------------------------------------------
       
   782 // CItem::SetDomain
       
   783 // Sets domain to item
       
   784 // (other items were commented in a header).
       
   785 // -----------------------------------------------------------------------------
       
   786 //     
       
   787 void CItem::SetDomain( TUid aDomain )
       
   788     {
       
   789     iDomain = aDomain;
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CItem::Domain
       
   794 // Gets item domain
       
   795 // (other items were commented in a header).
       
   796 // -----------------------------------------------------------------------------
       
   797 //     
       
   798 TUid CItem::Domain() const
       
   799     {
       
   800     return iDomain;
       
   801     }
       
   802 
       
   803 // -----------------------------------------------------------------------------
       
   804 // CItem::SetCategory
       
   805 // Sets category to item
       
   806 // (other items were commented in a header).
       
   807 // -----------------------------------------------------------------------------
       
   808 //      
       
   809 void CItem::SetCategory( TUid aCategory )
       
   810     {
       
   811     iCategory = aCategory;
       
   812     }
       
   813 
       
   814 // -----------------------------------------------------------------------------
       
   815 // CItem::Category
       
   816 // Gets item category
       
   817 // (other items were commented in a header).
       
   818 // -----------------------------------------------------------------------------
       
   819 //      
       
   820 TUid CItem::Category() const
       
   821     {
       
   822     return iCategory;
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CItem::Policy
       
   827 // Returns the required capability set for the item (command or event)
       
   828 // (other items were commented in a header).
       
   829 // -----------------------------------------------------------------------------
       
   830 // 
       
   831 TCapabilitySet CItem::Policy() const
       
   832     {
       
   833     return iPolicy;
       
   834     }
       
   835 
       
   836 
       
   837 // -----------------------------------------------------------------------------
       
   838 // CItem::SetVersion
       
   839 // 
       
   840 // (other items were commented in a header).
       
   841 // -----------------------------------------------------------------------------
       
   842 //      
       
   843 void CItem::SetVersion( TVersion aVersion )
       
   844     {
       
   845     iVersion = aVersion;
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // CItem::Version
       
   850 // 
       
   851 // (other items were commented in a header).
       
   852 // -----------------------------------------------------------------------------
       
   853 // 
       
   854 TVersion CItem::Version() const
       
   855     {
       
   856     return iVersion;
       
   857     }
       
   858 
       
   859 
       
   860 // -----------------------------------------------------------------------------
       
   861 // CItem::SetSecureId
       
   862 // 
       
   863 // (other items were commented in a header).
       
   864 // -----------------------------------------------------------------------------
       
   865 //      
       
   866 void CItem::SetSecureId( TSecureId aSecureId )
       
   867     {
       
   868     iSecureId = aSecureId;
       
   869     }
       
   870 
       
   871 // -----------------------------------------------------------------------------
       
   872 // CItem::SecureId
       
   873 // 
       
   874 // (other items were commented in a header).
       
   875 // -----------------------------------------------------------------------------
       
   876 // 
       
   877 TSecureId CItem::SecureId() const
       
   878     {
       
   879     return iSecureId;
       
   880     }
       
   881 
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // CItem::SetParameterDataL
       
   885 // 
       
   886 // (other items were commented in a header).
       
   887 // -----------------------------------------------------------------------------
       
   888 //    
       
   889 void CItem::SetParameterDataL( const TDesC8& aData )
       
   890     {
       
   891     // Empty existing just to be sure
       
   892     delete iData;
       
   893     iData = NULL;
       
   894     
       
   895     iData = aData.AllocL();
       
   896     }
       
   897 
       
   898 // -----------------------------------------------------------------------------
       
   899 // CItem::ParameterData
       
   900 // 
       
   901 // (other items were commented in a header).
       
   902 // -----------------------------------------------------------------------------
       
   903 //     
       
   904 const TDesC8& CItem::ParameterData() const
       
   905     {
       
   906     if ( iData )
       
   907         {
       
   908         return *iData;
       
   909         }
       
   910     else
       
   911         {
       
   912         return KNullDesC8;
       
   913         }
       
   914     }
       
   915 
       
   916 // -----------------------------------------------------------------------------
       
   917 // CItem::CommitState
       
   918 // 
       
   919 // (other items were commented in a header).
       
   920 // -----------------------------------------------------------------------------
       
   921 //    
       
   922 CItem::TCommitState CItem::CommitState() const
       
   923     {
       
   924     return iCommitState;
       
   925     }
       
   926         
       
   927 // -----------------------------------------------------------------------------
       
   928 // CItem::SetCommitState
       
   929 // 
       
   930 // (other items were commented in a header).
       
   931 // -----------------------------------------------------------------------------
       
   932 //         
       
   933 void CItem::SetCommitState( TCommitState aState )
       
   934     {
       
   935     iCommitState = aState;
       
   936     }
       
   937 
       
   938 // =============================================================================
       
   939 // ============================ EVENT FUNCTIONS ================================
       
   940 // =============================================================================
       
   941 
       
   942 // -----------------------------------------------------------------------------
       
   943 // CEvent::CEvent
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 CEvent::CEvent( const TInt aId )
       
   947     {
       
   948     iId = aId;
       
   949     }
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 // CEvent::CEvent
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 CEvent::CEvent( const TEvent aEvent )
       
   956     {
       
   957     iId = aEvent.iEventId;
       
   958     iPolicy = aEvent.iCaps;
       
   959     iVersion = aEvent.iVersion;
       
   960     }
       
   961 
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CEvent::ConstructL
       
   965 // -----------------------------------------------------------------------------
       
   966 //
       
   967 void CEvent::ConstructL()
       
   968     {
       
   969     }
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 // CEvent::NewL
       
   973 // -----------------------------------------------------------------------------
       
   974 //
       
   975 CEvent* CEvent::NewL( const TInt aId )
       
   976     {
       
   977     CEvent* self = new( ELeave ) CEvent( aId );
       
   978     
       
   979     CleanupStack::PushL( self );
       
   980     self->ConstructL();
       
   981     CleanupStack::Pop( self );
       
   982 
       
   983     return self;
       
   984     }
       
   985     
       
   986 
       
   987 // -----------------------------------------------------------------------------
       
   988 // CEvent::NewL
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 CEvent* CEvent::NewL( const TEvent aEvent )
       
   992     {
       
   993     CEvent* self = new( ELeave ) CEvent( aEvent );
       
   994     
       
   995     CleanupStack::PushL( self );
       
   996     self->ConstructL();
       
   997     CleanupStack::Pop( self );
       
   998 
       
   999     return self;
       
  1000     }
       
  1001     
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // CEvent::~CEvent
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 CEvent::~CEvent()
       
  1007     {
       
  1008     }
       
  1009 
       
  1010 // -----------------------------------------------------------------------------
       
  1011 // CEvent::Type
       
  1012 // Returns EItemEvent
       
  1013 // -----------------------------------------------------------------------------
       
  1014 //
       
  1015 TItemType CEvent::Type() const
       
  1016     {
       
  1017     return EItemEvent;
       
  1018     }
       
  1019  
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CEvent::AddObserver
       
  1022 // 
       
  1023 // -----------------------------------------------------------------------------
       
  1024 //
       
  1025 TInt CEvent::AddObserver( MMediatorServerEventObserver* aObserver )
       
  1026     {
       
  1027     TInt error = KErrNone;
       
  1028     // Check that observer does not exists already for this event
       
  1029     TBool found = EFalse;
       
  1030     for (TInt index = 0; index < iObservers.Count() && !found; index++ )
       
  1031         {
       
  1032         if ( iObservers[index] == aObserver )
       
  1033             {
       
  1034             error = KErrMediatorAlreadySubscribed;
       
  1035             found = ETrue;
       
  1036             }
       
  1037         }
       
  1038     // Add observer in case no errors
       
  1039     if ( error == KErrNone )
       
  1040         {
       
  1041         error = iObservers.Append( aObserver );
       
  1042         }
       
  1043     return error;
       
  1044     }
       
  1045  
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CEvent::RemoveObserver
       
  1048 // 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 //       
       
  1051 TInt CEvent::RemoveObserver( MMediatorServerEventObserver* aObserver )
       
  1052     {
       
  1053     TInt error = KErrNone;
       
  1054     TBool found = EFalse;
       
  1055     for (TInt index = 0; index < iObservers.Count() && !found; index++ )
       
  1056         {
       
  1057         // Remove the fond observer
       
  1058         if ( iObservers[index] == aObserver )
       
  1059             {
       
  1060             iObservers.Remove( index );
       
  1061             found = ETrue;
       
  1062             }
       
  1063         }
       
  1064     if ( !found )
       
  1065         {
       
  1066         error = KErrMediatorNoSubscription;
       
  1067         }
       
  1068     return error;
       
  1069     }
       
  1070 
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // CEvent::GetObservers
       
  1073 // 
       
  1074 // -----------------------------------------------------------------------------
       
  1075 //
       
  1076 RPointerArray<MMediatorServerEventObserver>& CEvent::GetObservers()
       
  1077     {
       
  1078     return iObservers;
       
  1079     }
       
  1080 
       
  1081 // -----------------------------------------------------------------------------
       
  1082 // CEvent::AddObservers
       
  1083 // 
       
  1084 // -----------------------------------------------------------------------------
       
  1085 //
       
  1086 void CEvent::AddObservers( RPointerArray<MMediatorServerEventObserver>& aObservers )
       
  1087     {
       
  1088     // Check that observer does not exists already for this event
       
  1089     for (TInt index = 0; index < aObservers.Count(); index++ )
       
  1090         {
       
  1091         iObservers.Append( aObservers[index] );
       
  1092         }
       
  1093     }
       
  1094 
       
  1095 // -----------------------------------------------------------------------------
       
  1096 // CEvent::Event
       
  1097 // Returns EItemEvent
       
  1098 // -----------------------------------------------------------------------------
       
  1099 //
       
  1100 MediatorService::TEvent CEvent::Event() const
       
  1101     {
       
  1102     MediatorService::TEvent event;
       
  1103     event.iEventId  = Id();
       
  1104     event.iVersion  = Version();
       
  1105     event.iCaps     = Policy();
       
  1106     return event;
       
  1107     }
       
  1108  
       
  1109 
       
  1110 // =============================================================================
       
  1111 // ============================ COMMAND FUNCTIONS ==============================
       
  1112 // =============================================================================
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CCommand::CCommand
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 CCommand::CCommand( const TInt aId )
       
  1119     {
       
  1120     iId = aId;
       
  1121     iStatus = ECommandPending; // pending command by default
       
  1122     }
       
  1123 
       
  1124 // -----------------------------------------------------------------------------
       
  1125 // CCommand::CCommand
       
  1126 // -----------------------------------------------------------------------------
       
  1127 //
       
  1128 CCommand::CCommand( const TCommand aCommand )
       
  1129     {
       
  1130     iId = aCommand.iCommandId;
       
  1131     iPolicy = aCommand.iCaps;
       
  1132     iVersion = aCommand.iVersion;
       
  1133     iTimeout = aCommand.iTimeout;
       
  1134     iStatus = ECommandPending; // pending command by default
       
  1135     }
       
  1136 
       
  1137 // -----------------------------------------------------------------------------
       
  1138 // CCommand::ConstructL
       
  1139 // -----------------------------------------------------------------------------
       
  1140 //
       
  1141 void CCommand::ConstructL()
       
  1142     {
       
  1143     iCommandTimer = CMediatorCommandTimer::NewL();
       
  1144     }
       
  1145 
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CCommand::NewL
       
  1148 // -----------------------------------------------------------------------------
       
  1149 //
       
  1150 CCommand* CCommand::NewL( const TInt aId )
       
  1151     {
       
  1152     CCommand* self = new( ELeave ) CCommand( aId );
       
  1153     
       
  1154     CleanupStack::PushL( self );
       
  1155     self->ConstructL();
       
  1156     CleanupStack::Pop( self );
       
  1157 
       
  1158     return self;
       
  1159     }
       
  1160 
       
  1161 // -----------------------------------------------------------------------------
       
  1162 // CCommand::NewL
       
  1163 // -----------------------------------------------------------------------------
       
  1164 //
       
  1165 CCommand* CCommand::NewL( const TCommand aCommand )
       
  1166     {
       
  1167     CCommand* self = new( ELeave ) CCommand( aCommand );
       
  1168     
       
  1169     CleanupStack::PushL( self );
       
  1170     self->ConstructL();
       
  1171     CleanupStack::Pop( self );
       
  1172 
       
  1173     return self;
       
  1174     }
       
  1175 
       
  1176 // -----------------------------------------------------------------------------
       
  1177 // CCommand::~CCommand
       
  1178 // -----------------------------------------------------------------------------
       
  1179 //
       
  1180 CCommand::~CCommand()
       
  1181     {
       
  1182     if ( iCommandTimer )
       
  1183         {
       
  1184         iCommandTimer->Cancel();
       
  1185         }
       
  1186     delete iCommandTimer;
       
  1187     }
       
  1188 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 // CCommand::Type
       
  1191 // Returns EItemCommand
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //
       
  1194 TItemType CCommand::Type() const
       
  1195     {
       
  1196     return EItemCommand;
       
  1197     }
       
  1198 
       
  1199 // -----------------------------------------------------------------------------
       
  1200 // CCommand::SetTimeOut
       
  1201 // 
       
  1202 // -----------------------------------------------------------------------------
       
  1203 //
       
  1204 void CCommand::SetTimeout( TInt aTimeout )
       
  1205     {
       
  1206     iTimeout = aTimeout;
       
  1207     }
       
  1208 
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // CCommand::TimeOut
       
  1211 // 
       
  1212 // -----------------------------------------------------------------------------
       
  1213 //
       
  1214 TInt CCommand::Timeout() const
       
  1215     {
       
  1216     return iTimeout;
       
  1217     }
       
  1218 
       
  1219 // -----------------------------------------------------------------------------
       
  1220 // CCommand::Command
       
  1221 // 
       
  1222 // -----------------------------------------------------------------------------
       
  1223 //
       
  1224 MediatorService::TCommand CCommand::Command() const
       
  1225     {
       
  1226     MediatorService::TCommand command;
       
  1227     command.iCommandId  = Id();
       
  1228     command.iVersion    = Version();
       
  1229     command.iTimeout    = Timeout();
       
  1230     command.iCaps       = Policy();
       
  1231     return command;
       
  1232     }
       
  1233 
       
  1234 // -----------------------------------------------------------------------------
       
  1235 // CCommand::SetObserver
       
  1236 // 
       
  1237 // -----------------------------------------------------------------------------
       
  1238 // 
       
  1239 void CCommand::SetObserver( MMediatorCommandObserver* aObserver )
       
  1240     {
       
  1241     iObserver = aObserver;
       
  1242     }
       
  1243 
       
  1244 // -----------------------------------------------------------------------------
       
  1245 // CCommand::Observer
       
  1246 // 
       
  1247 // -----------------------------------------------------------------------------
       
  1248 // 
       
  1249 MMediatorCommandObserver* CCommand::Observer()
       
  1250     {
       
  1251     return iObserver;
       
  1252     }
       
  1253 
       
  1254 // -----------------------------------------------------------------------------
       
  1255 // CCommand::SetResponseObserver
       
  1256 // 
       
  1257 // -----------------------------------------------------------------------------
       
  1258 //
       
  1259 void CCommand::SetResponseObserver( MMediatorCommandResponseObserver* aObserver )
       
  1260     {
       
  1261     iResponseObserver = aObserver;
       
  1262     }
       
  1263 
       
  1264 // -----------------------------------------------------------------------------
       
  1265 // CCommand::ResponseObserver
       
  1266 // 
       
  1267 // -----------------------------------------------------------------------------
       
  1268 // 
       
  1269 MMediatorCommandResponseObserver* CCommand::ResponseObserver()
       
  1270     {
       
  1271     return iResponseObserver;
       
  1272     }
       
  1273 
       
  1274 // -----------------------------------------------------------------------------
       
  1275 // CCommand::StartTimer
       
  1276 // 
       
  1277 // -----------------------------------------------------------------------------
       
  1278 // 
       
  1279 TInt CCommand::StartTimer( MMediatorTimerCallback* aCallBack )
       
  1280     {
       
  1281     // Start timer
       
  1282     return iCommandTimer->StartTimer( aCallBack, Domain(), Category(), Id(), Timeout() );
       
  1283     }
       
  1284 
       
  1285 // -----------------------------------------------------------------------------
       
  1286 // CCommand::CancelTimer
       
  1287 // 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // 
       
  1290 void CCommand::CancelTimer()
       
  1291     {
       
  1292     iCommandTimer->Cancel();
       
  1293     }
       
  1294 
       
  1295 // -----------------------------------------------------------------------------
       
  1296 // CCommand::SetStatus
       
  1297 // 
       
  1298 // -----------------------------------------------------------------------------
       
  1299 //
       
  1300 void CCommand::SetStatus( TCommandStatus aStatus )
       
  1301     {
       
  1302     iStatus = aStatus;
       
  1303     }
       
  1304 
       
  1305 // -----------------------------------------------------------------------------
       
  1306 // CCommand::Status
       
  1307 // 
       
  1308 // -----------------------------------------------------------------------------
       
  1309 // 
       
  1310 TCommandStatus CCommand::Status() const
       
  1311     {
       
  1312     return iStatus;
       
  1313     }
       
  1314 
       
  1315 //  End of File