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 // Demonstrates the pure event distribution pattern of publishing an integer property 00015 // 00016 00017 00018 00023 #include "publishpe.h" 00024 00025 LOCAL_D CConsoleBase* console; 00026 00027 void DoExampleL() 00028 { 00029 console->Printf(KTxtPEPublish); 00030 RProperty myProperty; 00031 00032 // Define the property and create a handle to it 00033 User::LeaveIfError(RProperty::Define(KMyPropertyCat, KMyPropertyName,RProperty::EInt,KAllowAllPolicy,KAllowAllPolicy)); 00034 User::LeaveIfError(myProperty.Attach(KMyPropertyCat,KMyPropertyName,EOwnerThread)); 00035 00036 // The value of the property 00037 TInt value; 00038 00039 // Publish the property after every 3 seconds 00040 for(TInt ix = 0; ix <= KMax ; ix += 20) 00041 { 00042 User::After(KTimeInterval); 00043 // Publish random values 00044 // In the pure event pattern of publishing, the value of the property is insignificant 00045 // Multiple publishing is only to let the subscriber know that an event has occurred 00046 value = Math::Random(); 00047 console->Printf(KTxtInt,value); 00048 User::LeaveIfError(myProperty.Set(value)); 00049 } 00050 00051 // Free the handle to the property 00052 myProperty.Close(); 00053 00054 // The publisher has finished so delete the property 00055 User::LeaveIfError(RProperty::Delete(KMyPropertyCat,KMyPropertyName)); 00056 } 00057 00058 GLDEF_C TInt E32Main() 00059 { 00060 __UHEAP_MARK; 00061 CTrapCleanup* cleanup = CTrapCleanup::New(); 00062 00063 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen))); 00064 if (createError) 00065 return createError; 00066 00067 TRAPD(mainError, DoExampleL()); 00068 if (mainError) 00069 console->Printf(KTextFailed, mainError); 00070 console->Printf(KTextPressAnyKey); 00071 console->Getch(); 00072 00073 delete console; 00074 delete cleanup; 00075 __UHEAP_MARKEND; 00076 return KErrNone; 00077 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.