- * Copyright 1999, 2000, 2001, 2003 Bernardo Innocenti <bernie@develer.com>
+ * Copyright 1999, 2000, 2001, 2003 Bernie Innocenti <bernie@codewiz.org>
- * KFile is a generic interface for file I/O.
- * It uses an object-oriented model to supply
- * a generic interface for drivers to communicate.
+ *
+ * KFile is a simple, generic interface for file I/O. It uses an
+ * object-oriented model to supply a device-neutral interface to
+ * communicate with drivers.
+ *
- * and an API.
- * Each KFile user should implement at least some methods.
- * E.G.
- * If you have a serial driver and want to comply to KFile interface,
- * you have to declare your context structure:
+ * and the common API.
+ * Each KFile subclass can override one or more methods of the interface,
+ * and can extend the base KFile structure with its own private data.
+ * For instance, a serial driver might implement the KFile interface by
+ * declaring a context structure like this:
- * Then you can implement as much interface functions as you like
- * and leave the others to NULL.
- * ser_close implementation example:
+ * Then you can implement as many interface functions as needed
+ * and leave the rest to NULL.
+ *
+ * Example implementation of the close KFile method for Serial:
- * KFile interface do not supply the open function: this is deliberate,
+ * The SERIAL_CAST() macro helps ensure that the passed object is
+ * really of type Serial.
+ *
+ * The KFile interface does not supply an open function: this is deliberate,
- * For the same reason specific file settings (like baudrate for Serial, for example)
- * are demanded to specific driver implementation.
+ * For the same reason, specific device settings like, for example,
+ * the baudrate, are not part of interface and should be handled by the
+ * driver-specific API.
-typedef int32_t kfile_off_t; ///< KFile offset type, used by kfile_seek function.
-typedef int32_t kfile_size_t; ///< KFile size type, used in kfile struct.
+typedef int32_t kfile_off_t; ///< KFile offset type, used by kfile_seek().
int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write.
int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read.
int kfile_printf(struct KFile *fd, const char *format, ...);
int kfile_print(struct KFile *fd, const char *s);
int kfile_gets(struct KFile *fd, char *buf, int size);
int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write.
int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read.
int kfile_printf(struct KFile *fd, const char *format, ...);
int kfile_print(struct KFile *fd, const char *s);
int kfile_gets(struct KFile *fd, char *buf, int size);
int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo);
-bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
+int kfile_testSetup(void);
+int kfile_testRun(void);
+int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size);
+int kfile_testTearDown(void);
+