tstaskmonitor/client/s60/src/tstaskmonitor_p.cpp
changeset 102 8b8b34fa9751
parent 100 0920c6a9b6c8
child 106 e78d6e055a5b
equal deleted inserted replaced
100:0920c6a9b6c8 102:8b8b34fa9751
     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 "tstaskmonitor_p.h"
       
    18 #include "tstaskmonitor.h"
       
    19 
       
    20 #include <eikenv.h>
       
    21 
       
    22 #include "tstaskmonitorclient.h"
       
    23 #include "tsapplicationtask.h"
       
    24 
       
    25 #include "tsutils.h"
       
    26 using TaskSwitcher::CleanupResetAndDestroyPushL;
       
    27 
       
    28 TsTaskMonitorPrivate::TsTaskMonitorPrivate(TsTaskMonitor *q) : q_ptr(q), mClient(0), mWsSession(CEikonEnv::Static()->WsSession())
       
    29 {
       
    30     QT_TRAP_THROWING(mClient = CTsTaskMonitorClient::NewL());
       
    31     mClient->Subscribe(*this);
       
    32 }
       
    33 
       
    34 TsTaskMonitorPrivate::~TsTaskMonitorPrivate()
       
    35 {
       
    36     mClient->CancelSubscribe();
       
    37     delete mClient;
       
    38 }
       
    39 
       
    40 QList< QSharedPointer<TsTask> > TsTaskMonitorPrivate::taskList()
       
    41 {
       
    42     QList< QSharedPointer<TsTask> > tasks;
       
    43 
       
    44     QT_TRAP_THROWING (    
       
    45         RPointerArray<CTsEntry> entries;   
       
    46         CleanupResetAndDestroyPushL<CTsEntry>(entries);
       
    47         mClient->TaskListL(entries);
       
    48         
       
    49         // TsTask claims ownership of CTsFswEntry, so we have to remove entries from 
       
    50         // entries array after adding task to tasks array to prevent double delete of
       
    51         // CTsFswEntry objects in case of leave (for example due to OOM) in the middle 
       
    52         // of the loop below.
       
    53         while (entries.Count()) {
       
    54             CTsEntry *firstEntry = entries[0];
       
    55             CleanupStack::PushL(firstEntry);
       
    56             entries.Remove(0);
       
    57             
       
    58             // @todo switch by entry type
       
    59             QT_TRYCATCH_LEAVING(tasks.append(QSharedPointer<TsTask>(new TsApplicationTask(mWsSession, firstEntry))));
       
    60             
       
    61             CleanupStack::Pop(firstEntry);
       
    62         }
       
    63         
       
    64         CleanupStack::PopAndDestroy(&entries);    
       
    65     );
       
    66     
       
    67     return tasks;
       
    68 }
       
    69 
       
    70 void TsTaskMonitorPrivate::HandleRunningAppChange()
       
    71 {
       
    72     emit q_ptr->taskListChanged();
       
    73 }