00001 #include <exception> // for uncaught exception (keep this first) 00002 00003 #include "window_demo_qt.hpp" 00004 00005 #include "application_config.h" 00006 #include "ac_app_context_private.h" 00007 #include "guilog.h" 00008 #include "kr_controller.h" 00009 #include "client-run.h" 00010 #include "epoc-ao-gerror.hpp" 00011 #include "er_errors.h" 00012 00013 #include "common/utilities.h" 00014 00015 #include <e32std.h> 00016 #include <e32base.h> 00017 00018 #include <estlib.h> // __crt0 00019 00020 #include <QApplication> 00021 #include <QDebug> 00022 #include <QObject> 00023 00024 #include <QtGlobal> 00025 00026 #include <stdio.h> 00027 00028 // -------------------------------------------------- 00029 // exit functions 00030 // -------------------------------------------------- 00031 00032 // Immediate process exit. 00033 extern "C" void ExitApplication() 00034 { 00035 logt("ExitApplication"); 00036 User::Exit(KErrGeneral); 00037 } 00038 00039 // Orderly shutdown. This is only done via a Lua binding, and there it 00040 // is useful to be able to send a response before exiting, hence a 00041 // proper shutdown. 00042 extern "C" void ShutdownApplication() 00043 { 00044 logt("ShutdownApplication"); 00045 QApplication::quit(); 00046 } 00047 00048 // -------------------------------------------------- 00049 // MainObj 00050 // -------------------------------------------------- 00051 00052 NONSHARABLE_CLASS(CMainObj) : 00053 public CBase, 00054 public MAppContextInitObserver 00055 { 00056 public: 00057 static CMainObj* NewL(); 00058 ~CMainObj(); 00059 private: 00060 void ConstructL(); 00061 private: // MAppContextInitObserver 00062 void AppContextReady(TInt aError); 00063 private: 00064 kr_Controller* controller; 00065 }; 00066 00067 CMainObj* CMainObj::NewL() 00068 { 00069 CMainObj* obj = new (ELeave) CMainObj; 00070 CleanupStack::PushL(obj); 00071 obj->ConstructL(); 00072 CleanupStack::Pop(obj); 00073 return obj; 00074 } 00075 00076 CMainObj::~CMainObj() 00077 { 00078 if (controller) { 00079 logt("destroying controller"); 00080 kr_Controller_destroy(controller); 00081 logt("controller destroyed"); 00082 } 00083 } 00084 00085 void CMainObj::ConstructL() 00086 { 00087 // Invokes AppContextReady upon completion. 00088 ac_AppContext_PlatInitAsyncL(ac_get_global_AppContext(), *this); 00089 } 00090 00091 void CMainObj::AppContextReady(TInt aError) 00092 { 00093 logt("app context ready"); 00094 00095 if (aError) { 00096 er_log_symbian(er_FATAL, aError, "error in app ctx async init"); 00097 return; // not reached 00098 } 00099 00100 GError* localError = NULL; 00101 00102 controller = kr_Controller_new(&localError); 00103 if (!controller) { 00104 er_log_gerror(er_FATAL|er_FREE, localError, "error in controller creation"); 00105 return; // not reached 00106 } 00107 00108 if (!kr_Controller_start(controller, &localError)) { 00109 er_log_gerror(er_FATAL|er_FREE, localError, "error starting controller"); 00110 return; // not reached 00111 } 00112 } 00113 00114 // -------------------------------------------------- 00115 // E32Main 00116 // -------------------------------------------------- 00117 00118 // May throw exceptions, but not leave. 00119 static TInt QtMainE(int argc, char *argv[], char *envp[]) 00120 { 00121 // This seems a fairly heavy-duty class. It may be unsafe to try to 00122 // do anything really after it gets destroyed. Hence we complete 00123 // cleanup for CL2 engine before letting it fall out of scope. 00124 QApplication app(argc, argv); 00125 00126 TInt errCode = 0; 00127 CMainObj* mainObj = NULL; 00128 00129 MainWindow w; 00130 00131 // Creates application context. 00132 errCode = cl2GlobalInit(); 00133 if (errCode) { 00134 logt("error in global init"); 00135 goto gifail; 00136 } 00137 00138 logg("compiled against Qt %s", QT_VERSION_STR); 00139 logg("running with Qt %s", qVersion()); 00140 00141 logg("argc is %d", argc); 00142 for (int i=0; i<argc; i++) 00143 logg("arg %d is '%s'", i, argv[i]); 00144 00145 // Handles async initialization tasks. If and when those complete, 00146 // the controller is created and set up with things to do. 00147 TRAP(errCode, mainObj = CMainObj::NewL()); 00148 if (errCode) { 00149 logt("error creating main object"); 00150 goto mofail; 00151 } 00152 00153 // Get rid of the "Actions" menu item. 00154 { 00155 QWidgetList widgets = QApplication::allWidgets(); 00156 QWidget* wdg = 0; 00157 foreach(wdg, widgets) { 00158 wdg->setContextMenuPolicy(Qt::NoContextMenu); 00159 } 00160 } 00161 00162 guilog(__APP_NAME__); 00163 guilogf("variant %s", __VARIANT_NAME__); 00164 guilogf("version %s", __VERSION_STRING__); 00165 guilogf("capas %s", __CERT_NAME__); 00166 guilogf("compiled against Qt %s", QT_VERSION_STR); 00167 guilogf("running with Qt %s", qVersion()); 00168 guilog("Welcome."); 00169 w.showMaximized(); 00170 00171 // This invokation actually runs the controller in an event loop. 00172 try { 00173 errCode = qApp->exec(); 00174 logg("qApp->exec() returned with %d", errCode); 00175 } catch (const std::exception &ex) { 00176 logg("Qt error exception: %s", ex.what()); 00177 errCode = qt_symbian_exception2Error(ex); 00178 } 00179 00180 // Deletes controller. 00181 delete mainObj; 00182 00183 mofail: 00184 // Deletes application context. 00185 cl2GlobalCleanup(); 00186 00187 gifail: 00188 logg("exit code %d", errCode); 00189 return errCode; 00190 } 00191 00192 static TInt QtMainWrapper() 00193 { 00194 // These must persist for as long as QApplication does. 00195 int argc = 0; 00196 char **argv = 0; 00197 char **envp = 0; 00198 __crt0(argc, argv, envp); 00199 TRAPD(errCode, QT_TRYCATCH_LEAVING(errCode = QtMainE(argc, argv, envp);)); 00200 delete[] argv; 00201 delete[] envp; 00202 return errCode; 00203 } 00204 00205 GLDEF_C TInt E32Main() 00206 { 00207 CTrapCleanup *cleanupStack = q_check_ptr(CTrapCleanup::New()); 00208 TRAPD(errCode, errCode = QtMainWrapper()); 00209 delete cleanupStack; 00210 return errCode; 00211 } 00212 00213 /** 00214 00215 Copyright 2011 Helsinki Institute for Information Technology (HIIT) 00216 and the authors. All rights reserved. 00217 00218 Authors: Tero Hasu <tero.hasu@hut.fi> 00219 00220 Permission is hereby granted, free of charge, to any person 00221 obtaining a copy of this software and associated documentation files 00222 (the "Software"), to deal in the Software without restriction, 00223 including without limitation the rights to use, copy, modify, merge, 00224 publish, distribute, sublicense, and/or sell copies of the Software, 00225 and to permit persons to whom the Software is furnished to do so, 00226 subject to the following conditions: 00227 00228 The above copyright notice and this permission notice shall be 00229 included in all copies or substantial portions of the Software. 00230 00231 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00232 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00233 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00234 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00235 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00236 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00237 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00238 SOFTWARE. 00239 00240 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:55 2011 by Doxygen 1.6.1