cl2appappui.cpp

Go to the documentation of this file.
00001 #include <aknnotedialog.h>
00002 #include <aknnotewrappers.h>
00003 #include <avkon.hrh>
00004 #include "cl2app.hrh"
00005 #include <cl2app.rsg>
00006 #include "cl2appappui.h"
00007 #include "cl2appcontainer.h"
00008 
00009 #include "client-run.h"
00010 #include "utils_cl2.h"
00011 
00012 #include "common/assertions.h"
00013 #include "er_errors.h"
00014 #include "common/logging.h"
00015 
00016 #define KEnableSkinFlag 0x1000
00017 #define KLayoutAwareFlag 0x08
00018 
00019 // Immediate process exit.
00020 extern "C" void ExitApplication()
00021 {
00022   logt("ExitApplication");
00023   // This should make sure that the process gets killed, assuming it
00024   // is the main process that calls this.
00025   User::Exit(KErrGeneral);
00026 }
00027 
00028 extern "C" void ShutdownApplication()
00029 {
00030   logt("ShutdownApplication");
00031 #if 0
00032   // Yes, a leave from an Exit() actually is possible, and we
00033   // typically get KErrNoSuitable core. This makes little sense unless
00034   // one knows that the app UI exit is actually implemented with a
00035   // leave as a non-local return. More info here:
00036   // http://developer.symbian.com/forum/thread.jspa?messageID=76366&#76366
00037   TRAPD(errCode,
00038   ((CCl2appAppUi*)(CEikonEnv::Static()->EikAppUi()))->Exit());
00039   logg("ShutdownApplication (%d)", errCode);
00040 #else
00041   // Exiting an application from a RunL is tricky, but luckily in S60
00042   // there is a facility that takes care of this difficulty. We can
00043   // just invoke RunAppShutter.
00044   ((CAknAppUi*)(CEikonEnv::Static()->EikAppUi()))->RunAppShutter();
00045 #endif
00046 }
00047 
00048 extern "C" void KillLogger()
00049 {
00050   logt("KillLogger");
00051   ((CCl2appAppUi*)(CEikonEnv::Static()->EikAppUi()))->DestroyLogger();
00052 }
00053 
00054 void CCl2appAppUi::DestroyLogger()
00055 {
00056   if (iClient) {
00057     kr_Controller_destroy(iClient);
00058     iClient = NULL;
00059     logt("logger killed");
00060   }
00061 }
00062 
00063 // This sort of thing is often required...
00064 static void DisplayText(TDesC const &aText)
00065 {
00066   CAknInformationNote *informationNote;
00067   (informationNote = new (ELeave) CAknInformationNote());
00068   informationNote->ExecuteLD(aText);
00069 }
00070 
00071 void CCl2appAppUi::ConstructL()
00072 {
00073   // This renaming code would not appear to be effective, according to
00074   // Y-Tasks. As a workaround, the CL2 watchdog supports both this
00075   // name and the default name. Possibly the name can be set for
00076   // programs that are not applications (in the application framework
00077   // sense).
00078   COMPONENT_NAME_LIT(KProcessName); //_LIT(KProcessName, "cl2app");
00079   // Return value undocumented, assuming error code.
00080   User::LeaveIfError(RProcess().RenameMe(KProcessName));
00081 
00082 #ifdef __SERIES60_3X__
00083   BaseConstructL(EAknEnableSkin);
00084 #else
00085   BaseConstructL(KEnableSkinFlag | KLayoutAwareFlag);
00086 #endif
00087 
00088   iAppContainer = new (ELeave) CCl2appContainer;
00089   iAppContainer->SetMopParent( this );
00090   iAppContainer->ConstructL( ClientRect() );
00091   AddToStackL( iAppContainer );
00092 
00093 #if 0
00094   CCoeEnv* coeEnv = CCoeEnv::Static();
00095   assert(coeEnv && "CCoeEnv not set yet");
00096 #endif
00097 
00098   // initializes logging, too
00099   if (cl2GlobalInit()) {
00100     _LIT(KInitErrMsg, "Global init failed");
00101     DisplayText(KInitErrMsg);
00102     return;
00103   }
00104   logt("global init complete");
00105 
00106   // Invokes AppContextReady upon completion.
00107   ac_AppContext_PlatInitAsyncL(ac_get_global_AppContext(), *this);
00108 }
00109 
00110 void CCl2appAppUi::AppContextReady(TInt aError)
00111 {
00112   logt("app context ready");
00113 
00114   if (aError) {
00115     er_log_symbian(er_FATAL, aError, "error in app ctx async init");
00116     return; // not reached
00117   }
00118 
00119   //cl_lua_eval_string("do x = \"hello world\"; return x end");
00120 
00121   {
00122     GError* localError = NULL;
00123     iClient = kr_Controller_new(&localError);
00124     logg("client init %s", iClient ? "ok" : "failed");
00125     if (!iClient) {
00126       er_log_gerror(er_FATAL|er_FREE, localError, "error in client creation");
00127       return; // not reached
00128     }
00129   }
00130 
00131   logg("scheduler running %d", (CEikonEnv::Static()->IsSchedulerRunning()) ? 1 : 0);
00132 
00133   Start();
00134 }
00135 
00136 CCl2appAppUi::~CCl2appAppUi()
00137 {
00138   logt("clean application exit in progress");
00139 
00140   if (iAppContainer)
00141     {
00142       RemoveFromStack(iAppContainer);
00143       delete iAppContainer;
00144     }
00145 
00146   DestroyLogger();
00147 
00148   cl2GlobalCleanup();
00149 }
00150 
00151 void CCl2appAppUi::DynInitMenuPaneL(TInt /*aResourceId*/, 
00152            CEikMenuPane* /*aMenuPane*/)
00153 {
00154 }
00155 
00156 TKeyResponse CCl2appAppUi::HandleKeyEventL
00157 (const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
00158 {
00159   return EKeyWasNotConsumed;
00160 }
00161 
00162 void CCl2appAppUi::Start()
00163 {
00164   if (!iClient) return;
00165 
00166   GError* localError = NULL;
00167   if (!kr_Controller_start(iClient, &localError)) {
00168     gx_txtlog_error_free(localError);
00169     _LIT(msg, "failed to start");
00170     DisplayText(msg);
00171   } else {
00172     /*
00173     _LIT(msg, "started");
00174     DisplayText(msg);
00175     */
00176   }
00177 }
00178 
00179 void CCl2appAppUi::Stop()
00180 {
00181   if (!iClient) return;
00182   kr_Controller_stop(iClient);
00183   /*
00184     _LIT(msg, "stopped");
00185     DisplayText(msg);
00186   */
00187 }
00188 
00189 void CCl2appAppUi::HandleCommandL(TInt aCommand)
00190 {
00191   switch (aCommand)
00192     {
00193     case EAknSoftkeyBack:
00194     case EAknSoftkeyExit:
00195     case EEikCmdExit:
00196       {
00197   Exit();
00198   break;
00199       }
00200     case ECl2appCmdOneMenuCommand:
00201       {
00202   /*
00203   TBuf<50> buf;
00204   _LIT(fmt, "value is %d");
00205   buf.Format(fmt, 555);
00206   DisplayText(buf);
00207   */
00208   //Start();
00209   break;
00210       }
00211     case ECl2appCmdAnotherMenuCommand:
00212       {
00213   //Stop();
00214   break;
00215       }
00216     default:
00217       break;
00218     }
00219 }
00220 
00221 /**
00222 
00223 cl2appappui.cpp
00224 
00225 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00226 and the authors. All rights reserved.
00227 
00228 Authors: Tero Hasu <tero.hasu@hut.fi>
00229 
00230 Permission is hereby granted, free of charge, to any person
00231 obtaining a copy of this software and associated documentation files
00232 (the "Software"), to deal in the Software without restriction,
00233 including without limitation the rights to use, copy, modify, merge,
00234 publish, distribute, sublicense, and/or sell copies of the Software,
00235 and to permit persons to whom the Software is furnished to do so,
00236 subject to the following conditions:
00237 
00238 The above copyright notice and this permission notice shall be
00239 included in all copies or substantial portions of the Software.
00240 
00241 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00242 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00243 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00244 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00245 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00246 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00247 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00248 SOFTWARE.
00249 
00250  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1