An event is a way to notify an application that a specified action has occurred in the host session, so that the application can respond accordingly. In Attachmate e-Vantage Airlines SDK, the Screen object receives an event from the host session, and then passes the event to the application.
The SDK provides support for the events that can occur during a host session as follows:
||Is generated when
||The connection to the host is broken.
||An error occurs.
||Any part of the host screen changes.
||The host screen shape (number of rows and/or columns) changes.
To use events in your application, your Screen object must implement the appropriate event interface: IScreenListener (for Java) or IScreenListenerEx (for COM).
Once you have implemented the proper interface, you can use the Screen object's screen listener methods to add event listening capabilities to your application. The Screen object provides four methods for event handling, two that are specific to Java-based applications and two that are specific to COM-based applications:
Details on coding events for each of these environments are provided in Handling Events in Java and Handling Events in Visual C++, below.
||It is very important that the code in your event handlers does as little processing as possible, so that the callback can return quickly to the SDK objects. Never call a Screen object method from inside an event handler method.
|To add event support to your Java application
- Import the following package for event support:
- Specify that your class extends IScreenListener:
public class MyClass extends Thread implements IScreenListener
- Implement the IScreenListener interface by providing methods for handling the events within your class.
- Call the Screen objectís implementation of addIScreenListener, passing in the class that implements IScreenListener, as outlined in steps 2 and 3, above:
- After your application is finished receiving events but before destroying the Screen object always remove the screen listener, again passing in the class that implements IScreenListener:
Adding event support in Visual C++ is a bit more complex than in Java, so each of the major tasks is broken down into individual steps. If you are using Microsoft Foundation Classes (MFC) and your class derives from CCmdTarget, you can use ClassWizard to do much of the work. If your class derives from CWinThread, however, it must be added manually; the code for doing so is provided in the following procedure.
Complete the following major tasks to add event support to your Visual C++ application:
- Set up the class to receive events.
- Register and de-register the class with the screen object.
- Initialize OLE.
|To set up the class to receive events
- Declare an event class that extends a class that supports message maps; for example, CCmdTarget or CWinThread:
class CSessn : public CWinThread
||The event class calls
DECLARE_DYNCREATE(ClassName). You must also call
IMPLEMENT_DYNCREATE(ClassName, CWinThread) in the implementation file (*.CPP) before the event class declaration:
- Add the following statement to the header file for this event class:
This includes the IID for IID_IScreenListenerEx that you will need in step 4, below.
- In the header file for the event class, declare a message map and an interface map as part of the class; this will be handed back to the SDK during run-time using addIScreenListenerEx:
//Generated OLE dispatch map functions
afx_msg void onConnectionLost();
afx_msg void onError();
afx_msg void onScreenChanged();
afx_msg void onScreenShapeChanged();
- Include a dispatch map in your implementation file (*.CPP), declaring which of your Member methods handle the corresponding events, as well as the IID that is included in the header file for the interface map:
INTERFACE_PART(CSessn, IID_IScreenListenerEx, Dispatch)
DISP_FUNCTION(CSessn, "onConnectionLost", onConnectionLost, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CSessn, "onError", onError, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CSessn, "onScreenChanged", onScreenChanged, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CSessn, "onScreenShapeChanged", onScreenShapeChanged, VT_EMPTY, VTS_NONE)
- Enable OLE automation in the application class; for example, using the CCmdTarget::EnableAutomation (or similar) method.
|To register and de-register the class with the screen object
- Call addIScreenListenerEx, passing in the Dispatch pointer of the class that implemented the event interface. In the example below, the class that implements the event is the current class (CSessn):
// enable event notification
//open the host connection
- Remove the screen listener from the Screen object when event processing is finished:
pScreen = NULL;
||Be sure to always remove the screen listener before destroying the Screen object; failure to do so may cause a fault to occur.
|To initialize OLE Automation