Exemplo n.º 1
0
extern "C" int main(int argc, char* argv[])
{
	PDirWatch dirWatch1;
	PDirWatch dirWatch2;
    DirWatchNotifications notifications;
    signal(SIGINT, onsig);
    if (0 != dir_watch_Add("/home/shore/lab/test/c/fam", dirWatch1))
    {
		std::cerr << "dir_watch_Add fail" << std::endl;
		return EXIT_FAILURE;
    }
    std::cout << "dirWatch1 OK" << std::endl;
    if (0 != dir_watch_Add("/home/shore/lab/test/c", dirWatch2))
    {
		std::cerr << "dir_watch_Add fail" << std::endl;
		return EXIT_FAILURE;
    }
    std::cout << "dirWatch2 OK" << std::endl;

    std::cout << "dir_watch_Add OK" << std::endl;
    do {
        sleep(4);
        if (0 != dir_watch_Poll(notifications))
        {
		    std::cerr << "dir_watch_Poll fail" << std::endl;
		    return EXIT_FAILURE;
        }

	    for(size_t i = 0; i < notifications.size(); ++i)
        {
            std::cout << notifications[i].Pathname() << std::endl;
            switch(notifications[i].Type())
            {
                case DirWatchNotification::Created:
                    std::cout << "event:Created" << std::endl;
                    break;
                case DirWatchNotification::Deleted:
                    std::cout << "event:Deleted" << std::endl;
                    break;
                case DirWatchNotification::Changed:
                    std::cout << "event:Changed" << std::endl;
                    break;
            }
        }
        if (notifications.size() > 0)
            notifications.clear();
        else
            std::cout << "nothing fetched" << std::endl;
    } while(true);

    dirWatch1.reset();
    dirWatch2.reset();

    return 0;
}
Exemplo n.º 2
0
Status ReloadChangedFiles()
{
	std::vector<DirWatchNotification> notifications;
	RETURN_STATUS_IF_ERR(dir_watch_Poll(notifications));
	for(size_t i = 0; i < notifications.size(); i++)
	{
		if(!CanIgnore(notifications[i]))
		{
			VfsPath pathname;
			RETURN_STATUS_IF_ERR(g_VFS->GetVirtualPath(notifications[i].Pathname(), pathname));
			RETURN_STATUS_IF_ERR(g_VFS->Invalidate(pathname));

			// Tell each hotloadable system about this file change:

			RETURN_STATUS_IF_ERR(g_GUI->ReloadChangedFiles(pathname));

			for (size_t j = 0; j < g_ReloadFuncs.size(); ++j)
				g_ReloadFuncs[j].first(g_ReloadFuncs[j].second, pathname);

			RETURN_STATUS_IF_ERR(h_reload(g_VFS, pathname));
		}
	}
	return INFO::OK;
}