xref: /illumos-gate/usr/src/lib/libnisdb/db_c.x (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	db_c.x
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #if RPC_HDR
30 %#ifndef _DB_DB_H
31 %#define _DB_DB_H
32 
33 #ifdef USINGC
34 %#include "db_mindex_c.h"
35 %#include "db_vers_c.h"
36 %#include "db_entry_c.h"
37 #else
38 %#include "nisdb_rw.h"
39 %#include "db_log.h"
40 %#include "db_mindex.h"
41 %#include "db_vers.h"
42 %#include "db_entry.h"
43 %#include "db_scheme.h"
44 #endif /* USINGC */
45 #endif /* RPC_HDR */
46 
47 #if RPC_HDR || RPC_XDR
48 #ifdef USINGC
49 struct db {
50   char* logfilename;
51   char* dbfilename;
52   char* tmpfilename;
53   db_log *logfile;
54   db_mindex internal_db;
55   bool logfile_opened;
56   bool changed;
57   __nisdb_rwlock_t db_rwlock;
58 };
59 #endif /* USINGC */
60 #endif /* RPC_HDR */
61 
62 #ifndef USINGC
63 #ifdef RPC_HDR
64 %class db {
65 %  char* logfilename;
66 %  char* dbfilename;
67 %  char* tmpfilename;
68 %  db_log *logfile;
69 %  db_mindex internal_db;
70 %  bool_t logfile_opened;
71 %  bool_t changed;
72 %  STRUCTRWLOCK(db);
73 %
74 %/* Delete old log file and descriptor */
75 %  int reset_log();
76 %
77 %/* Open log file (and creates descriptor) if it has not been opened */
78 %  int open_log(bool_t copylog);
79 %
80 %/* Incorporate updates in log to database already loaded.
81 %   Does not affect "logfile" */
82 %  int incorporate_log( char * );
83 %
84 %/* Execute the specified action using the rest of the arguments as input.
85 %   Return  a structure db_result containing the result. */
86 %  db_result * exec_action( db_action, db_query *, entry_object *,
87 %			  db_next_desc *previous );
88 % public:
89 %/*  Log the given action and execute it.
90 %    The minor version of the database is updated after the action has
91 %    been executed and the database is flagged as being changed.
92 %    Return the structure db_result, or NULL if the loggin failed or the
93 %    action is unknown. */
94 %  db_result * log_action( db_action, db_query *, entry_object * );
95 %
96 %  /* closes log file if opened */
97 %  /* removes self from list of dbs have opened files */
98 %  int close_log(int bypass_standby = 0);
99 %
100 %/* Constructor:  Create a database using the given name, 'dbname.'
101 %   The database is stored in a file named 'dbname'.
102 %   The log file is stored in a file named 'dbname'.log.
103 %   A temporary file 'dbname'.tmp is also used.   */
104 %  db( char * );
105 %
106 %/* Destructor:  deletes filenames and logfile descriptor.
107 %   Note that associated files should be removed separately.  */
108 %  ~db();
109 %
110 %/* Write out in-memory copy of database to file.
111 %   1.  Update major version.
112 %   2.  Dump contents to temporary file.
113 %   3.  Rename temporary file to real database file.
114 %   4.  Remove log file.
115 %   A checkpoint is done only if it has changed since the previous checkpoint.
116 %   Returns TRUE if checkpoint was successful; FALSE otherwise. */
117 %  bool_t checkpoint();
118 %
119 %/* Load database and incorporate any logged updates into the loaded copy.
120 %   Return TRUE if load succeeds; FALSE otherwise. */
121 %  bool_t load();
122 %
123 %/* Dump this database to a file.
124 %   Return TRUE if dump succeeds; FALSE otherwise. */
125 %  bool_t dump(char *outfile) {return (internal_db.dump(outfile));};
126 %
127 %/* Initialize the database using table scheme 's'.
128 %   Because the 'scheme' must be 'remembered' between restarts,
129 %   after the initialization, the empty database is checkpointed to record
130 %   the scheme. Returns TRUE if initialization succeeds; FALSE otherwise. */
131 %  bool_t init( db_scheme *s );
132 %
133 %/* Print out the database's statistics. */
134 %  void print()    { internal_db.print_stats();}
135 %
136 %/* Return whether the database has changed since its previous checkpoint. */
137 %  bool_t changedp() { return changed;}
138 %
139 %/* Return the version of the database. */
140 %  vers* get_version() { return internal_db.get_version(); }
141 %
142 %
143 %/* Execute 'action' using the rest of the arguments as input.
144 %   Return the result of the operation in a db_result structure;
145 %   Return NULL if the request is unknown.
146 %   If the action involves updates (ADD and REMOVE), it is logged first. */
147 %  db_result* execute( db_action, db_query *, entry_object *,
148 %			  db_next_desc* previous );
149 %
150 %/* Execute log entry 'j' on this db.  'j' is executed if its version is
151 %   later than that of the database; if executed, the database's version
152 %   will be changed to that of 'j', regardless of the status of the operation.
153 %   Returns TRUE if 'j' was executed;   FALSE if it was not.
154 %   Log entry is added to this database's log if log_entry is applied. */
155 %  bool_t execute_log_entry( db_log_entry * );
156 %
157 %/* Return structure db_log_list containing entries that are later
158 %   than the version 'v' given.  */
159 %  db_log_list * get_log_entries_since( vers * );
160 %
161 %/* Sync the table log file */
162 %  db_status	sync_log();
163 %
164 %/* Delete all files associated with database. */
165 %  int remove_files();
166 %
167 %  /* for debugging */
168 %/* Print information on all indices of the database to stdout. */
169 %  void print_all_indices() {internal_db.print_all_indices();}
170 %
171 %/* Print information on specified index of the the database to stdout. */
172 %  void print_index( int n ) {internal_db.print_index( n ); }
173 %
174 %/* Mark this instance deferred */
175 %  void markDeferred(void) {
176 %	internal_db.markDeferred();
177 %  }
178 %
179 %/* Remove defer marking */
180 %  void unmarkDeferred(void) {
181 %	internal_db.unmarkDeferred();
182 %  }
183 %
184 %/* Exclusive access to this instance */
185 %  int acqexcl(void) {
186 %	return (WLOCK(db));
187 %  }
188 %
189 %/* Non-blocking exclusive access */
190 %  int tryacqexcl(void) {
191 %	return (TRYWLOCK(db));
192 %  }
193 %
194 %/* Release exclusive access */
195 %  int relexcl(void) {
196 %	return (WULOCK(db));
197 %  }
198 %
199 %/* Non-exclusive (readonly) access to this instance */
200 %  int acqnonexcl(void) {
201 %	return (RLOCK(db));
202 %  }
203 %
204 %/* Release non-exlusive access */
205 %  int relnonexcl(void) {
206 %	return (RULOCK(db));
207 %  }
208 %
209 %/* Destroy instance lock */
210 %  int destroylock(void) {
211 %	return (DESTROYRW(db));
212 %  }
213 %
214 %/* Pass configuration information to the db_mindex */
215 %  bool_t configure(char *objName);
216 %
217 %/* Export a pointer to the db_mindex structure */
218 %  db_mindex *mindex(void);
219 %};
220 %
221 %typedef class db * dbp;
222 #endif /* USINGC */
223 #endif /* RPC_HDR */
224 
225 #if RPC_HDR
226 %#endif /* _DB_DB_H */
227 #endif /* RPC_HDR */
228