taskswitcher/server/src/tsrunningappserver.cpp
changeset 116 305818acdca4
child 119 50e220be30d1
equal deleted inserted replaced
112:dbfb5e38438b 116:305818acdca4
       
     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 <tswindowgroupsobserver.h>
       
    18 #include "tstaskmonitorglobals.h"
       
    19 #include "tsrunningappserver.h"
       
    20 #include "tsrunningappsession.h"
       
    21 #include "tsbacksteppingactivation.h"
       
    22 
       
    23 #include "tsmodel.h"
       
    24 #include "tsstorage.h"
       
    25 #include "tsservicesprovider.h"
       
    26 #include "tsserializeddataprovider.h"
       
    27 #include "tsrunningappmodel.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 /**
       
    31  * Constructor for performing 1st stage construction
       
    32  */
       
    33 CTsRunningAppServer::CTsRunningAppServer()
       
    34 :
       
    35 CServer2(EPriorityStandard)
       
    36     {
       
    37     // No implementation required
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 /**
       
    42  * Destructor.
       
    43  */
       
    44 CTsRunningAppServer::~CTsRunningAppServer()
       
    45     {
       
    46     delete iBacksteppingEngine;
       
    47     delete iStorage;
       
    48     delete iAppsModel;
       
    49     delete iServiceProvider;
       
    50     delete iSerializer;
       
    51     delete iMonitor;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 /**
       
    56  * Two-phased constructor.
       
    57  */
       
    58 CTsRunningAppServer* CTsRunningAppServer::NewLC()
       
    59     {
       
    60     CTsRunningAppServer* self = new (ELeave) CTsRunningAppServer();
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 /**
       
    68  * Default constructor for performing 2nd stage construction
       
    69  */
       
    70 void CTsRunningAppServer::ConstructL()
       
    71     {
       
    72     StartL(KRunningAppServerName);
       
    73     iResources = CTsResourceManager::NewL();
       
    74     iMonitor = CTsWindowGroupsMonitor::NewL(*iResources);
       
    75     
       
    76     iSerializer = CTsSerializedDataProvider::NewL(*this);
       
    77     
       
    78     RPointerArray<MTsModel> providers;
       
    79     CleanupClosePushL(providers);
       
    80     
       
    81     iAppsModel = CTsRunningAppModel::NewL(*iResources, *iMonitor);
       
    82     providers.AppendL(iAppsModel);
       
    83     
       
    84     CTsServiceProviderConfig *cfg = CTsServiceProviderConfig::NewLC();
       
    85     iServiceProvider = CTsServiceProvider::NewL(*cfg);
       
    86     CleanupStack::PopAndDestroy(cfg);
       
    87     addProviders(providers, *iServiceProvider);
       
    88 
       
    89     iStorage = CTsStorage::NewL(providers.Array());
       
    90     iStorage->SetObserver(iSerializer);
       
    91     CleanupStack::PopAndDestroy(&providers);
       
    92 
       
    93     // load initial data
       
    94     iStorage->DataChanged();
       
    95 
       
    96     TRAP_IGNORE(iBacksteppingEngine = CTsBacksteppingActivation::NewL(*iMonitor);)
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 /**
       
   101  * Interface implementation
       
   102  * @see CServer2::NewSessionL(const TVersion&, const RMessage2&)
       
   103  */
       
   104 CSession2* CTsRunningAppServer::NewSessionL( const TVersion & /*aVersion*/, 
       
   105                                              const RMessage2& /*aMsg*/) const
       
   106     {
       
   107     RPointerArray<MTsDataStorage> dataStorages;
       
   108     CleanupClosePushL(dataStorages);
       
   109     dataStorages.AppendL(const_cast<CTsRunningAppServer *>(this)->iAppsModel);
       
   110     dataStorages.AppendL(const_cast<CTsRunningAppServer *>(this)->iStorage);
       
   111     CSession2* retVal = 
       
   112         CTsRunningAppSession::NewL( *const_cast<CTsRunningAppServer *>(this)->iSerializer,
       
   113                                     dataStorages.Array());
       
   114     CleanupStack::PopAndDestroy(&dataStorages);
       
   115     return retVal;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 void CTsRunningAppServer::DataChanged()
       
   120     {
       
   121     TAny* currentObserver(0);
       
   122     TDblQueIter<CSession2> currentItem(iSessionIter);
       
   123     currentItem.SetToFirst();
       
   124     do
       
   125         {
       
   126         currentObserver = currentItem++;
       
   127         if(currentObserver)
       
   128             {
       
   129             static_cast<CTsRunningAppSession*>(currentObserver)->DataChanged();
       
   130             }
       
   131         }
       
   132     while(0 != currentObserver);
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 void CTsRunningAppServer::addProviders( RPointerArray<MTsModel> &dst, 
       
   137                                         const CTsServiceProvider& serviceProvider)
       
   138     {
       
   139     for ( TInt offset(0); offset < serviceProvider.Count(); ++offset )
       
   140         {
       
   141         dst.Append(&serviceProvider[offset]);
       
   142         }
       
   143     }