citrus_mapper.h revision 1.3 1 1.3 tshiozak /* $NetBSD: citrus_mapper.h,v 1.3 2003/07/12 15:39:19 tshiozak Exp $ */
2 1.1 tshiozak
3 1.1 tshiozak /*-
4 1.1 tshiozak * Copyright (c)2003 Citrus Project,
5 1.1 tshiozak * All rights reserved.
6 1.1 tshiozak *
7 1.1 tshiozak * Redistribution and use in source and binary forms, with or without
8 1.1 tshiozak * modification, are permitted provided that the following conditions
9 1.1 tshiozak * are met:
10 1.1 tshiozak * 1. Redistributions of source code must retain the above copyright
11 1.1 tshiozak * notice, this list of conditions and the following disclaimer.
12 1.1 tshiozak * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tshiozak * notice, this list of conditions and the following disclaimer in the
14 1.1 tshiozak * documentation and/or other materials provided with the distribution.
15 1.1 tshiozak *
16 1.1 tshiozak * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 tshiozak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 tshiozak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 tshiozak * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 tshiozak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 tshiozak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 tshiozak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 tshiozak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 tshiozak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 tshiozak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 tshiozak * SUCH DAMAGE.
27 1.1 tshiozak */
28 1.1 tshiozak
29 1.1 tshiozak #ifndef _CITRUS_MAPPER_H_
30 1.1 tshiozak #define _CITRUS_MAPPER_H_
31 1.1 tshiozak
32 1.1 tshiozak struct _citrus_mapper_area;
33 1.1 tshiozak struct _citrus_mapper;
34 1.1 tshiozak struct _citrus_mapper_ops;
35 1.1 tshiozak struct _citrus_mapper_traits;
36 1.1 tshiozak
37 1.1 tshiozak __BEGIN_DECLS
38 1.1 tshiozak int _citrus_mapper_create_area(
39 1.1 tshiozak struct _citrus_mapper_area *__restrict *__restrict,
40 1.1 tshiozak const char *__restrict);
41 1.1 tshiozak int _citrus_mapper_open(struct _citrus_mapper_area *__restrict,
42 1.1 tshiozak struct _citrus_mapper *__restrict *__restrict,
43 1.1 tshiozak const char *__restrict);
44 1.1 tshiozak int _citrus_mapper_open_direct(
45 1.1 tshiozak struct _citrus_mapper_area *__restrict,
46 1.1 tshiozak struct _citrus_mapper *__restrict *__restrict,
47 1.1 tshiozak const char *__restrict, const char *__restrict);
48 1.1 tshiozak void _citrus_mapper_close(struct _citrus_mapper *);
49 1.1 tshiozak void _citrus_mapper_set_persistent(struct _citrus_mapper * __restrict);
50 1.1 tshiozak __END_DECLS
51 1.1 tshiozak
52 1.1 tshiozak #include "citrus_mapper_local.h"
53 1.1 tshiozak
54 1.1 tshiozak /* return values of _citrus_mapper_convert */
55 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_SUCCESS (0)
56 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_NONIDENTICAL (1)
57 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_SRC_MORE (2)
58 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_DST_MORE (3)
59 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_ILSEQ (4)
60 1.3 tshiozak #define _CITRUS_MAPPER_CONVERT_FATAL (5)
61 1.1 tshiozak
62 1.1 tshiozak /*
63 1.1 tshiozak * _citrus_mapper_convert:
64 1.1 tshiozak * convert an index.
65 1.1 tshiozak * - if the converter supports M:1 converter, the function may return
66 1.1 tshiozak * _CITRUS_MAPPER_CONVERT_SRC_MORE and the storage pointed by dst
67 1.1 tshiozak * may be unchanged in this case, although the internal status of
68 1.1 tshiozak * the mapper is affected.
69 1.1 tshiozak * - if the converter supports 1:N converter, the function may return
70 1.1 tshiozak * _CITRUS_MAPPER_CONVERT_DST_MORE. In this case, the contiguous
71 1.1 tshiozak * call of this function ignores src and changes the storage pointed
72 1.1 tshiozak * by dst.
73 1.1 tshiozak * - if the converter supports M:N converter, the function may behave
74 1.1 tshiozak * the combination of the above.
75 1.1 tshiozak *
76 1.1 tshiozak */
77 1.1 tshiozak static __inline int
78 1.1 tshiozak _citrus_mapper_convert(struct _citrus_mapper * __restrict cm,
79 1.1 tshiozak _citrus_index_t * __restrict dst,
80 1.1 tshiozak _citrus_index_t src,
81 1.1 tshiozak void * __restrict ps)
82 1.1 tshiozak {
83 1.1 tshiozak
84 1.1 tshiozak _DIAGASSERT(cm && cm->cm_ops && cm->cm_ops->mo_convert && dst);
85 1.1 tshiozak
86 1.1 tshiozak return (*cm->cm_ops->mo_convert)(cm, dst, src, ps);
87 1.1 tshiozak }
88 1.1 tshiozak
89 1.1 tshiozak /*
90 1.1 tshiozak * _citrus_mapper_init_state:
91 1.1 tshiozak * initialize the state.
92 1.1 tshiozak */
93 1.1 tshiozak static __inline void
94 1.1 tshiozak _citrus_mapper_init_state(struct _citrus_mapper * __restrict cm,
95 1.1 tshiozak void * __restrict ps)
96 1.1 tshiozak {
97 1.1 tshiozak
98 1.2 tshiozak _DIAGASSERT(cm && cm->cm_ops && cm->cm_ops->mo_init_state);
99 1.1 tshiozak
100 1.1 tshiozak (*cm->cm_ops->mo_init_state)(cm, ps);
101 1.1 tshiozak }
102 1.1 tshiozak
103 1.1 tshiozak /*
104 1.1 tshiozak * _citrus_mapper_get_state_size:
105 1.1 tshiozak * get the size of state storage.
106 1.1 tshiozak */
107 1.1 tshiozak static __inline size_t
108 1.1 tshiozak _citrus_mapper_get_state_size(struct _citrus_mapper * __restrict cm)
109 1.1 tshiozak {
110 1.1 tshiozak
111 1.1 tshiozak _DIAGASSERT(cm && cm->cm_traits);
112 1.1 tshiozak
113 1.1 tshiozak return cm->cm_traits->mt_state_size;
114 1.1 tshiozak }
115 1.1 tshiozak
116 1.1 tshiozak /*
117 1.1 tshiozak * _citrus_mapper_get_src_max:
118 1.1 tshiozak * get the maximum number of suspended sources.
119 1.1 tshiozak */
120 1.1 tshiozak static __inline size_t
121 1.1 tshiozak _citrus_mapper_get_src_max(struct _citrus_mapper * __restrict cm)
122 1.1 tshiozak {
123 1.1 tshiozak
124 1.1 tshiozak _DIAGASSERT(cm && cm->cm_traits);
125 1.1 tshiozak
126 1.1 tshiozak return cm->cm_traits->mt_src_max;
127 1.1 tshiozak }
128 1.1 tshiozak
129 1.1 tshiozak /*
130 1.1 tshiozak * _citrus_mapper_get_dst_max:
131 1.1 tshiozak * get the maximum number of suspended destinations.
132 1.1 tshiozak */
133 1.1 tshiozak static __inline size_t
134 1.1 tshiozak _citrus_mapper_get_dst_max(struct _citrus_mapper * __restrict cm)
135 1.1 tshiozak {
136 1.1 tshiozak
137 1.1 tshiozak _DIAGASSERT(cm && cm->cm_traits);
138 1.1 tshiozak
139 1.1 tshiozak return cm->cm_traits->mt_dst_max;
140 1.1 tshiozak }
141 1.1 tshiozak
142 1.1 tshiozak #endif
143