diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/condvarlocal_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/condvarlocal_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,121 @@ + + + + +TB9.2 Example Applications: examples/Base/IPC/condvar/condvarlocal/src/condvarlocal.cpp Source File + + + + + +

examples/Base/IPC/condvar/condvarlocal/src/condvarlocal.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+00002 // All rights reserved.
+00003 // This component and the accompanying materials are made available
+00004 // under the terms of "Eclipse Public License v1.0"
+00005 // which accompanies this distribution, and is available
+00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00007 //
+00008 // Initial Contributors:
+00009 // Nokia Corporation - initial contribution.
+00010 //
+00011 // Contributors:
+00012 //
+00013 // Description:
+00014 // Contains the E32Main() function, which executes the example.
+00015 // The example demonstrates the use of local condition variable IPC mechanism. The threads created in the process use this condition variable to co-operate with each other.
+00016 // The example performs the following tasks:
+00017 // - create an object of the CQueue class, which in turn crates a queue of integer tokens
+00018 // - create an object of the CProducer class, which in turn creates the producer thread
+00019 // - create an object of the CConsumer class, which in turn creates the consumer thread
+00020 // - create an object of the CUserInterface class ,which accepts asynchronous key press events from the console.
+00021 // The CUserInterface class provides an interface for the user to interact with the threads created in the example.
+00022 // The CQueue::iCondVar is the local condition varaibale that is used by the two threads to co-operate with each other.
+00023 //
+00024 
+00025 
+00026 
+00035 #include "globals.h"
+00036 #include "queue.h"
+00037 #include "producer.h"
+00038 #include "consumer.h"
+00039 #include "userinterface.h"
+00040 
+00041 LOCAL_D CConsoleBase* console;
+00042 LOCAL_C void DoExampleL();
+00043 LOCAL_C void callExampleL();
+00044 
+00045 LOCAL_C void DoExampleL()
+00046         {
+00047         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
+00048         CleanupStack::PushL(scheduler);
+00049         CActiveScheduler::Install(scheduler);
+00050 
+00051         // Create an object of the CQueue class.
+00052         CQueue* tokens = CQueue::NewL();
+00053         CleanupStack::PushL(tokens);
+00054 
+00055         // Print the KTextInvokeProducer string and wait for a key press.
+00056         _LIT(KTextInvokeProducer,"Creating and starting the Producer Thread...[This produces a token every two seconds]\n");
+00057         console->Printf(KTextInvokeProducer);
+00058         _LIT(KTxtPressAnyKeyToContinue,"[press any key to continue]\n");
+00059         console->Printf(KTxtPressAnyKeyToContinue);
+00060         console->Getch();
+00061         // Create an object of the CProducer class.
+00062         CProducer* prod = CProducer::NewL(console,tokens);
+00063         CleanupStack::PushL(prod);
+00064 
+00065         // Print the KTextInvokeConsumer string and wait for a key press.
+00066         _LIT(KTextInvokeConsumer,"Creating and starting the Consumer Thread...[This consumes a token every second]\n");
+00067         console->Printf(KTextInvokeConsumer);
+00068         console->Printf(KTxtPressAnyKeyToContinue);
+00069         console->Getch();
+00070 
+00071         // Create an object of the CConsumer class.
+00072         CConsumer* cons = CConsumer::NewL(console,tokens);
+00073         CleanupStack::PushL(cons);
+00074 
+00075         // Create an object of the CUserInterface class.
+00076         // This handles key press requests from the console.
+00077         CUserInterface* ui = CUserInterface::NewL(console,prod);
+00078         CleanupStack::PushL(ui);
+00079         
+00080         _LIT(KTextStartAS,"Starting the active scheduler...\n");
+00081         console->Printf(KTextStartAS);
+00082         // Issue an asynchronous read request.
+00083         ui->ReadFunc();
+00084         // Start the active scheduler.
+00085         CActiveScheduler::Start();
+00086 
+00087         CleanupStack::PopAndDestroy(5,scheduler);
+00088         }
+00089 
+00090 GLDEF_C TInt E32Main()
+00091     {
+00092         __UHEAP_MARK;
+00093         CTrapCleanup* cleanup=CTrapCleanup::New();
+00094         TRAPD(error,callExampleL());
+00095         delete cleanup;
+00096         __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
+00097         __UHEAP_MARKEND;
+00098         return 0;
+00099     }
+00100 
+00101 LOCAL_C void callExampleL()
+00102     {
+00103         console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
+00104         CleanupStack::PushL(console);
+00105         TRAPD(error,DoExampleL());
+00106         if (error)
+00107                 console->Printf(KFormatFailed, error);
+00108         else
+00109                 console->Printf(KTxtOK);
+00110         console->Printf(KTxtPressAnyKey);
+00111         console->Getch();
+00112         CleanupStack::PopAndDestroy();
+00113     }
+
+
Generated by  + +doxygen 1.6.2
+ +