* Install and start the active scheduler
* Pseudo-code example of the activity Scheduler
* Functions of the activity Scheduler
* Custom activity Scheduler
* Install and start the active scheduler
-The GUI application will automatically install and run the activity scheduler without manual installation.
-For non-GUI applications, You need to manually create, install, and run the activity scheduler, such
If the thread already has the active scheduler installed, re-installation will cause a serious error (E32USER-CBase43)
// Create
Cactivescheduler * mysched = new (eleave) cactivescheduler;
// Install
Cactivescheduler: Install (mysched );
// Add an activity object and initiate an asynchronous function request
// Run the activity Scheduler
Cactivescheduler: Start ();
* Sample code of the activity Scheduler
Do
{
Waitforanyrequest ();
For (I = 0; I <number_of_active_objects; I ++)
{
If (active_object [I], iactive & (active_object [I]. istatus! = Krequestpending ))
{
Active_object [I]. runl ();
Break;
}
If (I = number_of_active_objects)
{
Generate_stray_signal_exception ();
}
} While (activescheduler: Stop ()
}
* Activity scheduler Functions
-Void add (cactive * aactiveobject)
Add the activity object to the current activity scheduler.
-Void install (cactivescheduler * aactivescheduler)
Install aactivesched as the active scheduler of the current thread
-Void Replace (cacitvescheduler * aactivescheduler)
Similar to install (), when the current thread has installed the active scheduler, use aactivescheduler to replace the current active scheduler.
-Void start ()
Start the activity scheduler and start to process activity object events.
-Void stop ()
Exit the event loop of the current active height Device
-Cactivescheduler * Current ()
Returns the pointer of the active scheduler of the current thread.
* Custom activity Scheduler
-Virtual void onstarting ()
Before the event loop starts, it is called by the START () function of the cactivescheduler base class.
-Virtual void onstopping ()
Called by the stop () function of the cactivescheduler base class. The default implementation is null.
-Virtual void error (tint AERR)
When an activity Object exits abnormally in the runl () function and the runerror () function of the activity object does not handle this, the function is called by the activity object scheduler.
The default implementation is to issue an E32USER-CBase47 exception
-Virtual void waitforanyrequest ()
It is called cyclically by the event scheduler of the activity object to wait for the completion of asynchronous functions.
The default implementation is to call User: waitforrequest ()