kfile.h File Reference
Virtual KFile I/O interface. More...
#include <cfg/compiler.h>
#include <cfg/debug.h>
#include <cfg/macros.h>
Go to the source code of this file.
Data Structures | |
| struct | KFile |
| Context data for callback functions which operate on pseudo files. More... | |
Typedefs | |
| typedef int32_t | kfile_off_t |
| KFile offset type, used by kfile_seek function. | |
| typedef size_t(* | ReadFunc_t )(struct KFile *fd, void *buf, size_t size) |
| Prototypes for KFile access functions. | |
| typedef size_t(* | WriteFunc_t )(struct KFile *fd, const void *buf, size_t size) |
| Write to file. | |
| typedef kfile_off_t(* | SeekFunc_t )(struct KFile *fd, kfile_off_t offset, KSeekMode whence) |
| Seek into file (if seekable). | |
| typedef struct KFile *(* | ReOpenFunc_t )(struct KFile *fd) |
| Close and reopen file fd. | |
| typedef int(* | CloseFunc_t )(struct KFile *fd) |
| Close file. | |
| typedef int(* | FlushFunc_t )(struct KFile *fd) |
| Flush file I/O. | |
| typedef int(* | ErrorFunc_t )(struct KFile *fd) |
| Get file error mask. | |
| typedef void(* | ClearErrFunc_t )(struct KFile *fd) |
| Clear errors. | |
Enumerations | |
| enum | KSeekMode { KSM_SEEK_SET, KSM_SEEK_CUR, KSM_SEEK_END } |
| Costants for repositioning read/write file offset. More... | |
Functions | |
| kfile_off_t | kfile_genericSeek (struct KFile *fd, kfile_off_t offset, KSeekMode whence) |
| Generic implementation of kfile_seek. | |
| struct KFile * | kfile_genericReopen (struct KFile *fd) |
| Generic implementation of kfile_reopen. | |
| 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_print (struct KFile *fd, const char *s) |
| Write a string to kfile fd. | |
| bool | kfile_test (KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size) |
| Kfile test function. | |
| size_t | kfile_read (struct KFile *fd, void *buf, size_t size) |
| Interface functions for KFile access. | |
Detailed Description
Virtual KFile I/O interface.KFile is a generic interface for file I/O. It uses an object-oriented model to supply a generic interface for drivers to communicate. This module contains only definitions, the instance structure 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:
You should also supply a macro for casting KFile to KFileSerial:
INLINE KFileSerial * KFILESERIAL(KFile *fd) { ASSERT(fd->_type == KFT_SERIAL); return (KFileSerial *)fd; }
Then you can implement as much interface functions as you like and leave the others to NULL. ser_close implementation example:
static int ser_kfile_close(struct KFile *fd) { KFileSerial *fds = KFILESERIAL(fd); ser_close(fds->ser); return 0; }
KFile interface do not supply the open function: this is deliberate, because in embedded systems each device has its own init parameters. For the same reason specific file settings (like baudrate for Serial, for example) are demanded to specific driver implementation.
- Version:
- Id
- kfile.h 1144 2008-02-19 16:56:14Z batt
Definition in file kfile.h.
Typedef Documentation
| typedef int(* CloseFunc_t)(struct KFile *fd) |
| typedef int(* ErrorFunc_t)(struct KFile *fd) |
| typedef int(* FlushFunc_t)(struct KFile *fd) |
| typedef size_t(* ReadFunc_t)(struct KFile *fd, void *buf, size_t size) |
| typedef struct KFile*(* ReOpenFunc_t)(struct KFile *fd) |
| typedef kfile_off_t(* SeekFunc_t)(struct KFile *fd, kfile_off_t offset, KSeekMode whence) |
| typedef size_t(* WriteFunc_t)(struct KFile *fd, const void *buf, size_t size) |
Enumeration Type Documentation
| enum KSeekMode |
Function Documentation
| kfile_off_t kfile_genericSeek | ( | struct KFile * | fd, | |
| kfile_off_t | offset, | |||
| KSeekMode | whence | |||
| ) |
| int kfile_print | ( | struct KFile * | fd, | |
| const char * | s | |||
| ) |
| size_t kfile_read | ( | struct KFile * | fd, | |
| void * | buf, | |||
| size_t | size | |||
| ) | [inline] |
