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