summaryrefslogtreecommitdiff
path: root/src/lib/nfs
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-10 23:15:16 +0100
committerMax Kellermann <max@musicpd.org>2017-01-15 00:58:49 +0100
commit6c293a3d7f4ce3a06fbd881349d69d2e9a69284f (patch)
treebf74a112653cbfcdc7ffbfd50837fac10cae523a /src/lib/nfs
parente847ddf0110d498764e179ba7958253eecaece64 (diff)
lib/nfs: add more API documentation
Diffstat (limited to 'src/lib/nfs')
-rw-r--r--src/lib/nfs/Callback.hxx12
-rw-r--r--src/lib/nfs/FileReader.hxx43
2 files changed, 55 insertions, 0 deletions
diff --git a/src/lib/nfs/Callback.hxx b/src/lib/nfs/Callback.hxx
index a21d9e5d8..18bba6343 100644
--- a/src/lib/nfs/Callback.hxx
+++ b/src/lib/nfs/Callback.hxx
@@ -24,9 +24,21 @@
#include <exception>
+/**
+ * Callbacks for an asynchronous libnfs operation.
+ *
+ * Note that no callback is invoked for cancelled operations.
+ */
class NfsCallback {
public:
+ /**
+ * The operation completed successfully.
+ */
virtual void OnNfsCallback(unsigned status, void *data) = 0;
+
+ /**
+ * An error has occurred.
+ */
virtual void OnNfsError(std::exception_ptr &&e) = 0;
};
diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx
index d43103cd0..911e62053 100644
--- a/src/lib/nfs/FileReader.hxx
+++ b/src/lib/nfs/FileReader.hxx
@@ -35,6 +35,14 @@
struct nfsfh;
class NfsConnection;
+/**
+ * A helper class which helps with reading from a file. It obtains a
+ * connection lease (#NfsLease), opens the given file, "stats" the
+ * file, and finally allos you to read its contents.
+ *
+ * To get started, derive your class from it and implement the pure
+ * virtual methods, construct an instance, and call Open().
+ */
class NfsFileReader : NfsLease, NfsCallback, DeferredMonitor {
enum class State {
INITIAL,
@@ -63,14 +71,30 @@ public:
void DeferClose();
/**
+ * Open the file. This method is thread-safe.
+ *
* Throws std::runtime_error on error.
*/
void Open(const char *uri);
/**
+ * Attempt to read from the file. This may only be done after
+ * OnNfsFileOpen() has been called. Only one read operation
+ * may be performed at a time.
+ *
+ * This method is not thread-safe and must be called from
+ * within the I/O thread.
+ *
* Throws std::runtime_error on error.
*/
void Read(uint64_t offset, size_t size);
+
+ /**
+ * Cancel the most recent Read() call.
+ *
+ * This method is not thread-safe and must be called from
+ * within the I/O thread.
+ */
void CancelRead();
bool IsIdle() const {
@@ -78,8 +102,27 @@ public:
}
protected:
+ /**
+ * The file has been opened successfully. It is a regular
+ * file, and its size is known. It is ready to be read from
+ * using Read().
+ *
+ * This method will be called from within the I/O thread.
+ */
virtual void OnNfsFileOpen(uint64_t size) = 0;
+
+ /**
+ * A Read() has completed successfully.
+ *
+ * This method will be called from within the I/O thread.
+ */
virtual void OnNfsFileRead(const void *data, size_t size) = 0;
+
+ /**
+ * An error has occurred, which can be either while waiting
+ * for OnNfsFileOpen(), or while waiting for OnNfsFileRead(),
+ * or if disconnected while idle.
+ */
virtual void OnNfsFileError(std::exception_ptr &&e) = 0;
private: