-/** Type of source callback */
-typedef function<bool(Glib::IOCondition)>
- SourceCallbackFunction;
-
-/* Data required for C callback function to call a C++ source callback */
-class SR_PRIV SourceCallbackData
-{
-public:
- bool run(int revents);
-protected:
- SourceCallbackData(shared_ptr<EventSource> source);
- shared_ptr<EventSource> _source;
- friend class Session;
-};
-
-/** An I/O event source */
-class SR_API EventSource
-{
-public:
- /** Create an event source from a file descriptor.
- * @param fd File descriptor.
- * @param events GLib IOCondition event mask.
- * @param timeout Timeout in milliseconds.
- * @param callback Callback of the form callback(events) */
- static shared_ptr<EventSource> create(int fd, Glib::IOCondition events,
- int timeout, SourceCallbackFunction callback);
- /** Create an event source from a GLib PollFD
- * @param pollfd GLib PollFD
- * @param timeout Timeout in milliseconds.
- * @param callback Callback of the form callback(events) */
- static shared_ptr<EventSource> create(Glib::PollFD pollfd, int timeout,
- SourceCallbackFunction callback);
- /** Create an event source from a GLib IOChannel
- * @param channel GLib IOChannel.
- * @param events GLib IOCondition event mask.
- * @param timeout Timeout in milliseconds.
- * @param callback Callback of the form callback(events) */
- static shared_ptr<EventSource> create(
- Glib::RefPtr<Glib::IOChannel> channel, Glib::IOCondition events,
- int timeout, SourceCallbackFunction callback);
-protected:
- EventSource(int timeout, SourceCallbackFunction callback);
- ~EventSource();
- enum source_type {
- SOURCE_FD,
- SOURCE_POLLFD,
- SOURCE_IOCHANNEL
- } _type;
- int _fd;
- Glib::PollFD _pollfd;
- Glib::RefPtr<Glib::IOChannel> _channel;
- Glib::IOCondition _events;
- int _timeout;
- SourceCallbackFunction _callback;
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(EventSource *source) { delete source; }
- };
- friend class Deleter;
- friend class Session;
- friend class SourceCallbackData;
-};
-