#include #include static GMainLoop *main_loop = NULL; /* g_main_loop_quit (main_loop); */ static gboolean data_pending (GIOChannel *source, GIOCondition condition, FAMConnection *fam_connection) { g_assert (condition == G_IO_IN || condition == G_IO_PRI); while (FAMPending (fam_connection)) { FAMEvent event; if (FAMNextEvent (fam_connection, &event) != 1) { FAMClose (fam_connection); /* io_watch = 0; */ return FALSE; } /* can user event.user_data, passed as final argument to monitor */ /* note event.filename can be a relative or absolute path * if relative append it to the directory you're monitoring */ #define PRINT_EVENT(e) g_print ("Got event: %d %s " e "\n", event.code, event.filename); switch (event.code) { case FAMChanged: PRINT_EVENT ("changed"); break; case FAMDeleted: PRINT_EVENT ("deleted"); break; case FAMStartExecuting: PRINT_EVENT ("start-executing"); break; case FAMStopExecuting: PRINT_EVENT ("stop-executing"); break; case FAMCreated: PRINT_EVENT ("created"); break; case FAMAcknowledge: PRINT_EVENT ("acknowledge"); break; case FAMExists: PRINT_EVENT ("exists"); break; case FAMEndExist: PRINT_EVENT ("end-exist"); break; case FAMMoved: PRINT_EVENT ("moved"); break; default: g_assert_not_reached (); break; } } return TRUE; /* return FALSE to remove */ } int main (int argc, char **argv) { FAMConnection fam_connection; FAMRequest fam_request; GIOChannel *io_channel; guint io_watch; if (FAMOpen (&fam_connection) != 0) { g_warning ("Failed to connect to the FAM server: %s", FamErrlist[FAMErrno]); return 1; } if (FAMMonitorDirectory (&fam_connection, "/home/markmc", &fam_request, NULL) != 0) { g_warning ("Failed to add homedir monitor: %s", FamErrlist[FAMErrno]); return 1; } io_channel = g_io_channel_unix_new (FAMCONNECTION_GETFD (&fam_connection)); io_watch = g_io_add_watch (io_channel, G_IO_IN|G_IO_PRI, (GIOFunc) data_pending, &fam_connection); main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); g_source_remove (io_watch); g_io_channel_unref (io_channel); return 0; }