taskswitcher/server/src/hsrunningappserver.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     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 "hsrunningappserver.h"
       
    20 #include "hsrunningappsession.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 _LIT(KErrObserverExists, "Observer already exists");
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CRunningAppServer::CRunningAppServer()
       
    35 :
       
    36 CServer2(EPriorityStandard)
       
    37 {
       
    38     // No implementation required
       
    39 }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CRunningAppServer::~CRunningAppServer()
       
    46 {
       
    47     delete mBacksteppingEngine;
       
    48     delete mStorage;
       
    49     delete mAppsModel;
       
    50     delete mServiceProvider;
       
    51     delete mSerializer;
       
    52     delete mMonitor;
       
    53     mObservers.ResetAndDestroy();
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CRunningAppServer* CRunningAppServer::NewLC()
       
    61 {
       
    62     CRunningAppServer* self = new (ELeave) CRunningAppServer();
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     return self;
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CRunningAppServer::ConstructL()
       
    73 {
       
    74     StartL(KRunningAppServerName);
       
    75     User::LeaveIfError(mWsSession.Connect());
       
    76     mResources = CTsResourceManager::NewL();
       
    77     mMonitor = CTsWindowGroupsMonitor::NewL(*mResources);
       
    78     
       
    79     mSerializer = CTsSerializedDataProvider::NewL(*this);
       
    80     
       
    81     RPointerArray<MTsModel> providers;
       
    82     CleanupClosePushL(providers);
       
    83     
       
    84     mAppsModel = CTsRunningAppModel::NewL(*mResources, *mMonitor);
       
    85     providers.AppendL(mAppsModel);
       
    86     
       
    87     CTsServiceProviderConfig *cfg = CTsServiceProviderConfig::NewLC();
       
    88     mServiceProvider = CTsServiceProvider::NewL(*cfg);
       
    89     CleanupStack::PopAndDestroy(cfg);
       
    90     addProviders(providers, *mServiceProvider);
       
    91 
       
    92     mStorage = CTsStorage::NewL(providers.Array());
       
    93     mStorage->setObserver(mSerializer);
       
    94     CleanupStack::PopAndDestroy(&providers);
       
    95 
       
    96     // load initial data
       
    97     mStorage->DataChanged();
       
    98 
       
    99     TRAP_IGNORE(mBacksteppingEngine = CTsBacksteppingActivation::NewL(*mMonitor);)
       
   100 }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CSession2* CRunningAppServer::NewSessionL(const TVersion &, const RMessage2&) const
       
   107 {
       
   108     RPointerArray<MTsDataStorage> dataStorages;
       
   109     CleanupClosePushL(dataStorages);
       
   110     dataStorages.AppendL(const_cast<CRunningAppServer *>(this)->mAppsModel);
       
   111     dataStorages.AppendL(const_cast<CRunningAppServer *>(this)->mStorage);
       
   112     CSession2* retVal = CRunningAppSession::NewL(*const_cast<CRunningAppServer *>(this),
       
   113                                                  *const_cast<CRunningAppServer *>(this)->mSerializer,
       
   114                                                  dataStorages.Array());
       
   115     CleanupStack::PopAndDestroy(&dataStorages);
       
   116     return retVal;
       
   117     
       
   118 }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CRunningAppServer::DataChanged()
       
   125 {
       
   126     while (0 < mObservers.Count()) {
       
   127         mObservers[0]->DataChanged();
       
   128     }
       
   129 }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CRunningAppServer::PushL(CTsDataObserver* observer)
       
   136 {
       
   137     ( 0 <= mObservers.Find(observer)) ?
       
   138     User::Panic(KErrObserverExists, KErrAlreadyExists) :
       
   139     mObservers.AppendL(observer);
       
   140 }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CRunningAppServer::Pop(CTsDataObserver* observer)
       
   147 {
       
   148     const TInt offset(mObservers.Find(observer));
       
   149     if(0 <= offset) {
       
   150         mObservers.Remove(offset);
       
   151     }
       
   152 }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CRunningAppServer::Cancel(const RMessage2& reason)
       
   159 {
       
   160     for (TInt iter(mObservers.Count() - 1); 0 <= iter; --iter) {
       
   161         mObservers[iter]->Cancel(reason);
       
   162     }
       
   163     reason.Complete(KErrNone);
       
   164 }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CRunningAppServer::Invalidate(const CSession2* session)
       
   171 {
       
   172     for (TInt iter(mObservers.Count() - 1); 0 <= iter; --iter) {
       
   173         if(mObservers[iter]->IsParent(session)) {
       
   174             delete mObservers[iter];
       
   175             mObservers.Remove(iter);
       
   176         }
       
   177     }
       
   178 }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 void CRunningAppServer::addProviders(RPointerArray<MTsModel> &dst, 
       
   182                                      const CTsServiceProvider& serviceProvider)
       
   183 {
       
   184     for (TInt offset(0); offset < serviceProvider.count(); ++offset) {
       
   185         dst.Append(&serviceProvider[offset]);
       
   186     }
       
   187 }