summaryrefslogtreecommitdiff
path: root/usr/src/lib/libnisdb/db_c.x
blob: c07bba18b113a47c60fcebd0da4e86a6e429a5fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 *	db_c.x
 *
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

%#pragma ident	"%Z%%M%	%I%	%E% SMI"

#if RPC_HDR
%#ifndef _DB_DB_H
%#define _DB_DB_H

#ifdef USINGC
%#include "db_mindex_c.h"
%#include "db_vers_c.h"
%#include "db_entry_c.h"
#else
%#include "nisdb_rw.h"
%#include "db_log.h"
%#include "db_mindex.h"
%#include "db_vers.h"
%#include "db_entry.h"
%#include "db_scheme.h"
#endif /* USINGC */
#endif /* RPC_HDR */

#if RPC_HDR || RPC_XDR 
#ifdef USINGC
struct db {
  char* logfilename;
  char* dbfilename;
  char* tmpfilename;
  db_log *logfile;
  db_mindex internal_db;
  bool logfile_opened;
  bool changed;
  __nisdb_rwlock_t db_rwlock;
};
#endif /* USINGC */
#endif /* RPC_HDR */

#ifndef USINGC
#ifdef RPC_HDR 
%class db {
%  char* logfilename;
%  char* dbfilename;
%  char* tmpfilename;
%  db_log *logfile;
%  db_mindex internal_db;
%  bool_t logfile_opened;
%  bool_t changed;
%  STRUCTRWLOCK(db);
%
%/* Delete old log file and descriptor */
%  int reset_log();
%
%/* Open log file (and creates descriptor) if it has not been opened */
%  int open_log(bool_t copylog);
%
%/* Incorporate updates in log to database already loaded.
%   Does not affect "logfile" */
%  int incorporate_log( char * );
%
%/* Execute the specified action using the rest of the arguments as input.
%   Return  a structure db_result containing the result. */
%  db_result * exec_action( db_action, db_query *, entry_object *, 
%			  db_next_desc *previous );
% public:
%/*  Log the given action and execute it.
%    The minor version of the database is updated after the action has
%    been executed and the database is flagged as being changed.
%    Return the structure db_result, or NULL if the loggin failed or the
%    action is unknown. */
%  db_result * log_action( db_action, db_query *, entry_object * );
%
%  /* closes log file if opened */
%  /* removes self from list of dbs have opened files */
%  int close_log(int bypass_standby = 0);
%
%/* Constructor:  Create a database using the given name, 'dbname.'
%   The database is stored in a file named 'dbname'.
%   The log file is stored in a file named 'dbname'.log.
%   A temporary file 'dbname'.tmp is also used.   */
%  db( char * );
%
%/* Destructor:  deletes filenames and logfile descriptor. 
%   Note that associated files should be removed separately.  */
%  ~db();
%
%/* Write out in-memory copy of database to file.
%   1.  Update major version.
%   2.  Dump contents to temporary file.
%   3.  Rename temporary file to real database file.
%   4.  Remove log file. 
%   A checkpoint is done only if it has changed since the previous checkpoint.
%   Returns TRUE if checkpoint was successful; FALSE otherwise. */
%  bool_t checkpoint();
%
%/* Load database and incorporate any logged updates into the loaded copy.
%   Return TRUE if load succeeds; FALSE otherwise. */
%  bool_t load();
%
%/* Dump this database to a file. 
%   Return TRUE if dump succeeds; FALSE otherwise. */
%  bool_t dump(char *outfile) {return (internal_db.dump(outfile));};
%
%/* Initialize the database using table scheme 's'.
%   Because the 'scheme' must be 'remembered' between restarts,
%   after the initialization, the empty database is checkpointed to record
%   the scheme. Returns TRUE if initialization succeeds; FALSE otherwise. */
%  bool_t init( db_scheme *s );
%
%/* Print out the database's statistics. */
%  void print()    { internal_db.print_stats();}
%
%/* Return whether the database has changed since its previous checkpoint. */
%  bool_t changedp() { return changed;}
%
%/* Return the version of the database. */
%  vers* get_version() { return internal_db.get_version(); }
%
%
%/* Execute 'action' using the rest of the arguments as input.
%   Return the result of the operation in a db_result structure;
%   Return NULL if the request is unknown.
%   If the action involves updates (ADD and REMOVE), it is logged first. */
%  db_result* execute( db_action, db_query *, entry_object *, 
%			  db_next_desc* previous );
%
%/* Execute log entry 'j' on this db.  'j' is executed if its version is
%   later than that of the database; if executed, the database's version
%   will be changed to that of 'j', regardless of the status of the operation.
%   Returns TRUE if 'j' was executed;   FALSE if it was not.
%   Log entry is added to this database's log if log_entry is applied. */
%  bool_t execute_log_entry( db_log_entry * );
%
%/* Return structure db_log_list containing entries that are later
%   than the version 'v' given.  */
%  db_log_list * get_log_entries_since( vers * );
%
%/* Sync the table log file */
%  db_status	sync_log();
%
%/* Delete all files associated with database. */
%  int remove_files();
%
%  /* for debugging */
%/* Print information on all indices of the database to stdout. */
%  void print_all_indices() {internal_db.print_all_indices();}
%
%/* Print information on specified index of the the database to stdout. */
%  void print_index( int n ) {internal_db.print_index( n ); }
%
%/* Mark this instance deferred */
%  void markDeferred(void) {
%	internal_db.markDeferred();
%  }
%
%/* Remove defer marking */
%  void unmarkDeferred(void) {
%	internal_db.unmarkDeferred();
%  }
%
%/* Exclusive access to this instance */
%  int acqexcl(void) {
%	return (WLOCK(db));
%  }
%
%/* Non-blocking exclusive access */
%  int tryacqexcl(void) {
%	return (TRYWLOCK(db));
%  }
%
%/* Release exclusive access */
%  int relexcl(void) {
%	return (WULOCK(db));
%  }
%
%/* Non-exclusive (readonly) access to this instance */
%  int acqnonexcl(void) {
%	return (RLOCK(db));
%  }
%
%/* Release non-exlusive access */
%  int relnonexcl(void) {
%	return (RULOCK(db));
%  }
%
%/* Destroy instance lock */
%  int destroylock(void) {
%	return (DESTROYRW(db));
%  }
%
%/* Pass configuration information to the db_mindex */
%  bool_t configure(char *objName);
%
%/* Export a pointer to the db_mindex structure */
%  db_mindex *mindex(void);
%};
%
%typedef class db * dbp;
#endif /* USINGC */
#endif /* RPC_HDR */

#if RPC_HDR
%#endif /* _DB_DB_H */
#endif /* RPC_HDR */