Typically, the GlishSysEvent objects are either returned by the GlishSysEventSource class or passed as a parameter to a callback function. As a result, this class will rarely be constructed by the user.
This example simply prints out the events it receives. It does
this in a procedural manner.
For another example of this type of processing see
the example
in the Glish module page. For an example of how this class is
used in an event driven setting see the
other example in the
Glish module file or the example below.
Example
GlishSysEventSource source(argc, argv);
GlishSysEvent event;
GlishValue value;
GlishArray array;
GlishRecord record;
while (source.connected()) {
event = source.nextGlishEvent();
cout << "Event " << event.type() << " : ";
value = event.val();
if (value.type() == GlishValue::ARRAY) {
array = value;
cout << array.format() << endl;
} else {
record = value;
cout << record.format() << endl;
}
}
Copy constructor which uses reference semantics.
Default constructor which creates an invalid event.
Assignment Operator using reference semantics.
Returns the group to which this event belongs.
Returns the GlishValue which is stored in this event. This is the actual raw Glish value.
Returns the type of the value stored in the event.
Returns the event type of this Glish event. This is the name of the event.
Used to deliver this particular event to the SysEventTarget parameter.
Is this event a request event?
Is this event a reply to a request event?
This will return the source of this event.
Returns a deep copy of this object.
This demonstrates an echo client which simply echoes its events back through the GlishSysEventSource.
GlishSysEventSource source(argc, argv); GlishSysEvent event; while (source.connected()) { event = source.nextGlishEvent(); source.postEvent(event.type(),event.val()); }For another example of this type of event processing see the example in the Glish module page.
This class can also be used in an event driven manner. This next example
demonstrates this:
In this example all of the events whose name begins with
hello get directed to the helloCallback.
The rest get directed to the defaultCallback. For
other examples of event driven processing see
the example in the
Glish module page, or
the example in the XSysEvent page which
includes X Windows events in the loop.
Event Driven Example
#include <aips/Glish.h>
Bool helloCallback(GlishSysEvent &e, void *) {
GlishSysEventSource *src = (GlishSysEventSource*)e.source();
(*src).postEvent("hello_got",e.type());
return True;
}
Bool defaultCallback(GlishSysEvent &e, void *) {
GlishSysEventSource *src = (GlishSysEventSource*)e.source();
(*src).postEvent("default_got",e.type());
return True;
}
int main(int argc, char **argv)
{
GlishSysEventSource eventStream(argc, argv);
eventStream.setDefault(defaultCallback);
eventStream.addTarget(helloCallback,"^hello");
eventStream.loop();
}
Returns the group which this event source belongs to. The group indicates which type of events this particular SysEventSource generates.
Gets the "raw" Glish Client for performing operations.
If it is necessary to manipulate the underlying Glish Client, then the public interface of one or more of these classes probably needs extending.
Get the next event which is queued up. This will block.
Get the next Glish event. This blocks until there is an event.
Get the next event. If the event has not occurred in the timeout period, return False, otherwise return True and set event. Timeout of zero means return immediately if there is no pending event, less than zero means to block until there is an event.
Check to see if there are any Glish events waiting to be handled.
Process one Glish event.
Indicated if the source is still connected to the event stream.
Post an event to the Glish system in reply to the last event received.
Post an event to indicate that the last event was not understood.
get the client FDs
Called to report that the current event has an error.
Check to see other can be combined with this event stream.
Combine other with this event stream. If this is impossible, False is returned.
Invoke the specified target whenever the event matches the regular expression (the second parameter). If the target cannot be added False is returned.
Specifies the default action. This target is invoked whenever none of the other targets apply. If the target cannot be added False is returned.
loop and deliver events to targets as they arrive. The process will be blocked until an event arrives.
This is for internal use, and is invoked when an event may be available for processing on this event source.
Get the next base-level Glish event which is queued up. This will block.
This example simply takes an event, modifies it, i.e. sticks the letters 'MOD' on the front of the event type, and then reposts the event.
void eventhandler(GlishSysEvent &evt) { GlishValue &val = evt.val(); GlishSysEventSource *s = (GlishSysEventSource *) evt.source(); String mod("MOD"); String sval = val.format(); mod += evt.type(); s->postEvent(mod,sval); } main(int argc, char **argv) { GlishSysEventSource gsrc(argc,argv); GlishSysEventTarget gtgt(eventhandler); SysEvent event; while (gsrc.connected()) { // 1 if (gsrc.waitingEvent()) { // 2 event = gsrc.nextEvent(); // 3 event.dispatch(gtgt); // 4 } // ... // 5 } }
If an extra event source were added to this loop, the 'group()' and perhaps the 'type()' of the event could be used to choose among a number of SysEventTargets. Here:
Construct an event with a target function which takes an event and a SysEventSource. This is useful when the handling function must know another event source. A case where this happens is when a Glish handler function must post X events. In this case, the XSysEventSource must be available.
Constructs an event target which ignores events.
Return the group to which this handler belongs.
Handle the given event.
This class is used as a container of information for dispatching targets. It facilitates invoking targets based on regular expressions.
This class is not intended for external use.