source: trunk/kStuff/include/k/kRdr.h@ 3542

Last change on this file since 3542 was 3542, checked in by bird, 18 years ago

Refactorying kLdrRdr into kRdr.

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: kRdr.h 3542 2007-08-25 04:40:45Z bird $ */
2/** @file
3 * kRdr - The File Provider.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This file is part of kStuff.
10 *
11 * kStuff is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kStuff is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with kStuff; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef ___kRdr_h___
28#define ___kRdr_h___
29
30#include <k/kDefs.h>
31#ifndef ___k_kLdr___
32/* avoid dragging in kLdr.h */
33typedef enum KLDRPROT { KLDRPROT_32BIT_HACK = 0x7fffffff } KLDRPROT;
34typedef const struct KLDRSEG *PCKLDRSEG;
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41
42/** @defgroup grp_kRdr kRdr - The File Provider
43 * @{ */
44
45/** Pointer to a file provider instance core. */
46typedef struct KRDR *PKRDR;
47/** Pointer to a file provider instance core pointer. */
48typedef struct KRDR **PPKRDR;
49
50/**
51 * File provider instance operations.
52 */
53typedef struct KRDROPS
54{
55 /** The name of this file provider. */
56 const char *pszName;
57 /** Pointer to the next file provider. */
58 const struct KRDROPS *pNext;
59
60 /** Try create a new file provider instance.
61 *
62 * @returns 0 on success, OS specific error code on failure.
63 * @param ppRdr Where to store the file provider instance.
64 * @param pszFilename The filename to open.
65 */
66 int (* pfnCreate)( PPKRDR ppRdr, const char *pszFilename);
67 /** Destroy the file provider instance.
68 *
69 * @returns 0 on success, OS specific error code on failure.
70 * On failure, the file provider instance will be in an indeterminate state - don't touch it!
71 * @param pRdr The file provider instance.
72 */
73 int (* pfnDestroy)( PKRDR pRdr);
74 /** @copydoc kRdrRead */
75 int (* pfnRead)( PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);
76 /** @copydoc kRdrAllMap */
77 int (* pfnAllMap)( PKRDR pRdr, const void **ppvBits);
78 /** @copydoc kRdrAllUnmap */
79 int (* pfnAllUnmap)(PKRDR pRdr, const void *pvBits);
80 /** @copydoc kRdrSize */
81 KFOFF (* pfnSize)( PKRDR pRdr);
82 /** @copydoc kRdrTell */
83 KFOFF (* pfnTell)( PKRDR pRdr);
84 /** @copydoc kRdrName */
85 const char * (* pfnName)(PKRDR pRdr);
86 /** @copydoc kRdrPageSize */
87 KSIZE (* pfnPageSize)(PKRDR pRdr);
88 /** @copydoc kRdrMap */
89 int (* pfnMap)( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed);
90 /** @copydoc kRdrRefresh */
91 int (* pfnRefresh)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
92 /** @copydoc kRdrProtect */
93 int (* pfnProtect)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
94 /** @copydoc kRdrUnmap */
95 int (* pfnUnmap)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
96 /** @copydoc kRdrDone */
97 void (* pfnDone)( PKRDR pRdr);
98 /** The usual non-zero dummy that makes sure we've initialized all members. */
99 KU32 u32Dummy;
100} KRDROPS;
101/** Pointer to file provider operations. */
102typedef KRDROPS *PKRDROPS;
103/** Pointer to const file provider operations. */
104typedef const KRDROPS *PCKRDROPS;
105
106
107/**
108 * File provider instance core.
109 */
110typedef struct KRDR
111{
112 /** Magic number (KLDRRDR_MAGIC). */
113 KU32 u32Magic;
114 /** Pointer to the file provider operations. */
115 PCKRDROPS pOps;
116} KRDR;
117
118/** The magic for KRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */
119#define KRDR_MAGIC 0x19610919
120
121void kRdrAddProvider(PKRDROPS pAdd);
122
123int kRdrOpen(PPKRDR ppRdr, const char *pszFilename);
124int kRdrOpenBuffered(PPKRDR ppRdr, const char *pszFilename);
125
126int kRdrClose( PKRDR pRdr);
127int kRdrRead( PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);
128int kRdrAllMap( PKRDR pRdr, const void **ppvBits);
129int kRdrAllUnmap(PKRDR pRdr, const void *pvBits);
130KFOFF kRdrSize( PKRDR pRdr);
131KFOFF kRdrTell( PKRDR pRdr);
132const char *kRdrName(PKRDR pRdr);
133KIPTR kRdrNativeFH(PKRDR pRdr);
134
135KSIZE kRdrPageSize(PKRDR pRdr);
136int kRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed);
137int kRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
138int kRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
139int kRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
140void kRdrDone( PKRDR pRdr);
141
142/** @} */
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif
149
Note: See TracBrowser for help on using the repository browser.