1 /* gs_example_receive.c */
27 void disp_l(struct list *l);
29 string_size_callback(void *vars,
30 struct s_gs_type *p_type,
35 disp_l(struct list *l) {
43 string_size_callback(void *vars,
44 struct s_gs_type *p_type,
46 return 1+(long int)strlen(data);
51 main(int argc, char **argv) {
52 struct list **pl = NULL;
54 struct s_pair *p_pair = NULL;
56 // struct s_mixed *mixed = NULL;
58 struct s_gs_type_driver *t_driver = NULL;
59 struct s_gs_net_driver *n_driver = NULL;
60 struct s_gs_type_bag *bag = NULL;
61 struct s_gs_connection *cnx = NULL;
63 struct s_gs_type_bag_ops *bag_ops = NULL;
65 struct s_gs_type *t_signed_int = NULL;
66 struct s_gs_type *t_list = NULL;
67 struct s_gs_type *t_ref_list = NULL;
69 struct s_gs_type *t_array = NULL;
71 struct s_gs_type *t_ref_sint = NULL;
72 struct s_gs_type *t_pair = NULL;
74 struct s_gs_type *t_char = NULL;
75 struct s_gs_type *t_string = NULL;
77 struct s_gs_type *t_u_char = NULL;
78 struct s_gs_type *t_u_long_int = NULL;
79 struct s_gs_type *t_mixed = NULL;
81 struct s_gs_message_instance *mi = NULL;
84 gs_purge_cmd_line(&argc, argv);
86 t_driver = gs_type_driver_init("rl");
87 n_driver = gs_net_driver_init("fd");
89 bag = gs_type_bag_alloc(t_driver);
90 bag_ops = bag->bag_ops;
94 cnx = gs_net_connection_accept(n_driver, &fd);
97 bag_ops->register_incoming_connection(bag, cnx);
100 t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int");
101 t_list = gs_type_new_struct(bag, NULL, "list");
102 t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list);
104 gs_type_struct_append_field(t_list, "v", t_signed_int);
105 gs_type_struct_append_field(t_list, "l", t_ref_list);
108 t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int);
111 t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int);
112 t_pair = gs_type_new_struct(bag, NULL, "pair");
114 gs_type_struct_append_field(t_pair, "pa", t_ref_sint);
115 gs_type_struct_append_field(t_pair, "pb", t_ref_sint);
118 t_char = bag_ops->get_type_by_name(bag, NULL, "signed char");
119 t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL);
122 t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char");
123 t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int");
124 t_mixed = gs_type_new_struct(bag, NULL, "mixed");
126 gs_type_struct_append_field(t_mixed, "c1", t_u_char);
127 gs_type_struct_append_field(t_mixed, "l1", t_u_long_int);
128 gs_type_struct_append_field(t_mixed, "c2", t_u_char);
129 gs_type_struct_append_field(t_mixed, "l2", t_u_long_int);
131 /* message receive */
132 mi = gs_message_init_receive(bag, cnx);
133 fprintf(stderr, "\nreceiving sequence 1\n----------------\n");
134 pl = gs_message_receive_next_sequence(mi);
140 fprintf(stderr, "\nreceiving sequence 2\n----------------\n");
141 array = gs_message_receive_next_sequence(mi);
145 for (i = 0; i < 5; i++) {
146 printf("array[%d] = %d\n", i, array[i]);
150 fprintf(stderr, "\nreceiving sequence 3\n----------------\n");
151 p_pair = gs_message_receive_next_sequence(mi);
152 printf("pair.pa = %p, *pair.pa = %d\n", (*p_pair).pa, *((*p_pair).pa));
153 printf("pair.pb = %p, *pair.pb = %d\n", (*p_pair).pb, *((*p_pair).pb));
155 fprintf(stderr, "\nreceiving sequence 4\n----------------\n");
156 str = gs_message_receive_next_sequence(mi);
157 printf("str = %s\n", str);
160 fprintf(stderr, "\nreceiving sequence 5\n----------------\n");
161 mixed = gs_message_receive_next_sequence(mi);
162 printf("c1=%c c2=%c; l1=%ld l2=%ld\n",
163 mixed->c1, mixed->c2, mixed->l1, mixed->l2);