]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - forb-idl/forb-idl-c-stubs.c
IDL compiler: Invoke methods directly only within the same executor
[frescor/forb.git] / forb-idl / forb-idl-c-stubs.c
index b18f8aa6396c4985fc22fcc26d82b3e5b578c0e7..6405e32aa4b544b0bc0606b12c4361ca0c25b1d2 100644 (file)
@@ -44,10 +44,10 @@ cs_output_stub (IDL_tree     tree,
 /*             fprintf(of, "    return "FORB_RETVAL_VAR_NAME";\n"); */
 /*     } */
         fprintf(of, "  if (ev) ev->major = FORB_EX_NONE;\n");
-        fprintf(of, "  if (_obj->implementation) {\n"
-                    "    /* in-proc object */\n");
+        fprintf(of, "  if (forb_object_is_local(_obj) &&\n"
+                          "forb_get_current_executor() == forb_object_get_executor(_obj)) {\n");
         fprintf(of, "    if (!_obj->interface ||\n"
-                    "        strncmp(_obj->interface->name, \"%s\", %d) != 0) {\n"
+                    "        strncmp(_obj->interface->name, \"%s\", %zd) != 0) {\n"
                     "      ev->major = FORB_EX_BAD_OPERATION;\n"
                     "      return %s;\n"
                     "    }\n", iface_id, strlen(iface_id), has_retval ? FORB_RETVAL_VAR_NAME : "");
@@ -69,24 +69,26 @@ cs_output_stub (IDL_tree     tree,
        fprintf(of, "    ex_on_fail(forb_request_init(&req, _obj) == 0, FORB_EX_INTERNAL);\n");
        fprintf(of, "    forb_iop_prepare_request(&req, \"%s\", FORB_METHOD_INDEX(%s), ev);\n",
                iface_id, opname);
-       fprintf(of, "    if (forb_exception_occured(ev)) goto exception;\n");
+       fprintf(of, "    if (forb_exception_occurred(ev)) goto exception;\n");
        for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
                IDL_tree        parm = IDL_LIST (sub).data;
                IDL_ParamRole   role;
                role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
                if (role == DATA_IN || role == DATA_INOUT) {
-                 char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
+                 char      *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
+                 gboolean  isSlice;
+                 IDL_tree  ts = forb_cbe_get_typespec(parm);
+                 int       n = oidl_param_info (ts, role, &isSlice);
                  fprintf(of, "    ex_on_fail(");
                  forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
                  fprintf(of, "_serialize(&req.cdr_request, %s%s), FORB_EX_IMP_LIMIT);\n",
-                         role == DATA_IN ? "&":"",
-                         name);
+                         n == 0 ? "&":"", name);
                }
        }
-       fprintf(of, "    forb_proto_send_request(&req, ev);\n");
-       fprintf(of, "    if (forb_exception_occured(ev)) goto exception;\n");
+       fprintf(of, "    forb_request_send(&req, ev);\n");
+       fprintf(of, "    if (forb_exception_occurred(ev)) goto exception;\n");
        fprintf(of, "    forb_request_wait_for_reply(&req);\n");
-       fprintf(of, "    if (forb_exception_occured(ev)) goto exception;\n");
+       fprintf(of, "    if (forb_exception_occurred(ev)) goto exception;\n");
        if (has_retval) {
          fprintf(of, "    ");
          forb_cbe_write_typespec(of, IDL_OP_DCL(tree).op_type_spec);
@@ -98,9 +100,20 @@ cs_output_stub (IDL_tree     tree,
                role = oidl_attr_to_paramrole(IDL_PARAM_DCL(parm).attr);
                if (role == DATA_OUT || role == DATA_INOUT) {
                  char *name = IDL_IDENT(IDL_PARAM_DCL(parm).simple_declarator).str;
+                 gboolean  isSlice;
+                 IDL_tree  ts = forb_cbe_get_typespec(parm);
+                 int       n = oidl_param_info (ts, role, &isSlice);
+                 if (IDL_NODE_TYPE(forb_cbe_get_typespec(parm)) == IDLN_TYPE_SEQUENCE &&
+                     role == DATA_OUT) { /* Allocate out sequence */
+                         fprintf(ci->fh, "    *%s = forb_malloc(sizeof(**%s));\n", name, name);
+                         fprintf(ci->fh, "    if (!*%s) { ev->major = FORB_EX_NO_MEMORY; goto exception; }\n", name);
+                         fprintf(ci->fh, "    memset(*%s, 0, sizeof(**%s));\n", name, name);
+                         fprintf(ci->fh, "    CORBA_sequence_set_release(*%s, CORBA_TRUE);\n", name);
+                         /* TODO: Free previously allocated parameters on no memory error. */
+                 }
                  fprintf(of, "    ");
                  forb_cbe_write_typespec(of, IDL_PARAM_DCL(parm).param_type_spec);
-                 fprintf(of, "_deserialize(req.cdr_reply, %s);\n", name);
+                 fprintf(ci->fh, "_deserialize(req.cdr_reply, %s%s);\n", n==2?"*":"", name);
                }
        }
        fprintf(of, "    forb_request_signal_processed(&req);\n"
@@ -185,6 +198,8 @@ forb_idl_output_c_stubs (IDL_tree       tree,
        fprintf (ci->fh, "#include <forb/forb-internal.h>\n");
        fprintf (ci->fh, "#include <forb/request.h>\n");
        fprintf (ci->fh, "#include <forb/iop.h>\n");
+       fprintf (ci->fh, "#include <forb/cdr.h>\n");
+       fprintf (ci->fh, "#include <forb/object.h>\n\n");
        fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
 
        fprintf (ci->fh, "#define ex_on_fail(command, ex) if (!(command)) do { ev->major = (ex); goto exception; } while(0)\n");