-
-// handler used to process events on event loop sources
-class WXDLLIMPEXP_BASE wxEventLoopSourceHandler
-{
-public:
- // called when descriptor is available for non-blocking read
- virtual void OnReadWaiting() = 0;
-
- // called when descriptor is available for non-blocking write
- virtual void OnWriteWaiting() = 0;
-
- // called when there is exception on descriptor
- virtual void OnExceptionWaiting() = 0;
-
- // virtual dtor for the base class
- virtual ~wxEventLoopSourceHandler() { }
-};
-
-// those flags describes what events should be reported
-enum
-{
- wxEVENT_SOURCE_INPUT = 0x01,
- wxEVENT_SOURCE_OUTPUT = 0x02,
- wxEVENT_SOURCE_EXCEPTION = 0x04,
- wxEVENT_SOURCE_ALL = wxEVENT_SOURCE_INPUT | wxEVENT_SOURCE_OUTPUT |
- wxEVENT_SOURCE_EXCEPTION,
-};
-
-class wxAbstractEventLoopSource
-{
-public:
- wxAbstractEventLoopSource() :
- m_handler(NULL), m_flags(-1)
- {}
-
- wxAbstractEventLoopSource(wxEventLoopSourceHandler* handler, int flags) :
- m_handler(handler), m_flags(flags)
- {}
-
- virtual ~wxAbstractEventLoopSource() { }
-
- virtual bool IsOk() const = 0;
-
- virtual void Invalidate() = 0;
-
- void SetHandler(wxEventLoopSourceHandler* handler)
- {
- m_handler = handler;
- }
-
- wxEventLoopSourceHandler* GetHandler() const
- {
- return m_handler;
- }
-
- void SetFlags(int flags)
- {
- m_flags = flags;
- }
-
- int GetFlags() const
- {
- return m_flags;
- }
-
-protected:
- wxEventLoopSourceHandler* m_handler;
- int m_flags;
-};
-
-// This class is a simple wrapper for OS specific resources than can be a
-// source of I/O. On Unix,for instance these are file descriptors.
-//
-// Instances of this class doesn't take resposibility of any resource you pass
-// to them, I.E. you have to release them yourself.
-template<class T>
-class WXDLLIMPEXP_BASE wxEventLoopSourceBase : public wxAbstractEventLoopSource
-{
-public:
- typedef T Resource;
-
- // copy ctor
- wxEventLoopSourceBase(const wxEventLoopSourceBase& source) :
- wxAbstractEventLoopSource(source.GetHandler(), source.GetFlags()),
- m_res(source.GetResource())
- {
- }
-
- virtual const T InvalidResource() const
- {
- return (T)-1;
- }
-
- virtual void Invalidate()
- {
- SetResource(InvalidResource());
- SetHandler(NULL);
- }
-
- // sets internal value to res
- void SetResource(T res)
- {
- m_res = res;
- }
-
- // returns associated resource
- T GetResource() const
- {
- return m_res;
- }
-
- virtual bool IsOk() const
- {
- // flags < 0 are invalid and flags == 0 mean monitoring for nothing
- return m_res != InvalidResource() && m_handler && m_flags >=1;
- }
-
-protected:
- // empty ctor, beacuse we often store event sources as values
- wxEventLoopSourceBase() :
- wxAbstractEventLoopSource(),
- m_res(InvalidResource())
- {
- }
-
- // ctor setting internal value to the os resource res
- wxEventLoopSourceBase(T res, wxEventLoopSourceHandler* handler,
- int flags) :
- wxAbstractEventLoopSource(handler, flags),
- m_res(res)
- { }
-
- T m_res;
-};
-
-#if defined(__WXMAC__)
-class wxMacEventLoopSource : public wxEventLoopSourceBase<CFRunLoopSourceRef>
-{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- int GetFileDescriptor() const
- {
- return m_fd;
- }
-#endif
-protected:
- wxMacEventLoopSource() : wxEventLoopSourceBase<CFRunLoopSourceRef>() { }
-
- // ctor setting internal value to the os resource res
- wxMacEventLoopSource(CFRunLoopSourceRef res,
- wxEventLoopSourceHandler* handler, int flags) :
- wxEventLoopSourceBase<CFRunLoopSourceRef>(res, handler, flags)
- {
- }
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- int m_fd;