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