hop-2012/server/meta.c

47 lines
1.1 KiB
C

/* Copyright (C) 2010 Tony Garnock-Jones. All rights reserved. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
#include "cmsg_private.h"
#include "ref.h"
#include "sexp.h"
#include "hashtable.h"
#include "node.h"
#include "meta.h"
static sexp_t *meta_sym = NULL;
void init_meta(void) {
sexp_t *args;
meta_sym = INCREF(sexp_cstring("meta"));
args = INCREF(sexp_cons(meta_sym, NULL));
new_node(lookup_node_class(cmsg_cstring_bytes("direct")), args, NULL);
DECREF(args, sexp_destructor);
}
void announce_subscription(sexp_t *source,
sexp_t *filter,
sexp_t *sink,
sexp_t *name,
int onoff)
{
if (meta_sym != NULL) { /* use this as a proxy for whether meta has been initialized or not */
sexp_t *msg = NULL;
msg = sexp_cons(name, msg);
msg = sexp_cons(sink, msg);
msg = sexp_cons(filter, msg);
msg = sexp_cons(source, msg);
msg = sexp_cons(sexp_cstring(onoff ? "subscribed" : "unsubscribed"), msg);
INCREF(msg);
post_node(sexp_data(meta_sym), sexp_data(source), msg, NULL);
DECREF(msg, sexp_destructor);
}
}