~ubuntu-branches/ubuntu/edgy/rxtx/edgy-201105201527

« back to all changes in this revision

Viewing changes to CNI/Zystem.java

  • Committer: Bazaar Package Importer
  • Author(s): Mario Joussen
  • Date: 2006-03-01 18:56:52 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060301185652-ri9941gi01goklvz
Tags: 2.1.7-2
Fixed stupid bug in clean target.
(closes: Bug#354859)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------
 
2
|   Zystem is a native interface for message reporting in java.
 
3
|   Copyright 2003-2004 by Trent Jarvi taj@www.linux.org.uk.
 
4
|
 
5
|   This library is free software; you can redistribute it and/or
 
6
|   modify it under the terms of the GNU Library General Public
 
7
|   License as published by the Free Software Foundation; either
 
8
|   version 2 of the License, or (at your option) any later version.
 
9
|
 
10
|   This library is distributed in the hope that it will be useful,
 
11
|   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
|   Library General Public License for more details.
 
14
|
 
15
|   You should have received a copy of the GNU Library General Public
 
16
|   License along with this library; if not, write to the Free
 
17
|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
--------------------------------------------------------------------------*/
 
19
package gnu.io;
 
20
 
 
21
import java.io.RandomAccessFile;
 
22
 
 
23
public class Zystem
 
24
{
 
25
        public static final int SILENT_MODE     = 0;
 
26
        public static final int FILE_MODE       = 1;
 
27
        public static final int NET_MODE        = 2;
 
28
        public static final int MEX_MODE        = 3;
 
29
        public static final int PRINT_MODE      = 4;
 
30
        public static final int J2EE_MSG_MODE   = 5;
 
31
 
 
32
        static int mode;
 
33
 
 
34
        static
 
35
        {
 
36
                /* 
 
37
                The rxtxZystem library uses Python code and is not
 
38
                included with RXTX.  A seperate library will be released
 
39
                to avoid potential license conflicts.
 
40
 
 
41
                Trent Jarvi taj@www.linux.org.uk
 
42
                */
 
43
 
 
44
                //System.loadLibrary( "rxtxZystem" );
 
45
                mode = SILENT_MODE;
 
46
        }
 
47
 
 
48
        private static String target;
 
49
 
 
50
        public Zystem( int m ) throws UnSupportedLoggerException
 
51
        {
 
52
                mode = m;
 
53
                startLogger( "asdf" );
 
54
        }
 
55
 
 
56
 
 
57
        public void startLogger( ) throws UnSupportedLoggerException
 
58
        {
 
59
                if ( mode == SILENT_MODE || mode == PRINT_MODE )
 
60
                {
 
61
                        //nativeNetInit( );
 
62
                        return;
 
63
                }
 
64
                throw new UnSupportedLoggerException( "Target Not Allowed" );
 
65
        }
 
66
 
 
67
        /*  accept the host or file to log to. */
 
68
 
 
69
        public void startLogger( String t ) throws UnSupportedLoggerException
 
70
        {
 
71
                target = t;
 
72
        /*
 
73
                if ( mode == NET_MODE )
 
74
                {
 
75
                        nativeNetInit( );
 
76
                }
 
77
                if ( nativeInit( ) )
 
78
                {
 
79
                        throw new UnSupportedLoggerException(
 
80
                                "Port initializion failed" );
 
81
                }
 
82
        */
 
83
                return;
 
84
        }
 
85
 
 
86
        public void finalize()
 
87
        {
 
88
        /*
 
89
                if ( mode == NET_MODE )
 
90
                {
 
91
                        nativeNetFinalize( );
 
92
                }
 
93
                nativeFinalize();
 
94
        */
 
95
                mode = SILENT_MODE;
 
96
                target = null;
 
97
        }
 
98
 
 
99
        public void filewrite( String s )
 
100
        {
 
101
                try {
 
102
                        RandomAccessFile w =
 
103
                                new RandomAccessFile( target, "rw" );;
 
104
                        w.seek( w.length() );
 
105
                        w.writeBytes( s );
 
106
                        w.close();
 
107
                } catch ( Exception e ) {
 
108
                        System.out.println("Debug output file write failed");
 
109
                }
 
110
        }
 
111
 
 
112
        public boolean report( String s)
 
113
        {
 
114
                if ( mode == NET_MODE )
 
115
                {
 
116
                //      return( nativeNetReportln( s ) );
 
117
                }
 
118
                else if ( mode == PRINT_MODE )
 
119
                {
 
120
                        System.out.println( s );
 
121
                        return( true );
 
122
                }
 
123
                else if ( mode == MEX_MODE )
 
124
                {
 
125
                //      return( nativeMexReport( s ) );
 
126
                }
 
127
                else if ( mode == SILENT_MODE )
 
128
                {
 
129
                        return( true );
 
130
                }
 
131
                else if ( mode == FILE_MODE )
 
132
                {
 
133
                        filewrite( s );
 
134
                }
 
135
                else if ( mode == J2EE_MSG_MODE )
 
136
                {
 
137
                        return( false );
 
138
                }
 
139
                return( false );
 
140
        }
 
141
 
 
142
        public boolean reportln( )
 
143
        {
 
144
                boolean b;
 
145
                if ( mode == NET_MODE )
 
146
                {
 
147
                //      b= nativeNetReportln( "\n" );
 
148
                //      return(b);
 
149
                }
 
150
                else if ( mode == PRINT_MODE )
 
151
                {
 
152
                        System.out.println( );
 
153
                        return( true );
 
154
                }
 
155
                else if ( mode == MEX_MODE )
 
156
                {
 
157
                //      b = nativeMexReportln( "\n" );
 
158
                //      return(b);
 
159
                }
 
160
                else if ( mode == SILENT_MODE )
 
161
                {
 
162
                        return( true );
 
163
                }
 
164
                else if ( mode == FILE_MODE )
 
165
                {
 
166
                        filewrite( "\n" );
 
167
                }
 
168
                else if ( mode == J2EE_MSG_MODE )
 
169
                {
 
170
                        return( false );
 
171
                }
 
172
                return( false );
 
173
        }
 
174
 
 
175
        public boolean reportln( String s)
 
176
        {
 
177
                boolean b;
 
178
                if ( mode == NET_MODE )
 
179
                {
 
180
                //      b= nativeNetReportln( s + "\n" );
 
181
                //      return(b);
 
182
                }
 
183
                else if ( mode == PRINT_MODE )
 
184
                {
 
185
                        System.out.println( s );
 
186
                        return( true );
 
187
                }
 
188
                else if ( mode == MEX_MODE )
 
189
                {
 
190
                //      b = nativeMexReportln( s + "\n" );
 
191
                //      return(b);
 
192
                }
 
193
                else if ( mode == SILENT_MODE )
 
194
                {
 
195
                        return( true );
 
196
                }
 
197
                else if ( mode == FILE_MODE )
 
198
                {
 
199
                        filewrite( s + "\n" );
 
200
                }
 
201
                else if ( mode == J2EE_MSG_MODE )
 
202
                {
 
203
                        return( false );
 
204
                }
 
205
                return( false );
 
206
        }
 
207
 
 
208
/*
 
209
        private native boolean nativeInit( );
 
210
        private native void nativeFinalize();
 
211
*/
 
212
 
 
213
        /* open and close the socket */
 
214
/*
 
215
        private native boolean nativeNetInit( );
 
216
        private native void nativeNetFinalize();
 
217
*/
 
218
 
 
219
        /* dumping to a remote machine */
 
220
/*
 
221
        public native boolean nativeNetReport( String s );
 
222
        public native boolean nativeNetReportln( String s );
 
223
*/
 
224
 
 
225
        /*  specific to Matlab */
 
226
/*
 
227
        public native boolean nativeMexReport( String s );
 
228
        public native boolean nativeMexReportln( String s );
 
229
*/
 
230
}