xref: /titanic_44/usr/src/lib/libnisdb/db_log_entry.cc (revision 24db46411fd54f70c35b94bb952eb7ba040e43b4)
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_entry.cc
24  *
25  *	Copyright (c) 1988-1992 Sun Microsystems Inc
26  *	All Rights Reserved.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <stdio.h>
32 
33 #include "db_headers.h"
34 #include "db_log_entry.h"
35 #include "db_table.h"
36 
37 extern void print_entry(entryp, entry_object *);
38 
39 /*
40  * Constructor:  Create a log entry using the given parameters.  Note that
41  * pointers to db_query and entry_object are simply assigned, not copied.
42  */
43 db_log_entry::db_log_entry(db_action a, vers * v, db_query *q,
44 			    entry_object *obj)
45 {
46 	action = a;
47 	aversion.assign(v);
48 	query = q;
49 	object = obj;
50 	next = NULL;
51 	bversion.assign(v);
52 }
53 
54 db_log_entry::~db_log_entry()
55 {
56 /* we might not have allocated these ourselves, so we cannot delete them */
57 //	if (query) delete query;
58 //	if (object) free_entry(object);
59 }
60 
61 /* prints a line from the journal */
62 void
63 db_log_entry::print()
64 {
65 	switch (action) {
66 	case DB_ADD:
67 	    printf("add: ");
68 	    break;
69 	case DB_REMOVE:
70 	    printf("remove: ");
71 	    break;
72 	default:
73 	    printf("action(%d): ", action);
74 	    break;
75 	}
76 
77 	aversion.print(stdout);
78 	putchar(' ');
79 	if (query != NULL)
80 		query->print();
81 	else
82 		printf("no query!\n");
83 
84 	if (object != NULL) {
85 		print_entry(0, object);
86 	} else {
87 		printf("no object\n");
88 	}
89 	bversion.print(stdout);
90 	putchar('\n');
91 }
92