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: /** OS
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 class OS {
027:
028: /* OS Enums */
029: private static final int UNIX = 1;
030: private static final int NETWARE = 2;
031: private static final int WIN32 = 3;
032: private static final int WIN64 = 4;
033: private static final int LINUX = 5;
034: private static final int SOLARIS = 6;
035: private static final int BSD = 7;
036:
037: public static final int LOG_EMERG = 1;
038: public static final int LOG_ERROR = 2;
039: public static final int LOG_NOTICE = 3;
040: public static final int LOG_WARN = 4;
041: public static final int LOG_INFO = 5;
042: public static final int LOG_DEBUG = 6;
043:
044: /**
045: * Check for OS type.
046: * @param type OS type to test.
047: */
048: private static native boolean is(int type);
049:
050: public static final boolean IS_UNIX = is(UNIX);
051: public static final boolean IS_NETWARE = is(NETWARE);
052: public static final boolean IS_WIN32 = is(WIN32);
053: public static final boolean IS_WIN64 = is(WIN64);
054: public static final boolean IS_LINUX = is(LINUX);
055: public static final boolean IS_SOLARIS = is(SOLARIS);
056: public static final boolean IS_BSD = is(BSD);
057:
058: /**
059: * Get the name of the system default characer set.
060: * @param pool the pool to allocate the name from, if needed
061: */
062: public static native String defaultEncoding(long pool);
063:
064: /**
065: * Get the name of the current locale character set.
066: * Defers to apr_os_default_encoding if the current locale's
067: * data can't be retreved on this system.
068: * @param pool the pool to allocate the name from, if needed
069: */
070: public static native String localeEncoding(long pool);
071:
072: /**
073: * Generate random bytes.
074: * @param buf Buffer to fill with random bytes
075: * @param len Length of buffer in bytes
076: */
077: public static native int random(byte[] buf, int len);
078:
079: /**
080: * Gather system info.
081: * <PRE>
082: * On exit the inf array will be filled with:
083: * inf[0] - Total usable main memory size
084: * inf[1] - Available memory size
085: * inf[2] - Total page file/swap space size
086: * inf[3] - Page file/swap space still available
087: * inf[4] - Amount of shared memory
088: * inf[5] - Memory used by buffers
089: * inf[6] - Memory Load
090: *
091: * inf[7] - Idle Time in microseconds
092: * inf[8] - Kernel Time in microseconds
093: * inf[9] - User Time in microseconds
094: *
095: * inf[10] - Process creation time (apr_time_t)
096: * inf[11] - Process Kernel Time in microseconds
097: * inf[12] - Process User Time in microseconds
098: *
099: * inf[13] - Current working set size.
100: * inf[14] - Peak working set size.
101: * inf[15] - Number of page faults.
102: * </PRE>
103: * @param inf array that will be filled with system information.
104: * Array length must be at least 16.
105: */
106: public static native int info(long[] inf);
107:
108: /**
109: * Expand environment variables.
110: * @param str String to expand
111: * @return Expanded string with replaced environment variables.
112: */
113: public static native String expand(String str);
114:
115: /**
116: * Initialize system logging.
117: * @param domain String that will be prepended to every message
118: */
119: public static native void sysloginit(String domain);
120:
121: /**
122: * Log message.
123: * @param level Log message severity. See LOG_XXX enums.
124: * @param message Message to log
125: */
126: public static native void syslog(int level, String message);
127:
128: }
|