javauis/runtimeui_akn/src.s60/globalmsgobserver.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2007 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 
       
    18 #include "globalmsgobserver.h"
       
    19 
       
    20 using namespace java::runtimeui;
       
    21 
       
    22 EXPORT_C GlobalMsgObserver* GlobalMsgObserver::NewL()
       
    23 {
       
    24     GlobalMsgObserver* self = new(ELeave) GlobalMsgObserver();
       
    25     CleanupStack::PushL(self);
       
    26     self->ConstructL();
       
    27     CleanupStack::Pop();
       
    28     return self;
       
    29 }
       
    30 
       
    31 EXPORT_C GlobalMsgObserver* GlobalMsgObserver::NewLC()
       
    32 {
       
    33     GlobalMsgObserver* self = new(ELeave) GlobalMsgObserver();
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     return self;
       
    37 }
       
    38 
       
    39 EXPORT_C int GlobalMsgObserver::getAnswer()
       
    40 {
       
    41     // set the active object as active
       
    42     SetActive();
       
    43     // enter scheduler loop
       
    44     iActiveSchedulerWait->Start();
       
    45     return iStatus.Int();
       
    46 }
       
    47 
       
    48 void GlobalMsgObserver::ConstructL()
       
    49 {
       
    50     if (!CActiveScheduler::Current())
       
    51     {
       
    52         // create own ActiveScheduler since one doesn't exist yet
       
    53         iActiveScheduler = new(ELeave) CActiveScheduler;
       
    54         CActiveScheduler::Install(iActiveScheduler);
       
    55     }
       
    56     // register myself as an active object
       
    57     CActiveScheduler::Add(this);
       
    58     // create wait object for nested loop control
       
    59     iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait;
       
    60 }
       
    61 
       
    62 GlobalMsgObserver::~GlobalMsgObserver()
       
    63 {
       
    64     // cancel any outstanding requests
       
    65     Cancel();
       
    66     // delete own active scheduler if it was created
       
    67     delete iActiveScheduler;
       
    68     // delete wait object that is always created
       
    69     delete iActiveSchedulerWait;
       
    70 }
       
    71 
       
    72 void GlobalMsgObserver::Complete()
       
    73 {
       
    74     // stop the active scheduler loop
       
    75     iActiveSchedulerWait->AsyncStop();
       
    76 }
       
    77 
       
    78 void GlobalMsgObserver::DoCancel()
       
    79 {
       
    80     // This implementation is not correct. It should call the cancel provided
       
    81     // by the asynchronous service provider. If something leaves while in the
       
    82     // scheduler loop in getAnswer() then now it will try to stop the scheduler
       
    83     // which isn't running anymore because of the leave and there will be
       
    84     // TooManyStops panic.
       
    85     Complete();
       
    86 }
       
    87 
       
    88 void GlobalMsgObserver::RunL()
       
    89 {
       
    90     Complete();
       
    91 }