1 | /* |
2 | * IntCall.java |
3 | * |
4 | * Created on 07.09.2004. |
5 | * |
6 | * eaio: NativeCall - calling operating system methods from Java |
7 | * Copyright (c) 2004-2006 Johann Burkard (<mailto:jb@eaio.com>) |
8 | * <http://eaio.com> |
9 | * |
10 | * Permission is hereby granted, free of charge, to any person obtaining a |
11 | * copy of this software and associated documentation files (the "Software"), |
12 | * to deal in the Software without restriction, including without limitation |
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 | * and/or sell copies of the Software, and to permit persons to whom the |
15 | * Software is furnished to do so, subject to the following conditions: |
16 | * |
17 | * The above copyright notice and this permission notice shall be included |
18 | * in all copies or substantial portions of the Software. |
19 | * |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
23 | * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
24 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
25 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
26 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
27 | * |
28 | */ |
29 | package com.eaio.nativecall; |
30 | |
31 | /** |
32 | * An IntCall instance encapsulates an operating system method that returns |
33 | * an integer. |
34 | * |
35 | * @author <a href="mailto:jb@eaio.com">Johann Burkard</a> |
36 | * @version $Id: IntCall.java,v 1.1 2006/01/05 20:02:44 grnull Exp $ |
37 | */ |
38 | public class IntCall extends NativeCall { |
39 | |
40 | /** |
41 | * Constructor for IntCall. |
42 | * |
43 | * @see NativeCall#NativeCall(String) |
44 | */ |
45 | public IntCall(String function) throws SecurityException, |
46 | IllegalArgumentException, NullPointerException { |
47 | super(function); |
48 | } |
49 | |
50 | /** |
51 | * Constructor for IntCall. |
52 | * |
53 | * @see NativeCall#NativeCall(String, String) |
54 | */ |
55 | public IntCall(String module, String function) throws SecurityException, |
56 | IllegalArgumentException, NullPointerException { |
57 | super(module, function); |
58 | } |
59 | |
60 | /** |
61 | * Returns <code>false</code> if calling {@link #executeCall()} returned |
62 | * 0, <code>true</code> otherwise. |
63 | * <p> |
64 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
65 | * |
66 | * @return <code>true</code> or <code>false</code> |
67 | */ |
68 | public boolean executeBooleanCall() { |
69 | return executeCall() == 0 ? false : true; |
70 | } |
71 | |
72 | /** |
73 | * Returns <code>false</code> if calling {@link #executeCall(Object)} |
74 | * returned 0, <code>true</code> otherwise. |
75 | * <p> |
76 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
77 | * |
78 | * @param param the parameter, may be <code>null</code> |
79 | * @return <code>true</code> or <code>false</code> |
80 | * @see #executeBooleanCall(Object[]) |
81 | */ |
82 | public boolean executeBooleanCall(Object param) { |
83 | return executeCall(param) == 0 ? false : true; |
84 | } |
85 | |
86 | /** |
87 | * Returns <code>false</code> if calling |
88 | * {@link #executeCall(Object[])} returned 0, <code>true</code> otherwise. |
89 | * <p> |
90 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
91 | * <p> |
92 | * During this operation, the contents of the array might be changed. |
93 | * |
94 | * @param params the parameter array, may be <code>null</code> |
95 | * @return <code>true</code> or <code>false</code> |
96 | */ |
97 | public boolean executeBooleanCall(Object[] params) { |
98 | return executeCall(params) == 0 ? false : true; |
99 | } |
100 | |
101 | /** |
102 | * Calls the function, returning its output. |
103 | * <p> |
104 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
105 | * |
106 | * @return an <code>int</code> |
107 | */ |
108 | public native int executeCall(); |
109 | |
110 | /** |
111 | * Calls the function using the given parameter. |
112 | * <p> |
113 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
114 | * |
115 | * @param param the parameter, may be <code>null</code> |
116 | * @return an <code>int</code> |
117 | * @see #executeCall(Object[]) |
118 | */ |
119 | public int executeCall(Object param) { |
120 | return executeCall(new Object[] { param }); |
121 | } |
122 | |
123 | /** |
124 | * Calls the function using the given parameters. |
125 | * <p> |
126 | * <em>Updates the error code field. See {@link #getLastError()}.</em> |
127 | * <p> |
128 | * During this operation, the contents of the array might be changed. |
129 | * |
130 | * @param params the parameter array, may be <code>null</code> |
131 | * @return an <code>int</code> |
132 | */ |
133 | public int executeCall(Object[] params) { |
134 | if (params == null || params.length == 0) { |
135 | return executeCall(); |
136 | } |
137 | check(params); |
138 | return executeCall0(params); |
139 | } |
140 | |
141 | private native int executeCall0(Object[] params); |
142 | |
143 | } |