Debian Codegraph @

src/core/chuck_io.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // name: chuck_io.h
28 // desc: chuck i/o
29 //
30 // authors: Spencer Salazar ([email protected])
31 // date: Summer 2012
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_IO_H__
34 #define __CHUCK_IO_H__
35
36 #include "chuck_oo.h"
37 #include "chuck_dl.h"
38 #include "util_buffers.h"
39
40 #include <list>
41 #include <fstream>
42 #include <sstream> // REFACTOR-2017: for custom output
43
44
45
46
47 // class initialization
48 // do not __DISABLE_MIDI__ this one in particular
49 t_CKBOOL init_class_Midi( Chuck_Env * env );
50 #ifndef __DISABLE_MIDI__
51 t_CKBOOL init_class_MidiRW( Chuck_Env * env );
52 #endif
53 #ifndef __DISABLE_HID__
54 t_CKBOOL init_class_HID( Chuck_Env * env );
55 #endif
56 t_CKBOOL init_class_io( Chuck_Env * env, Chuck_Type * type );
57 t_CKBOOL init_class_fileio( Chuck_Env * env, Chuck_Type * type );
58 // added 1.3.0.0 -- moved to be full-fledged class
59 t_CKBOOL init_class_chout( Chuck_Env * env, Chuck_Type * type );
60 // added 1.3.0.0 -- moved to be full-fledged class
61 t_CKBOOL init_class_cherr( Chuck_Env * env, Chuck_Type * type );
62 #ifndef __DISABLE_SERIAL__
63 // added 1.3.1
64 t_CKBOOL init_class_serialio( Chuck_Env * env );
65 #endif
66
67
68
69
70 //-----------------------------------------------------------------------------
71 // name: Chuck_IO
72 // desc: base Chuck IO class
73 //-----------------------------------------------------------------------------
74 struct Chuck_IO : public Chuck_Event
75 {
76 public:
77 Chuck_IO();
78 virtual ~Chuck_IO();
79
80 public:
81 // meta
82 virtual t_CKBOOL good() = 0;
83 virtual void close() = 0;
84 virtual void flush() = 0;
85 virtual t_CKINT mode() = 0;
86 virtual void mode( t_CKINT flag ) = 0;
87
88 // reading
89 virtual Chuck_String * readLine() = 0;
90 virtual t_CKINT readInt( t_CKINT flags ) = 0;
91 virtual t_CKFLOAT readFloat() = 0;
92 virtual t_CKFLOAT readFloat( t_CKINT flags ) = 0;
93 virtual t_CKBOOL readString( std::string & str ) = 0;
94 virtual t_CKBOOL eof() = 0;
95
96 // writing
97 virtual void write( const std::string & val ) = 0;
98 virtual void write( t_CKINT val ) = 0;
99 virtual void write( t_CKINT val, t_CKINT flags ) = 0;
100 virtual void write( t_CKFLOAT val ) = 0;
101 virtual void write( t_CKFLOAT val, t_CKINT flags ) = 0;
102 virtual void write( const t_CKCOMPLEX & val ) = 0;
103 virtual void write( const t_CKCOMPLEX & val, t_CKINT flags ) = 0;
104 virtual void write( const t_CKPOLAR & val ) = 0;
105 virtual void write( const t_CKPOLAR & val, t_CKINT flags ) = 0;
106 virtual void write( const t_CKVEC2 & val ) = 0;
107 virtual void write( const t_CKVEC2 & val, t_CKINT flags ) = 0;
108 virtual void write( const t_CKVEC3 & val ) = 0;
109 virtual void write( const t_CKVEC3 & val, t_CKINT flags ) = 0;
110 virtual void write( const t_CKVEC4 & val ) = 0;
111 virtual void write( const t_CKVEC4 & val, t_CKINT flags ) = 0;
112
113 public:
114 // type | moved to IO in 1.5.0.0 (ge)
115 static const t_CKINT TYPE_ASCII;
116 static const t_CKINT TYPE_BINARY;
117 // datatype
118 static const t_CKINT INT8;
119 static const t_CKINT INT16;
120 static const t_CKINT INT24; // 1.5.0.1 (ge) added
121 static const t_CKINT INT32;
122 static const t_CKINT INT64; // 1.5.0.1 (ge) added
123 // 1.5.0.1 (ge) added SINT and UINT type flags
124 static const t_CKINT SINT8;
125 static const t_CKINT SINT16;
126 static const t_CKINT SINT24;
127 static const t_CKINT SINT32;
128 static const t_CKINT SINT64;
129 static const t_CKINT UINT8;
130 static const t_CKINT UINT16;
131 static const t_CKINT UINT24;
132 static const t_CKINT UINT32;
133 static const t_CKINT UINT64;
134 // 1.5.0.1 (ge) added FLOAT type flags
135 static const t_CKINT FLOAT32;
136 static const t_CKINT FLOAT64;
137 // flags | moved to IO in 1.5.0.0 (ge)
138 static const t_CKINT FLAG_READ_WRITE;
139 static const t_CKINT FLAG_READONLY;
140 static const t_CKINT FLAG_WRITEONLY;
141 static const t_CKINT FLAG_APPEND;
142 // asynchronous I/O members
143 static const t_CKINT MODE_SYNC;
144 static const t_CKINT MODE_ASYNC;
145
146 Chuck_Event * m_asyncEvent;
147 #ifndef __DISABLE_THREADS__
148 XThread * m_thread;
149 #endif
150 struct async_args
151 {
152 Chuck_IO_File * fileio_obj;
153 void * RETURN; // actually a Chuck_DL_Return
154 t_CKINT intArg;
155 t_CKFLOAT floatArg;
156 std::string stringArg;
157 };
158 };
159
160
161
162
163 #ifndef __PLATFORM_WINDOWS__
164 #include <dirent.h>
165 #else
166 struct DIR;
167 #endif
168
169 //-----------------------------------------------------------------------------
170 // name: Chuck_IO_File
171 // desc: Chuck File IO class
172 //-----------------------------------------------------------------------------
173 struct Chuck_IO_File : public Chuck_IO
174 {
175 public:
176 // REFACTOR-2017
177 Chuck_IO_File( Chuck_VM * vm );
178 virtual ~Chuck_IO_File();
179
180 public:
181 // meta
182 virtual t_CKBOOL open( const std::string & path, t_CKINT flags );
183 virtual t_CKBOOL good();
184 virtual void close();
185 virtual void flush();
186 virtual t_CKINT mode();
187 virtual void mode( t_CKINT flag );
188 virtual t_CKINT size();
189
190 // seeking
191 virtual void seek( t_CKINT pos );
192 virtual t_CKINT tell();
193
194 // directories
195 virtual t_CKINT isDir();
196 virtual Chuck_ArrayInt * dirList();
197
198 // reading
199 // virtual Chuck_String * read( t_CKINT length );
200 virtual Chuck_String * readLine();
201 virtual t_CKINT readInt( t_CKINT flags );
202 virtual t_CKFLOAT readFloat();
203 virtual t_CKFLOAT readFloat( t_CKINT flags );
204 virtual t_CKBOOL readString( std::string & str );
205 virtual t_CKBOOL eof();
206
207 // reading -- async
208 /* TODO: doesn't look like asynchronous reads will work
209 static THREAD_RETURN ( THREAD_TYPE read_thread ) ( void *data );
210 static THREAD_RETURN ( THREAD_TYPE readLine_thread ) ( void *data );
211 static THREAD_RETURN ( THREAD_TYPE readInt_thread ) ( void *data );
212 static THREAD_RETURN ( THREAD_TYPE readFloat_thread ) ( void *data );
213 */
214
215 // writing
216 virtual void write( const std::string & val );
217 virtual void write( t_CKINT val );
218 virtual void write( t_CKINT val, t_CKINT flags );
219 virtual void write( t_CKFLOAT val );
220 virtual void write( t_CKFLOAT val, t_CKINT flags );
221 virtual void write( const t_CKCOMPLEX & val );
222 virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
223 virtual void write( const t_CKPOLAR & val );
224 virtual void write( const t_CKPOLAR & val, t_CKINT flags );
225 virtual void write( const t_CKVEC2 & val );
226 virtual void write( const t_CKVEC2 & val, t_CKINT flags );
227 virtual void write( const t_CKVEC3 & val );
228 virtual void write( const t_CKVEC3 & val, t_CKINT flags );
229 virtual void write( const t_CKVEC4 & val );
230 virtual void write( const t_CKVEC4 & val, t_CKINT flags );
231
232 #ifndef __DISABLE_THREADS__
233 // writing -- async
234 static THREAD_RETURN( THREAD_TYPE writeStr_thread ) (void * data);
235 static THREAD_RETURN( THREAD_TYPE writeInt_thread ) (void * data);
236 static THREAD_RETURN( THREAD_TYPE writeFloat_thread ) (void * data);
237 #endif
238
239 // get filename
240 std::string filename() const { return m_path; }
241
242 protected:
243 // open flags
244 t_CKINT m_flags;
245 // I/O mode
246 t_CKINT m_iomode;
247 // file stream
248 std::fstream m_io;
249 // directory pointer
250 DIR * m_dir;
251 // directory location
252 long m_dir_start;
253 // path
254 std::string m_path;
255 // vm and shred
256 Chuck_VM * m_vmRef;
257
258 public:
259 // auto prefix | 1.5.1.5
260 std::string m_autoPrefix;
261 // auto extension | 1.5.1.5
262 std::string m_autoExtension;
263 };
264
265
266
267
268 //-----------------------------------------------------------------------------
269 // name: Chuck_IO_Chout
270 // desc: Chuck console IO out
271 //-----------------------------------------------------------------------------
272 struct Chuck_IO_Chout : public Chuck_IO
273 {
274 public:
275 Chuck_IO_Chout( Chuck_Carrier * carrier );
276 virtual ~Chuck_IO_Chout();
277
278 public:
279 // meta
280 virtual t_CKBOOL good();
281 virtual void close();
282 virtual void flush();
283 virtual t_CKINT mode();
284 virtual void mode( t_CKINT flag );
285
286 // reading
287 virtual Chuck_String * readLine();
288 virtual t_CKINT readInt( t_CKINT flags );
289 virtual t_CKFLOAT readFloat();
290 virtual t_CKFLOAT readFloat( t_CKINT flags );
291 virtual t_CKBOOL readString( std::string & str );
292 virtual t_CKBOOL eof();
293
294 // writing
295 virtual void write( const std::string & val );
296 virtual void write( t_CKINT val );
297 virtual void write( t_CKINT val, t_CKINT flags );
298 virtual void write( t_CKFLOAT val );
299 virtual void write( t_CKFLOAT val, t_CKINT flags );
300 virtual void write( const t_CKCOMPLEX & val );
301 virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
302 virtual void write( const t_CKPOLAR & val );
303 virtual void write( const t_CKPOLAR & val, t_CKINT flags );
304 virtual void write( const t_CKVEC2 & val );
305 virtual void write( const t_CKVEC2 & val, t_CKINT flags );
306 virtual void write( const t_CKVEC3 & val );
307 virtual void write( const t_CKVEC3 & val, t_CKINT flags );
308 virtual void write( const t_CKVEC4 & val );
309 virtual void write( const t_CKVEC4 & val, t_CKINT flags );
310
311 public: // REFACTOR-2017
312 // set callback
313 void set_output_callback( void (*fp)(const char *) );
314
315 private:
316 // callback
317 void (*m_callback)(const char *);
318 // intermediate line storage
319 std::stringstream m_buffer;
320 };
321
322
323
324
325 //-----------------------------------------------------------------------------
326 // name: Chuck_IO_Cherr
327 // desc: Chuck console IO err
328 //-----------------------------------------------------------------------------
329 struct Chuck_IO_Cherr : public Chuck_IO
330 {
331 public:
332 Chuck_IO_Cherr( Chuck_Carrier * carrier );
333 virtual ~Chuck_IO_Cherr();
334
335 public:
336 // meta
337 virtual t_CKBOOL good();
338 virtual void close();
339 virtual void flush();
340 virtual t_CKINT mode();
341 virtual void mode( t_CKINT flag );
342
343 // reading
344 virtual Chuck_String * readLine();
345 virtual t_CKINT readInt( t_CKINT flags );
346 virtual t_CKFLOAT readFloat();
347 virtual t_CKFLOAT readFloat( t_CKINT flags );
348 virtual t_CKBOOL readString( std::string & str );
349 virtual t_CKBOOL eof();
350
351 // writing
352 virtual void write( const std::string & val );
353 virtual void write( t_CKINT val );
354 virtual void write( t_CKINT val, t_CKINT flags );
355 virtual void write( t_CKFLOAT val );
356 virtual void write( t_CKFLOAT val, t_CKINT flags );
357 virtual void write( const t_CKCOMPLEX & val );
358 virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
359 virtual void write( const t_CKPOLAR & val );
360 virtual void write( const t_CKPOLAR & val, t_CKINT flags );
361 virtual void write( const t_CKVEC2 & val );
362 virtual void write( const t_CKVEC2 & val, t_CKINT flags );
363 virtual void write( const t_CKVEC3 & val );
364 virtual void write( const t_CKVEC3 & val, t_CKINT flags );
365 virtual void write( const t_CKVEC4 & val );
366 virtual void write( const t_CKVEC4 & val, t_CKINT flags );
367
368 public:
369 // set callback | REFACTOR-2017
370 void set_output_callback( void (*fp)(const char *) );
371
372 private:
373 // callback
374 void (*m_callback)(const char *);
375 // intermediate line storage
376 std::stringstream m_buffer;
377 };
378
379
380
381
382 //-----------------------------------------------------------------------------
383 // io API
384 //-----------------------------------------------------------------------------
385 CK_DLL_MFUN( io_dummy_int );
386 CK_DLL_MFUN( io_dummy_float );
387 CK_DLL_MFUN( io_dummy_string );
388 CK_DLL_MFUN( io_dummy_void );
389 CK_DLL_SFUN( io_newline );
390 CK_DLL_SFUN( io_openfile );
391
392
393 //-----------------------------------------------------------------------------
394 // fileio API
395 //-----------------------------------------------------------------------------
396 CK_DLL_CTOR( fileio_ctor );
397 CK_DLL_DTOR( fileio_dtor );
398 CK_DLL_MFUN( fileio_open );
399 CK_DLL_MFUN( fileio_openflags );
400 CK_DLL_MFUN( fileio_good );
401 CK_DLL_MFUN( fileio_close );
402 CK_DLL_MFUN( fileio_flush );
403 CK_DLL_MFUN( fileio_getmode );
404 CK_DLL_MFUN( fileio_setmode );
405 CK_DLL_MFUN( fileio_size );
406 CK_DLL_MFUN( fileio_seek );
407 CK_DLL_MFUN( fileio_tell );
408 CK_DLL_MFUN( fileio_isdir );
409 CK_DLL_MFUN( fileio_dirlist );
410 CK_DLL_MFUN( fileio_read );
411 CK_DLL_MFUN( fileio_readline );
412 CK_DLL_MFUN( fileio_readint );
413 CK_DLL_MFUN( fileio_readintflags );
414 CK_DLL_MFUN( fileio_readint8 );
415 CK_DLL_MFUN( fileio_readint16 );
416 CK_DLL_MFUN( fileio_readint32 );
417 CK_DLL_MFUN( fileio_readfloat );
418 CK_DLL_MFUN( fileio_readfloatflags );
419 CK_DLL_MFUN( fileio_eof );
420 CK_DLL_MFUN( fileio_more );
421 CK_DLL_MFUN( fileio_writestring );
422 CK_DLL_MFUN( fileio_writeint );
423 CK_DLL_MFUN( fileio_writeintflags );
424 CK_DLL_MFUN( fileio_writefloat );
425 CK_DLL_MFUN( fileio_writefloatflags );
426 CK_DLL_MFUN( file_ctrl_autoPrefixAndExtension );
427 CK_DLL_MFUN( file_cget_autoPrefix );
428 CK_DLL_MFUN( file_cget_autoExtension );
429 CK_DLL_MFUN( file_cget_filename );
430 CK_DLL_SFUN( fileio_expandpath_impl );
431
432
433 //-----------------------------------------------------------------------------
434 // chout API -- added 1.3.0.0 as full class
435 //-----------------------------------------------------------------------------
436 CK_DLL_MFUN( chout_good );
437 CK_DLL_MFUN( chout_close );
438 CK_DLL_MFUN( chout_flush );
439 CK_DLL_MFUN( chout_getmode );
440 CK_DLL_MFUN( chout_setmode );
441 CK_DLL_MFUN( chout_read );
442 CK_DLL_MFUN( chout_readline );
443 CK_DLL_MFUN( chout_readint );
444 CK_DLL_MFUN( chout_readintflags );
445 CK_DLL_MFUN( chout_readfloat );
446 CK_DLL_MFUN( chout_eof );
447 CK_DLL_MFUN( chout_more );
448 CK_DLL_MFUN( chout_writestring );
449 CK_DLL_MFUN( chout_writeint );
450 CK_DLL_MFUN( chout_writefloat );
451
452
453 //-----------------------------------------------------------------------------
454 // cherr API -- added 1.3.0.0 as full class
455 //-----------------------------------------------------------------------------
456 CK_DLL_MFUN( cherr_good );
457 CK_DLL_MFUN( cherr_close );
458 CK_DLL_MFUN( cherr_flush );
459 CK_DLL_MFUN( cherr_getmode );
460 CK_DLL_MFUN( cherr_setmode );
461 CK_DLL_MFUN( cherr_read );
462 CK_DLL_MFUN( cherr_readline );
463 CK_DLL_MFUN( cherr_readint );
464 CK_DLL_MFUN( cherr_readintflags );
465 CK_DLL_MFUN( cherr_readfloat );
466 CK_DLL_MFUN( cherr_eof );
467 CK_DLL_MFUN( cherr_more );
468 CK_DLL_MFUN( cherr_writestring );
469 CK_DLL_MFUN( cherr_writeint );
470 CK_DLL_MFUN( cherr_writefloat );
471
472
473
474
475 //-----------------------------------------------------------------------------
476 // MidiMsg API
477 //-----------------------------------------------------------------------------
478 CK_DLL_CTOR( MidiMsg_ctor );
479
480 extern t_CKUINT MidiMsg_offset_data1;
481 extern t_CKUINT MidiMsg_offset_data2;
482 extern t_CKUINT MidiMsg_offset_data3;
483 extern t_CKUINT MidiMsg_offset_when;
484
485 #ifndef __DISABLE_MIDI__
486 //-----------------------------------------------------------------------------
487 // MidiRW API
488 //-----------------------------------------------------------------------------
489 CK_DLL_CTOR( MidiRW_ctor );
490 CK_DLL_DTOR( MidiRW_dtor );
491 CK_DLL_MFUN( MidiRW_open );
492 CK_DLL_MFUN( MidiRW_close );
493 CK_DLL_MFUN( MidiRW_read );
494 CK_DLL_MFUN( MidiRW_write );
495
496
497 //-----------------------------------------------------------------------------
498 // MidiMsgOut API
499 //-----------------------------------------------------------------------------
500 CK_DLL_CTOR( MidiMsgOut_ctor );
501 CK_DLL_DTOR( MidiMsgOut_dtor );
502 CK_DLL_MFUN( MidiMsgOut_open );
503 CK_DLL_MFUN( MidiMsgOut_close );
504 CK_DLL_MFUN( MidiMsgOut_write );
505
506
507 //-----------------------------------------------------------------------------
508 // MidiMsgIn API
509 //-----------------------------------------------------------------------------
510 CK_DLL_CTOR( MidiMsgIn_ctor );
511 CK_DLL_DTOR( MidiMsgIn_dtor );
512 CK_DLL_MFUN( MidiMsgIn_open );
513 CK_DLL_MFUN( MidiMsgIn_close );
514 CK_DLL_MFUN( MidiMsgIn_read );
515
516
517 //-----------------------------------------------------------------------------
518 // MidiIn API
519 //-----------------------------------------------------------------------------
520 CK_DLL_CTOR( MidiIn_ctor );
521 CK_DLL_DTOR( MidiIn_dtor );
522 CK_DLL_MFUN( MidiIn_open );
523 CK_DLL_MFUN( MidiIn_open_named ); // added 1.3.0.0
524 CK_DLL_MFUN( MidiIn_open_named_i ); // added 1.3.0.0
525 CK_DLL_MFUN( MidiIn_good );
526 CK_DLL_MFUN( MidiIn_num );
527 CK_DLL_MFUN( MidiIn_name );
528 CK_DLL_MFUN( MidiIn_printerr );
529 CK_DLL_MFUN( MidiIn_recv );
530 CK_DLL_MFUN( MidiIn_can_wait );
531
532
533 //-----------------------------------------------------------------------------
534 // MidiOut API
535 //-----------------------------------------------------------------------------
536 CK_DLL_CTOR( MidiOut_ctor );
537 CK_DLL_DTOR( MidiOut_dtor );
538 CK_DLL_MFUN( MidiOut_open );
539 CK_DLL_MFUN( MidiOut_open_named ); // added 1.3.0.0
540 CK_DLL_MFUN( MidiOut_open_named_i); // added 1.3.0.0
541 CK_DLL_MFUN( MidiOut_good );
542 CK_DLL_MFUN( MidiOut_num );
543 CK_DLL_MFUN( MidiOut_name );
544 CK_DLL_MFUN( MidiOut_printerr );
545 CK_DLL_MFUN( MidiOut_send );
546 CK_DLL_MFUN( MidiOut_send_msg );
547 CK_DLL_MFUN( MidiOut_noteOn );
548 CK_DLL_MFUN( MidiOut_noteOff );
549 CK_DLL_MFUN( MidiOut_controlChange );
550 CK_DLL_MFUN( MidiOut_programChange );
551 CK_DLL_MFUN( MidiOut_pitchBend );
552 CK_DLL_MFUN( MidiOut_pitchBend_fine );
553 CK_DLL_MFUN( MidiOut_polyPressure );
554 CK_DLL_MFUN( MidiOut_channelPressure );
555 #endif // __DISABLE_MIDI__
556
557
558
559 #ifndef __DISABLE_HID__
560 //-----------------------------------------------------------------------------
561 // HidMsg API
562 //-----------------------------------------------------------------------------
563 CK_DLL_MFUN( HidMsg_is_axis_motion );
564 CK_DLL_MFUN( HidMsg_is_button_down );
565 CK_DLL_MFUN( HidMsg_is_button_up );
566 CK_DLL_MFUN( HidMsg_is_mouse_motion );
567 CK_DLL_MFUN( HidMsg_is_hat_motion );
568 CK_DLL_MFUN( HidMsg_is_wheel_motion );
569
570 //-----------------------------------------------------------------------------
571 // HidIn API
572 //-----------------------------------------------------------------------------
573 CK_DLL_CTOR( HidIn_ctor );
574 CK_DLL_DTOR( HidIn_dtor );
575 CK_DLL_MFUN( HidIn_open );
576 CK_DLL_MFUN( HidIn_open_named );
577 CK_DLL_MFUN( HidIn_open_named_i ); // added 1.3.0.0
578 CK_DLL_MFUN( HidIn_open_joystick );
579 CK_DLL_MFUN( HidIn_open_joystick_2 );
580 CK_DLL_MFUN( HidIn_open_mouse );
581 CK_DLL_MFUN( HidIn_open_mouse_2 );
582 CK_DLL_MFUN( HidIn_open_keyboard );
583 CK_DLL_MFUN( HidIn_open_keyboard_2 );
584 CK_DLL_MFUN( HidIn_open_tiltsensor );
585 CK_DLL_MFUN( HidIn_good );
586 CK_DLL_MFUN( HidIn_num );
587 CK_DLL_MFUN( HidIn_name );
588 CK_DLL_MFUN( HidIn_printerr );
589 CK_DLL_MFUN( HidIn_recv );
590 CK_DLL_MFUN( HidIn_read );
591 CK_DLL_MFUN( HidIn_send );
592 CK_DLL_MFUN( HidIn_can_wait );
593 CK_DLL_SFUN( HidIn_read_tilt_sensor );
594 CK_DLL_SFUN( HidIn_ctrl_tiltPollRate );
595 CK_DLL_SFUN( HidIn_cget_tiltPollRate );
596 CK_DLL_SFUN( HidIn_start_cursor_track );
597 CK_DLL_SFUN( HidIn_stop_cursor_track );
598
599
600 //-----------------------------------------------------------------------------
601 // HidOut API
602 //-----------------------------------------------------------------------------
603 CK_DLL_CTOR( HidOut_ctor );
604 CK_DLL_DTOR( HidOut_dtor );
605 CK_DLL_MFUN( HidOut_open );
606 CK_DLL_MFUN( HidOut_good );
607 CK_DLL_MFUN( HidOut_num );
608 CK_DLL_MFUN( HidOut_name );
609 CK_DLL_MFUN( HidOut_printerr );
610 CK_DLL_MFUN( HidOut_send );
611
612 CK_DLL_CTOR( MouseCursor_ctor );
613 CK_DLL_DTOR( MouseCursor_dtor );
614 CK_DLL_SFUN( MouseCursor_scaled );
615 CK_DLL_SFUN( MouseCursor_abs );
616 CK_DLL_SFUN( MouseCursor_abs_x );
617 CK_DLL_SFUN( MouseCursor_abs_y );
618
619 CK_DLL_CTOR( Mousor_ctor );
620 CK_DLL_DTOR( Mousor_dtor );
621
622 #endif // __DISABLE_HID__1
623
624
625
626
627 #ifndef __DISABLE_SERIAL__
628 //-----------------------------------------------------------------------------
629 // name: struct Chuck_IO_Serial
630 // desc: chuck serial I/O
631 //-----------------------------------------------------------------------------
632 struct Chuck_IO_Serial : public Chuck_IO
633 {
634 public:
635 Chuck_IO_Serial( Chuck_VM * vm );
636 virtual ~Chuck_IO_Serial();
637
638 static void shutdown();
639
640 public:
641 // meta
642 virtual t_CKBOOL open( const t_CKUINT i, t_CKINT flags, t_CKUINT baud = CK_BAUD_9600 );
643 virtual t_CKBOOL open( const std::string & path, t_CKINT flags, t_CKUINT baud = CK_BAUD_9600 );
644
645 virtual t_CKBOOL can_wait();
646
647 virtual t_CKBOOL good();
648 virtual void close();
649 virtual void flush();
650 virtual t_CKINT mode();
651 virtual void mode( t_CKINT flag );
652
653 // reading
654 virtual Chuck_String * readLine();
655 virtual t_CKINT readInt( t_CKINT flags );
656 virtual t_CKFLOAT readFloat();
657 virtual t_CKFLOAT readFloat( t_CKINT flags );
658 virtual t_CKBOOL readString( std::string & str );
659 virtual t_CKBOOL eof();
660
661 // writing
662 virtual void write( const std::string & val );
663 virtual void write( t_CKINT val );
664 virtual void write( t_CKINT val, t_CKINT flags );
665 virtual void writeBytes( Chuck_ArrayInt * arr );
666 virtual void write( t_CKFLOAT val );
667 virtual void write( t_CKFLOAT val, t_CKINT flags );
668 virtual void write( const t_CKCOMPLEX & val );
669 virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
670 virtual void write( const t_CKPOLAR & val );
671 virtual void write( const t_CKPOLAR & val, t_CKINT flags );
672 virtual void write( const t_CKVEC2 & val );
673 virtual void write( const t_CKVEC2 & val, t_CKINT flags );
674 virtual void write( const t_CKVEC3 & val );
675 virtual void write( const t_CKVEC3 & val, t_CKINT flags );
676 virtual void write( const t_CKVEC4 & val );
677 virtual void write( const t_CKVEC4 & val, t_CKINT flags );
678
679 // serial stuff
680 virtual t_CKBOOL setBaudRate( t_CKUINT rate );
681 virtual t_CKUINT getBaudRate();
682
683 // async reading
684 virtual t_CKBOOL readAsync( t_CKUINT type, t_CKUINT num );
685 virtual Chuck_String * getLine();
686 virtual t_CKINT getByte();
687 virtual Chuck_Array * getBytes();
688 virtual Chuck_Array * getInts();
689 virtual Chuck_Array * getFloats();
690 virtual Chuck_String * getString();
691
692 static const t_CKUINT TYPE_NONE;
693 static const t_CKUINT TYPE_BYTE;
694 static const t_CKUINT TYPE_WORD;
695 static const t_CKUINT TYPE_INT;
696 static const t_CKUINT TYPE_FLOAT;
697 static const t_CKUINT TYPE_STRING;
698 static const t_CKUINT TYPE_LINE;
699 static const t_CKUINT TYPE_WRITE;
700
701 struct Request
702 {
703 t_CKUINT m_type; // type
704 t_CKUINT m_num; // how many
705 t_CKUINT m_status;
706 t_CKUINT m_val; // ISSUE: 64-bit
707
708 enum Status
709 {
710 RQ_STATUS_PENDING,
711 RQ_STATUS_SUCCESS,
712 RQ_STATUS_FAILURE,
713 RQ_STATUS_INVALID,
714 RQ_STATUS_EOF,
715 };
716 };
717
718 virtual t_CKBOOL ready();
719
720 // available baud rates
721 static const t_CKUINT CK_BAUD_2400;
722 static const t_CKUINT CK_BAUD_4800;
723 static const t_CKUINT CK_BAUD_9600;
724 static const t_CKUINT CK_BAUD_19200;
725 static const t_CKUINT CK_BAUD_38400;
726 static const t_CKUINT CK_BAUD_7200;
727 static const t_CKUINT CK_BAUD_14400;
728 static const t_CKUINT CK_BAUD_28800;
729 static const t_CKUINT CK_BAUD_57600;
730 static const t_CKUINT CK_BAUD_76800;
731 static const t_CKUINT CK_BAUD_115200;
732 static const t_CKUINT CK_BAUD_230400;
733
734 protected:
735
736 void start_read_thread();
737 XThread * m_read_thread;
738 static void *shell_read_cb(void *);
739 void read_cb();
740
741 XThread * m_write_thread;
742 static void *shell_write_cb(void *);
743 void write_cb();
744
745 void close_int();
746
747 t_CKBOOL get_buffer(t_CKINT timeout_ms = 1);
748 t_CKINT peek_buffer();
749 t_CKINT pull_buffer();
750 t_CKINT buffer_bytes_to_tmp(t_CKINT num_bytes);
751
752 t_CKBOOL handle_line(Request &);
753 t_CKBOOL handle_string(Request &);
754 t_CKBOOL handle_float_ascii(Request &);
755 t_CKBOOL handle_int_ascii(Request &);
756 t_CKBOOL handle_byte(Request &);
757 t_CKBOOL handle_float_binary(Request &);
758 t_CKBOOL handle_int_binary(Request &);
759
760 bool m_do_read_thread;
761 bool m_do_write_thread;
762
763 CircularBuffer<Request> m_asyncRequests;
764 CircularBuffer<Request> m_asyncResponses;
765 CBufferSimple * m_event_buffer;
766
767 int m_fd;
768 FILE * m_cfd;
769
770 std::string m_path;
771
772 unsigned char * m_io_buf;
773 t_CKUINT m_io_buf_max;
774 t_CKUINT m_io_buf_available;
775 t_CKUINT m_io_buf_pos;
776
777 unsigned char * m_tmp_buf;
778 t_CKUINT m_tmp_buf_max;
779
780 CircularBuffer<Request> m_asyncWriteRequests;
781 CircularBuffer<char> m_writeBuffer;
782
783 t_CKINT m_flags;
784 t_CKINT m_iomode; // SYNC or ASYNC
785 t_CKBOOL m_eof;
786
787 t_CKBOOL m_do_exit;
788
789 static std::list<Chuck_IO_Serial *> s_serials;
790
791 Chuck_VM * m_vmRef;
792 };
793 #endif // __DISABLE_SERIAL__
794
795
796
797
798
799 #endif // __CHUCK_IO_H__