*** empty log message ***
[chuck-blob.git] / v2 / chuck_shell.h
blobd95f39a2aab8b262e3b1b2cf9091a546eda2afac
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
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_shell.h
27 // desc: ...
29 // author: Spencer Salazar (ssalazar@princeton.edu)
30 // date: Autumn 2005
31 //-----------------------------------------------------------------------------
32 #ifndef __CHUCK_SHELL_H__
33 #define __CHUCK_SHELL_H__
35 #include "chuck_def.h"
36 #include "chuck_errmsg.h"
37 #include "chuck_vm.h"
39 #include <string>
40 #include <map>
41 #include <vector>
43 using namespace std;
45 // forward references
46 class Chuck_Shell_VM;
47 class Chuck_Shell_UI;
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
55 // shell mode.
56 //-----------------------------------------------------------------------------
57 class Chuck_Shell
59 public:
60 Chuck_Shell();
61 virtual ~Chuck_Shell();
63 t_CKBOOL init( Chuck_VM * process_vm, Chuck_Shell_UI * );
64 void run();
65 t_CKBOOL execute( string &, string & );
66 void close();
67 void exit();
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;
74 //forward declaration
75 class Command;
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;
85 string code;
87 // helper functions
88 t_CKBOOL do_glob( const string &, string &, vector < string > & );
89 void do_code( string &, string &, string command = "+ " );
90 void do_code_context( string & );
92 protected:
93 // helper functions
94 void do_aliases();
95 void do_variables();
97 // code helper functions
98 void start_code();
99 void continue_code( string & );
100 void string_hash( string &, string & );
102 Chuck_Shell_UI * ui;
104 t_CKBOOL initialized;
105 t_CKBOOL stop;
107 string prompt;
109 string in;
111 // code entry variables
112 t_CKBOOL code_entry_active;
113 t_CKUINT scope;
115 public: // HACK-GE: moved from protected for win32
117 //-----------------------------------------------------------------------------
118 // name: class Chuck_Shell::Command
119 // desc: superclass to Chuck_Shell_Commands
120 //-----------------------------------------------------------------------------
121 class Command
123 public:
124 // virtual destructor (gewang)
125 virtual ~Command() { }
127 public:
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();
133 protected:
134 Chuck_Shell * caller;
137 //-----------------------------------------------------------------------------
138 // name: class Chuck_Shell::Command_VM
139 // desc: ...
140 //-----------------------------------------------------------------------------
141 class Command_VM : public Command
143 public:
144 ~Command_VM();
145 t_CKBOOL init( Chuck_Shell * );
146 t_CKINT execute( vector< string > &, string & );
147 string usage();
149 protected:
150 map < string, Command * > commands;
151 vector < Command * > allocated_commands;
154 //-----------------------------------------------------------------------------
155 // name: class Chuck_Shell::Command_VM_Add
156 // desc: ...
157 //-----------------------------------------------------------------------------
158 class Command_VMAdd : public Command
160 public:
161 t_CKINT execute( vector< string > &, string & );
164 //-----------------------------------------------------------------------------
165 // name: class Chuck_Shell::Command_VM_Remove
166 // desc: ...
167 //-----------------------------------------------------------------------------
168 class Command_VMRemove : public Command
170 public:
171 t_CKINT execute( vector< string > &, string & );
174 //-----------------------------------------------------------------------------
175 // name: class Chuck_Shell::Command_VM_Attach
176 // desc: ...
177 //-----------------------------------------------------------------------------
178 class Command_VMAttach : public Command
180 public:
181 t_CKINT execute( vector< string > &, string & );
184 //-----------------------------------------------------------------------------
185 // name: class Chuck_Shell::Command_VM_List
186 // desc: ...
187 //-----------------------------------------------------------------------------
188 class Command_VMList : public Command
190 public:
191 t_CKINT execute( vector< string > &, string & );
194 //-----------------------------------------------------------------------------
195 // name: class Chuck_Shell::Command_VM_Swap
196 // desc: ...
197 //-----------------------------------------------------------------------------
198 class Command_VMSwap : public Command
200 public:
201 t_CKINT execute( vector< string > &, string & );
204 //-----------------------------------------------------------------------------
205 // name: class Chuck_Shell::Command_VM_AttachAdd
206 // desc: ...
207 //-----------------------------------------------------------------------------
208 class Command_VMAttachAdd : public Command
210 public:
211 t_CKINT execute( vector< string > &, string & );
214 //-----------------------------------------------------------------------------
215 // name: class Chuck_Shell::Command_Add
216 // desc: ...
217 //-----------------------------------------------------------------------------
218 class Command_Add : public Command
220 public:
221 t_CKINT execute( vector < string > &, string & );
222 string usage();
225 //-----------------------------------------------------------------------------
226 // name: class Chuck_Shell::Command_Remove
227 // desc: ...
228 //-----------------------------------------------------------------------------
229 class Command_Remove : public Command
231 public:
232 t_CKINT execute( vector < string > &, string & );
233 string usage();
236 //-----------------------------------------------------------------------------
237 // name: class Chuck_Shell::Command_Status
238 // desc: ...
239 //-----------------------------------------------------------------------------
240 class Command_Status : public Command
242 public:
243 t_CKINT execute( vector < string > &, string & );
244 string usage();
247 //-----------------------------------------------------------------------------
248 // name: class Chuck_Shell::Command_Removeall
249 // desc: ...
250 //-----------------------------------------------------------------------------
251 class Command_Removeall : public Command
253 public:
254 t_CKINT execute( vector< string > &, string & );
255 string usage();
258 //-----------------------------------------------------------------------------
259 // name: class Chuck_Shell::Command_Removelast
260 // desc: ...
261 //-----------------------------------------------------------------------------
262 class Command_Removelast : public Command
264 public:
265 t_CKINT execute( vector< string > &, string & );
266 string usage();
269 //-----------------------------------------------------------------------------
270 // name: class Chuck_Shell::Command_Replace
271 // desc: ...
272 //-----------------------------------------------------------------------------
273 class Command_Replace : public Command
275 public:
276 t_CKINT execute( vector< string > &, string & );
277 string usage();
280 //-----------------------------------------------------------------------------
281 // name: class Chuck_Shell::Command_Kill
282 // desc: ...
283 //-----------------------------------------------------------------------------
284 class Command_Kill : public Command
286 public:
287 t_CKINT execute( vector< string > &, string & );
288 //string usage();
291 //-----------------------------------------------------------------------------
292 // name: class Chuck_Shell::Command_Close
293 // desc: ...
294 //-----------------------------------------------------------------------------
295 class Command_Close : public Command
297 public:
298 t_CKINT execute( vector< string > &, string & );
299 //string usage();
302 //-----------------------------------------------------------------------------
303 // name: class Chuck_Shell::Command_Exit
304 // desc: ...
305 //-----------------------------------------------------------------------------
306 class Command_Exit : public Command
308 public:
309 t_CKINT execute( vector< string > &, string & );
310 //string usage();
313 //-----------------------------------------------------------------------------
314 // name: class Chuck_Shell::Command_Ls
315 // desc: ...
316 //-----------------------------------------------------------------------------
317 class Command_Ls : public Command
319 public:
320 t_CKINT execute( vector< string > &, string & );
321 //string usage();
324 //-----------------------------------------------------------------------------
325 // name: class Chuck_Shell::Command_Cd
326 // desc: ...
327 //-----------------------------------------------------------------------------
328 class Command_Cd : public Command
330 public:
331 t_CKINT execute( vector< string > &, string & );
332 //string usage();
335 //-----------------------------------------------------------------------------
336 // name: class Chuck_Shell::Command_Pwd
337 // desc: ...
338 //-----------------------------------------------------------------------------
339 class Command_Pwd : public Command
341 public:
342 t_CKINT execute( vector< string > &, string & );
345 //-----------------------------------------------------------------------------
346 // name: class Chuck_Shell::Command_Alias
347 // desc: ...
348 //-----------------------------------------------------------------------------
349 class Command_Alias : public Command
351 public:
352 t_CKINT execute( vector< string > &, string & );
355 //-----------------------------------------------------------------------------
356 // name: class Chuck_Shell::Command_Unalias
357 // desc: ...
358 //-----------------------------------------------------------------------------
359 class Command_Unalias : public Command
361 public:
362 t_CKINT execute( vector< string > &, string & );
365 //-----------------------------------------------------------------------------
366 // name: class Chuck_Shell::Command_Source
367 // desc: ...
368 //-----------------------------------------------------------------------------
369 class Command_Source : public Command
371 public:
372 t_CKINT execute( vector< string > &, string & );
375 //-----------------------------------------------------------------------------
376 // name: class Chuck_Shell::Command_Code
377 // desc: ...
378 //-----------------------------------------------------------------------------
379 class Command_Code : public Command
381 public:
382 ~Command_Code();
383 t_CKBOOL init( Chuck_Shell * );
384 t_CKINT execute( vector< string > &, string & );
385 string usage();
387 private:
388 map < string, Command * > commands;
389 vector < Command * > allocated_commands;
392 //-----------------------------------------------------------------------------
393 // name: class Chuck_Shell::Command_CodeContext
394 // desc: ...
395 //-----------------------------------------------------------------------------
396 class Command_CodeContext : public Command
398 public:
399 t_CKINT execute( vector< string > &, string & );
402 //-----------------------------------------------------------------------------
403 // name: class Chuck_Shell::Command_CodeSave
404 // desc: ...
405 //-----------------------------------------------------------------------------
406 class Command_CodeSave : public Command
408 public:
409 t_CKINT execute( vector< string > &, string & );
412 //-----------------------------------------------------------------------------
413 // name: class Chuck_Shell::Command_CodeDelete
414 // desc: ...
415 //-----------------------------------------------------------------------------
416 class Command_CodeDelete : public Command
418 public:
419 t_CKINT execute( vector< string > &, string & );
422 //-----------------------------------------------------------------------------
423 // name: class Chuck_Shell::Command_CodeAdd
424 // desc: ...
425 //-----------------------------------------------------------------------------
426 class Command_CodeAdd : public Command
428 public:
429 t_CKINT execute( vector< string > &, string & );
432 //-----------------------------------------------------------------------------
433 // name: class Chuck_Shell::Command_CodeList
434 // desc: ...
435 //-----------------------------------------------------------------------------
436 class Command_CodeList : public Command
438 public:
439 t_CKINT execute( vector< string > &, string & );
442 //-----------------------------------------------------------------------------
443 // name: class Chuck_Shell::Command_CodePrint
444 // desc: ...
445 //-----------------------------------------------------------------------------
446 class Command_CodePrint : public Command
448 public:
449 t_CKINT execute( vector< string > &, string & );
452 //-----------------------------------------------------------------------------
453 // name: class Chuck_Shell::Command_CodeWrite
454 // desc: ...
455 //-----------------------------------------------------------------------------
456 class Command_CodeWrite : public Command
458 public:
459 t_CKINT execute( vector< string > &, string & );
462 //-----------------------------------------------------------------------------
463 // name: class Chuck_Shell::Command_CodeRead
464 // desc: ...
465 //-----------------------------------------------------------------------------
466 class Command_CodeRead : public Command
468 public:
469 t_CKINT execute( vector< string > &, string & );
472 //-----------------------------------------------------------------------------
473 // name: class Chuck_Shell::Command_Help
474 // desc: ...
475 //-----------------------------------------------------------------------------
476 class Command_Help : public Command
478 public:
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 //-----------------------------------------------------------------------------
489 class Chuck_Shell_VM
491 public:
492 virtual ~Chuck_Shell_VM() {}
494 public:
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
512 public:
513 virtual ~Chuck_Shell_Network_VM() {}
515 public:
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 & );
525 string fullname();
527 private:
528 string hostname;
529 t_CKINT port;
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
538 public:
539 virtual ~Chuck_Shell_Process_VM() {}
541 public:
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 & );
551 string fullname();
553 t_CKUINT last_shred_id();
555 private:
556 Chuck_VM * vm;
557 Chuck_Compiler * compiler;
560 //-----------------------------------------------------------------------------
561 // name: class Chuck_Shell_UI
562 // desc: superclass to various types of Chuck UIs
563 //-----------------------------------------------------------------------------
564 class Chuck_Shell_UI
566 public:
567 virtual ~Chuck_Shell_UI() {}
569 public:
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__