appfw/apparchitecture/tef/ChildIII_Main.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // A simple application containing a single view with the text "Child III !" drawn on it.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent - Internal Symbian test code
       
    21 */
       
    22 
       
    23 #include <coeccntx.h>
       
    24 
       
    25 #include <eikenv.h>
       
    26 #include <eikappui.h>
       
    27 #include <eikapp.h>
       
    28 #include <eikdoc.h>
       
    29 #include <techview/eikmenup.h>
       
    30 
       
    31 #include <techview/eikon.hrh>
       
    32 #include <f32file.h>
       
    33 
       
    34 #include <childiii.rsg>
       
    35 #include "ChildIII.hrh"
       
    36 
       
    37 
       
    38 #include <eikstart.h>
       
    39 _LIT(KFilePath,"c:\\logs\\TestExecute\\Proc.txt");
       
    40 _LIT8(KTPass, "PASS");
       
    41 _LIT8(KTFail, "FAIL");
       
    42 
       
    43 //
       
    44 //
       
    45 // CExampleAppView
       
    46 //
       
    47 //
       
    48 
       
    49 class CExampleAppView : public CCoeControl
       
    50     {
       
    51 public:
       
    52 	static CExampleAppView* NewL(const TRect& aRect);
       
    53 	CExampleAppView();
       
    54 	~CExampleAppView();
       
    55     void ConstructL(const TRect& aRect);
       
    56 
       
    57 private:
       
    58 	           // Inherited from CCoeControl
       
    59 	void Draw(const TRect& /*aRect*/) const;
       
    60 
       
    61 private:
       
    62 	HBufC*  iExampleText;
       
    63     };
       
    64 
       
    65 //
       
    66 //             Constructor for the view.
       
    67 //
       
    68 CExampleAppView::CExampleAppView()
       
    69 	{
       
    70 	}
       
    71 
       
    72 //             Static NewL() function to start the standard two
       
    73 //             phase construction.
       
    74 //
       
    75 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
       
    76 	{
       
    77 	CExampleAppView* self = new(ELeave) CExampleAppView();
       
    78 	CleanupStack::PushL(self);
       
    79 	self->ConstructL(aRect);
       
    80 	CleanupStack::Pop();
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 //
       
    85 //             Destructor for the view.
       
    86 //
       
    87 CExampleAppView::~CExampleAppView()
       
    88 	{
       
    89 	delete iExampleText;
       
    90 	}
       
    91 
       
    92 //             Second phase construction.
       
    93 //
       
    94 void CExampleAppView::ConstructL(const TRect& aRect)
       
    95     {
       
    96 			   // Fetch the text from the resource file.
       
    97 	iExampleText = iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_CHILDIII);
       
    98 	           // Control is a window owning control
       
    99 	CreateWindowL();
       
   100 	           // Extent of the control. This is
       
   101 	           // the whole rectangle available to application.
       
   102 	           // The rectangle is passed to us from the application UI.
       
   103 	SetRect(aRect);
       
   104 			   // At this stage, the control is ready to draw so
       
   105 	           // we tell the UI framework by activating it.
       
   106 	ActivateL();
       
   107 	}
       
   108 
       
   109 
       
   110 //             Drawing the view - in this example, 
       
   111 //             consists of drawing a simple outline rectangle
       
   112 //             and then drawing the text in the middle.
       
   113 //             We use the Normal font supplied by the UI.
       
   114 //
       
   115 //             In this example, we don't use the redraw
       
   116 //             region because it's easier to redraw to
       
   117 //             the whole client area.
       
   118 //
       
   119 void CExampleAppView::Draw(const TRect& /*aRect*/) const
       
   120 	{
       
   121                // Window graphics context
       
   122 	CWindowGc& gc = SystemGc();
       
   123 	           // Area in which we shall draw
       
   124 	TRect      drawRect = Rect();
       
   125 			   // Font used for drawing text
       
   126 	const CFont*     fontUsed;
       
   127 	
       
   128 	           // Start with a clear screen
       
   129 	gc.Clear();
       
   130 			   // Draw an outline rectangle (the default pen
       
   131 	           // and brush styles ensure this) slightly
       
   132 	           // smaller than the drawing area.
       
   133 	drawRect.Shrink(10,10);		   	
       
   134 	gc.DrawRect(drawRect);
       
   135                // Use the title font supplied by the UI
       
   136 	fontUsed = iEikonEnv->TitleFont();
       
   137 	gc.UseFont(fontUsed);
       
   138 			   // Draw the text in the middle of the rectangle.
       
   139 	TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
       
   140 	gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
       
   141                // Finished using the font
       
   142 	gc.DiscardFont();
       
   143 	}
       
   144 
       
   145 //
       
   146 //
       
   147 // CExampleAppUi
       
   148 //
       
   149 //
       
   150 
       
   151 class CExampleAppUi : public CEikAppUi
       
   152     {
       
   153 public:
       
   154     void ConstructL();
       
   155 	TBool ProcessCommandParametersL(CApaCommandLine& aCommandLine);
       
   156 	//void PrepareToExit();
       
   157 	void CompParentPidL(void);
       
   158 	~CExampleAppUi();
       
   159 
       
   160 private:
       
   161               // Inherirted from class CEikAppUi
       
   162 	void HandleCommandL(TInt aCommand);
       
   163 
       
   164 private:
       
   165 	CCoeControl* iAppView;
       
   166 	TProcessId iParentProcessId;
       
   167 	RFile iFile;
       
   168 	RFs iFs;
       
   169 	};
       
   170 
       
   171 //             The second phase constructor of the application UI class.
       
   172 //             The application UI creates and owns the one and only view.
       
   173 // 
       
   174 void CExampleAppUi::ConstructL()
       
   175     {
       
   176 	           // BaseConstructL() completes the UI framework's
       
   177 	           // construction of the App UI.
       
   178     BaseConstructL();
       
   179 	           // Create the single application view in which to
       
   180 	           // draw the text "Child III", passing into it
       
   181 	           // the rectangle available to it.
       
   182 	iAppView = CExampleAppView::NewL(ClientRect());
       
   183 	}
       
   184 
       
   185 //             The app Ui owns the two views and is. 
       
   186 //             therefore, responsible for destroying them
       
   187 //
       
   188 CExampleAppUi::~CExampleAppUi()
       
   189 	{
       
   190 	delete iAppView;
       
   191 	}
       
   192 
       
   193 //             Called by the UI framework when a command has been issued.
       
   194 //             In this example, a command can originate through a 
       
   195 //             hot-key press or by selection of a menu item.
       
   196 //             The command Ids are defined in the .hrh file
       
   197 //             and are 'connected' to the hot-key and menu item in the
       
   198 //             resource file.
       
   199 //             Note that the EEikCmdExit is defined by the UI
       
   200 //             framework and is pulled in by including eikon.hrh
       
   201 //
       
   202 void CExampleAppUi::HandleCommandL(TInt aCommand)
       
   203 	{
       
   204 	switch (aCommand)
       
   205 		{
       
   206 		      // Just issue simple info messages to show that
       
   207 		      // the menu items have been selected
       
   208 	case EExampleItem0:
       
   209 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM0);
       
   210 		break;
       
   211 
       
   212 	
       
   213 	case EExampleItem1:
       
   214 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM1);
       
   215 		break;
       
   216 	
       
   217 	case EExampleItem2:
       
   218 		iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM2);
       
   219 		break;
       
   220                // Exit the application. The call is
       
   221 		       // implemented by the UI framework.
       
   222 
       
   223 	case EEikCmdExit: 
       
   224 		Exit();
       
   225 		break;
       
   226 		}
       
   227 	}
       
   228 
       
   229 TBool CExampleAppUi::ProcessCommandParametersL(CApaCommandLine& aCommandLine)
       
   230 	{
       
   231 	iParentProcessId=aCommandLine.ParentProcessId();
       
   232 	CompParentPidL();
       
   233 	return CEikAppUi::ProcessCommandParametersL(aCommandLine);
       
   234 	}
       
   235 
       
   236 
       
   237 void CExampleAppUi::CompParentPidL()
       
   238 	{
       
   239 	TInt val;
       
   240 	TInt ret;
       
   241 	ret = User::GetTIntParameter(12, val);
       
   242 	if(ret == KErrNone)
       
   243 		{
       
   244 		User::LeaveIfError(iFs.Connect());
       
   245 		TInt err = iFile.Create(iFs,KFilePath,EFileWrite | EFileShareAny);
       
   246 		if(err == KErrAlreadyExists)
       
   247 			{
       
   248 			iFile.Open(iFs,KFilePath,EFileWrite | EFileShareAny);
       
   249 			}
       
   250 
       
   251 		if(val == iParentProcessId.Id())
       
   252 			{
       
   253 			iFile.Write(KTPass);	
       
   254 			}
       
   255 		else
       
   256 			{
       
   257 			iFile.Write(KTFail);
       
   258 			}
       
   259 		iFile.Close();
       
   260 		iFs.Close();
       
   261 		}
       
   262 	}
       
   263 
       
   264 //
       
   265 //
       
   266 // CExampleDocument
       
   267 //
       
   268 //
       
   269 class CExampleDocument : public CEikDocument
       
   270 	{
       
   271 public:
       
   272 	static CExampleDocument* NewL(CEikApplication& aApp);
       
   273 	CExampleDocument(CEikApplication& aApp);
       
   274 	void ConstructL();
       
   275 private: 
       
   276 	           // Inherited from CEikDocument
       
   277 	CEikAppUi* CreateAppUiL();
       
   278 	};
       
   279 
       
   280 //             The constructor of the document class just passes the
       
   281 //             supplied reference to the constructor initialisation list.
       
   282 //             The document has no real work to do in this application.
       
   283 //
       
   284 CExampleDocument::CExampleDocument(CEikApplication& aApp)
       
   285 		: CEikDocument(aApp)
       
   286 	{
       
   287 	}
       
   288 
       
   289 
       
   290 //             This is called by the UI framework as soon as the 
       
   291 //             document has been created. It creates an instance
       
   292 //             of the ApplicationUI. The Application UI class is
       
   293 //             an instance of a CEikAppUi derived class.
       
   294 //
       
   295 CEikAppUi* CExampleDocument::CreateAppUiL()
       
   296 	{
       
   297     return new(ELeave) CExampleAppUi;
       
   298 	}
       
   299 
       
   300 //
       
   301 //
       
   302 // CExampleApplication
       
   303 //
       
   304 //
       
   305 
       
   306 class CExampleApplication : public CEikApplication
       
   307 	{
       
   308 private: 
       
   309 	           // Inherited from class CApaApplication
       
   310 	CApaDocument* CreateDocumentL();
       
   311 	TUid AppDllUid() const;
       
   312 	};
       
   313 
       
   314 const TUid KUidChildIII = { 0x10207f86 }; 
       
   315 
       
   316 //             The function is called by the UI framework to ask for the
       
   317 //             application's UID. The returned value is defined by the
       
   318 //             constant KUidChildIIIe and must match the second value
       
   319 //             defined in the project definition file.
       
   320 // 
       
   321 TUid CExampleApplication::AppDllUid() const
       
   322 	{
       
   323 	return KUidChildIII;
       
   324 	}
       
   325 
       
   326 //             This function is called by the UI framework at
       
   327 //             application start-up. It creates an instance of the
       
   328 //             document class.
       
   329 //
       
   330 
       
   331 CApaDocument* CExampleApplication::CreateDocumentL()
       
   332 	{
       
   333 	return new (ELeave) CExampleDocument(*this);
       
   334 	}
       
   335 //             The entry point for the application code. It creates
       
   336 //             an instance of the CApaApplication derived
       
   337 //             class, CExampleApplication.
       
   338 //
       
   339 
       
   340 LOCAL_C CApaApplication* NewApplication()
       
   341 	{
       
   342 	return new CExampleApplication;
       
   343 	}
       
   344 	
       
   345 GLDEF_C TInt E32Main()
       
   346 	{
       
   347 	return EikStart::RunApplication(NewApplication);
       
   348 	}