Active Object: (Asynchronous event driven multi tasking)
An Active object requests an asynchronous service and handles the resulting completion event some time after the request. It Provides way to cancel the outstanding request and may provide error handling for exceptional condition.
An Active object class must derive directly or indirectly from CActive class.
CActive is an abstract class with two pure virtual functions RunL() & DoCancel(). It has a TRequestStatus member variable which is passed to asynchronous request to receive the completion result.
Each Active object have a priority value (CActive::EPriorityStandard) to determine how they are scheduled. The priority value is only used to determine the order in which the event handlers are run. While an active object handling an event, it can be pre empted until the event handler function return back to the active scheduler.
As on part of construction, the active object must call a static function of the active scheduler (CActiveScheduler::Add()). This will add the active object in to a list, maintained by active scheduler, of event handling object on that thread.
Submitting an asynchronous request.
Check for previous outstanding request. Each active on must have only one outstanding request. The active object passes the iStatus to the service provider as the part of the request. The service provider will set the value to KRequestPending before initiating the asynchronous service.
If the request submitted successfully then the request method calls SetActive() method of CActive class, to indicate the active scheduler that the request has been submitted and is currently outstanding.
Event handling:
Each active object must implement the RunL () function of the CActive base class. When a completion event occurs from the associated service provider, the active scheduler selects the active object to handle the event and call this method.
Note: The RunL () method should completed as quickly as possible, because it can’t be pre-empted by other active object even handler.
Cancel outstading request:
Each active object must be able to cancel any outstanding asynchronous request it has issued. The CActive base class implements a Cancel() method, which calls the pure virtual DoCancel() method. Any implementation of DoCancel() should call the appropriate cancellation method of the asynchronous service provider.
Error handling:
The CActive base class provides a virtual function, the active scheduler calls this if leave occurs inside the RunL() This method takes the error code as a parameter and the default implementation just returns the error code. The active object class can override the CActive::RunError() method to handle the error.
Note: The destructor of the active oject class should always call the Cancel() method to cancel the outstanding request as part of clean up.
Active object example: (Retreive IMSI Number using Active object Concept)
An Active object requests an asynchronous service and handles the resulting completion event some time after the request. It Provides way to cancel the outstanding request and may provide error handling for exceptional condition.
An Active object class must derive directly or indirectly from CActive class.
CActive is an abstract class with two pure virtual functions RunL() & DoCancel(). It has a TRequestStatus member variable which is passed to asynchronous request to receive the completion result.
Each Active object have a priority value (CActive::EPriorityStandard) to determine how they are scheduled. The priority value is only used to determine the order in which the event handlers are run. While an active object handling an event, it can be pre empted until the event handler function return back to the active scheduler.
As on part of construction, the active object must call a static function of the active scheduler (CActiveScheduler::Add()). This will add the active object in to a list, maintained by active scheduler, of event handling object on that thread.
Submitting an asynchronous request.
Check for previous outstanding request. Each active on must have only one outstanding request. The active object passes the iStatus to the service provider as the part of the request. The service provider will set the value to KRequestPending before initiating the asynchronous service.
If the request submitted successfully then the request method calls SetActive() method of CActive class, to indicate the active scheduler that the request has been submitted and is currently outstanding.
Event handling:
Each active object must implement the RunL () function of the CActive base class. When a completion event occurs from the associated service provider, the active scheduler selects the active object to handle the event and call this method.
Note: The RunL () method should completed as quickly as possible, because it can’t be pre-empted by other active object even handler.
Cancel outstading request:
Each active object must be able to cancel any outstanding asynchronous request it has issued. The CActive base class implements a Cancel() method, which calls the pure virtual DoCancel() method. Any implementation of DoCancel() should call the appropriate cancellation method of the asynchronous service provider.
Error handling:
The CActive base class provides a virtual function, the active scheduler calls this if leave occurs inside the RunL() This method takes the error code as a parameter and the default implementation just returns the error code. The active object class can override the CActive::RunError() method to handle the error.
Note: The destructor of the active oject class should always call the Cancel() method to cancel the outstanding request as part of clean up.
Active object example: (Retreive IMSI Number using Active object Concept)
0 comments:
Post a Comment