11

Posted on 2014-04-04 14:40  xiaomaogong  阅读(133)  评论(0编辑  收藏  举报

#include <stdio.h>
#include <stdlib.h>

#include <avis/elvin.h>
#include <avis/errors.h>
#include <avis/stdtypes.h>
#include "errors_private.h"
#include "avis/attributes.h"
#include "avis/keys.h"

void test_subscribe_sub_listener (Subscription *sub,
Attributes *attributes, bool secure,
void *user_data)
{
Array *data = attributes_get_opaque (attributes, "opaque");
}

int main(int argc, char* argv[]) {
Elvin elvin;
Subscription *sub;
Attributes *ntfn = attributes_create ();
Array data;

data.item_count = 100 * 1024;
data.items = malloc (data.item_count);

memset (data.items, 42, data.item_count);

/* check invalid subscription is handled */
sub = elvin_subscribe (&elvin, "size (bogus");

sub =
elvin_subscribe
(&elvin,
"require (test) && string (message) && int32 == 32 && int64 == 64L");

elvin_subscription_add_listener (sub, test_subscribe_sub_listener,
"user_data");

attributes_set_int32 (ntfn, "test", 1);
attributes_set_int32 (ntfn, "int32", 32);
attributes_set_int64 (ntfn, "int64", 64);
attributes_set_real64 (ntfn, "pi", 3.14);
attributes_set_string (ntfn, "message", "hello world");
attributes_set_opaque (ntfn, "opaque", data);

elvin_send (&elvin, ntfn) && elvin_poll (&elvin);

//elvin_unsubscribe (&elvin, sub);

/* test sub change*/
sub = elvin_subscribe (&elvin, "require (bogus)");

/*elvin_subscription_add_listener (sub, test_subscribe_sub_listener,
"user_data");*/

//elvin_subscription_set_expr (sub, "require (test)");

elvin_send (&elvin, ntfn) && elvin_poll (&elvin);

attributes_destroy (ntfn);

/* test general listener */
ntfn = attributes_create ();
attributes_set_int32 (ntfn, "test", 1);

attributes_destroy (ntfn);

elvin_unsubscribe (&elvin, sub);

elvin_close (&elvin);

system("pause");
}

Copyright © 2024 xiaomaogong
Powered by .NET 9.0 on Kubernetes