XSysEvent.h

Classes

XSysEvent -- X event wrapper (full description)
XSysEventSource -- X event generation wrapper (full description)
XSysEventTarget -- X event handling wrapper (full description)
XSysEventSourceInfo -- Internal class (full description)

class XSysEvent : public SysEvent

Interface

Public Members
XSysEvent(const XSysEvent &other) : SysEvent(other.src), event(other.event)
XSysEvent(const XSysEvent *other) : SysEvent((*other).src), event((*other).event)
~XSysEvent()
SysEvent::Group group() const
String type() const
int xtype() const
Bool dispatch(SysEventTarget &)
Bool dispatch(SysEventTarget &, SysEventSource &)
Protected Members
XSysEvent()
XSysEvent(XEvent *v,SysEventSource *xs) : SysEvent(xs), event(v)
XEvent *xevent()
SysEvent *clone() const

Description

Prerequisite

Etymology

See SysEvent

Synopsis

This class is a wrapper for X events. It provides a standard (minimal) interface to X events. This can be important when several types of events, e.g. GlishEvents and XEvents, must both be handled. This is why this SysEvent hierarchy was developed.

See XSysEventSource for more information.

Example

See the example in XSysEventSource.

Motivation

Often one needs to mix X events with other types of events. This class provides a common interface for X events, and all of the related classes provide a system for handling most asynchronous types of events which occur.

Member Description

XSysEvent(const XSysEvent &other) : SysEvent(other.src), event(other.event)
XSysEvent(const XSysEvent *other) : SysEvent((*other).src), event((*other).event)

These copy constructors allow on to copy XSysEvents

~XSysEvent()

SysEvent::Group group() const

Returns the group to which this event belongs. The SysEvent::Group is just an enumeration of the possible event types.

String type() const

Returns the type this event. The type is a string which represents the type of the event.

int xtype() const

Returns the type of the event in X-speak.

Bool dispatch(SysEventTarget &)

Dispatches this event to the event target parameter.

Bool dispatch(SysEventTarget &, SysEventSource &)

Dispatches this event to the event target parameter, and carries along an extra event source in case it is needed. This might be needed if a GUI application wanted to post Glish events as buttons are pressed.

XSysEvent()

XSysEvent(XEvent *v,SysEventSource *xs) : SysEvent(xs), event(v)

XEvent *xevent()

Return the underlying data structure

SysEvent *clone() const

Return a copy of this event.


class XSysEventSource : public SysEventSource

Interface

Public Members
XSysEventSource(int argc, char **argv, const char *name="EventSource")
XSysEventSource(int argc, char **argv, void *options, char **fallback_resources, const char *name="EventSource")
~XSysEventSource()
SysEvent::Group group() const
XtAppContext &context()
Widget &toplevel()
SysEvent nextEvent()
Bool waitingEvent()
Bool connected()
Bool canCombine(const SysEventSource &other) const
Bool canCombine(const SysEventSource *other) const
Bool combine(SysEventSource &other)
Bool combine(SysEventSource *other)
Bool addTarget(SysEventTarget &, const String &)
Bool addTarget(SysEventTarget *, const String &, Bool ownTarget=False)
Bool addTarget(SysEventTargetProc, const String &, void *userData=0)
Bool setDefault(SysEventTarget &)
Bool setDefault(SysEventTarget *, Bool ownTarget=False)
Bool setDefault(SysEventTargetProc, void *userData=0)
Bool loop()
void invokeTarget()
Protected Members
XSysEventSource(XtAppContext *v, Bool DeleteIt = True) : context_(v,DeleteIt), srcInfo(0)
Bool addSource(GlishSysEventSource *other)
void setFD(int fd, XSysEventSourceInfo*)
void clrFD(int fd, XSysEventSourceInfo*)

Description

Prerequisite

Etymology

See SysEvent

Synopsis

This class provides a wrapper around the X mechanics of event generation. So that the event source can be queried about waiting events. This is useful because it is part of a general to all types of system events.

If the event driven interface to these event sources is used, there is no more overhead than the typical X event loop, shown below. Using the procedural interface, however, incurs a performance penalty due to polling

Tip This class is most useful when both Glish and X Windows events are used.

Example

