3 #include "forb-idl-c-backend.h"
8 cs_output_stub (IDL_tree tree,
17 gboolean has_retval, has_args;
19 g_return_if_fail (idx != NULL);
21 iface_id = IDL_ns_ident_to_qstring (
22 IDL_IDENT_TO_NS (IDL_INTERFACE (
23 IDL_get_parent_node (tree, IDLN_INTERFACE, NULL)
25 opname_plain = IDL_IDENT(IDL_OP_DCL (tree).ident).str;
26 opname = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (IDL_OP_DCL (tree).ident), "_", 0);
28 has_retval = IDL_OP_DCL (tree).op_type_spec != NULL;
29 has_args = IDL_OP_DCL (tree).parameter_dcls != NULL;
31 forb_cbe_op_write_proto (of, tree, "", FALSE);
33 fprintf (of, "\n{\n");
37 forb_cbe_write_param_typespec (of, tree);
38 fprintf (of, " " FORB_RETVAL_VAR_NAME ";\n");
41 fprintf(of, " if (_obj->type != %s_type) {\n"
42 " ev->major = FORB_EX_BAD_OPERATION;\n", iface_id);
44 fprintf(of, " return "FORB_RETVAL_VAR_NAME";\n");
47 " if (_obj->methods) {\n"
48 " /* in-proc object */\n"
51 fprintf(of, FORB_RETVAL_VAR_NAME " = ");
53 fprintf(of, "forb_%s_methods(obj)->%s(_obj, ",
54 iface_id, opname_plain);
55 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
56 IDL_tree parm = IDL_LIST (sub).data;
57 fprintf (of, "%s, ", IDL_IDENT (IDL_PARAM_DCL (parm).simple_declarator).str);
59 fprintf(of, "ev);\n");
61 fprintf(of, " } else {\n");
62 fprintf(of, " /* remote object */\n"
65 " forb_request_handle req;\n"
66 " CDR_codec_init_static(&codec);\n"
67 " ex_on_fail(CDR_buffer_init(&codec, 256), FORB_EX_NO_MEMORY);\n");
68 /* fprintf(of, " forb_prepare_request(&codec, _obj, FORB_METHOD_INDEX(%s));\n", */
70 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
71 IDL_tree parm = IDL_LIST (sub).data;
73 role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
74 if (role == DATA_IN || role == DATA_INOUT) {
75 char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
76 fprintf(of, " ex_on_fail(");
77 forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
78 fprintf(of, "_serialize(&codec, %s), FORB_EX_IMP_LIMIT);\n", name);
81 fprintf(of, " forb_send_request(_obj, FORB_METHOD_INDEX(%s), &codec, &req, ev);\n",
83 fprintf(of, " if (forb_exception_occured(ev)) goto exception;\n");
84 fprintf(of, " forb_wait_for_reply(&req, ev);\n");
85 fprintf(of, " if (forb_exception_occured(ev)) goto exception;\n");
88 forb_cbe_write_typespec(of, IDL_OP_DCL(tree).op_type_spec);
89 fprintf(of, "_deserialize(&codec, &"FORB_RETVAL_VAR_NAME");\n");
91 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
92 IDL_tree parm = IDL_LIST (sub).data;
94 role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
95 if (role == DATA_OUT || role == DATA_INOUT) {
96 char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
98 forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
99 fprintf(of, "_deserialize(&codec, %s);\n", name);
102 fprintf(of, "exception:\n"
103 " CDR_codec_release_buffer(&codec);\n");
106 fprintf(of, " return " FORB_RETVAL_VAR_NAME ";\n");
109 fprintf (of, "}\n\n");
118 cs_output_stubs (IDL_tree tree,
125 switch (IDL_NODE_TYPE (tree)) {
127 cs_output_stubs (IDL_MODULE (tree).definition_list, ci, idx);
132 for (sub = tree; sub; sub = IDL_LIST (sub).next)
133 cs_output_stubs (IDL_LIST (sub).data, ci, idx);
136 case IDLN_ATTR_DCL: {
139 /* for (node = IDL_ATTR_DCL (tree).simple_declarations; node; node = IDL_LIST (node).next) { */
140 /* OIDL_Attr_Info *ai; */
142 /* ai = IDL_LIST (node).data->data; */
144 /* cs_output_stubs (ai->op1, ci, idx); */
147 /* cs_output_stubs (ai->op2, ci, idx); */
151 case IDLN_INTERFACE: {
154 cs_output_stubs (IDL_INTERFACE (tree).body, ci, &real_idx);
158 cs_output_stub (tree, ci, idx);
166 forb_idl_output_c_stubs (IDL_tree tree,
167 OIDL_Run_Info *rinfo,
170 fprintf (ci->fh, OIDL_C_WARNING);
171 /* fprintf (ci->fh, "#include <string.h>\n"); */
172 /* fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
173 fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
175 fprintf (ci->fh, "#define ex_on_fail(command, ex) if (!(command)) do { ev->major = (ex); goto exception; } while(0)\n\n");
177 cs_output_stubs (tree, ci, NULL);