Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
RBufConsole class example
This code example show how to add an observer to RBuf descriptors.
Whilst your application does some actions it needs to generate messages for user or for debug purposes.
If you have GUI application you will need some text storage which can be filled up and be shown as GUI message. I’ve developed such a class called RBufConsole which is comfortable for the aims above and is a good example of RBuf Symbian descriptor.
RBuf is a Symbian descriptor designed to manipulate strings and binary data.
In this example RBuf is used for appending strings, reallocation memory buffer, passing function parameters.
In addition, some Active Object can save messages to the same storage while performing it’s tasks. This is possible with RBufConsoleObserver interface class which relates to Observer paradigm.
So when Active object produces some action it calls Observer's callback function to add message to the RBufConsole storage.
After Active Object completes it can call the show message event or main program can do it.
Assigns the resource (from rss file) for GUI Message (will be shown below). Initializes MessageStorage variable – RBuf class instance.
//Set resource ID from rss file
MessageDialogResourceID = aResourceID;
TInt maxSizeOfMsgData = 150;
_LIT(KGenesis , "App starts\n");
RBufConsole Append() method
The Append() method will check if the new message can exceed the descriptor’s size and will reallocate memory in this case
void CRBufConsole::Append(TPtrC16 appendString)
const TInt newLength = MessageStorage.Length() + appendString.Length();
if (MessageStorage.MaxLength() < newLength )
//Reallocate storage's memory if it is not enough
RBufConsole Show() method
When programmer decides, he can show all messages stored in RBufConsole storage, in GUI Popup.
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
//Assign storage to be outputed
//show scrollable message
Resource file for Message Query Dialog
In your .rss file you should define resource for CAknMessageQueryDialog. It would be passed as a parameter to constructor: CRBufConsole (R_RBUFCONSOLE_QUERY_DIALOG);
RESOURCE DIALOG r_rbufconsole_query_dialog
flags = EGeneralQueryFlags | EEikDialogFlagNoBorder | EEikDialogFlagNoShadow;
buttons = R_AVKON_SOFTKEYS_OK_EMPTY;
type = EAknCtPopupHeadingPane;
id = EAknMessageQueryHeaderId;
itemflags = EEikDlgItemNonFocusing;
control = AVKON_HEADING
type = EAknCtMessageQuery;
id = EAknMessageQueryContentId;
control = AVKON_MESSAGE_QUERY
Append new message:
Show storage contents:
iConsole.Show(); //Shows RBufConsole contents as a GUI scrollable message
Execute Append() callback function inside Active Object:
iRBufConsoleObserver->ObserverAppend(_L("Active object completes\n"));
Download this example
Download Zip archive with full example: File:WikiConsoleExample.zip . It is based on Carbide C++ basic GUI application. I will grow functionality in the course of time.
To know how to import project from Zip see How to get project from CVS to Carbide C++.