1 /* 2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC. 3 LLNL-CODE-425250. 4 All rights reserved. 5 6 This file is part of Silo. For details, see silo.llnl.gov. 7 8 Redistribution and use in source and binary forms, with or without 9 modification, are permitted provided that the following conditions 10 are met: 11 12 * Redistributions of source code must retain the above copyright 13 notice, this list of conditions and the disclaimer below. 14 * Redistributions in binary form must reproduce the above copyright 15 notice, this list of conditions and the disclaimer (as noted 16 below) in the documentation and/or other materials provided with 17 the distribution. 18 * Neither the name of the LLNS/LLNL nor the names of its 19 contributors may be used to endorse or promote products derived 20 from this software without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE 26 LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35 This work was produced at Lawrence Livermore National Laboratory under 36 Contract No. DE-AC52-07NA27344 with the DOE. 37 38 Neither the United States Government nor Lawrence Livermore National 39 Security, LLC nor any of their employees, makes any warranty, express 40 or implied, or assumes any liability or responsibility for the 41 accuracy, completeness, or usefulness of any information, apparatus, 42 product, or process disclosed, or represents that its use would not 43 infringe privately-owned rights. 44 45 Any reference herein to any specific commercial products, process, or 46 services by trade name, trademark, manufacturer or otherwise does not 47 necessarily constitute or imply its endorsement, recommendation, or 48 favoring by the United States Government or Lawrence Livermore 49 National Security, LLC. The views and opinions of authors expressed 50 herein do not necessarily state or reflect those of the United States 51 Government or Lawrence Livermore National Security, LLC, and shall not 52 be used for advertising or product endorsement purposes. 53 */ 54 #ifndef _FILTER_H 55 #define _FILTER_H 56 57 58 /* 59 * Support for writing filters. 60 */ 61 62 #include "silo_private.h" 63 64 /*------------------------------------------------------------------------- 65 * Obtain the file id number to be used as an index into local filter tables. 66 * If the file is the null pointer, then we should immediately raise an 67 * error. 68 * F: A pointer (possibly NULL) to a DBfile 69 * M: Character pointer to filter function name (`me') 70 * 71 * This macro evaluates to the fileid on success, -1 on failure. 72 * 73 * Typical use: 74 * if ((id=FILTER_ID(dbfile,me))<0) return NULL ; 75 * 76 *------------------------------------------------------------------------- 77 */ 78 #define FILTER_ID(F,M) (!(F)||(F)->pub.fileid<0||(F)->pub.fileid>=DB_NFILES?\ 79 db_perror(NULL,E_NOFILE,(M)): \ 80 (F)->pub.fileid) 81 82 /*------------------------------------------------------------------------- 83 * Filters should be careful when calling the next filter or device driver 84 * since the function might not be supported by the device driver. This 85 * routine conditionally calls the device driver or returns the specified 86 * default value. 87 * CB: Ptr to the device driver function (possibly NULL). 88 * ARGS: An argument list for the device driver function. 89 * DFLT: Default value if CB is NULL. 90 * ME: Name of current filter function. 91 * 92 * Typical use: 93 * retval = FILTER_CALL (f_debug_cb[id].pub.mkdir,(dbfile,name), 94 * -1, me) ; 95 * 96 * Notes: 97 * The type of `DFLT' must be the same as the device driver routine 98 * return type. 99 *------------------------------------------------------------------------- 100 */ 101 #define FILTER_CALL(CB,ARGS,DFLT,ME) \ 102 ((CB)?(CB)ARGS: \ 103 (db_perror(NULL,E_NOTIMP,(ME)),DFLT)) 104 105 /*------------------------------------------------------------------------- 106 * Filter callbacks should usually be inserted into the DBfile structure 107 * only if the underlying filter or driver already supports the operation. 108 * NM: Name of the callback field in DBfile_pub. 109 * CB: The filter callback routine for this functionality. 110 * 111 * Typical use: 112 * FILTER_CB (close, f_debug_Close) ; 113 * 114 * Notes: 115 * The DBfile structure must be named `dbfile' 116 *------------------------------------------------------------------------- 117 */ 118 #define FILTER_CB(NM,CB) (dbfile->pub.NM=(dbfile->pub.NM?(CB):NULL)) 119 120 #endif /* !_FILTER_H */ 121