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