|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : OpenCHelloGlibEventExHandler.cpp 00004 * Part of : Open C Hello World with Glib Events Example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2007 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #include "OpenCHelloGlibEventExHandler.h" 00017 #include <glib.h> 00018 00019 // ============================ MEMBER FUNCTIONS =============================== 00020 00021 // ----------------------------------------------------------------------------- 00022 // COpenCHelloGlibEventExHandler::NewL() 00023 // Static function to create an instance of COpenCHelloGlibEventExHandler using 00024 // 2-phase construction pattern 00025 // ----------------------------------------------------------------------------- 00026 // 00027 COpenCHelloGlibEventExHandler* COpenCHelloGlibEventExHandler::NewL(GMainContext* aMainContext) 00028 { 00029 COpenCHelloGlibEventExHandler* self = new(ELeave) COpenCHelloGlibEventExHandler(aMainContext); 00030 CleanupStack::PushL(self); 00031 self->ConstructL(); 00032 CleanupStack::Pop(); 00033 return self; 00034 } 00035 00036 00037 // ----------------------------------------------------------------------------- 00038 // COpenCHelloGlibEventExHandler::COpenCHelloGlibEventExHandler() 00039 // Constructor 00040 // ----------------------------------------------------------------------------- 00041 // 00042 COpenCHelloGlibEventExHandler::COpenCHelloGlibEventExHandler(GMainContext* aMainContext):CActive(EPriorityStandard) 00043 { 00044 iMainContext = aMainContext; 00045 } 00046 00047 00048 // ----------------------------------------------------------------------------- 00049 // COpenCHelloGlibEventExHandler::ConstructL() 00050 // Symbian 2nd phase constructor can leave. 00051 // ----------------------------------------------------------------------------- 00052 // 00053 void COpenCHelloGlibEventExHandler::ConstructL() 00054 { 00055 // Create a timer 00056 User::LeaveIfError(iTimer.CreateLocal()); 00057 00058 // Add the active object to the active scheduler 00059 CActiveScheduler::Add(this); 00060 } 00061 00062 00063 // ----------------------------------------------------------------------------- 00064 // COpenCHelloGlibEventExHandler::~COpenCHelloGlibEventExHandler() 00065 // Destructor 00066 // ----------------------------------------------------------------------------- 00067 // 00068 COpenCHelloGlibEventExHandler::~COpenCHelloGlibEventExHandler() 00069 { 00070 // Cancel any outstanding requests 00071 Cancel(); 00072 00073 // Close the timer 00074 iTimer.Close(); 00075 } 00076 00077 00078 // ----------------------------------------------------------------------------- 00079 // COpenCHelloGlibEventExHandler::Start() 00080 // Start the timer-based event handling 00081 // ----------------------------------------------------------------------------- 00082 // 00083 void COpenCHelloGlibEventExHandler::Start() 00084 { 00085 // start an asynchronous request 00086 iTimer.After(iStatus, TTimeIntervalMicroSeconds32(1000)); 00087 00088 // mark the active object as "active" 00089 SetActive(); 00090 } 00091 00092 00093 // ----------------------------------------------------------------------------- 00094 // COpenCHelloGlibEventExHandler::Stop() 00095 // Stop the timer-based event handling 00096 // ----------------------------------------------------------------------------- 00097 // 00098 void COpenCHelloGlibEventExHandler::Stop() 00099 { 00100 // cancel any outstanding requests 00101 Cancel(); 00102 } 00103 00104 00105 // ----------------------------------------------------------------------------- 00106 // COpenCHelloGlibEventExHandler::RunL() 00107 // Called by the active scheduler when the asynchronous request is complete 00108 // ----------------------------------------------------------------------------- 00109 // 00110 void COpenCHelloGlibEventExHandler::RunL() 00111 { 00112 // run one iteration of the event loop for the given context 00113 // (without blocking) 00114 g_main_context_iteration(iMainContext, FALSE); 00115 00116 // schedule the next asynchronous request 00117 iTimer.After(iStatus, TTimeIntervalMicroSeconds32(1000)); 00118 00119 // mark the active object as "active" 00120 SetActive(); 00121 } 00122 00123 00124 // ----------------------------------------------------------------------------- 00125 // COpenCHelloGlibEventExHandler::DoCancel() 00126 // Called as a result of Cancel() if there was a pending asynchronous request 00127 // ----------------------------------------------------------------------------- 00128 // 00129 void COpenCHelloGlibEventExHandler::DoCancel() 00130 { 00131 // Cancel the asynchronous request to the timer 00132 iTimer.Cancel(); 00133 } 00134 00135 // End of File
|
© Nokia 2009 |