examples/Base/ArraysAndLists/linkedlist/deltaque/src/deltaque.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // Contains the E32Main() function, which executes the example.
00015 // The example demonstrates the use of the TDeltaQue class, which represents
00016 // a delta queue.
00017 // An object of the CPeriodic class generates periodic timer events.
00018 // Either the tick count is added to the delta queue or
00019 // elements are removed from the list, depending on the state of the queue.
00020 // The user can stop the generation of timer events by pressing a key.
00021 //
00022 
00023 
00024 
00029 #include "userinterface.h"
00030 
00031 LOCAL_D CConsoleBase* console;
00032 
00033 LOCAL_C void DoStartL();
00034 LOCAL_C void CallExampleL();
00035 
00036 LOCAL_C void DoStartL()
00037         {
00038         // Create and install the active scheduler.
00039         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00040         CleanupStack::PushL(scheduler);
00041         CActiveScheduler::Install(scheduler);
00042 
00043         _LIT(KTextExample, "Delta Queue Example\nCreating and starting timer object\n");
00044         console->Printf(KTextExample);
00045         
00046         // Create an object of the CTimerEntry class.
00047         CTimerEntry* entry = CTimerEntry::NewL(console);
00048         CleanupStack::PushL(entry);
00049 
00050         // Create an object of the CUserInterface class.
00051         CUserInterface* interface = CUserInterface::NewL(console,entry);
00052         CleanupStack::PushL(interface);
00053 
00054         // Wait for a key press from the user.
00055         // Generate an asynchronous read request.
00056         interface->ReadFunc();
00057 
00058         // Start the active scheduler.
00059         CActiveScheduler::Start();
00060 
00061         // Destroy the objects in the cleanup stack.
00062         CleanupStack::PopAndDestroy(3,scheduler); // interface, entry, scheduler.
00063         }
00064 
00065 GLDEF_C TInt E32Main() // main function called by E32
00066     {
00067         __UHEAP_MARK;
00068         CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
00069         TRAPD(error, CallExampleL()); // more initialization, then do example
00070         delete cleanup; // destroy clean-up stack
00071         __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32EX, error));
00072         __UHEAP_MARKEND;
00073         return 0; // and return
00074     }
00075 
00076 LOCAL_C void CallExampleL() // initialize and call example code under cleanup stack
00077     {
00078         console=Console::NewL(KTxtExampleCode, TSize(KConsFullScreen, KConsFullScreen));
00079         CleanupStack::PushL(console);
00080         TRAPD(error, DoStartL()); // perform example function
00081         if (error)
00082                 console->Printf(KFormatFailed, error);
00083         else
00084                 console->Printf(KTxtOK);
00085         console->Printf(KTextPressAnyKey);
00086         console->Getch(); // get and ignore character
00087         CleanupStack::PopAndDestroy(); // close console
00088     }

Generated by  doxygen 1.6.2