00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: FS_EventGenerator.h ( FS Library, C++ ) 00015 * 00016 * COMMENTS: 00017 * This class is used to define an event generator for the UI, 00018 * without actually relying on the UI library. There is a 00019 * wrapper around this class that allows it to fit into the UI 00020 * event loop and there is a wrapper that lets it fit into 00021 * hbatch's event loop. These wrapper classes call setInstaller() 00022 * set set a callback to notify them when an event generator should 00023 * be installed or uninstalled. Note that event generators can only 00024 * be installed after setInstaller() has been called. 00025 */ 00026 00027 #ifndef __FS_EventGenerator__ 00028 #define __FS_EventGenerator__ 00029 00030 #include "FS_API.h" 00031 class FS_EventGenerator; 00032 typedef int (*FS_EventInstaller)(FS_EventGenerator *gen, int install); 00033 typedef void (*FS_PollCallback)(bool /*drain_queue*/); 00034 00035 class FS_API FS_EventGenerator { 00036 public: 00037 FS_EventGenerator(); 00038 virtual ~FS_EventGenerator(); 00039 00040 // Method to get the class name for the event generator 00041 virtual const char *getClassName() const = 0; 00042 00043 // For efficiency in the UI event loop, it's advantageous to be able to 00044 // tell if there are actually events waiting to be processed. There are 00045 // two mechanisms for doing this. 00046 // 00047 // If a file descriptor is available, the UI event loop will check to see 00048 // if there's any data waiting to be read. If there is, the event 00049 // processor will be called. If a negative number is returned, then we 00050 // cannot use this mechanism. By default, this method assumes no file 00051 // descriptor exists. 00052 virtual int getFileDescriptor(); 00053 00054 // If file descriptor is not available, then we have to poll for events. 00055 // The poll time is expressed in milliseconds, so a poll time of 10 will 00056 // poll every 10 ms. 00057 // 00058 // Note that event generators with valid file descriptors will also poll 00059 // if they specify a positive poll time. The default poll time is -1, 00060 // meaning that polling will not occur when the file descriptor is valid. 00061 virtual int getPollTime(); 00062 00063 // Return whether or not events are waiting. 00064 virtual bool areEventsWaiting() { return false; } 00065 00066 // When there is either data on the file descriptor, or the poll time has 00067 // elapsed, the processEvent() method is called. The processEvents method 00068 // should return 1 if there are futher possible events, 0 if there aren't. 00069 // For example, if you delete the event generator, this should return 0. 00070 virtual int processEvents() = 0; 00071 00072 // These methods install the generator into the event loop or uninstall it 00073 // from the event loop. Note that UI applications and hbatch both have 00074 // event loops. The installGenerator() command will return 0 if the 00075 // application does not have an event loop. 00076 int installGenerator(); 00077 void uninstallGenerator(); 00078 00079 // This method is called by the event loop to set an installer callback 00080 // that is used to install FS_EventGenerators into the real event loop. 00081 // It should not be called by users. 00082 static void setInstaller(FS_EventInstaller installer); 00083 00084 // This method is called by the event loop to set a callback. The callback 00085 // is used by the event generator when it needs to explicitly drain 00086 // events on the queue. It's used by the tcl and java commands while it 00087 // waits for the hwish and java processes to exit. 00088 static void setEventLoopPollCallback(FS_PollCallback callback); 00089 00090 // Has the event loop callback been set? 00091 static bool isEventLoopPollCallbackSet(); 00092 00093 // This method uses the event loop poll callback to poll event generators 00094 // for any events that are waiting. If the event loop callback wasn't set, 00095 // it won't do anything. If drain_queue is false, events will be processed 00096 // and possibly added to the event queue, but the queue will not be drained. 00097 void pollEventLoop(bool drain_queue=true); 00098 00099 private: 00100 }; 00101 00102 #endif
1.5.9