xref: /titanic_41/usr/src/lib/libnisdb/db_table_c.x (revision a506a34ceb0e9dcc6c61bf0560202f8538928650)
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_table_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_TABLE_H
33 %#define _DB_TABLE_H
34 
35 #ifdef USINGC
36 %#include "db_query_c.h"
37 %#include "db_scheme_c.h"
38 #else
39 %#include "db_query.h"
40 %#include "db_scheme.h"
41 #endif /* USINGC */
42 #endif /* RPC_HDR */
43 %
44 %#include "nisdb_ldap.h"
45 %#include "nisdb_rw.h"
46 %#include "ldap_parse.h"
47 %#include "ldap_map.h"
48 %#include "ldap_util.h"
49 %#include "ldap_nisdbquery.h"
50 %#include "ldap_print.h"
51 %#include "ldap_xdr.h"
52 %
53 typedef long entryp;      /* specifies location of an entry within table */
54 
55 struct db_free_entry {
56   entryp where;
57   struct db_free_entry *next;
58 };
59 
60 typedef struct db_free_entry * db_free_entry_p;
61 
62 #if RPC_HDR || RPC_XDR
63 #ifdef USINGC
64 struct db_free_list {
65   db_free_entry_p head;
66   long count;
67   __nisdb_rwlock_t free_list_rwlock;
68 };
69 typedef struct db_free_list * db_free_list_p;
70 #endif /* USINGC */
71 #endif /* RPC_HDR */
72 
73 #ifndef USINGC
74 #ifdef RPC_HDR
75 %class db_free_list {
76 %  db_free_entry_p head;
77 %  long count;
78 %  STRUCTRWLOCK(free_list);
79 % public:
80 %  db_free_list() {   /* free list constructor */
81 %	head = NULL;
82 %	count = 0;
83 %	INITRW(free_list);
84 %  }
85 %
86 %  ~db_free_list();
87 %
88 %  void reset();   /* empty contents of free list */
89 %
90 %  void init();		/* Empty free list */
91 %
92 %/* Returns the location of a free entry, or NULL, if there aren't any. */
93 %  entryp pop();
94 %
95 %/* Adds given location to the free list.
96 %   Returns TRUE if successful, FALSE otherwise (when out of memory). */
97 %  bool_t push( entryp );
98 %
99 %/* Returns in a vector the information in the free list.
100 %   Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
101 %   Leave the first 'n' cells free.
102 %   n1 is the number of entries that should be in the freelist.
103 %   n2 is the number of entries actually found in the freelist.
104 %   <loc1...locn> are the entries.   n2 <= n1 because we never count beyond n1.
105 %   It is up to the caller to free the returned vector when he is through. */
106 % long* stats( int n );
107 %
108 %/* Locking methods */
109 %
110 %  int acqexcl(void) {
111 %	return (WLOCK(free_list));
112 %  }
113 %
114 %  int relexcl(void) {
115 %	return (WULOCK(free_list));
116 %  }
117 %
118 %  int acqnonexcl(void) {
119 %	return (RLOCK(free_list));
120 %  }
121 %
122 %  int relnonexcl(void) {
123 %	return (RULOCK(free_list));
124 %  }
125 %};
126 #endif /* RPC_HDR */
127 #endif /* USINGC */
128 
129 #if RPC_HDR || RPC_XDR
130 #ifdef USINGC
131 struct db_table
132 {
133   entry_object_p tab <>;
134   long last_used;        /* last entry used; maintained for quick insertion */
135   long count;            /* measures fullness of table */
136   db_free_list freelist;
137   __nisdb_rwlock_t table_rwlock;
138   __nisdb_flag_t enumMode;
139   __nisdb_ptr_t  enumArray;
140   __nis_table_mapping_t mapping;
141 };
142 typedef struct db_table * db_table_p;
143 
144 #endif /* USINGC */
145 #endif /* RPC_HDR */
146 
147 #ifndef USINGC
148 #ifdef RPC_HDR
149 %class db_table
150 %{
151 %  long table_size;
152 %  entry_object_p *tab;   /* pointer to array of pointers to entry objects */
153 %  long last_used;        /* last entry used; maintained for quick insertion */
154 %  long count;            /* measures fullness of table */
155 %  db_free_list freelist;
156 %  STRUCTRWLOCK(table);
157 %  __nisdb_flag_t enumMode;
158 %  __nisdb_flag_t enumCount;
159 %  __nisdb_ptr_t  enumIndex;
160 %  __nisdb_ptr_t  enumArray;
161 %
162 %  void grow();           /* Expand the table.
163 %			    Fatal error if insufficient error. */
164 %
165 %/* Allocate expiration time array */
166 %  db_status allocateExpire(long oldSize, long newSize);
167 %
168 % public:
169 %  __nisdb_table_mapping_t mapping;
170 %
171 %  db_table();            /* constructor for brand new, empty table. */
172 %  db_table( char * );    /* constructor for creating a table by loading
173 %			    in an existing one. */
174 %
175 %/* Init of LDAP/MT portion of class instance */
176 %  void db_table_ldap_init(void);
177 %/* Size of the non-MT/LDAP portion of the db_table structure */
178 %  ulong_t oldstructsize(void) {
179 %	return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
180 %  }
181 %/* Mark this instance as deferred */
182 %  void markDeferred(void) {
183 %	mapping.isDeferredTable = TRUE;
184 %  }
185 %/* Remove deferred mark */
186 %  void unmarkDeferred(void) {
187 %	mapping.isDeferredTable = FALSE;
188 %  }
189 %
190 %/* Return the current 'tab' */
191 %  entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
192 %/* Return how many entries there are in table. */
193 %  long fullness() { return count; }
194 %
195 %/* Deletes table, entries, and free list */
196 %  ~db_table();
197 %
198 %  int tryacqexcl(void) {
199 %	return (TRYWLOCK(table));
200 %  }
201 %
202 %  int acqexcl(void) {
203 %	return (WLOCK(table));
204 %  }
205 %
206 %  int relexcl(void) {
207 %	return (WULOCK(table));
208 %  }
209 %
210 %  int acqnonexcl(void) {
211 %	return (RLOCK(table));
212 %  }
213 %
214 %  int relnonexcl(void) {
215 %	return (RULOCK(table));
216 %  }
217 %
218 %/* empties table by deleting all entries and other associated data structures */
219 %   void reset();
220 %
221 %  int dump( char *);
222 %
223 %/* Returns whether location is valid. */
224 %  bool_t entry_exists_p( entryp i );
225 %
226 %/* Returns table size. */
227 %  long getsize()  { return table_size; }
228 %
229 %/* Returns the first entry in table, also return its position in
230 %   'where'.  Return NULL in both if no next entry is found. */
231 %  entry_object_p first_entry( entryp * where );
232 %
233 %/* Returns the next entry in table from 'prev', also return its position in
234 %   'newentry'.  Return NULL in both if no next entry is found. */
235 %  entry_object_p next_entry( entryp, entryp* );
236 %
237 %/* Returns entry at location 'where', NULL if location is invalid. */
238 %  entry_object_p get_entry( entryp );
239 %
240 %/* Adds given entry to table in first available slot (either look in freelist
241 %   or add to end of table) and return the the position of where the record
242 %   is placed. 'count' is incremented if entry is added. Table may grow
243 %   as a side-effect of the addition. Copy is made of the input. */
244 %  entryp add_entry(entry_object_p, int);
245 %
246 % /* Replaces object at specified location by given entry.
247 %   Returns TRUE if replacement successful; FALSE otherwise.
248 %   There must something already at the specified location, otherwise,
249 %   replacement fails. Copy is not made of the input.
250 %   The pre-existing entry is freed.*/
251 %  bool_t replace_entry( entryp, entry_object_p );
252 %
253 %/* Deletes entry at specified location.  Returns TRUE if location is valid;
254 %   FALSE if location is invalid, or the freed location cannot be added to
255 %   the freelist.  'count' is decremented if the deletion occurs.  The object
256 %   at that location is freed. */
257 %  bool_t delete_entry( entryp );
258 %
259 %/* Returns statistics of table.
260 %   <table_size><last_used><count>[freelist].
261 %   It is up to the caller to free the returned vector when his is through
262 %   The free list is included if 'fl' is TRUE. */
263 %long * stats( bool_t fl );
264 %
265 %/* Configure LDAP mapping */
266 %  bool_t configure(char *objName);
267 %
268 %/* Initialize the mapping structure with default values */
269 %  void initMappingStruct(__nisdb_table_mapping_t *mapping);
270 %
271 %/* Check if entry at 'loc' is valid (not expired) */
272 %  bool_t cacheValid(entryp loc);
273 %
274 %/* Update expiration time if supplied object same as the one at 'loc' */
275 %  bool_t dupEntry(entry_object *obj, entryp loc);
276 %
277 %/* Set expiration time for entry */
278 %  void setEntryExp(entryp where, entry_object *obj, int initialLoad);
279 %
280 %/* Enable enum mode */
281 %  void setEnumMode(long count);
282 %/* Clear enum mode */
283 %  void clearEnumMode(void);
284 %/* End enum mode, return array of untouched entries */
285 %  entry_object **endEnumMode(long *numEa);
286 %/* Mark the indicated entry used for enum purposes */
287 %  void enumTouch(entryp loc);
288 %/* Add entry to enumIndex array */
289 %  void enumSetup(entryp loc, long index);
290 %/* Touch the indicated entry */
291 %  void touchEntry(entryp loc);
292 %
293 %  db_status allocateEnumArray(long oldSize, long newSize);
294 %};
295 %#ifdef __cplusplus
296 %extern "C" bool_t xdr_db_table( XDR*, db_table*);
297 %#elif __STDC__
298 %extern bool_t xdr_db_table(XDR*, db_table*);
299 %#endif
300 %typedef class db_table * db_table_p;
301 #endif /* RPC_HDR */
302 #endif /* USINGC */
303 
304 #if RPC_HDR
305 %#endif /* _DB_TABLE_H */
306 #endif /* RPC_HDR */
307