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
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]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 %#pragma ident "%Z%%M% %I% %E% SMI"
32 %#ifndef _DB_DICTLOG_H
33 %#define _DB_DICTLOG_H
36 %/* A log entry that describes an action to be performed and its parameters. */
40 #if RPC_HDR || RPC_XDR
42 %#include "db_vers_c.h"
45 %#include "db_pickle.h"
47 %#include <rpcsvc/nis.h>
50 %#include "nisdb_rw.h"
52 %#define DB_ADD_TABLE 1
53 %#define DB_REMOVE_TABLE 2
55 #if RPC_HDR || RPC_XDR
57 struct db_dictlog_entry {
58 vers aversion; /* version of log entry */
59 int action; /* action to be invoked */
60 string table_name<>; /* table_name supplied with action */
61 table_obj *table_object; /* object involved in action (if any) */
62 struct db_dictlog_entry *next; /* Used in constructing list */
63 vers bversion; /* sanity check;should be same as aversion*/
65 typedef struct db_dictlog_entry* db_dictlog_entry_p;
71 %bool_t xdr_table_obj();
77 %class db_dictlog_entry {
78 % vers aversion; /* version of log entry */
79 % int action; /* action to be invoked */
80 % char *table_name; /* table_name supplied with action (if any) */
81 % table_obj *table_object; /* object involved in action (if any) */
82 % db_dictlog_entry *next; /* Used in constructing list */
83 % vers bversion; /* sanity check */
86 %/*Constructor: Create an empty log entry, with no table_name and not object */
87 % db_dictlog_entry() { table_name = NULL, table_object = NULL; next = NULL; }
89 %/*Constructor: Create a log entry using the given parameters. Note that
90 % pointers to table_name and table_object are simply assigned, not copied. */
91 % db_dictlog_entry(int, vers *, char*, table_obj*);
93 % ~db_dictlog_entry();
95 %/* Print this log entry to stdout */
98 %/* Accessor: return version of log entry */
99 % vers *get_version() { return( &aversion ); }
101 %/* Accessor: return pointer to action of log entry */
102 % int get_action() { return( action ); }
104 %/* Accessor: return pointer to table_name part of log entry */
105 % char* get_table_name() { return( table_name ); }
107 %/* Predicate: return whether log entry is complete and not truncated */
108 % bool_t sane() { return( aversion.equal( &bversion ) ); }
110 %/* Accessor: return pointer to copy of object in log entry */
111 % table_obj *get_table_object() { return( table_object ); }
113 %/* Accessor: return pointer to to next log entry */
114 % db_dictlog_entry * getnextptr() { return( next ); }
116 %/* Accessor: return pointer to copy of object in log entry */
117 % void setnextptr( db_dictlog_entry *p ) { next = p; }
120 %extern "C" bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
122 %extern bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
124 %typedef class db_dictlog_entry * db_dictlog_entry_p;
128 struct db_dictlog_list {
129 db_dictlog_entry_p list<>;
134 %class db_dictlog: public pickle_file {
135 % STRUCTRWLOCK(dictlog);
138 %/* Constructor: create log file; default is PICKLE_READ mode. */
139 % db_dictlog( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f,m) {
143 % ~db_dictlog(void) {
144 % DESTROYRW(dictlog);
147 %/* Execute given function 'func' on log.
148 % function takes as arguments: pointer to log entry, character pointer to
149 % another argument, and pointer to an integer, which is used as a counter.
150 % 'func' should increment this value for each successful application.
151 % The log is traversed until either 'func' returns FALSE, or when the log
152 % is exhausted. The second argument to 'execute_on_log' is passed as the
153 % second argument to 'func'. The third argument, 'clean' determines whether
154 % the log entry is deleted after the function has been applied.
155 % Returns the number of times that 'func' incremented its third argument. */
156 % int execute_on_log( bool_t(* func) (db_dictlog_entry *, char *, int *),
157 % char *, bool_t = TRUE );
159 %/* Print contents of log file to stdout */
162 %/*Append given log entry to log. */
163 % int append( db_dictlog_entry * );
165 %/* Return the next element in current log; return NULL if end of log or error.
166 % Log must have been opened for READ. */
167 % db_dictlog_entry *get();
170 % * Locking methods. Protect the db_dictlog as well as db_dictlog_entries
171 % * hanging off of it.
173 % int acqexcl(void) {
174 % return (WLOCK(dictlog));
177 % int relexcl(void) {
178 % return (WULOCK(dictlog));
181 % int acqnonexcl(void) {
182 % return (RLOCK(dictlog));
185 % int relnonexcl(void) {
186 % return (RULOCK(dictlog));
194 %#endif /* _DB_DICTLOG_H */