1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_shell.h
29 // author: Spencer Salazar (ssalazar@princeton.edu)
31 //-----------------------------------------------------------------------------
32 #ifndef __CHUCK_SHELL_H__
33 #define __CHUCK_SHELL_H__
35 #include "chuck_def.h"
36 #include "chuck_errmsg.h"
49 typedef string Chuck_Shell_Request
;
50 typedef string Chuck_Shell_Response
;
52 //-----------------------------------------------------------------------------
53 // name: class Chuck_Shell
54 // desc: controller class for facilitating interaction between a shell UI and a
56 //-----------------------------------------------------------------------------
61 virtual ~Chuck_Shell();
63 t_CKBOOL
init( Chuck_VM
* process_vm
, Chuck_Shell_UI
* );
65 t_CKBOOL
execute( string
&, string
& );
69 public: // HACK-GE: these were moved from protected for win32
70 vector
< Chuck_Shell_VM
* > vms
;
71 Chuck_VM
* process_vm
;
72 Chuck_Shell_VM
* current_vm
;
77 // alias, variable, and command maps
78 map
< string
, string
> aliases
;
79 map
< string
, string
> variables
;
80 map
< string
, Command
* > commands
;
81 vector
< Command
* > allocated_commands
;
83 map
< string
, string
> saved_code
;
88 t_CKBOOL
do_glob( const string
&, string
&, vector
< string
> & );
89 void do_code( string
&, string
&, string command
= "+ " );
90 void do_code_context( string
& );
97 // code helper functions
99 void continue_code( string
& );
100 void string_hash( string
&, string
& );
104 t_CKBOOL initialized
;
111 // code entry variables
112 t_CKBOOL code_entry_active
;
115 public: // HACK-GE: moved from protected for win32
117 //-----------------------------------------------------------------------------
118 // name: class Chuck_Shell::Command
119 // desc: superclass to Chuck_Shell_Commands
120 //-----------------------------------------------------------------------------
124 // virtual destructor (gewang)
125 virtual ~Command() { }
128 virtual t_CKBOOL
init( Chuck_Shell
* );
129 virtual t_CKINT
execute( vector
< string
> &, string
& ) = 0;
130 virtual string
usage();
131 virtual string
long_usage();
134 Chuck_Shell
* caller
;
137 //-----------------------------------------------------------------------------
138 // name: class Chuck_Shell::Command_VM
140 //-----------------------------------------------------------------------------
141 class Command_VM
: public Command
145 t_CKBOOL
init( Chuck_Shell
* );
146 t_CKINT
execute( vector
< string
> &, string
& );
150 map
< string
, Command
* > commands
;
151 vector
< Command
* > allocated_commands
;
154 //-----------------------------------------------------------------------------
155 // name: class Chuck_Shell::Command_VM_Add
157 //-----------------------------------------------------------------------------
158 class Command_VMAdd
: public Command
161 t_CKINT
execute( vector
< string
> &, string
& );
164 //-----------------------------------------------------------------------------
165 // name: class Chuck_Shell::Command_VM_Remove
167 //-----------------------------------------------------------------------------
168 class Command_VMRemove
: public Command
171 t_CKINT
execute( vector
< string
> &, string
& );
174 //-----------------------------------------------------------------------------
175 // name: class Chuck_Shell::Command_VM_Attach
177 //-----------------------------------------------------------------------------
178 class Command_VMAttach
: public Command
181 t_CKINT
execute( vector
< string
> &, string
& );
184 //-----------------------------------------------------------------------------
185 // name: class Chuck_Shell::Command_VM_List
187 //-----------------------------------------------------------------------------
188 class Command_VMList
: public Command
191 t_CKINT
execute( vector
< string
> &, string
& );
194 //-----------------------------------------------------------------------------
195 // name: class Chuck_Shell::Command_VM_Swap
197 //-----------------------------------------------------------------------------
198 class Command_VMSwap
: public Command
201 t_CKINT
execute( vector
< string
> &, string
& );
204 //-----------------------------------------------------------------------------
205 // name: class Chuck_Shell::Command_VM_AttachAdd
207 //-----------------------------------------------------------------------------
208 class Command_VMAttachAdd
: public Command
211 t_CKINT
execute( vector
< string
> &, string
& );
214 //-----------------------------------------------------------------------------
215 // name: class Chuck_Shell::Command_Add
217 //-----------------------------------------------------------------------------
218 class Command_Add
: public Command
221 t_CKINT
execute( vector
< string
> &, string
& );
225 //-----------------------------------------------------------------------------
226 // name: class Chuck_Shell::Command_Remove
228 //-----------------------------------------------------------------------------
229 class Command_Remove
: public Command
232 t_CKINT
execute( vector
< string
> &, string
& );
236 //-----------------------------------------------------------------------------
237 // name: class Chuck_Shell::Command_Status
239 //-----------------------------------------------------------------------------
240 class Command_Status
: public Command
243 t_CKINT
execute( vector
< string
> &, string
& );
247 //-----------------------------------------------------------------------------
248 // name: class Chuck_Shell::Command_Removeall
250 //-----------------------------------------------------------------------------
251 class Command_Removeall
: public Command
254 t_CKINT
execute( vector
< string
> &, string
& );
258 //-----------------------------------------------------------------------------
259 // name: class Chuck_Shell::Command_Removelast
261 //-----------------------------------------------------------------------------
262 class Command_Removelast
: public Command
265 t_CKINT
execute( vector
< string
> &, string
& );
269 //-----------------------------------------------------------------------------
270 // name: class Chuck_Shell::Command_Replace
272 //-----------------------------------------------------------------------------
273 class Command_Replace
: public Command
276 t_CKINT
execute( vector
< string
> &, string
& );
280 //-----------------------------------------------------------------------------
281 // name: class Chuck_Shell::Command_Kill
283 //-----------------------------------------------------------------------------
284 class Command_Kill
: public Command
287 t_CKINT
execute( vector
< string
> &, string
& );
291 //-----------------------------------------------------------------------------
292 // name: class Chuck_Shell::Command_Close
294 //-----------------------------------------------------------------------------
295 class Command_Close
: public Command
298 t_CKINT
execute( vector
< string
> &, string
& );
302 //-----------------------------------------------------------------------------
303 // name: class Chuck_Shell::Command_Exit
305 //-----------------------------------------------------------------------------
306 class Command_Exit
: public Command
309 t_CKINT
execute( vector
< string
> &, string
& );
313 //-----------------------------------------------------------------------------
314 // name: class Chuck_Shell::Command_Ls
316 //-----------------------------------------------------------------------------
317 class Command_Ls
: public Command
320 t_CKINT
execute( vector
< string
> &, string
& );
324 //-----------------------------------------------------------------------------
325 // name: class Chuck_Shell::Command_Cd
327 //-----------------------------------------------------------------------------
328 class Command_Cd
: public Command
331 t_CKINT
execute( vector
< string
> &, string
& );
335 //-----------------------------------------------------------------------------
336 // name: class Chuck_Shell::Command_Pwd
338 //-----------------------------------------------------------------------------
339 class Command_Pwd
: public Command
342 t_CKINT
execute( vector
< string
> &, string
& );
345 //-----------------------------------------------------------------------------
346 // name: class Chuck_Shell::Command_Alias
348 //-----------------------------------------------------------------------------
349 class Command_Alias
: public Command
352 t_CKINT
execute( vector
< string
> &, string
& );
355 //-----------------------------------------------------------------------------
356 // name: class Chuck_Shell::Command_Unalias
358 //-----------------------------------------------------------------------------
359 class Command_Unalias
: public Command
362 t_CKINT
execute( vector
< string
> &, string
& );
365 //-----------------------------------------------------------------------------
366 // name: class Chuck_Shell::Command_Source
368 //-----------------------------------------------------------------------------
369 class Command_Source
: public Command
372 t_CKINT
execute( vector
< string
> &, string
& );
375 //-----------------------------------------------------------------------------
376 // name: class Chuck_Shell::Command_Code
378 //-----------------------------------------------------------------------------
379 class Command_Code
: public Command
383 t_CKBOOL
init( Chuck_Shell
* );
384 t_CKINT
execute( vector
< string
> &, string
& );
388 map
< string
, Command
* > commands
;
389 vector
< Command
* > allocated_commands
;
392 //-----------------------------------------------------------------------------
393 // name: class Chuck_Shell::Command_CodeContext
395 //-----------------------------------------------------------------------------
396 class Command_CodeContext
: public Command
399 t_CKINT
execute( vector
< string
> &, string
& );
402 //-----------------------------------------------------------------------------
403 // name: class Chuck_Shell::Command_CodeSave
405 //-----------------------------------------------------------------------------
406 class Command_CodeSave
: public Command
409 t_CKINT
execute( vector
< string
> &, string
& );
412 //-----------------------------------------------------------------------------
413 // name: class Chuck_Shell::Command_CodeDelete
415 //-----------------------------------------------------------------------------
416 class Command_CodeDelete
: public Command
419 t_CKINT
execute( vector
< string
> &, string
& );
422 //-----------------------------------------------------------------------------
423 // name: class Chuck_Shell::Command_CodeAdd
425 //-----------------------------------------------------------------------------
426 class Command_CodeAdd
: public Command
429 t_CKINT
execute( vector
< string
> &, string
& );
432 //-----------------------------------------------------------------------------
433 // name: class Chuck_Shell::Command_CodeList
435 //-----------------------------------------------------------------------------
436 class Command_CodeList
: public Command
439 t_CKINT
execute( vector
< string
> &, string
& );
442 //-----------------------------------------------------------------------------
443 // name: class Chuck_Shell::Command_CodePrint
445 //-----------------------------------------------------------------------------
446 class Command_CodePrint
: public Command
449 t_CKINT
execute( vector
< string
> &, string
& );
452 //-----------------------------------------------------------------------------
453 // name: class Chuck_Shell::Command_CodeWrite
455 //-----------------------------------------------------------------------------
456 class Command_CodeWrite
: public Command
459 t_CKINT
execute( vector
< string
> &, string
& );
462 //-----------------------------------------------------------------------------
463 // name: class Chuck_Shell::Command_CodeRead
465 //-----------------------------------------------------------------------------
466 class Command_CodeRead
: public Command
469 t_CKINT
execute( vector
< string
> &, string
& );
472 //-----------------------------------------------------------------------------
473 // name: class Chuck_Shell::Command_Help
475 //-----------------------------------------------------------------------------
476 class Command_Help
: public Command
479 t_CKINT
execute( vector
< string
> &, string
& );
485 //-----------------------------------------------------------------------------
486 // name: class Chuck_Shell_VM
487 // desc: encapsulates local and network VMs into a single class
488 //-----------------------------------------------------------------------------
492 virtual ~Chuck_Shell_VM() {}
495 virtual Chuck_Shell_VM
* copy()=0;
496 virtual t_CKBOOL
add_shred( const vector
< string
> &, string
& )=0;
497 virtual t_CKBOOL
remove_shred( const vector
< string
> &, string
& )=0;
498 virtual t_CKBOOL
remove_all( string
& )=0;
499 virtual t_CKBOOL
remove_last( string
& )=0;
500 virtual t_CKBOOL
replace_shred( const vector
< string
> &, string
& )=0;
501 virtual t_CKBOOL
status( string
& )=0;
502 virtual t_CKBOOL
kill( string
& )=0;
503 virtual string
fullname()=0;
506 //-----------------------------------------------------------------------------
507 // name: class Chuck_Shell_Network_VM
508 // desc: VM across the network
509 //-----------------------------------------------------------------------------
510 class Chuck_Shell_Network_VM
: public Chuck_Shell_VM
513 virtual ~Chuck_Shell_Network_VM() {}
516 Chuck_Shell_VM
* copy();
517 t_CKBOOL
init( const string
&, t_CKINT
);
518 t_CKBOOL
add_shred( const vector
< string
> &, string
& );
519 t_CKBOOL
remove_shred( const vector
< string
> &, string
& );
520 t_CKBOOL
remove_all( string
& );
521 t_CKBOOL
remove_last( string
& );
522 t_CKBOOL
replace_shred( const vector
< string
> &, string
& );
523 t_CKBOOL
status( string
& );
524 t_CKBOOL
kill( string
& );
532 //-----------------------------------------------------------------------------
533 // name: class Chuck_Shell_Network_VM
534 // desc: VM across the network
535 //-----------------------------------------------------------------------------
536 class Chuck_Shell_Process_VM : public Chuck_Shell_VM
539 virtual ~Chuck_Shell_Process_VM() {}
542 Chuck_Shell_VM * copy();
543 t_CKBOOL init( const string &, t_CKINT );
544 t_CKBOOL add_shred( const vector< string > &, string & );
545 t_CKBOOL remove_shred( const vector< string > &, string & );
546 t_CKBOOL remove_all( string & );
547 t_CKBOOL remove_last( string & );
548 t_CKBOOL replace_shred( const vector< string > &, string & );
549 t_CKBOOL status( string & );
550 t_CKBOOL kill( string & );
553 t_CKUINT last_shred_id();
557 Chuck_Compiler * compiler;
560 //-----------------------------------------------------------------------------
561 // name: class Chuck_Shell_UI
562 // desc: superclass to various types of Chuck UIs
563 //-----------------------------------------------------------------------------
567 virtual ~Chuck_Shell_UI() {}
570 virtual t_CKBOOL
init();
571 virtual t_CKBOOL
next_command( const string
&, string
& ) = 0;
572 virtual void next_result( const string
& ) = 0;
575 // prototype for shell thread routine
576 void * shell_cb( void * p
);
578 #endif //__CHUCK_SHELL_H__