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); */
43 /* if (has_retval) { */
44 /* fprintf(of, " return "FORB_RETVAL_VAR_NAME";\n"); */
46 fprintf(of, " if (ev) ev->major = FORB_EX_NONE;\n");
47 fprintf(of, " if (_obj->implementation) {\n"
48 " /* in-proc object */\n");
49 fprintf(of, " if (!_obj->interface ||\n"
50 " strncmp(_obj->interface->name, \"%s\", %d) != 0) {\n"
51 " ev->major = FORB_EX_BAD_OPERATION;\n"
53 " }\n", iface_id, strlen(iface_id), has_retval ? FORB_RETVAL_VAR_NAME : "");
56 fprintf(of, FORB_RETVAL_VAR_NAME " = ");
58 fprintf(of, "_%s_impl(_obj)->%s(_obj, ",
59 iface_id, opname_plain);
60 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
61 IDL_tree parm = IDL_LIST (sub).data;
62 fprintf (of, "%s, ", IDL_IDENT (IDL_PARAM_DCL (parm).simple_declarator).str);
64 fprintf(of, "ev);\n");
66 fprintf(of, " } else {\n");
67 fprintf(of, " /* remote object */\n"
69 " forb_request_t req;\n"
70 " CDR_codec_init_static(&codec);\n"
71 " ex_on_fail(CDR_buffer_init(&codec, 256, forb_iop_MESSAGE_HEADER_SIZE), FORB_EX_NO_MEMORY);\n");
72 fprintf(of, " ex_on_fail(forb_request_init(&req, _obj->orb) == 0, FORB_EX_INTERNAL);\n");
73 fprintf(of, " forb_iop_prepare_request(&req, &codec, \"%s\", _obj, FORB_METHOD_INDEX(%s), ev);\n",
75 fprintf(of, " if (forb_exception_occured(ev)) goto exception;\n");
76 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
77 IDL_tree parm = IDL_LIST (sub).data;
79 role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
80 if (role == DATA_IN || role == DATA_INOUT) {
81 char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
82 fprintf(of, " ex_on_fail(");
83 forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
84 fprintf(of, "_serialize(&codec, %s%s), FORB_EX_IMP_LIMIT);\n",
85 role == DATA_IN ? "&":"",
89 fprintf(of, " forb_send_request(&req, ev);\n");
90 fprintf(of, " if (forb_exception_occured(ev)) goto exception;\n");
91 fprintf(of, " forb_wait_for_reply(&req, ev);\n");
92 fprintf(of, " if (forb_exception_occured(ev)) goto exception;\n");
95 forb_cbe_write_typespec(of, IDL_OP_DCL(tree).op_type_spec);
96 fprintf(of, "_deserialize(req.cdr_reply, &"FORB_RETVAL_VAR_NAME");\n");
98 for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
99 IDL_tree parm = IDL_LIST (sub).data;
101 role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
102 if (role == DATA_OUT || role == DATA_INOUT) {
103 char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
105 forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
106 fprintf(of, "_deserialize(req.cdr_reply, %s);\n", name);
109 fprintf(of, "exception:\n"
110 " forb_reply_processed(&req);\n"
111 " forb_request_destroy(&req);\n"
112 " CDR_codec_release_buffer(&codec);\n");
115 fprintf(of, " return " FORB_RETVAL_VAR_NAME ";\n");
118 fprintf (of, "}\n\n");
127 cs_output_stubs (IDL_tree tree,
134 switch (IDL_NODE_TYPE (tree)) {
136 cs_output_stubs (IDL_MODULE (tree).definition_list, ci, idx);
141 for (sub = tree; sub; sub = IDL_LIST (sub).next)
142 cs_output_stubs (IDL_LIST (sub).data, ci, idx);
145 case IDLN_ATTR_DCL: {
148 /* for (node = IDL_ATTR_DCL (tree).simple_declarations; node; node = IDL_LIST (node).next) { */
149 /* OIDL_Attr_Info *ai; */
151 /* ai = IDL_LIST (node).data->data; */
153 /* cs_output_stubs (ai->op1, ci, idx); */
156 /* cs_output_stubs (ai->op2, ci, idx); */
160 case IDLN_INTERFACE: {
163 /* Do not output skeletons for PIDL interfaces */
164 if ((tree->declspec & IDLF_DECLSPEC_PIDL) == 0) {
165 id = IDL_ns_ident_to_qstring (IDL_INTERFACE (tree).ident, "_", 0);
166 fprintf(ci->fh, "#define _%s_impl(obj) ((struct forb_%s_impl*)(obj)->implementation)\n\n",
169 cs_output_stubs (IDL_INTERFACE (tree).body, ci, &real_idx);
174 cs_output_stub (tree, ci, idx);
182 forb_idl_output_c_stubs (IDL_tree tree,
183 OIDL_Run_Info *rinfo,
186 fprintf (ci->fh, OIDL_C_WARNING);
187 fprintf (ci->fh, "#include <string.h>\n");
188 /* fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
189 fprintf (ci->fh, "#include <forb/forb-idl.h>\n");
190 fprintf (ci->fh, "#include <forb/forb-internal.h>\n");
191 fprintf (ci->fh, "#include <forb/iop.h>\n");
192 fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
194 fprintf (ci->fh, "#define ex_on_fail(command, ex) if (!(command)) do { ev->major = (ex); goto exception; } while(0)\n");
195 fprintf (ci->fh, "#define FORB_REQEST_HDR_SIZE (forb_iop_MESSAGE_HEADER_SIZE + forb_iop_REQUEST_HEADER_SIZE)\n\n");
197 cs_output_stubs (tree, ci, NULL);