examples/Base/ThreadsAndProcesses/TLS1/TLS1exe.cpp

00001 //TLS1exe.cpp
00002 
00003 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
00004 // All rights reserved.
00005 // This component and the accompanying materials are made available
00006 // under the terms of "Eclipse Public License v1.0"
00007 // which accompanies this distribution, and is available
00008 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00009 //
00010 // Initial Contributors:
00011 // Nokia Corporation - initial contribution.
00012 //
00013 // Contributors:
00014 //
00015 // Description:
00016 // An example to demonstrate Thread Local Storage (TLS)
00017 // (See also the DLL implementation in TLS1dll.cpp)
00018 //
00019 
00020         // standard example header
00021 #include "CommonFramework.h"
00022         // dll header file
00023 #include "TLS1dll.h"
00024 
00025 //
00026 // Common literal text
00027 //
00028 
00029 _LIT(KTxtNewLines,"\n\n");
00030 
00031 
00032         // This function uses a statically loaded DLL to create a new CSetter object.
00033         // It then uses this object to set up some static data accessed through 
00034     // thread-local storage.
00035         // Thex example then shows how the static data can be accessed through
00036         // the member functions of another class (CGeneral).
00037         // All implementation code for these two classes is provided in the DLL
00038 LOCAL_C void doExampleL()
00039     {
00040                 // Introduction
00041         _LIT(KTxtIntro,"Thread local storage example (1) \n\n");
00042         console->Printf(KTxtIntro);
00043         
00044                 // Construct CSetter object, set up some static data via the
00045                 // thread local storage and use CSetter to show it.
00046         CSetter* theSetter = new (ELeave) CSetter(*console);
00047         CleanupStack::PushL(theSetter);
00048         
00049         _LIT(KTxt1,"SOME STATIC TEXT");
00050         theSetter->SetStaticTextL(KTxt1);
00051         _LIT(KTxt2,"Static data set by CSetter object\n");
00052         console->Printf(KTxt2);
00053         _LIT(KTxt3,"Static data displayed by CSetter object...\n");
00054         console->Printf(KTxt3);
00055         theSetter->ShowStaticText();
00056 
00057                 // Construct a CGeneral object and see that it can show 
00058             // this static data. CGeneral knows nothing about the CSetter object
00059         CGeneral* theGeneral = new  (ELeave) CGeneral(*console);
00060         CleanupStack::Pop();
00061         _LIT(KTxt4,"Static data now accessed by CGeneral object...\n");
00062         console->Printf(KTxt4);
00063         theGeneral->ShowStaticText();
00064         console->Printf(KTxtNewLines);
00065 
00066                 // Delete the CSetter object and then use the CGeneral object to
00067             // try and show static data - there should be none.
00068         delete theSetter;
00069         _LIT(KTxt5,"Static data accessed again by CGeneral object after deletion of data...\n");
00070         console->Printf(KTxt5);
00071         theGeneral->ShowStaticText();
00072         console->Printf(KTxtNewLines);
00073 
00074                 // tidy up before finishing the example
00075         delete theGeneral;
00076         }
00077 
00078 

Generated by  doxygen 1.6.2