xref: /illumos-gate/usr/src/lib/libnisdb/db_dictlog_c.x (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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 #if RPC_HDR
30 %#ifndef _DB_DICTLOG_H
31 %#define _DB_DICTLOG_H
32 
33 %
34 %/* A log entry that describes an action to be performed and its parameters. */
35 %
36 #endif /* RPC_HDR */
37 
38 #if RPC_HDR || RPC_XDR
39 #ifdef USINGC
40 %#include "db_vers_c.h"
41 #else
42 %#include "db_vers.h"
43 %#include "db_pickle.h"
44 #endif /* USINGC */
45 %#include <rpcsvc/nis.h>
46 #endif /* RPC_HDR */
47 %
48 %#include "nisdb_rw.h"
49 %
50 %#define DB_ADD_TABLE 1
51 %#define DB_REMOVE_TABLE 2
52 
53 #if RPC_HDR || RPC_XDR
54 #ifdef USINGC
55 struct db_dictlog_entry {
56   vers aversion;                    /* version of log entry */
57   int       action;                 /* action to be invoked */
58   string table_name<>;                /* table_name supplied with action */
59   table_obj *table_object;          /* object involved in action (if any) */
60   struct db_dictlog_entry *next;    /* Used in constructing list */
61   vers bversion;                    /* sanity check;should be same as aversion*/
62 };
63 typedef  struct db_dictlog_entry* db_dictlog_entry_p;
64 #endif /* USINGC */
65 #endif /* RPC_HDR */
66 
67 #ifdef USINGC
68 #if RPC_HDR
69 %bool_t xdr_table_obj();
70 #endif
71 #endif /* USINGC */
72 
73 #ifndef USINGC
74 #ifdef RPC_HDR
75 %class db_dictlog_entry {
76 %  vers aversion;                     /* version of log entry */
77 %  int action;                        /* action to be invoked */
78 %  char *table_name;                  /* table_name supplied with action (if any) */
79 %  table_obj *table_object;           /* object involved in action (if any) */
80 %  db_dictlog_entry *next;                /* Used in constructing list */
81 %  vers bversion;                     /* sanity check */
82 % public:
83 %
84 %/*Constructor:  Create an empty log entry, with no table_name and not object */
85 %  db_dictlog_entry() { table_name = NULL, table_object = NULL; next = NULL; }
86 %
87 %/*Constructor:  Create a log entry using the given parameters.  Note that
88 %  pointers to table_name and table_object are simply assigned, not copied. */
89 %  db_dictlog_entry(int, vers *, char*, table_obj*);
90 %
91 %  ~db_dictlog_entry();
92 %
93 %/* Print this log entry to stdout */
94 %  void print();
95 %
96 %/* Accessor: return version of log entry */
97 %  vers *get_version()  { return( &aversion ); }
98 %
99 %/* Accessor: return pointer to action of log entry */
100 %  int get_action()  { return( action ); }
101 %
102 %/* Accessor:  return pointer to table_name part of log entry */
103 %  char* get_table_name()  { return( table_name ); }
104 %
105 %/* Predicate:  return whether log entry is complete and not truncated */
106 %  bool_t sane() { return( aversion.equal( &bversion ) ); }
107 %
108 %/* Accessor:  return pointer to copy of object in log entry */
109 %  table_obj *get_table_object()  { return( table_object ); }
110 %
111 %/* Accessor:  return pointer to to next log entry */
112 %  db_dictlog_entry * getnextptr()  { return( next ); }
113 %
114 %/* Accessor:  return pointer to copy of object in log entry */
115 %  void setnextptr( db_dictlog_entry *p )  { next = p; }
116 %};
117 %#ifdef __cplusplus
118 %extern "C" bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
119 %#elif __STDC__
120 %extern bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
121 %#endif
122 %typedef class db_dictlog_entry * db_dictlog_entry_p;
123 #endif /* RPC_HDR */
124 #endif /* USINGC */
125 
126 struct db_dictlog_list {
127   db_dictlog_entry_p list<>;
128 };
129 
130 #ifndef USINGC
131 #ifdef RPC_HDR
132 %class db_dictlog: public pickle_file {
133 %	STRUCTRWLOCK(dictlog);
134 % public:
135 %
136 %/* Constructor:  create log file; default is PICKLE_READ mode. */
137 %  db_dictlog( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f,m) {
138 %	INITRW(dictlog);
139 %  }
140 %
141 %  ~db_dictlog(void) {
142 %	DESTROYRW(dictlog);
143 %  }
144 %
145 %/* Execute given function 'func' on log.
146 %  function takes as arguments: pointer to log entry, character pointer to
147 %  another argument, and pointer to an integer, which is used as a counter.
148 %  'func' should increment this value for each successful application.
149 %  The log is traversed until either 'func' returns FALSE, or when the log
150 %  is exhausted.  The second argument to 'execute_on_log' is passed as the
151 %  second argument to 'func'. The third argument, 'clean' determines whether
152 %  the log entry is deleted after the function has been applied.
153 %  Returns the number of times that 'func' incremented its third argument. */
154 %  int execute_on_log( bool_t(* func) (db_dictlog_entry *, char *, int *),
155 %		      char *, bool_t = TRUE );
156 %
157 %/* Print contents of log file to stdout */
158 %  int print();
159 %
160 %/*Append given log entry to log. */
161 %  int append( db_dictlog_entry * );
162 %
163 %/* Return the next element in current log; return NULL if end of log or error.
164 %   Log must have been opened for READ. */
165 %  db_dictlog_entry *get();
166 %
167 %/*
168 % * Locking methods. Protect the db_dictlog as well as db_dictlog_entries
169 % * hanging off of it.
170 % */
171 %  int acqexcl(void) {
172 %	return (WLOCK(dictlog));
173 %  }
174 %
175 %  int relexcl(void) {
176 %	return (WULOCK(dictlog));
177 %  }
178 %
179 %  int acqnonexcl(void) {
180 %	return (RLOCK(dictlog));
181 %  }
182 %
183 %  int relnonexcl(void) {
184 %	return (RULOCK(dictlog));
185 %  }
186 %
187 %};
188 #endif /* RPC_HDR */
189 #endif /* USINGC */
190 
191 #if RPC_HDR
192 %#endif /* _DB_DICTLOG_H */
193 #endif /* RPC_HDR */
194