aboutsummaryrefslogtreecommitdiff
path: root/sql_query.c
diff options
context:
space:
mode:
Diffstat (limited to 'sql_query.c')
-rw-r--r--sql_query.c86
1 files changed, 64 insertions, 22 deletions
diff --git a/sql_query.c b/sql_query.c
index 754e0b9..85f674e 100644
--- a/sql_query.c
+++ b/sql_query.c
@@ -44,44 +44,51 @@
*/
static t_class *sql_query_class;
+static t_class *proxy_inlet_class;
+
+typedef struct _proxy_inlet
+{
+ t_pd pd;
+ void *owner;
+ unsigned int id;
+} t_proxy_inlet;
+
typedef struct _sql_query
{
t_object x_obj;
t_binbuf* x_query_binbuf;
- int inlet_count;
+ unsigned int placeholder_count;
+ struct _proxy_inlet*inlets;
+ t_atom** atoms;
t_outlet* x_data_outlet;
t_outlet* x_status_outlet;
} t_sql_query;
+/*------------------------------------------------------------------------------
+ * FUNCTION PROTOTYPES
+ */
+static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom);
/*------------------------------------------------------------------------------
* PROXY INLET FUNCTIONS
*/
-static t_class *proxy_inlet_class = NULL;
-typedef struct _proxy_inlet
-{
- t_pd pd;
- void *owner;
- unsigned int id;
-} t_proxy_inlet;
-
-static void proxy_inlet_new(t_proxy_inlet *p, void *owner, unsigned int id)
+static void proxy_inlet_new(t_proxy_inlet *p, t_object *owner, unsigned int id)
{
p->pd = proxy_inlet_class;
p->owner = owner;
p->id = id;
+ inlet_new(owner, &p->pd, 0, 0);
}
-static void proxy_inlet_anything(t_proxy_inlet *x, t_symbol *s, int argc, t_atom *argv)
+static void proxy_inlet_anything(t_proxy_inlet *p, t_symbol *s, int argc, t_atom *argv)
{
- int i;
- char buf[MAXPDSTRING];
- post("proxy_inlet_anything: %s", s -> s_name);
+ post("proxy_inlet_anything: %s %d", s->s_name, argc);
+ sql_query_set_atom(p->owner, p->id, s, argv);
}
static void proxy_inlet_setup(void)
@@ -101,7 +108,33 @@ static void proxy_inlet_setup(void)
* STANDARD CLASS FUNCTIONS
*/
-static void *sql_query_free(t_sql_query *x)
+static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom)
+{
+ char *buf;
+ int bufsize;
+ if( (&s == &s_symbol) || (&s == &s_list) )
+ {
+ atom_string(atom, buf, bufsize);
+ }
+ else
+ {
+ atom_string(atom, buf, bufsize);
+ }
+ post("set atom %s", buf);
+ x->atoms[atom_num] = atom;
+}
+
+static void sql_query_anything(t_sql_query *x, t_symbol *s, int argc, t_atom *argv)
+{
+ sql_query_set_atom(x, 0, s, argv);
+}
+
+static void sql_query_bang(t_sql_query *x)
+{
+
+}
+
+static void sql_query_free(t_sql_query *x)
{
binbuf_free(x->x_query_binbuf);
}
@@ -109,10 +142,10 @@ static void *sql_query_free(t_sql_query *x)
static void *sql_query_new(t_symbol *s, int argc, t_atom *argv)
{
DEBUG(post("sql_query_new"););
- char *buf;
+ unsigned int i;
int bufsize;
+ char *buf;
char *current = NULL;
- unsigned int total_inlets = 0;
t_sql_query *x = (t_sql_query *)pd_new(sql_query_class);
x->x_query_binbuf = binbuf_new();
@@ -120,14 +153,23 @@ static void *sql_query_new(t_symbol *s, int argc, t_atom *argv)
binbuf_gettext(x->x_query_binbuf, &buf, &bufsize);
buf[bufsize] = 0;
+ x->placeholder_count = 0;
current = strchr(buf, PLACEHOLDER);
while (current != NULL)
{
post("found placeholder %c", PLACEHOLDER);
- total_inlets++;
+ x->placeholder_count++;
current = strchr(current + 1, PLACEHOLDER);
}
- post("creating %d inlets", total_inlets);
+ post("creating %d inlets", x->placeholder_count);
+ x->inlets = getbytes(x->placeholder_count * sizeof(t_proxy_inlet));
+ x->atoms = getbytes(x->placeholder_count * sizeof(t_atom *));
+ for(i=1; i< x->placeholder_count; ++i)
+ {
+ proxy_inlet_new(&x->inlets[i], (t_object *)x, x->placeholder_count);
+ post("\tinlet %d", i);
+ }
+
x->x_data_outlet = outlet_new(&x->x_obj, 0);
x->x_status_outlet = outlet_new(&x->x_obj, 0);
@@ -139,14 +181,14 @@ void sql_query_setup(void)
DEBUG(post("sql_query_setup"););
sql_query_class = class_new(gensym("sql_query"),
(t_newmethod)sql_query_new,
- (t_newmethod)sql_query_free,
+ (t_method)sql_query_free,
sizeof(t_sql_query),
0,
A_GIMME,
0);
/* add inlet datatype methods */
-// class_addbang(sql_query_class, (t_method) sql_query_bang);
-// class_addanything(sql_query_class, (t_method) sql_query_anything);
+ class_addbang(sql_query_class, (t_method) sql_query_bang);
+ class_addanything(sql_query_class, (t_method) sql_query_anything);
}