File: bundletest.c

package info (click to toggle)
o2 1.0~repack-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,156 kB
  • sloc: ansic: 9,132; python: 137; sh: 111; makefile: 10
file content (82 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//  dispatchtest.c -- dispatch messages between local services
//

#include <stdio.h>
#include "o2.h"
#include "assert.h"
#include "o2_message.h"


#define N_ADDRS 20

int expected = 0;

void service_one(o2_msg_data_ptr data, const char *types,
                 o2_arg_ptr *argv, int argc, void *user_data)
{
    assert(argc == 1);
    assert(argv[0]->i == 1234);
    printf("service_one called\n");
    assert(expected % 10 == 1);
    expected /= 10;
}

void service_two(o2_msg_data_ptr data, const char *types,
                 o2_arg_ptr *argv, int argc, void *user_data)
{
    assert(argc == 1);
    assert(argv[0]->i == 2345);
    printf("service_two called\n");
    assert(expected % 10 == 2);
    expected /= 10;
}


int main(int argc, const char * argv[])
{
    o2_initialize("test");
    o2_service_new("one");
    o2_method_new("/one/i", "i", &service_one, NULL, TRUE, TRUE);  
    o2_service_new("two");
    o2_method_new("/two/i", "i", &service_two, NULL, TRUE, TRUE);

    // make a bundle, starting with two messages
    o2_send_start();
    o2_add_int32(1234);
    o2_message_ptr one = o2_message_finish(0.0, "/one/i", TRUE);

    o2_send_start();
    o2_add_int32(2345);
    o2_message_ptr two = o2_message_finish(0.0, "/two/i", TRUE);

    expected = 21;
    o2_send_start();
    o2_add_message(one);
    o2_add_message(two);
    o2_send_finish(0.0, "#one", TRUE);
    assert(expected == 0);
    
    expected = 21;
    o2_send_start();
    o2_add_message(one);
    o2_add_message(two);
    o2_send_finish(0.0, "#two", TRUE);
    assert(expected == 0);
    
    // make a nested bundle ((12)(12))
    o2_send_start();
    o2_add_message(one);
    o2_add_message(two);
    o2_message_ptr bdl = o2_message_finish(0.0, "#one", TRUE);

    expected = 2121;
    o2_send_start();
    o2_add_message(bdl);
    o2_add_message(bdl);
    o2_send_finish(0.0, "#two", TRUE);
    assert(expected == 0);
    
    o2_finish();
    printf("DONE\n");
    return 0;
}