xref: /titanic_41/usr/src/lib/libnisdb/db_dictlog_c.x (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
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_dictlog_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_DICTLOG_H
33 %#define _DB_DICTLOG_H
34 
35 %
36 %/* A log entry that describes an action to be performed and its parameters. */
37 %
38 #endif /* RPC_HDR */
39 
40 #if RPC_HDR || RPC_XDR
41 #ifdef USINGC
42 %#include "db_vers_c.h"
43 #else
44 %#include "db_vers.h"
45 %#include "db_pickle.h"
46 #endif /* USINGC */
47 %#include <rpcsvc/nis.h>
48 #endif /* RPC_HDR */
49 %
50 %#include "nisdb_rw.h"
51 %
52 %#define DB_ADD_TABLE 1
53 %#define DB_REMOVE_TABLE 2
54 
55 #if RPC_HDR || RPC_XDR
56 #ifdef USINGC
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*/
64 };
65 typedef  struct db_dictlog_entry* db_dictlog_entry_p;
66 #endif /* USINGC */
67 #endif /* RPC_HDR */
68 
69 #ifdef USINGC
70 #if RPC_HDR
71 %bool_t xdr_table_obj();
72 #endif
73 #endif /* USINGC */
74 
75 #ifndef USINGC
76 #ifdef RPC_HDR
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 */
84 % public:
85 %
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; }
88 %
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*);
92 %
93 %  ~db_dictlog_entry();
94 %
95 %/* Print this log entry to stdout */
96 %  void print();
97 %
98 %/* Accessor: return version of log entry */
99 %  vers *get_version()  { return( &aversion ); }
100 %
101 %/* Accessor: return pointer to action of log entry */
102 %  int get_action()  { return( action ); }
103 %
104 %/* Accessor:  return pointer to table_name part of log entry */
105 %  char* get_table_name()  { return( table_name ); }
106 %
107 %/* Predicate:  return whether log entry is complete and not truncated */
108 %  bool_t sane() { return( aversion.equal( &bversion ) ); }
109 %
110 %/* Accessor:  return pointer to copy of object in log entry */
111 %  table_obj *get_table_object()  { return( table_object ); }
112 %
113 %/* Accessor:  return pointer to to next log entry */
114 %  db_dictlog_entry * getnextptr()  { return( next ); }
115 %
116 %/* Accessor:  return pointer to copy of object in log entry */
117 %  void setnextptr( db_dictlog_entry *p )  { next = p; }
118 %};
119 %#ifdef __cplusplus
120 %extern "C" bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
121 %#elif __STDC__
122 %extern bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
123 %#endif
124 %typedef class db_dictlog_entry * db_dictlog_entry_p;
125 #endif /* RPC_HDR */
126 #endif /* USINGC */
127 
128 struct db_dictlog_list {
129   db_dictlog_entry_p list<>;
130 };
131 
132 #ifndef USINGC
133 #ifdef RPC_HDR
134 %class db_dictlog: public pickle_file {
135 %	STRUCTRWLOCK(dictlog);
136 % public:
137 %
138 %/* Constructor:  create log file; default is PICKLE_READ mode. */
139 %  db_dictlog( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f,m) {
140 %	INITRW(dictlog);
141 %  }
142 %
143 %  ~db_dictlog(void) {
144 %	DESTROYRW(dictlog);
145 %  }
146 %
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 );
158 %
159 %/* Print contents of log file to stdout */
160 %  int print();
161 %
162 %/*Append given log entry to log. */
163 %  int append( db_dictlog_entry * );
164 %
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();
168 %
169 %/*
170 % * Locking methods. Protect the db_dictlog as well as db_dictlog_entries
171 % * hanging off of it.
172 % */
173 %  int acqexcl(void) {
174 %	return (WLOCK(dictlog));
175 %  }
176 %
177 %  int relexcl(void) {
178 %	return (WULOCK(dictlog));
179 %  }
180 %
181 %  int acqnonexcl(void) {
182 %	return (RLOCK(dictlog));
183 %  }
184 %
185 %  int relnonexcl(void) {
186 %	return (RULOCK(dictlog));
187 %  }
188 %
189 %};
190 #endif /* RPC_HDR */
191 #endif /* USINGC */
192 
193 #if RPC_HDR
194 %#endif /* _DB_DICTLOG_H */
195 #endif /* RPC_HDR */
196