Activity object framework 4: Use the activity Scheduler

Source: Internet
Author: User

* 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 ()

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.