This is an example of how these classes might be used. It demonstrates how Glish and X Windows events can be cleanly combined into one event stream. The Glish event stream can also be used by itself in this manner as well (see the event driven example in the GlishEvent header file).
    #include <Xm/Xm.h>                                         // --+
    #include <Xm/Form.h>                                       //   |
    #include <Xm/PushB.h>                                      //   +->  1
    #include <iostream>                                      // --+
    #include <aips/Glish.h>                                    //        2
    #include <aips/Glish/XSysEvent.h>                          //        3
                                                               // --+
    Bool helloCallback(GlishSysEvent &e, void *) {             //   |
        GlishSysEventSource *src =  e.glishSource();           //   |
        (*src).postEvent("hello_got",e.type());                //   |
        return True;                                           //   |
    }                                                          //   +->  4
                                                               //   |
    Bool defaultCallback(GlishSysEvent &e, void *) {           //   |
        GlishSysEventSource *src =  e.glishSource();           //   |
        (*src).postEvent("default_got",e.type());              //   |
        return True;                                           //   |
    }                                                          // --+
                                                               //
    Bool otherCallback(SysEvent &e, void *) {                  // --+
        if ( e.group() == SysEvent::GlishGroup ) {             //   |
         GlishSysEvent &ge = (GlishSysEvent &) e;              //   |
         GlishSysEventSource *src =  ge.glishSource();         //   |
         (*src).postEvent("other_got",ge.type());              //   +->  5
         return True;                                          //   |
        }                                                      //   |
        return False;                                          //   |
    }                                                          // --+
                                                               //
    static void DoXSetup(XSysEventSource &);                   //        6
    main(int argc, char **argv) {                              //        7
        XSysEventSource xStream(argc,argv);                    //        8
        GlishSysEventSource glishStream(argc, argv);           //        9
                                                               //       10
        glishStream.setDefault(defaultCallback);               // --+
        glishStream.addTarget(helloCallback,".*hello");        //   +-> 11
        glishStream.addTarget(otherCallback,"[a-z]+");         // --+
                                                               //
        xStream.combine(glishStream);                          //       12
                                                               //
        DoXSetup(xStream);                                     //       13
                                                               //
        XtRealizeWidget(xStream.toplevel());                   //       14
                                                               //
        xStream.loop();                                        //       15
    }
    
    void QuitCB (Widget, XtPointer,XtPointer) {
        cout << "Outttaaa here..." << endl;
        exit(0);
    }
    
    void DoCB (Widget, XtPointer,XtPointer) {
        cout << "Do'in it..." << endl;
    }
    
    static void DoXSetup(XSysEventSource &xStream) {
        Widget outerContainer, quitButton, doButton;
    
        outerContainer = XtVaCreateManagedWidget ("OuterForm", xmFormWidgetClass, 
                                                  xStream.toplevel(), NULL);
        quitButton = XtVaCreateManagedWidget ("QUIT", xmPushButtonWidgetClass,
                         outerContainer, XmNtopAttachment, XmATTACH_FORM,
                         XmNtopOffset, 0, XmNleftAttachment, XmATTACH_FORM,
                         XmNleftOffset, 0, NULL);
    
        doButton = XtVaCreateManagedWidget ("DO", xmPushButtonWidgetClass,
                         outerContainer, XmNtopAttachment, XmATTACH_FORM,
                         XmNtopOffset, 25, XmNleftAttachment, XmATTACH_FORM,
                         XmNleftOffset, 0, NULL);
    
        XtAddCallback(quitButton,XmNactivateCallback,QuitCB,(XtPointer) 0);
        XtAddCallback(doButton,XmNactivateCallback,DoCB,(XtPointer) 0);
    }
    
  1. These are the X related includes required by this particular example.
  2. Inclusion of the Glish module header file gets everything necessary for manipulation of Glish values.
  3. This is also required since we are going to be handling both X and Glish events. This is not included in the Glish module header file because it is only needed when X is involved (perhaps this is wrong).
  4. This is the typical layout for a Glish callback. This is more straight forward than the inherited callback format because no casting is required. True should be returned if the event is handled by the callback.
  5. This is the callback format inherited from SysEventSource. It requires that the user verify the type of the event parameter. If the type does not match False is returned to indicate that this callback can't handle the event.
  6. This local function is used to hide all of the Motif details.
  7. Initialization of Glish and X requires access to the command line parameters so they must be received.
  8. This object will be the source of X Windows events for this program.
  9. This object will be the source of Glish events for this program.
  10. These lines set up the Glish callbacks. The setDefault member function can be used to set the default callback. This callback will then be use if none of the other callbacks can be used. The other callbacks are set with addTarget. The second parameter (a String) specifies which event names this callback is intended to be used for. The first, ".*hello", indicates that the helloCallback should be used for any event whose name begins with anything (including nothing) followed by hello.
  11. To allow both Glish and X Windows events to be handled seamlessly the two event streams must be combined. This line does that. A Glish event stream can be combined with an X event stream, but not the reverse.
  12. This sets up the underlying X infrastructure for creating the display and then maps the display.
  13. This handles the X Windows events and, because the Glish event stream was combined with this X stream, the Glish events as well.

Member Description

XSysEventSource(int argc, char **argv, void *options, char **fallback_resources, const char *name="EventSource")

