22 GRAS_DEFINE_TYPE(struct_s_mixed,
40 struct list * cons(int v, struct list *l);
42 string_size_callback(void *vars,
43 struct s_gs_type *p_type,
48 cons(int v, struct list *l) {
49 struct list *nl = malloc(sizeof (struct list));
58 string_size_callback(void *vars,
59 struct s_gs_type *p_type,
61 return 1+(long int)strlen(data);
64 void parse_log_opt(int argc, char **argv,const char *deft);
68 main(int argc, char **argv) {
69 struct list *l = NULL;
78 struct s_mixed mixed =
83 struct s_gs_type_driver *t_driver = NULL;
84 struct s_gs_net_driver *n_driver = NULL;
85 struct s_gs_type_bag *bag = NULL;
86 struct s_gs_connection *cnx = NULL;
88 struct s_gs_type_bag_ops *bag_ops = NULL;
90 struct s_gs_type *t_signed_int = NULL;
91 struct s_gs_type *t_list = NULL;
92 struct s_gs_type *t_ref_list = NULL;
94 struct s_gs_type *t_array = NULL;
96 struct s_gs_type *t_ref_sint = NULL;
97 struct s_gs_type *t_pair = NULL;
99 struct s_gs_type *t_char = NULL;
100 struct s_gs_type *t_string = NULL;
103 struct s_gs_type *t_u_char = NULL;
104 struct s_gs_type *t_u_long_int = NULL;
107 struct s_gs_type *t_mixed = NULL;
109 struct s_gs_message *m = NULL;
110 struct s_gs_message_instance *mi = NULL;
113 parse_log_opt(argc,argv,"datadesc.thresh=debug");
115 gs_purge_cmd_line(&argc, argv);
116 gras_log_control_set("NDR.thresh=debug");
118 t_driver = gs_type_driver_init("rl");
119 n_driver = gs_net_driver_init("fd");
121 bag = gs_type_bag_alloc(t_driver);
122 bag_ops = bag->bag_ops;
126 cnx = gs_net_connection_connect(n_driver, &fd);
129 bag_ops->register_outgoing_connection(bag, cnx);
132 t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int");
133 t_list = gs_type_new_struct(bag, NULL, "list");
134 t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list);
136 gs_type_struct_append_field(t_list, "v", t_signed_int);
137 gs_type_struct_append_field(t_list, "l", t_ref_list);
140 t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int);
143 t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int);
144 t_pair = gs_type_new_struct(bag, NULL, "pair");
146 gs_type_struct_append_field(t_pair, "pa", t_ref_sint);
147 gs_type_struct_append_field(t_pair, "pb", t_ref_sint);
150 t_char = bag_ops->get_type_by_name(bag, NULL, "signed char");
151 t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL);
155 t_mixed = gs_type_get_by_symbol(bag,struct_s_mixed);
157 t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char");
158 t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int");
159 t_mixed = gs_type_new_struct(bag, NULL, "s_mixed");
161 gs_type_struct_append_field(t_mixed, "c1", t_u_char);
162 gs_type_struct_append_field(t_mixed, "l1", t_u_long_int);
163 gs_type_struct_append_field(t_mixed, "c2", t_u_char);
164 gs_type_struct_append_field(t_mixed, "l2", t_u_long_int);
167 /* message declaration */
168 m = gs_message_new(bag, NULL, "my msg");
169 gs_message_append_new_sequence(m, t_ref_list);
170 gs_message_append_new_sequence(m, t_array);
171 gs_message_append_new_sequence(m, t_pair);
172 gs_message_append_new_sequence(m, t_string);
173 gs_message_append_new_sequence(m, t_mixed);
180 pair.pa = malloc(sizeof(int));
185 mi = gs_message_init_send_by_name(bag, cnx, "my msg");
186 fprintf(stderr, "\nsending sequence 1\n----------------\n");
187 gs_message_send_next_sequence(mi, &l);
188 fprintf(stderr, "\nsending sequence 2\n----------------\n");
189 gs_message_send_next_sequence(mi, (void*)array);
190 fprintf(stderr, "\nsending sequence 3\n----------------\n");
191 gs_message_send_next_sequence(mi, &pair);
192 fprintf(stderr, "\nsending sequence 4\n----------------\n");
193 gs_message_send_next_sequence(mi, (void*)"Hello, World");
195 fprintf(stderr, "\nsending sequence 5\n----------------\n");
196 gs_message_send_next_sequence(mi, (void*)&mixed);