1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <zircon/compiler.h> 8 #include <lib/fdio/io.h> 9 10 __BEGIN_CDECLS 11 12 typedef zx_status_t (*watchdir_func_t)(int dirfd, int event, const char* fn, void* cookie); 13 14 // This event occurs when a file is added or removed, including 15 // (for fdio_watch_directory()) files that already exist. 16 #define WATCH_EVENT_ADD_FILE 1 17 #define WATCH_EVENT_REMOVE_FILE 2 18 19 // This event occurs, once, when fdio_watch_directory() runs 20 // out of existing files and has to start waiting for new 21 // files to be added. 22 #define WATCH_EVENT_IDLE 3 23 24 // Call the provided callback (cb) for each file in directory 25 // and each time a new file is added to the directory. 26 // 27 // If the callback returns a status other than ZX_OK, watching 28 // stops and the callback's status is returned to the caller 29 // of fdio_watch_directory. 30 // 31 // If the deadline expires, ZX_ERR_TIMED_OUT is returned to the 32 // caller. A deadline of ZX_TIME_INFINITE will never expire. 33 // 34 // The callback may use ZX_ERR_STOP as a way to signal to the 35 // caller that it wants to stop because it found what it was 36 // looking for, etc -- since this error code is not returned 37 // by syscalls or public APIs, the callback does not need to 38 // worry about it turning up normally. 39 40 zx_status_t fdio_watch_directory(int dirfd, watchdir_func_t cb, zx_time_t deadline, void* cookie); 41 42 43 __END_CDECLS 44