diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/publishstd_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/publishstd_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,147 @@ + +
+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 standard state pattern of publishing a byte-array property +00015 // +00016 +00017 +00018 +00023 #include "publish.h" +00024 +00025 LOCAL_D CConsoleBase* console; +00026 +00032 void PublishL(RProperty& aProperty,TDes16& aBuf) +00033 { +00034 console->Printf(KTxtPublish); +00035 +00036 // Publish the property +00037 // Failure to publish values in standard state publishing pattern is treated as a serious error +00038 User::LeaveIfError(aProperty.Set(aBuf)); +00039 console->Printf(KTxtArray); +00040 +00041 // Print the value of the byte-array +00042 TInt bufLength = aBuf.Length(); +00043 for(TInt ix = 0; ix < bufLength; ix++) +00044 { +00045 console->Printf(KTxtArrayElement,aBuf[ix]); +00046 } +00047 console->Printf(KTxtNewLine); +00048 } +00049 +00050 void DoExampleL() +00051 { +00052 console->Printf(KTxtStPublish); +00053 console->Printf(KTxtDefine); +00054 +00055 // Define and pre-allocate memory to the byte-array property +00056 RProperty::Define(KMyPropertyCat, KMyPropertyName,RProperty::EByteArray,KAllowAllPolicy,KAllowAllPolicy,KArraySize); +00057 RProperty myProperty; +00058 // Create a handle to the property +00059 User::LeaveIfError(myProperty.Attach(KMyPropertyCat,KMyPropertyName,EOwnerThread)); +00060 console->Printf(KTxtCreateHandle); +00061 +00062 // Byte-Array property value to be published +00063 TUint16 array[KArraySize] = {10,20,30,40}; +00064 +00065 // Descriptor that the array contents are copied into +00066 TBuf16<KBufSize> buf; +00067 +00068 // Copy array contents into the descriptor +00069 buf.Copy(&array[0],sizeof(array)); +00070 buf.SetLength(KArraySize); +00071 +00072 // Publish the property +00073 PublishL(myProperty,buf); +00074 +00075 // Change the array contents +00076 array[0] = 0x00ab; +00077 array[1] = 0x00bc; +00078 array[2] = 0x00cd; +00079 array[3] = 0x00de; +00080 array[4] = 0x00ef; +00081 array[5] = 0x00fa; +00082 +00083 buf.Copy(&array[0],sizeof(array)); +00084 // Copy array contents into the descriptor +00085 buf.SetLength(KArraySize); +00086 +00087 // Wait for a key press +00088 console->Printf(KTxtEnter); +00089 while(console->Getch()!= EKeyEnter) +00090 { +00091 console->Printf(KTxtEnter); +00092 } +00093 +00094 // Publish the property +00095 PublishL(myProperty,buf); +00096 +00097 // Indicate the publisher will not publish any more values +00098 // The subscriber stops its subscription to the property when this value is published +00099 buf.Copy(KStop); +00100 console->Printf(KTxtEnter); +00101 +00102 // Wait for a key press +00103 while(console->Getch()!= EKeyEnter) +00104 { +00105 console->Printf(KTxtEnter); +00106 } +00107 +00108 // Publish the property +00109 PublishL(myProperty,buf); +00110 +00111 // Close the handle to the property +00112 +00113 myProperty.Close(); +00114 +00115 // Wait for a key press +00116 while(console->Getch()!= EKeyEnter) +00117 { +00118 console->Printf(KTxtEnter); +00119 } +00120 +00121 // The publisher has finished so delete the property +00122 User::LeaveIfError(RProperty::Delete(KMyPropertyCat, KMyPropertyName)); +00123 } +00124 +00125 GLDEF_C TInt E32Main() +00126 { +00127 __UHEAP_MARK; +00128 CTrapCleanup* cleanup = CTrapCleanup::New(); +00129 +00130 TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen))); +00131 if (createError) +00132 return createError; +00133 +00134 TRAPD(mainError, DoExampleL()); +00135 if (mainError) +00136 console->Printf(KTextFailed, mainError); +00137 console->Printf(KTextPressAnyKey); +00138 console->Getch(); +00139 +00140 delete console; +00141 delete cleanup; +00142 __UHEAP_MARKEND; +00143 return KErrNone; +00144 } +