This initializes the event source. It takes the command line parameters, argc and argv, and the name if any of the source. This will do all of the X initialization. From here on, the XSysEventSource::toplevel() member function should be used to access the top level widget.

The parameter options should be a pointer to the X structure XrmOptionDescRec. It is void here to avoid inclusion of X header files.

XSysEventSource(int argc, char **argv, const char *name="EventSource")

This initializes the event source. It takes the command line parameters, argc and argv, and the name if any of the source. This will do all of the X initialization. From here on, the XSysEventSource::toplevel() member function should be used to access the top level widget.

~XSysEventSource()

SysEvent::Group group() const

Returns the group of the event source. SysEvent::Group is just an enumeration which lists all of the possible types of Events.

XtAppContext &context()

Returns the actual X context for use.

Widget &toplevel()

Returns the actual X top level widget for use.

SysEvent nextEvent()

Get the next waiting X event (blocks).

Bool waitingEvent()

Check to see if any X events are queued up.

Bool connected()

Indicates if the source is still connected to the event stream or not.

Bool canCombine(const SysEventSource &other) const
Bool canCombine(const SysEventSource *other) const

Used to check to see if the other SysEventSource can be combined with this XSysEventSource.

Bool combine(SysEventSource &other)
Bool combine(SysEventSource *other)

This is used to combine another event source, other. The SysEventSource, other, must persist as long as objects of this class persist, its address will be used.

Bool addTarget(SysEventTarget &, const String &)
Bool addTarget(SysEventTarget *, const String &, Bool ownTarget=False)
Bool addTarget(SysEventTargetProc, const String &, void *userData=0)

Invoke the target whenever the event matches the regular expression. These do not currently add targets, but rather they always return False indicating that the target couldn't be added.

Bool setDefault(SysEventTarget &)
Bool setDefault(SysEventTarget *, Bool ownTarget=False)
Bool setDefault(SysEventTargetProc, void *userData=0)

Specifies the default action which should be applied when no other targets are applicable. These do not currently add targets, but rather they always return False indicating that the target couldn't be added.

Bool loop()

loop and deliver events to targets as they arrive. The process will be blocked until an event arrives.

void invokeTarget()

This is for internal use, and is invoked when an event may be available for processing on this event source.

XSysEventSource(XtAppContext *v, Bool DeleteIt = True) : context_(v,DeleteIt), srcInfo(0)

Bool addSource(GlishSysEventSource *other)

void setFD(int fd, XSysEventSourceInfo*)
void clrFD(int fd, XSysEventSourceInfo*)

Used to set a file descriptor for monitoring by X and to install (set) or de-install (clr) a particular target for later invocation.

class XSysEventTarget : public SysEventTarget

Interface

Public Members
XSysEventTarget()
~XSysEventTarget()
SysEvent::Group group() const
SysEventTarget *clone() const
Bool handle(SysEvent)
virtual Bool handle(XSysEvent &)
virtual Bool handle(XSysEvent &, SysEventSource &)

Description

Prerequisite

Etymology

See SysEvent

Synopsis

This class provides a wrapper around the mechanics of handling an event generated by X. The actions this class can take are very limited. In general, all it can do is dispatch the event through the regular X channels, but this class is, none the less, one way to go when mixing of X and non-X events.

This default XSysEventTarget simply dispatches the XEvent using the typical X mechanics.

See XSysEventSource for more information.

Example

See the example in XSysEventSource.

Member Description

XSysEventTarget()

~XSysEventTarget()

SysEvent::Group group() const

Get the group of this X event target.

SysEventTarget *clone() const

Bool handle(SysEvent)

virtual Bool handle(XSysEvent &)

Pass the XSysEvent along to the handler parameter. This typically simply involved dispatching the event to the underlying X dispatch mechanism.

virtual Bool handle(XSysEvent &, SysEventSource &)

Pass the XSysEvent along to the event handler, but carry along the extra event source. This is useful when handlers of one SysEvent::Group need to post events to a different Group, i.e. X handlers posting Glish events.


class XSysEventSourceInfo

Interface

XSysEventSourceInfo(SysEventSource *s)
~XSysEventSourceInfo()

Description

This class is used as a container of information for sources which have been combined with XSysEventSource. It facilitates invoking targets based on regular expressions.

This class is not intended for external use.

Tip We would have liked to put this definition in the source (.cc) file, but the compiler SunOS Cfront doesn't seem to deal with it. Instead this class had to be put into this header file, and the X Windows specific information was put into the structure XSysEventSourceInfo_XGUTS to avoid exposing users of XSysEvent.h to X11 header files.

Member Description

XSysEventSourceInfo(SysEventSource *s)

~XSysEventSourceInfo()