When a Symbian activity object is implemented (if a long-running activity object is implemented)

Source: Internet
Author: User

Activity objects in Symbian should be a commonly used medium mechanism. Here we will summarize several methods of using activity objects.

Definition of activity objects: a mechanism that simulates multiple threads to implement multiple tasks. A simple understanding should be like this.

Specific use:

1. In combination with the rtime class, this is basically the case in many books (this is the case in the White Paper). I will not talk about it here.

2. Works with some asynchronous functions. For example, the write function used when writing a file is prototype:
Import_c void write (const tdesc8 & ades, trequeststatus & AStatus );

We can see that the parameters here are a little different from other functions. Here there is a trequeststatus & AStatus parameter, so we will think that this parameter is used in the activity object.
The usage is as follows:
A. Activate activity object
Void casyncfile: filewrite (const tdesc8 & ades)
{
Tint Pos = 0;
Ifile. Seek (eseekend, POS );
Ifile. Write (ades, istatus );
Setactive ();
}
B. process the runl function of the activity object
Void casyncfile: runl ()
{
Switch (istatus.int ())
{
Case kerrnone:
// Do something
Break;
}
}
C. Some processing operations in the future are the same as those in 1.
 
For example, import_c void rconnect: Start (tconnpref & apref, trequeststatus & AStatus) when connecting to the network is used.
 
3. Long-running tasks are implemented using activity objects. For example, if I want to explain this method, it would be easier to talk about both 1st and 2.

This method should also be commonly used, but it is possible that the online data is not implemented in this way. paste the detailed code:
A. The. H of the activity object
Class caotest: Public cactive
{
PRIVATE:
Void runl ();
Tint runerror (tint aerror );
Void docancel ();
Public:
Caotest ();
~ Caotest ();
Void start ();
};

B. cpp OF THE ACTIVITY object
Caotest: caotest (): cactive (eprioritystandard)
{
Cactivescheduler: add (this );
}

Caotest ::~ Caotest ()
{
Cancel ();
}
/*
After the start function is called, this function will be used. We have done some processing here, so that after the activity object calls the runl function,
Call the runl () function again to implement a long-running activity object.
*/
Void caotest: runl ()
{
Trequeststatus * mystatus = & istatus;
User: requestcomplete (mystatus, kerrnone );
Setactive ();
}
/*
Process the canceled activity object. Generally, this can be written in this way. You need to leave it empty when you use it.
*/
Void caotest: docancel ()
{

Trequeststatus * PS = & istatus;
User: requestcomplete (Ps, kerrcancel );

}
/*
Start the function and call the startup activity object. You need to set the value of istatus to krequestpending.
Can also, but generally do not recommend such direct value (initialization can be so), easy to appear E32Ueser-cbase 46 (appear game
Off-signal), which can be set as below
*/
Void caotest: Start ()
{

// Cancel ();
Trequeststatus * PS = & istatus;
User: requestcomplete (Ps, kerrnone );
If (! Isactive ())
Setactive ();
}
/*
To handle runl exceptions and exit, you do not need to use exception handling mechanisms such as trdp in runl to handle exceptions.
*/
Tint caotest: runerror (tint aerror)
{
Tint nerr = aerror;
Return nerr;
}

Chelloworlda0appview * chelloworlda0appview: newl (const trect & arect)
{
Chelloworlda0appview * Self = chelloworlda0appview: newlc (arect );
Cleanupstack: Pop (Self );
Return self;
}

C. Use activity objects
Directly create a hello World GUI Project
Then define a member in cantainer.
Caotest * iaotest;
Then it is instantiated in constructl of cantainer.

Void chelloworlda0appview: constructl (const trect & arect)
{
// Create a window for this application view
Createmediawl ();

Iaotest = new caotest;
// Set the Windows size
Setrect (arect );

// Activate the window, which makes it ready to be drawn
Activatel ();

Iaotest-> Start ();
}

At this time, you can run the DEBUG command in the next step. The runl function will continuously call back this function. At this time, a long-running activity object is successfully implemented.



Common problems:
1. Generally in the use of the activity object encountered more common panic is E32Ueser-cbase 46, the corresponding problem is to say that the signal,
2. In general, the following situations may occur:
A. if you forget to activate the activity object, you forget to call setactive.
B. Forget to initialize istatus as krequestding.
C. Two requests or two completed requests. This is generally caused by the manual setting of istatus.
3. Do not directly call docancel in the activity object, but indirectly call docancel by calling cancel.
4. The cancel function is generally called during activity object analysis.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.