xref: /titanic_44/usr/src/lib/libnisdb/db_log_c.x (revision 3db86aab554edbb4244c8d1a1c90f152eee768af)
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_log_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_LOG_H
33 %#define _DB_LOG_H
34 
35 #ifdef USINGC
36 %#include "db_log_entry_c.h"
37 #else
38 %#include "db_pickle.h"
39 %#include "db_log_entry.h"
40 #endif /* USINGC */
41 #endif /* RPC_HDR */
42 %
43 %#include "nisdb_rw.h"
44 %
45 #ifndef USINGC
46 #ifdef RPC_HDR
47 %class db_log: public pickle_file {
48 % private:
49 %	int	syncstate;	/* 0 if changes xfrd to <table>.log */
50 %	char	*tmplog;	/* <table>.log.tmp */
51 %	char	*stablelog;	/* <table>.log.stable */
52 %	char	*oldlog;	/* remember name of <table>.log */
53 %	STRUCTRWLOCK(log);
54 %
55 % public:
56 %
57 %/* Constructor:  create log file; default is PICKLE_READ mode. */
58 %  db_log( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f, m) {
59 %	syncstate = 0;
60 %	tmplog = stablelog = oldlog = 0;
61 %	INITRW(log);
62 %  }
63 %
64 %  ~db_log(void) {
65 %	DESTROYRW(log);
66 %  }
67 %
68 %/* Execute given function 'func' on log.
69 %  function takes as arguments: pointer to log entry, character pointer to
70 %  another argument, and pointer to an integer, which is used as a counter.
71 %  'func' should increment this value for each successful application.
72 %  The log is traversed until either 'func' returns FALSE, or when the log
73 %  is exhausted.  The second argument to 'execute_on_log' is passed as the
74 %  second argument to 'func'. The third argument, 'clean' determines whether
75 %  the log entry is deleted after the function has been applied.
76 %  Returns the number of times that 'func' incremented its third argument. */
77 %  int execute_on_log( bool_t(* f) (db_log_entry *, char *, int *),
78 %		      char *, bool_t = TRUE );
79 %
80 %
81 %/* Print contents of log file to stdout */
82 %  int print();
83 %
84 %/* Make copy of current log to log pointed to by 'f'. */
85 %  int copy( db_log*);
86 %
87 %/*Rewinds current log */
88 %  int rewind();
89 %
90 %/*Append given log entry to log. */
91 %  int append( db_log_entry * );
92 %
93 %/* Flush and sync log file. */
94 %  int sync_log();
95 %
96 %/* Return the next element in current log; return NULL if end of log or error.
97 %   Log must have been opened for READ. */
98 %  db_log_entry *get();
99 %
100 %/*  bool_t dump( pptr ) {return TRUE;}*/     // does nothing.
101 %
102 %/* Open log file */
103 %  int	open(void);
104 %/* Close log file */
105 %  int	close();
106 %/* Do we need to copy the log file */
107 %  bool_t copylog;
108 %
109 %/* Locking methods */
110 %
111 %  int acqexcl(void) {
112 %	return (WLOCK(log));
113 %  }
114 %
115 %  int relexcl(void) {
116 %	return (WULOCK(log));
117 %  }
118 %
119 %  int acqnonexcl(void) {
120 %	return (RLOCK(log));
121 %  }
122 %
123 %  int relnonexcl(void) {
124 %	return (RULOCK(log));
125 %  }
126 %};
127 #endif /* RPC_HDR */
128 #endif /* USINGC */
129 
130 #if RPC_HDR
131 %#endif /* _DB_LOG_H */
132 #endif /* RPC_HDR */
133