summaryrefslogtreecommitdiff
path: root/usr/src/lib/libnisdb/db_dictlog_c.x
blob: 46eb241d484449b07313fd59c5de9cd936732075 (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
/*
 * 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_dictlog_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_DICTLOG_H
%#define _DB_DICTLOG_H

%
%/* A log entry that describes an action to be performed and its parameters. */
%
#endif /* RPC_HDR */

#if RPC_HDR || RPC_XDR
#ifdef USINGC
%#include "db_vers_c.h"
#else
%#include "db_vers.h"
%#include "db_pickle.h"
#endif /* USINGC */
%#include <rpcsvc/nis.h>
#endif /* RPC_HDR */
%
%#include "nisdb_rw.h"
%
%#define DB_ADD_TABLE 1
%#define DB_REMOVE_TABLE 2

#if RPC_HDR || RPC_XDR
#ifdef USINGC
struct db_dictlog_entry {
  vers aversion;                    /* version of log entry */
  int       action;                 /* action to be invoked */
  string table_name<>;                /* table_name supplied with action */
  table_obj *table_object;          /* object involved in action (if any) */
  struct db_dictlog_entry *next;    /* Used in constructing list */
  vers bversion;                    /* sanity check;should be same as aversion*/
};
typedef  struct db_dictlog_entry* db_dictlog_entry_p;
#endif /* USINGC */
#endif /* RPC_HDR */

#ifdef USINGC
#if RPC_HDR
%bool_t xdr_table_obj();
#endif
#endif /* USINGC */

#ifndef USINGC
#ifdef RPC_HDR
%class db_dictlog_entry {
%  vers aversion;                     /* version of log entry */
%  int action;                        /* action to be invoked */
%  char *table_name;                  /* table_name supplied with action (if any) */
%  table_obj *table_object;           /* object involved in action (if any) */
%  db_dictlog_entry *next;                /* Used in constructing list */
%  vers bversion;                     /* sanity check */
% public:
%
%/*Constructor:  Create an empty log entry, with no table_name and not object */
%  db_dictlog_entry() { table_name = NULL, table_object = NULL; next = NULL; }
%
%/*Constructor:  Create a log entry using the given parameters.  Note that
%  pointers to table_name and table_object are simply assigned, not copied. */
%  db_dictlog_entry(int, vers *, char*, table_obj*);
%
%  ~db_dictlog_entry();
%
%/* Print this log entry to stdout */
%  void print();
%
%/* Accessor: return version of log entry */
%  vers *get_version()  { return( &aversion ); }
%
%/* Accessor: return pointer to action of log entry */
%  int get_action()  { return( action ); }
%
%/* Accessor:  return pointer to table_name part of log entry */
%  char* get_table_name()  { return( table_name ); }
%
%/* Predicate:  return whether log entry is complete and not truncated */
%  bool_t sane() { return( aversion.equal( &bversion ) ); }
%
%/* Accessor:  return pointer to copy of object in log entry */
%  table_obj *get_table_object()  { return( table_object ); }
%
%/* Accessor:  return pointer to to next log entry */
%  db_dictlog_entry * getnextptr()  { return( next ); }
%
%/* Accessor:  return pointer to copy of object in log entry */
%  void setnextptr( db_dictlog_entry *p )  { next = p; }
%};
%#ifdef __cplusplus
%extern "C" bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
%#elif __STDC__
%extern bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*);
%#endif
%typedef class db_dictlog_entry * db_dictlog_entry_p;
#endif /* RPC_HDR */
#endif /* USINGC */

struct db_dictlog_list {
  db_dictlog_entry_p list<>;
};
  
#ifndef USINGC
#ifdef RPC_HDR
%class db_dictlog: public pickle_file {
%	STRUCTRWLOCK(dictlog);
% public:
%
%/* Constructor:  create log file; default is PICKLE_READ mode. */
%  db_dictlog( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f,m) {
%	INITRW(dictlog);
%  }
%
%  ~db_dictlog(void) {
%	DESTROYRW(dictlog);
%  }
%
%/* Execute given function 'func' on log.
%  function takes as arguments: pointer to log entry, character pointer to 
%  another argument, and pointer to an integer, which is used as a counter.
%  'func' should increment this value for each successful application.
%  The log is traversed until either 'func' returns FALSE, or when the log
%  is exhausted.  The second argument to 'execute_on_log' is passed as the
%  second argument to 'func'. The third argument, 'clean' determines whether
%  the log entry is deleted after the function has been applied.
%  Returns the number of times that 'func' incremented its third argument. */
%  int execute_on_log( bool_t(* func) (db_dictlog_entry *, char *, int *), 
%		      char *, bool_t = TRUE );
%
%/* Print contents of log file to stdout */
%  int print();
%
%/*Append given log entry to log. */
%  int append( db_dictlog_entry * );
%
%/* Return the next element in current log; return NULL if end of log or error.
%   Log must have been opened for READ. */
%  db_dictlog_entry *get();
%
%/*
% * Locking methods. Protect the db_dictlog as well as db_dictlog_entries
% * hanging off of it.
% */
%  int acqexcl(void) {
%	return (WLOCK(dictlog));
%  }
%
%  int relexcl(void) {
%	return (WULOCK(dictlog));
%  }
%
%  int acqnonexcl(void) {
%	return (RLOCK(dictlog));
%  }
%
%  int relnonexcl(void) {
%	return (RULOCK(dictlog));
%  }
%
%};
#endif /* RPC_HDR */
#endif /* USINGC */

#if RPC_HDR
%#endif /* _DB_DICTLOG_H */
#endif /* RPC_HDR */