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: ulib_machine.cpp
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
32 //-----------------------------------------------------------------------------
33 #include "ulib_machine.h"
39 //-----------------------------------------------------------------------------
40 // name: machine_query()
41 // desc: query entry point
42 //-----------------------------------------------------------------------------
43 DLL_QUERY
machine_query( Chuck_DL_Query
* QUERY
)
45 QUERY
->set_name( QUERY
, "machine" );
48 ChucK runtime interface to the virtual machine.
49 this interface can be used to manage shreds.
50 They are similar to the <a href="otfp.html">
51 On-the-fly Programming Commands</a>, except these are
52 invoked from within a ChucK program, and are accessible
53 to the timing mechanism.
57 //! compile and spork a new shred from file at 'path' into the VM now
58 //! returns the shred ID
59 //! (see example/machine.ck)
60 QUERY
->add_export( QUERY
, "int", "add", machine_add_impl
, TRUE
);
61 QUERY
->add_param( QUERY
, "string", "path" );
65 QUERY
->add_export( QUERY
, "int", "spork", machine_add_impl
, TRUE
);
66 QUERY
->add_param( QUERY
, "string", "path" );
69 //! remove shred from VM by shred ID (returned by add/spork)
70 QUERY
->add_export( QUERY
, "int", "remove", machine_remove_impl
, TRUE
);
71 QUERY
->add_param( QUERY
, "int", "id" );
74 //! replace shred with new shred from file
75 //! returns shred ID , or 0 on error
76 QUERY
->add_export( QUERY
, "int", "replace", machine_replace_impl
, TRUE
);
77 QUERY
->add_param( QUERY
, "int", "id" );
78 QUERY
->add_param( QUERY
, "string", "path" );
81 //! display current status of VM
82 //! (see example/status.ck)
83 QUERY
->add_export( QUERY
, "int", "status", machine_status_impl
, TRUE
);
90 static Chuck_VM
* the_vm
= NULL
;
91 static proc_msg_func the_func
= NULL
;
92 //-----------------------------------------------------------------------------
93 // name: machine_init()
95 //-----------------------------------------------------------------------------
96 t_CKBOOL
machine_init( Chuck_VM
* vm
, proc_msg_func proc_msg
)
105 CK_DLL_FUNC( machine_add_impl
)
107 const char * v
= *(const char **)ARGS
;
111 strcpy( msg
.buffer
, v
);
112 RETURN
->v_int
= (int)the_func( &msg
, TRUE
, NULL
);
116 CK_DLL_FUNC( machine_remove_impl
)
118 t_CKUINT v
= *(t_CKUINT
*)ARGS
;
121 msg
.type
= MSG_REMOVE
;
123 RETURN
->v_int
= (int)the_func( &msg
, TRUE
, NULL
);
127 CK_DLL_FUNC( machine_replace_impl
)
129 t_CKUINT v
= *(t_CKUINT
*)ARGS
;
130 const char * v2
= *((const char **)ARGS
+1);
133 msg
.type
= MSG_REPLACE
;
135 strcpy( msg
.buffer
, v2
);
136 RETURN
->v_int
= (int)the_func( &msg
, TRUE
, NULL
);
140 CK_DLL_FUNC( machine_status_impl
)
144 msg
.type
= MSG_STATUS
;
145 RETURN
->v_int
= (int)the_func( &msg
, TRUE
, NULL
);