An example of how to use the Async::FdWatch class
#include <unistd.h>
#include <cstdio>
#include <iostream>
using namespace std;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
stdin_watch =
new FdWatch(STDIN_FILENO, FdWatch::FD_WATCH_RD);
stdin_watch->activity.connect(mem_fun(*this, &MyClass::onActivity));
}
~MyClass(void)
{
delete stdin_watch;
}
private:
{
char buf[1024];
int cnt = read(watch->
fd(), buf,
sizeof(buf)-1);
if (cnt == -1)
{
perror("read");
Application::app().quit();
return;
}
buf[cnt] = 0;
cout << "Read from STDIN: " << buf << endl;
}
};
int main(int argc, char **argv)
{
MyClass my_class;
}
The core class for writing asyncronous cpp applications.
Contains a watch for file descriptors.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A class for watching file descriptors.
int fd(void) const
Return the file descriptor being watched.
Namespace for the asynchronous programming classes.