cZen Issue No.1 - page 2

Much Shorter eh? Now, because the function BuildStuff can throw an exception (note the capital L that's marked at the end of its name) ... you need to be ready to catch the exception somewhere in your code .... There is a simple macro that will do the job for you:

tErr lErr; TRAP(lErr,BuildStuffL(&lObject)); if(!lErr) { // do stuff with lObject } else { // process error }

As you will notice, the code is much simplier to write and read. It is also less prone to mistakes, such as forgetting to delete the first object if the second one somehow failed ... When using the cleanup stack, every object still on the stack when the exception is caught is automatically deleted.

The static method ::VerifyLC() checks the validity of an object, and throws an exception if it is not valid or if it hasn't been allocated. The capital C in the name indicates that the object, if valid, will be left on the cleanup stack when the method ends. It is up to the developer to pop it from the stack when he wants.

An even easier way to go about it if you have full control over the class cMyClass and cMyClass2, is to use the second phase constructor :

class cMyClass : public pBase { public: static cMyClass* NewL(); ~cMyClass(); private: cMyClass(); void ConstructL(); private: tChar *iData; }; cMyClass *cMyClass::NewL() { cMyClass *lObject = new lObject(); if(lObject) { sCleanupStack::PushL(lObject); lObject->ConstructL(); sCleanupStack::PopL(lObject); return lObject; } else throw uException(kErrOutOfMemory,"cMyClass::NewL"); } cMyClass::cMyClass() { iData = NULL; } cMyClass::~cMyClass() { if(iData) delete [] iData; } void cMyClass::ConstructL() { iData = new tChar[3000]; if(!iData) throw uException(kErrOutOfMemory,"cMyClass::ConstructL"); }

Making your class use the two phase construction idiom is a bit of extra work, but in the end, it does improve your code clarity and robustness. It just a good habit to adopt ;-)

We will cover this idiom in more depth in a later article. In the meantime, we invite you to look at the many examples available in the Demos folder.

Kits/Libraries shuffle

Instead of sporting twelve to thirteen kits, the Zinzala SDK is now composed of just two kits:

The first kit, Cincinella, is the foundation of the SDK. It regroups all the basic classes and functions. The second kit, Farfalla, deals only with the user interface.

All the header files that were previously split in directories according to their origin kit, are now all in either Cincinella or Farfalla.

Each one of the kits is composed of several libraries. If you look in /usr/Zinzala/0.7/x86, you will see :

libzCiACore.so libzCiANetk.so libzCiAProg.so libzCiAStor.so libzCiATaZo.so libzCiATask.so libzCiATran.so libzCiAtLex.so libzFfACore.so libzFfAMain.so libzFfAxTnd.so libzFfAxTra.so libzFfAxWeb.so

Libraries starting with CiA are from the Cincinella kit. Libraries from Farfalla start with FfA. Similar to the kits of 0.6, each of the libraries deal with specific issues. Some of the libraries are very critical, like libzCiACore.so, while others are just additional features, like libzCiATask.so, which are not mandatory. Future versions of the SDK will have these libraries installed in /usr/Zinzala/0.X/x86. Unless you wish to link against a fixed version of the SDK, you should always link against the libraries in /usr/Zinzala/latest/x86. This will always point to the most recent release of Zinzala.

The following lists show the content of every library. You can use it to pinpoint the location of a specific class.

libzCiACore.so - Cincinella - Core elements

cAddOn pFlowIO pRunnable
cArea cGate cShelf
sArgs pIO sSnooze
cArray cList cStack
pBase cListOfPointers cStackOfItems
sBitwise cListOfStrings cStackOfPointers
cBuffer cListOfUint32s cStopwatch
cCan cListOfUint8s sStrTools
sCleanupStack cLocker pTargetable
cCountdown cMessage cTeam
cCrosswalk cPeriodic cThread
sEnv pPositionIO cTimeout
uException sRandom uTimer
pFlattenable pReferenced sTrace

libzCiANetk.so - Cincinella - Network

sNet cUDPMessenger cUPDSocket

libzCiAProg.so - Cincinella - Program

cProgram sRoster

libzCiAStor.so - Cincinella - Storage

cDirectory cEntry cFile cListOfEntries cSettings

libzCiATaZo.so - Cincinella - Activity/special multi-threading classes

cActivity

libzCiATask.so - Cincinella - Extra multi-threading classes

cJob cScalable cTask
All content © 2004-2007, hexaZen - Vancouver BC, Canada