6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / lib / libnisdb / db_pickle.h
blob91e1444619e0db21b1f08813f094c89ce397467b
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * db_pickle.h
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 #ifndef PICKLE_H
32 #define PICKLE_H
34 #include "nisdb_rw.h"
37 * 'pickle' is the package for storing data structures into files.
38 * 'pickle_file' is the base class. Classes that inherit this base
39 * class need to instantiate the virtual function 'dump'.
42 enum pickle_mode {
43 PICKLE_READ, PICKLE_WRITE, PICKLE_APPEND
46 typedef enum pickle_mode pickle_mode;
48 typedef void* pptr; /* pickle pointer */
50 class pickle_file {
51 protected:
52 FILE *file; /* file handle */
53 pickle_mode mode;
54 XDR xdr;
55 char *filename;
56 STRUCTRWLOCK(pickle);
57 public:
59 /* Constructor. Creates pickle_file with given name and mode. */
60 pickle_file(char *, pickle_mode);
62 ~pickle_file() { delete filename; DESTROYRW(pickle); }
65 * Opens pickle_file with mode specified with constructor.
66 * Returns TRUE if open was successful; FALSE otherwise.
68 bool_t open();
70 /* Closes pickle_file. Returns 0 if successful; -1 otherwise. */
71 int close();
74 * dump or load data structure to/from 'filename' using function 'f'.
75 * dump/load is determined by 'mode' with which pickle_file was created.
76 * Returns 0 if successful; 1 if file cannot be opened in mode
77 * specified; -1 if transfer failed do to encoding/decoding errors.
79 int transfer(pptr, bool_t (*f) (XDR*, pptr));
81 /* Exclusive access */
82 int acqexcl(void) {
83 return (WLOCK(pickle));
86 int relexcl(void) {
87 return (WULOCK(pickle));
90 #endif /* PICKLE_H */