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