001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.tomcat.jni;
019:
020: /** Library
021: *
022: * @author Mladen Turk
023: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
024: */
025:
026: public final class Library {
027:
028: /* Default library names */
029: private static String[] NAMES = { "tcnative-1", "libtcnative-1" };
030: /*
031: * A handle to the unique Library singleton instance.
032: */
033: static private Library _instance = null;
034:
035: private Library() {
036: boolean loaded = false;
037: String err = "";
038: for (int i = 0; i < NAMES.length; i++) {
039: try {
040: System.loadLibrary(NAMES[i]);
041: loaded = true;
042: } catch (Throwable e) {
043: if (i > 0)
044: err += ", ";
045: err += e.getMessage();
046: }
047: if (loaded)
048: break;
049: }
050: if (!loaded) {
051: err += "(";
052: err += System.getProperty("java.library.path");
053: err += ")";
054: throw new UnsatisfiedLinkError(err);
055: }
056: }
057:
058: private Library(String libraryName) {
059: System.loadLibrary(libraryName);
060: }
061:
062: /* create global TCN's APR pool
063: * This has to be the first call to TCN library.
064: */
065: private static native boolean initialize();
066:
067: /* destroy global TCN's APR pool
068: * This has to be the last call to TCN library.
069: */
070: public static native void terminate();
071:
072: /* Internal function for loading APR Features */
073: private static native boolean has(int what);
074:
075: /* Internal function for loading APR Features */
076: private static native int version(int what);
077:
078: /* Internal function for loading APR sizes */
079: private static native int size(int what);
080:
081: /* TCN_MAJOR_VERSION */
082: public static int TCN_MAJOR_VERSION = 0;
083: /* TCN_MINOR_VERSION */
084: public static int TCN_MINOR_VERSION = 0;
085: /* TCN_PATCH_VERSION */
086: public static int TCN_PATCH_VERSION = 0;
087: /* TCN_IS_DEV_VERSION */
088: public static int TCN_IS_DEV_VERSION = 0;
089: /* APR_MAJOR_VERSION */
090: public static int APR_MAJOR_VERSION = 0;
091: /* APR_MINOR_VERSION */
092: public static int APR_MINOR_VERSION = 0;
093: /* APR_PATCH_VERSION */
094: public static int APR_PATCH_VERSION = 0;
095: /* APR_IS_DEV_VERSION */
096: public static int APR_IS_DEV_VERSION = 0;
097:
098: /* TCN_VERSION_STRING */
099: public static native String versionString();
100:
101: /* APR_VERSION_STRING */
102: public static native String aprVersionString();
103:
104: /* APR Feature Macros */
105: public static boolean APR_HAVE_IPV6 = false;
106: public static boolean APR_HAS_SHARED_MEMORY = false;
107: public static boolean APR_HAS_THREADS = false;
108: public static boolean APR_HAS_SENDFILE = false;
109: public static boolean APR_HAS_MMAP = false;
110: public static boolean APR_HAS_FORK = false;
111: public static boolean APR_HAS_RANDOM = false;
112: public static boolean APR_HAS_OTHER_CHILD = false;
113: public static boolean APR_HAS_DSO = false;
114: public static boolean APR_HAS_SO_ACCEPTFILTER = false;
115: public static boolean APR_HAS_UNICODE_FS = false;
116: public static boolean APR_HAS_PROC_INVOKED = false;
117: public static boolean APR_HAS_USER = false;
118: public static boolean APR_HAS_LARGE_FILES = false;
119: public static boolean APR_HAS_XTHREAD_FILES = false;
120: public static boolean APR_HAS_OS_UUID = false;
121: /* Are we big endian? */
122: public static boolean APR_IS_BIGENDIAN = false;
123: /* APR sets APR_FILES_AS_SOCKETS to 1 on systems where it is possible
124: * to poll on files/pipes.
125: */
126: public static boolean APR_FILES_AS_SOCKETS = false;
127: /* This macro indicates whether or not EBCDIC is the native character set.
128: */
129: public static boolean APR_CHARSET_EBCDIC = false;
130: /* Is the TCP_NODELAY socket option inherited from listening sockets?
131: */
132: public static boolean APR_TCP_NODELAY_INHERITED = false;
133: /* Is the O_NONBLOCK flag inherited from listening sockets?
134: */
135: public static boolean APR_O_NONBLOCK_INHERITED = false;
136:
137: public static int APR_SIZEOF_VOIDP;
138: public static int APR_PATH_MAX;
139: public static int APRMAXHOSTLEN;
140: public static int APR_MAX_IOVEC_SIZE;
141: public static int APR_MAX_SECS_TO_LINGER;
142: public static int APR_MMAP_THRESHOLD;
143: public static int APR_MMAP_LIMIT;
144:
145: /* return global TCN's APR pool */
146: public static native long globalPool();
147:
148: /**
149: * Setup any APR internal data structures. This MUST be the first function
150: * called for any APR library.
151: * @param libraryName the name of the library to load
152: */
153: static public boolean initialize(String libraryName)
154: throws Exception {
155: if (_instance == null) {
156: if (libraryName == null)
157: _instance = new Library();
158: else
159: _instance = new Library(libraryName);
160: TCN_MAJOR_VERSION = version(0x01);
161: TCN_MINOR_VERSION = version(0x02);
162: TCN_PATCH_VERSION = version(0x03);
163: TCN_IS_DEV_VERSION = version(0x04);
164: APR_MAJOR_VERSION = version(0x11);
165: APR_MINOR_VERSION = version(0x12);
166: APR_PATCH_VERSION = version(0x13);
167: APR_IS_DEV_VERSION = version(0x14);
168:
169: APR_SIZEOF_VOIDP = size(1);
170: APR_PATH_MAX = size(2);
171: APRMAXHOSTLEN = size(3);
172: APR_MAX_IOVEC_SIZE = size(4);
173: APR_MAX_SECS_TO_LINGER = size(5);
174: APR_MMAP_THRESHOLD = size(6);
175: APR_MMAP_LIMIT = size(7);
176:
177: APR_HAVE_IPV6 = has(0);
178: APR_HAS_SHARED_MEMORY = has(1);
179: APR_HAS_THREADS = has(2);
180: APR_HAS_SENDFILE = has(3);
181: APR_HAS_MMAP = has(4);
182: APR_HAS_FORK = has(5);
183: APR_HAS_RANDOM = has(6);
184: APR_HAS_OTHER_CHILD = has(7);
185: APR_HAS_DSO = has(8);
186: APR_HAS_SO_ACCEPTFILTER = has(9);
187: APR_HAS_UNICODE_FS = has(10);
188: APR_HAS_PROC_INVOKED = has(11);
189: APR_HAS_USER = has(12);
190: APR_HAS_LARGE_FILES = has(13);
191: APR_HAS_XTHREAD_FILES = has(14);
192: APR_HAS_OS_UUID = has(15);
193: APR_IS_BIGENDIAN = has(16);
194: APR_FILES_AS_SOCKETS = has(17);
195: APR_CHARSET_EBCDIC = has(18);
196: APR_TCP_NODELAY_INHERITED = has(19);
197: APR_O_NONBLOCK_INHERITED = has(20);
198: if (APR_MAJOR_VERSION < 1) {
199: throw new UnsatisfiedLinkError(
200: "Unsupported APR Version ("
201: + aprVersionString() + ")");
202: }
203: if (!APR_HAS_THREADS) {
204: throw new UnsatisfiedLinkError(
205: "Missing APR_HAS_THREADS");
206: }
207: }
208: return initialize();
209: }
210: }
|