Giter VIP home page Giter VIP logo

readdirectorychanges's Introduction

ReadDirectoryChanges

Status: Release candidate. This code has been tested, but not exhaustively.

This sample code goes with my blog entry titled, Understanding ReadDirectoryChangesW

Please create a new issue or pull request for issues with this code.

This project is for Visual Studio 2010. It should build and work fine under Visual Studio 2005 through 2014, although you'll need new solution and project files for older versions. All project options were left at the default.

Usage

When the application starts, it immediately starts monitoring your home directory, including children, as well as C:, not including children. The application exits when you hit Esc.

You can add a directory to the monitoring list by typing the directory name and hitting Enter. Notifications will pause while you type.

Code overview

This sample includes four classes and a main() function to drive them.

CReadDirectoryChanges

This is the public interface. It starts the worker thread and shuts it down, provides a waitable queue, and allows you to add directories.

CReadChangesServer

This is the server class that runs in the worker thread. One instance of this object is allocated for each instance of CReadDirectoryChanges. This class is responsible for thread startup, orderly thread shutdown, and shimming the various C-style callback functions to C++ member functions.

CReadChangesRequest

One instance of CReadChangesRequest is created for each monitored directory. It contains the OVERLAPPED structure, the data buffer, the completion notification function, and code to unpack the notification buffer. When a notification arrives, the data is unpacked and each change is sent to the queue in CReadDirectoryChanges. All instances of this class run in the worker thread

CThreadSafeQueue

Generic template class that provides a thread-safe, bounded queue that can be waited on using any of the Win32 WaitXxx functions.

Implementation notes

This is a Unicode project. I haven't tried to build it single-byte, but it should work fine.

The only notably missing function is RemoveDirectory. This is straightforward to implement. Create the appropriate shim and member functions in CReadChangesServer. In the member function, search m_pBlocks for the directory, call RequestTermination() on that block, and delete the block from the m_pBlocks vector.

readdirectorychanges's People

Contributors

jimbeveridge avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.