*** empty log message ***
[chuck-blob.git] / v1 / ulib_machine.cpp
blobc536b327f61edc215db9a75f9378a7a77bfcdad3
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: ulib_machine.cpp
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Spring 2004
32 //-----------------------------------------------------------------------------
33 #include "ulib_machine.h"
34 #include "chuck_vm.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" );
47 /*! \nameinfo
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.
54 */
56 // add add
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" );
63 // add spork
64 //! same as add
65 QUERY->add_export( QUERY, "int", "spork", machine_add_impl, TRUE );
66 QUERY->add_param( QUERY, "string", "path" );
68 // add remove
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" );
73 // add replace
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" );
80 // add status
81 //! display current status of VM
82 //! (see example/status.ck)
83 QUERY->add_export( QUERY, "int", "status", machine_status_impl, TRUE );
85 return TRUE;
90 static Chuck_VM * the_vm = NULL;
91 static proc_msg_func the_func = NULL;
92 //-----------------------------------------------------------------------------
93 // name: machine_init()
94 // desc: ...
95 //-----------------------------------------------------------------------------
96 t_CKBOOL machine_init( Chuck_VM * vm, proc_msg_func proc_msg )
98 the_vm = vm;
99 the_func = proc_msg;
100 return TRUE;
104 // add
105 CK_DLL_FUNC( machine_add_impl )
107 const char * v = *(const char **)ARGS;
108 Net_Msg msg;
110 msg.type = MSG_ADD;
111 strcpy( msg.buffer, v );
112 RETURN->v_int = (int)the_func( &msg, TRUE, NULL );
115 // remove
116 CK_DLL_FUNC( machine_remove_impl )
118 t_CKUINT v = *(t_CKUINT *)ARGS;
119 Net_Msg msg;
121 msg.type = MSG_REMOVE;
122 msg.param = v;
123 RETURN->v_int = (int)the_func( &msg, TRUE, NULL );
126 // replace
127 CK_DLL_FUNC( machine_replace_impl )
129 t_CKUINT v = *(t_CKUINT *)ARGS;
130 const char * v2 = *((const char **)ARGS+1);
131 Net_Msg msg;
133 msg.type = MSG_REPLACE;
134 msg.param = v;
135 strcpy( msg.buffer, v2 );
136 RETURN->v_int = (int)the_func( &msg, TRUE, NULL );
139 // status
140 CK_DLL_FUNC( machine_status_impl )
142 Net_Msg msg;
144 msg.type = MSG_STATUS;
145 RETURN->v_int = (int)the_func( &msg, TRUE, NULL );