]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - forb-idl/forb-idl-c-common.c
forb: Split forb_port_destroy() to stop and destroy phases
[frescor/forb.git] / forb-idl / forb-idl-c-common.c
index 1d2e285fb0fdc03a094d65232db53a6dec88d605..b2e4ec7f959de9224308a352159568689a7e35ea 100644 (file)
@@ -118,7 +118,7 @@ cc_output_ser_struct(OIDL_C_Info *ci,
        char *id;
        id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(s).ident), "_", 0);
        
-       fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr)\n", id, id);
+       fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr)\n", id, id);
        fprintf(ci->fh, "{\n");
        for(cur = IDL_TYPE_STRUCT(s).member_list; cur; cur = IDL_LIST(cur).next) {
                for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
@@ -137,7 +137,7 @@ cc_output_ser_struct(OIDL_C_Info *ci,
                        "  return CORBA_FALSE;\n"
                        "}\n\n");
 
-       fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr)\n", id, id);
+       fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr)\n", id, id);
        fprintf(ci->fh, "{\n");
        for(cur = IDL_TYPE_STRUCT(s).member_list; cur; cur = IDL_LIST(cur).next) {
                for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
@@ -164,8 +164,10 @@ static void
 cc_output_ser_seqence(OIDL_C_Info *ci,
                      IDL_tree     s)
 {
-       IDL_tree cur, curmem;
+        //IDL_tree cur, curmem;
        char *id, *type;
+       IDL_tree tts;
+       gboolean fake_if;
        id = forb_cbe_get_typespec_str(s);
        type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(s).simple_type_spec);
 /*{
@@ -175,31 +177,36 @@ cc_output_ser_seqence(OIDL_C_Info *ci,
        for (i=0; i<(val)->_length && r; i++)                   
                r = type ## _serialize(codec, &((val)->_buffer[i])); 
 }*/
+       tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(s).simple_type_spec);
+       fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
+       if (fake_if) {
+               /* Header file already contains defines for CORBA_sequence_Object_[de]serialize */
+               return;
+       }
 
-       fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr)\n", id, id);
+       fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *seq)\n", id, id);
        fprintf(ci->fh, "{\n"
                        "  int i;\n"
                        "  CORBA_boolean ok;\n"
-                       "  ok = CORBA_unsigned_long_serialize(codec, &ptr->_length);\n"
-                       "  for (i = 0; i<ptr->_length && ok; i++)\n");
-       fprintf(ci->fh, "    ok = %s_serialize(codec, &(ptr->_buffer[i]));\n", type);
+                       "  ok = CORBA_unsigned_long_serialize(codec, &seq->_length);\n"
+                       "  for (i = 0; i<seq->_length && ok; i++)\n");
+       fprintf(ci->fh, "    ok = %s_serialize(codec, &(seq->_buffer[i]));\n", type);
        
        fprintf(ci->fh, "  return ok;\n"
                        "}\n\n");
 
-       fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr)\n", id, id);
+       fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *seq)\n", id, id);
        fprintf(ci->fh, "{\n"
-                       "  int i;\n"
+                       "  CORBA_unsigned_long i;\n"
                        "  CORBA_boolean ok;\n"
-                       "  ok = CORBA_unsigned_long_deserialize(codec, &ptr->_length);\n"
-                       "  ok = ok && (ptr->_length <= ptr->_maximum);\n"
+                       "  ok = CORBA_unsigned_long_deserialize(codec, &i);\n"
                        "  if (ok) {\n"
-                       "    if (CORBA_sequence_get_release(ptr)) CORBA_free(ptr->_buffer);\n",
-                       "    ptr->_buffer = CORBA_sequence_%s_allocbuf(ptr->_length);\n"
-                       "    CORBA_sequence_set_release(ptr, CORBA_TRUE);\n"
+                       "    ok = forb_sequence_alloc_buf(seq, i);\n"
+                       "    seq->_length = i;\n"
+                       "    CORBA_sequence_set_release(seq, CORBA_TRUE);\n"
                        "  }\n"
-                       "  for (i = 0; i<ptr->_length && ok; i++)\n", type);
-       fprintf(ci->fh, "    ok = %s_deserialize(codec, &(ptr->_buffer[i]));\n", type);
+                       "  for (i = 0; i<seq->_length && ok; i++)\n");
+       fprintf(ci->fh, "    ok = %s_deserialize(codec, &(seq->_buffer[i]));\n", type);
        
        fprintf(ci->fh, "  return ok;\n"
                        "}\n\n");
@@ -218,7 +225,7 @@ cc_output_ser_typedef_array(OIDL_C_Info *ci,
        for(cur = IDL_TYPE_DCL(tree).dcls; cur; cur = IDL_LIST(cur).next) {
                if (IDL_NODE_TYPE(IDL_LIST(cur).data) == IDLN_TYPE_ARRAY) {
                        id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_ARRAY(IDL_LIST(cur).data).ident), "_", 0);
-                       fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s array)\n", id, id);
+                       fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s array)\n", id, id);
                        fprintf(ci->fh, "{\n");
                        forb_cbe_write_ser_var(
                                ci->fh,
@@ -232,7 +239,7 @@ cc_output_ser_typedef_array(OIDL_C_Info *ci,
                                "  return CORBA_FALSE;\n"
                                "}\n\n");
 
-                       fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array)\n", id, id);
+                       fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s array)\n", id, id);
                        fprintf(ci->fh, "{\n");
                        forb_cbe_write_ser_var(
                                ci->fh,
@@ -859,7 +866,9 @@ forb_idl_output_c_common (IDL_tree       tree,
 /*     fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
 /*     fprintf (ci->fh, "#define FORB_IDL_C_COMMON\n"); */
 /*     fprintf (ci->fh, "#define %s_COMMON\n", ci->c_base_name); */
-       fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
+       fprintf (ci->fh, "#include \"%s.h\"\n", ci->base_name);
+       fprintf (ci->fh, "#include <forb/cdr.h>\n");
+       fprintf (ci->fh, "#include <forb/object.h>\n\n");
 /*     fprintf (ci->fh, "static const CORBA_unsigned_long Forb_zero_int = 0;\n"); */
 
        /* FIXME: this is slightly nasty, but we need these in common,