File: java_locked.h

package info (click to toggle)
evolution-data-server 1.0.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 39,504 kB
  • ctags: 26,423
  • sloc: ansic: 175,347; tcl: 30,499; sh: 20,699; perl: 11,320; xml: 9,039; java: 7,653; cpp: 6,029; makefile: 4,866; awk: 1,338; yacc: 1,103; sed: 772; cs: 505; lex: 134; asm: 14
file content (82 lines) | stat: -rw-r--r-- 2,653 bytes parent folder | download | duplicates (3)
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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1997-2002
 *	Sleepycat Software.  All rights reserved.
 *
 * $Id: java_locked.h,v 1.1.1.1 2003/11/20 22:13:34 toshok Exp $
 */

#ifndef _JAVA_LOCKED_H_
#define	_JAVA_LOCKED_H_

/*
 * Used as argument to locked_dbt_get().
 */
typedef enum _OpKind {
	inOp,		/* setting data in database (passing data in) */
	outOp,		/* getting data from database to user memory */
	inOutOp		/* both getting/setting data */
} OpKind;

/*
 * LOCKED_DBT
 *
 * A stack variable LOCKED_DBT should be declared for each Dbt used in a
 * native call to the DB API.  Before the DBT can be used, locked_dbt_get()
 * must be called to temporarily convert any java array found in the
 * Dbt (which has a pointer to a DBT_JAVAINFO struct) to actual bytes
 * in memory that remain locked in place.  These bytes are used during
 * the call to the DB C API, and are released and/or copied back when
 * locked_dbt_put is called.
 */
typedef struct _locked_dbt
{
	/* these are accessed externally to locked_dbt_ functions */
	DBT_JAVAINFO *javainfo;
	unsigned int java_array_len;
	jobject jdbt;

	/* these are for used internally by locked_dbt_ functions */
	jbyte *java_data;
	jbyte *before_data;
	OpKind kind;

#define	LOCKED_ERROR		0x01	/* error occurred */
#define	LOCKED_CREATE_DATA	0x02	/* must create data on the fly */
#define	LOCKED_REALLOC_NONNULL	0x04	/* DB_DBT_REALLOC flag, nonnull data */
	u_int32_t flags;
} LOCKED_DBT;

/* Fill the LOCKED_DBT struct and lock the Java byte array */
extern int locked_dbt_get(LOCKED_DBT *, JNIEnv *, DB_ENV *, jobject, OpKind);

/* unlock the Java byte array */
extern void locked_dbt_put(LOCKED_DBT *, JNIEnv *, DB_ENV *);

/* realloc the Java byte array */
extern int locked_dbt_realloc(LOCKED_DBT *, JNIEnv *, DB_ENV *);

/*
 * LOCKED_STRING
 *
 * A LOCKED_STRING exists temporarily to convert a java jstring object
 * to a char *.  Because the memory for the char * string is
 * managed by the JVM, it must be released when we are done
 * looking at it.  Typically, locked_string_get() is called at the
 * beginning of a function for each jstring object, and locked_string_put
 * is called at the end of each function for each LOCKED_STRING.
 */
typedef struct _locked_string
{
	/* this accessed externally to locked_string_ functions */
	const char *string;

	/* this is used internally by locked_string_ functions */
	jstring jstr;
} LOCKED_STRING;

extern int locked_string_get(LOCKED_STRING *, JNIEnv *jnienv, jstring jstr);
extern void locked_string_put(LOCKED_STRING *, JNIEnv *jnienv);  /* this unlocks and frees mem */

#endif /* !_JAVA_LOCKED_H_ */