examples/ForumNokia/Symbian_OS_Basics_Lab_Exercises_v3_1/Lab_04303.cb1/starter/src/SymbianOSBasicsLab.cpp

00001 // SymbianOSBasicsLab.cpp
00002 //
00003 // Copyright (c) 2003 Nokia Ltd.  All rights reserved.
00004 
00005 
00006 #include <e32cons.h>
00007 
00008 // Function prototype
00009 LOCAL_C void UseBasicTypesL();
00010 
00012 //
00013 // Main function called by E32
00014 //
00016 GLDEF_C TInt E32Main()
00017     {
00018 
00019     // Catch any Leaves thrown 
00020     TRAPD(error, UseBasicTypesL());
00021 
00022         _LIT(KMsgPanic,"Error in Symbian OS Basics Lab: ");
00023         __ASSERT_ALWAYS(!error, User::Panic(KMsgPanic, error));
00024 
00025         return 0;
00026     }
00027 
00028 
00030 //
00031 //
00032 //
00034 LOCAL_C void UseBasicTypesL() 
00035     {
00036     // Constant text used for the console app title 
00037         _LIT(KLabTitle,"Symbian OS Basics Lab");
00038     
00039     //
00040     // 'C' class usage:
00041     //
00042     // CConsoleBase derives from CBase and so should be declared on the heap
00043     // Console::NewL is a special way of doing this we will cover in the 
00044     // Memory and Resource Management lesson
00045     CConsoleBase* console = Console::NewL(KLabTitle, TSize(KConsFullScreen, KConsFullScreen));
00046 
00047     //
00048     // TInt usage
00049     //
00050     const TInt KOne = 1;
00051     const TInt KTwo = 2;
00052 
00053     // Edit 1: On the line below, declare a TInt called <sum> that adds KOne and KTwo
00054 
00055 
00056     _LIT(KSumOutput, "%d + %d is %d\n");
00057     // Edit 2: Uncomment the next line that prints the variables to the screen
00058     // console->Printf(KSumOutput, KOne, KTwo, sum);
00059 
00060     _LIT(KMaxIntOutput, "TInt max: %d\n");
00061     console->Printf(KMaxIntOutput, KMaxTInt);
00062 
00063     _LIT(KMinIntOutput, "TInt min: %d\n");
00064     console->Printf(KMinIntOutput, KMinTInt);
00065 
00066     //
00067     // TBool usage
00068     //
00069 
00070     // Edit 3: Declare a TBool called <flag> and initialize to EFalse
00071 
00072 
00073     // Edit 4: Uncomment the next 5 lines
00074     // if (!flag)
00075     //     {
00076     //     _LIT(KFlagFalse, "flag is EFalse\n");
00077     //     console->Printf(KFlagFalse);
00078     //     }
00079 
00080     // Edit 5: Toggle the value of <flag>
00081 
00082 
00083     // Edit 6: Uncomment the next 5 lines    
00084     // if (flag)
00085     //     {
00086     //     _LIT(KFlagTrue, "flag is ETrue\n");
00087     //     console->Printf(KFlagTrue);
00088     //     }
00089 
00090     //
00091     // enum (TKeyCode) and TText usage
00092     //
00093     _LIT(KEnterSpace, "Press space to start timer\n");
00094     console->Printf(KEnterSpace);
00095 
00096     // Look at key input
00097     TKeyCode key = console->Getch();
00098     while (EKeySpace != key)
00099         {
00100         _LIT(KCharVal, "Char entered is '%c'\n");
00101 
00102         // Edit 7: Delcare a TText called <keyVal> and set it to <key>.
00103         
00104 
00105 
00106         // Edit 8: Uncomment the next line
00107         // console->Printf(KCharVal, keyVal);
00108         key = console->Getch();
00109         }
00110 
00111     //
00112     // 'R' class usage
00113     //
00114     RTimer timer;
00115     if (KErrNone == timer.CreateLocal())
00116         {
00117         TRequestStatus status; // tracks the status of the request
00118         const TTimeIntervalMicroSeconds32 KTimerInterval = 5000000;
00119     
00120         // Edit 9: Uncomment next line to request timeout of 
00121         //          KTimerInterval micro seconds
00122         // timer.After(status, KTimerInterval); 
00123 
00124         // Edit 10: Uncomment next line to wait synchronously 
00125         //          for the timer to complete.
00126         // User::WaitForRequest(status);
00127 
00128         // Edit 11: Uncomment the next 2 lines that print to the screen
00129         // _LIT(KTimerComplete, "Timer completed after %d micro secs\n");
00130         // console->Printf(KTimerComplete, KTimerInterval );
00131         }
00132     else
00133         {
00134         _LIT(KTimerError, "Error creating timer\n");
00135         console->Printf(KTimerError);
00136         }
00137 
00138     timer.Close();
00139 
00140     // Continue
00141         _LIT(KMsgPressAnyKey,"Press any key to end");
00142         console->Printf(KMsgPressAnyKey);
00143         console->Getch();
00144     
00145     delete console;
00146     }
00147 
00148 
00149 
00150 

Generated by  doxygen 1.6.2