~ubuntu-branches/ubuntu/breezy/orbit2/breezy

« back to all changes in this revision

Viewing changes to src/idl-compiler/orbit-idl-c-stubs.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-09-06 16:37:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050906163702-hrqi0ctymth53bnn
Tags: 1:2.12.4-0ubuntu1
* New upstream version.
* debian/patches/100-compile-name-server.patch:
  - updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
#include <string.h>
6
6
 
7
 
static void cs_output_stubs(IDL_tree tree, OIDL_C_Info *ci);
8
 
static void cs_small_output_stubs(IDL_tree tree, OIDL_C_Info *ci, int *idx);
9
 
 
10
 
void
11
 
orbit_idl_output_c_stubs(OIDL_Output_Tree *tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
12
 
{
13
 
  fprintf(ci->fh, "/*\n"
14
 
                   " * This file was generated by orbit-idl - DO NOT EDIT!\n"
15
 
                   " */\n\n");
16
 
  fprintf(ci->fh, "#include <string.h>\n");
17
 
  fprintf(ci->fh, "#define ORBIT2_STUBS_API\n");
18
 
  fprintf(ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
19
 
 
20
 
  if (rinfo->small_stubs)
21
 
    cs_small_output_stubs(tree->tree, ci, NULL);
22
 
  else
23
 
    cs_output_stubs(tree->tree, ci);
24
 
}
25
 
 
26
 
static void cs_small_output_stub(IDL_tree tree, OIDL_C_Info *ci, int *idx);
27
 
 
28
 
/* Very similar to cs_output_stubs */
29
 
static void
30
 
cs_small_output_stubs(IDL_tree tree, OIDL_C_Info *ci, int *idx)
31
 
{
32
 
  if(!tree) return;
33
 
 
34
 
  switch(IDL_NODE_TYPE(tree)) {
35
 
  case IDLN_MODULE:
36
 
    cs_small_output_stubs(IDL_MODULE(tree).definition_list, ci, idx);
37
 
    break;
38
 
  case IDLN_LIST:
39
 
    {
40
 
      IDL_tree sub;
41
 
      for(sub = tree; sub; sub = IDL_LIST(sub).next) {
42
 
        cs_small_output_stubs(IDL_LIST(sub).data, ci, idx);
43
 
      }
44
 
    }
45
 
    break;
46
 
  case IDLN_ATTR_DCL:
47
 
    {
48
 
      OIDL_Attr_Info *ai = tree->data;
49
 
 
50
 
      IDL_tree curitem;
51
 
      
52
 
      for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
53
 
        ai = IDL_LIST(curitem).data->data;
54
 
        
55
 
        cs_small_output_stubs(ai->op1, ci, idx);
56
 
        if(ai->op2)
57
 
          cs_small_output_stubs(ai->op2, ci, idx);
58
 
      }
59
 
    }
60
 
    break;
61
 
  case IDLN_INTERFACE: {
62
 
    int real_idx = 0;
63
 
    cs_small_output_stubs(IDL_INTERFACE(tree).body, ci, &real_idx);
64
 
    break;
65
 
  }
66
 
  case IDLN_OP_DCL:
67
 
    cs_small_output_stub(tree, ci, idx);
68
 
    break;
69
 
  default:
70
 
    break;
71
 
  }
72
 
}
73
 
 
74
 
static void
75
 
cs_small_output_stub(IDL_tree tree, OIDL_C_Info *ci, int *idx)
76
 
{
77
 
        FILE         *of = ci->fh;
78
 
        char         *id;
79
 
        gboolean      has_retval, has_args;
 
7
static void
 
8
cs_output_stub (IDL_tree     tree,
 
9
                OIDL_C_Info *ci,
 
10
                int         *idx)
 
11
{
 
12
        FILE     *of = ci->fh;
 
13
        char     *iface_id;
 
14
        char     *opname;
 
15
        gboolean  has_retval, has_args;
80
16
 
81
17
        g_return_if_fail (idx != NULL);
82
18
 
83
 
        id = orbit_cbe_op_get_interface_name (tree);
84
 
        has_retval = IDL_OP_DCL(tree).op_type_spec != NULL;
85
 
        has_args   = IDL_OP_DCL(tree).parameter_dcls != NULL;
 
19
        iface_id = IDL_ns_ident_to_qstring (
 
20
                        IDL_IDENT_TO_NS (IDL_INTERFACE (
 
21
                                IDL_get_parent_node (tree, IDLN_INTERFACE, NULL)
 
22
                                        ).ident), "_", 0);
 
23
        opname = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (IDL_OP_DCL (tree).ident), "_", 0);
 
24
 
 
25
        has_retval = IDL_OP_DCL (tree).op_type_spec != NULL;
 
26
        has_args   = IDL_OP_DCL (tree).parameter_dcls != NULL;
86
27
 
87
28
        orbit_cbe_op_write_proto (of, tree, "", FALSE);
88
29
 
92
33
                orbit_cbe_write_param_typespec (of, tree);
93
34
                fprintf (of, " " ORBIT_RETVAL_VAR_NAME ";\n");
94
35
        }
95
 
 
96
 
        fprintf (of, "#ifndef ORBIT_STUB_DEBUG_LOCAL\n");
97
 
        {
98
 
                IDL_tree curitem;
99
 
                char *id;
100
 
 
101
 
                curitem = IDL_get_parent_node(tree, IDLN_INTERFACE, 0);
102
 
                g_assert(curitem);
103
 
                id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident),
104
 
                                             "_", 0);
105
 
 
106
 
                fprintf (ci->fh, "if (ORBIT_STUB_IsBypass (_obj, %s__classid)) {\n", id);
107
 
                fprintf (ci->fh, "POA_%s__epv *%s;\n", id, ORBIT_EPV_VAR_NAME);
108
 
                fprintf (ci->fh, "ORBIT_STUB_PreCall (_obj);\n");
109
 
                fprintf (ci->fh, "%s = (POA_%s__epv *) ORBIT_STUB_GetEpv (_obj, %s__classid);\n",
110
 
                         ORBIT_EPV_VAR_NAME, id, id);
111
 
 
112
 
                fprintf (ci->fh, "if (!%s->%s) {\n", ORBIT_EPV_VAR_NAME, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
113
 
                fprintf (ci->fh, "CORBA_exception_set_system (ev, ex_CORBA_NO_IMPLEMENT, CORBA_COMPLETED_NO);\n");
114
 
                fprintf (ci->fh, "return %s;\n}\n", IDL_OP_DCL (tree).op_type_spec ? ORBIT_RETVAL_VAR_NAME :"");
115
 
 
116
 
                fprintf (ci->fh, "%s%s->%s (ORBIT_STUB_GetServant (_obj), ",
117
 
                         IDL_OP_DCL (tree).op_type_spec? ORBIT_RETVAL_VAR_NAME " = ":"",
118
 
                         ORBIT_EPV_VAR_NAME,
119
 
                         IDL_IDENT (IDL_OP_DCL (tree).ident).str);
120
 
                g_free(id);
121
 
 
122
 
                for(curitem = IDL_OP_DCL(tree).parameter_dcls; curitem;
123
 
                    curitem = IDL_LIST(curitem).next) {
124
 
                        fprintf(ci->fh, "%s, ",
125
 
                                IDL_IDENT(IDL_PARAM_DCL(IDL_LIST(curitem).data).simple_declarator).str);
126
 
                }
127
 
                if(IDL_OP_DCL(tree).context_expr)
128
 
                        fprintf(ci->fh, "_ctx, ");
129
 
 
130
 
                fprintf(ci->fh, "ev);\n");
131
 
 
132
 
                fprintf(ci->fh, "ORBIT_STUB_PostCall (_obj);\n");
133
 
        }
134
 
 
135
 
        fprintf (of, " } else\n");
136
 
        fprintf (of, "#endif /* ORBIT_STUB_DEBUG_LOCAL */\n");
137
 
        fprintf (of, " { /* remote marshal */\n");
138
 
        {
139
 
                if (has_args)
140
 
                        cbe_small_flatten_args (tree, of, "_args");
141
 
 
142
 
                fprintf (of, "ORBit_small_invoke_stub (_obj, "
143
 
                         "&%s__iinterface.methods._buffer [%d], ", id, *idx);
144
 
 
145
 
                if (has_retval)
146
 
                        fprintf (of, "&_ORBIT_retval, ");
147
 
                else
148
 
                        fprintf (of, "NULL, ");
149
 
 
150
 
                if (has_args)
151
 
                        fprintf (of, "_args, ");
152
 
                else
153
 
                        fprintf (of, "NULL, ");
154
 
 
155
 
                if (IDL_OP_DCL(tree).context_expr)
156
 
                        fprintf(ci->fh, "_ctx, ");
157
 
                else
158
 
                        fprintf(ci->fh, "NULL, ");
 
36
#if 0
 
37
        fprintf (ci->fh, "POA_%s__epv *%s;\n", iface_id, ORBIT_EPV_VAR_NAME);
 
38
        fprintf (ci->fh, "gpointer _ORBIT_servant;\n");
 
39
 
 
40
        /* in-proc part */
 
41
        fprintf (ci->fh, "if ((%s = ORBit_c_stub_invoke\n", ORBIT_EPV_VAR_NAME);
 
42
        fprintf (ci->fh, "              (_obj, %s__classid, &_ORBIT_servant,\n", iface_id);
 
43
        fprintf (ci->fh, "               G_STRUCT_OFFSET (POA_%s__epv, %s)))) {\n",
 
44
                 iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
 
45
 
 
46
        fprintf (ci->fh, "if (ORBit_small_flags & ORBIT_SMALL_FAST_LOCALS && \n");
 
47
        fprintf (ci->fh, "    ORBIT_STUB_IsBypass (_obj, %s__classid) && \n", iface_id);
 
48
        fprintf (ci->fh, "    (%s = (POA_%s__epv*) ORBIT_STUB_GetEpv (_obj, %s__classid))->%s) {\n",
 
49
                 ORBIT_EPV_VAR_NAME, iface_id, iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
 
50
 
 
51
        fprintf (ci->fh, "ORBIT_STUB_PreCall (_obj);\n");
 
52
 
 
53
        fprintf (ci->fh, "%s%s->%s (_ORBIT_servant, ",
 
54
                 IDL_OP_DCL (tree).op_type_spec? ORBIT_RETVAL_VAR_NAME " = ":"",
 
55
                 ORBIT_EPV_VAR_NAME,
 
56
                 IDL_IDENT (IDL_OP_DCL (tree).ident).str);
 
57
 
 
58
        for (node = IDL_OP_DCL (tree).parameter_dcls; node; node = IDL_LIST (node).next)
 
59
                fprintf (ci->fh, "%s, ",
 
60
                         IDL_IDENT (IDL_PARAM_DCL (IDL_LIST (node).data).simple_declarator).str);
 
61
 
 
62
        if (IDL_OP_DCL (tree).context_expr)
 
63
                fprintf (ci->fh, "_ctx, ");
 
64
 
 
65
        fprintf (ci->fh, "ev);\n");
 
66
 
 
67
        fprintf (ci->fh, "ORBit_stub_post_invoke (_obj, %s);\n", ORBIT_EPV_VAR_NAME);
 
68
 
 
69
        fprintf (of, " } else { /* remote marshal */\n");
 
70
#endif
 
71
 
 
72
        /* remote invocation part */
 
73
        if (has_args)
 
74
                orbit_cbe_flatten_args (tree, of, "_args");
 
75
 
 
76
        fprintf (of, "ORBit_c_stub_invoke (_obj, "
 
77
                 "&%s__iinterface.methods, %d, ", iface_id, *idx);
 
78
 
 
79
        if (has_retval)
 
80
                fprintf (of, "&_ORBIT_retval, ");
 
81
        else
 
82
                fprintf (of, "NULL, ");
 
83
 
 
84
        if (has_args)
 
85
                fprintf (of, "_args, ");
 
86
        else
 
87
                fprintf (of, "NULL, ");
 
88
 
 
89
        if (IDL_OP_DCL (tree).context_expr)
 
90
                fprintf (ci->fh, "_ctx, ");
 
91
        else
 
92
                fprintf (ci->fh, "NULL, ");
159
93
                
160
 
                fprintf (of, "ev);\n\n");
161
 
 
162
 
        }
163
 
 
164
 
        fprintf (of, "}\n");
 
94
        fprintf (of, "ev, ");
 
95
 
 
96
        fprintf (of, "%s__classid, G_STRUCT_OFFSET (POA_%s__epv, %s),\n",
 
97
                 iface_id, iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
 
98
        fprintf (of, "(ORBitSmallSkeleton) _ORBIT_skel_small_%s);\n\n", opname);
165
99
 
166
100
        if (has_retval)
167
101
                fprintf (of, "return " ORBIT_RETVAL_VAR_NAME ";\n");
168
102
 
169
103
        fprintf (of, "}\n");
170
104
 
 
105
        g_free (iface_id);
 
106
 
171
107
        (*idx)++;
172
108
}
173
109
 
174
 
static void cs_output_stub(IDL_tree tree, OIDL_C_Info *ci);
175
 
static void cs_output_except(IDL_tree tree, OIDL_C_Info *ci);
176
 
 
177
 
/* Very similar to cs_output_small_stubs */
178
110
static void
179
 
cs_output_stubs(IDL_tree tree, OIDL_C_Info *ci)
 
111
cs_output_stubs (IDL_tree     tree,
 
112
                 OIDL_C_Info *ci,
 
113
                 int         *idx)
180
114
{
181
 
  if(!tree) return;
182
 
 
183
 
  switch(IDL_NODE_TYPE(tree)) {
184
 
  case IDLN_MODULE:
185
 
    cs_output_stubs(IDL_MODULE(tree).definition_list, ci);
186
 
    break;
187
 
  case IDLN_LIST:
188
 
    {
189
 
      IDL_tree sub;
190
 
      for(sub = tree; sub; sub = IDL_LIST(sub).next) {
191
 
        cs_output_stubs(IDL_LIST(sub).data, ci);
192
 
      }
193
 
    }
194
 
    break;
195
 
  case IDLN_ATTR_DCL:
196
 
    {
197
 
      OIDL_Attr_Info *ai = tree->data;
198
 
 
199
 
      IDL_tree curitem;
 
115
        if (!tree)
 
116
                return;
 
117
 
 
118
        switch (IDL_NODE_TYPE (tree)) {
 
119
        case IDLN_MODULE:
 
120
                cs_output_stubs (IDL_MODULE (tree).definition_list, ci, idx);
 
121
                break;
 
122
        case IDLN_LIST: {
 
123
                IDL_tree sub;
 
124
 
 
125
                for (sub = tree; sub; sub = IDL_LIST (sub).next)
 
126
                        cs_output_stubs (IDL_LIST (sub).data, ci, idx);
 
127
                break;
 
128
                }
 
129
        case IDLN_ATTR_DCL: {
 
130
                IDL_tree node;
200
131
      
201
 
      for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
202
 
        ai = IDL_LIST(curitem).data->data;
 
132
                for (node = IDL_ATTR_DCL (tree).simple_declarations; node; node = IDL_LIST (node).next) {
 
133
                        OIDL_Attr_Info *ai;
 
134
 
 
135
                        ai = IDL_LIST (node).data->data;
203
136
        
204
 
        cs_output_stubs(ai->op1, ci);
205
 
        if(ai->op2)
206
 
          cs_output_stubs(ai->op2, ci);
207
 
      }
208
 
    }
209
 
    break;
210
 
  case IDLN_INTERFACE:
211
 
    cs_output_stubs(IDL_INTERFACE(tree).body, ci);
212
 
    break;
213
 
  case IDLN_OP_DCL:
214
 
    cs_output_stub(tree, ci);
215
 
    break;
216
 
  case IDLN_EXCEPT_DCL:
217
 
    cs_output_except(tree, ci);
218
 
    break;
219
 
  default:
220
 
    break;
221
 
  }
222
 
}
223
 
 
224
 
/* Here's the fun part ;-) */
225
 
static void cs_stub_alloc_params(IDL_tree tree, OIDL_C_Info *ci);
226
 
static void cs_free_inout_params(IDL_tree tree, OIDL_C_Info *ci);
227
 
static void cs_stub_print_return(IDL_tree tree, OIDL_C_Info *ci);
228
 
 
229
 
static void
230
 
cs_output_stub(IDL_tree tree, OIDL_C_Info *ci)
231
 
{
232
 
  OIDL_Op_Info *oi;
233
 
 
234
 
  oi = tree->data;
235
 
  g_assert(oi);
236
 
 
237
 
  if ( oidl_tree_is_pidl(tree) )
238
 
        return;
239
 
 
240
 
  orbit_cbe_op_write_proto(ci->fh, tree, "", FALSE);
241
 
  fprintf(ci->fh, "{\n");
242
 
  if(IDL_OP_DCL(tree).raises_expr) {
243
 
    IDL_tree curitem;
244
 
    fprintf(ci->fh, "const ORBit_exception_demarshal_info _ORBIT_user_exceptions[] = { ");
245
 
    for(curitem = IDL_OP_DCL(tree).raises_expr; curitem;
246
 
        curitem = IDL_LIST(curitem).next) {
247
 
      char *id;
248
 
      IDL_tree curnode = IDL_LIST(curitem).data;
249
 
 
250
 
      id = orbit_cbe_get_typespec_str(curnode);
251
 
      fprintf(ci->fh, "{(const CORBA_TypeCode)&TC_%s_struct, (gpointer)_ORBIT_%s_demarshal},",
252
 
              id, id);
253
 
      g_free(id);
254
 
    }
255
 
    fprintf(ci->fh, "{CORBA_OBJECT_NIL, NULL}};\n");
256
 
  }
257
 
 
258
 
  if(IDL_OP_DCL(tree).context_expr) {
259
 
    IDL_tree curitem;
260
 
    fprintf(ci->fh, "const ORBit_ContextMarshalItem _context_items[] = {\n");
261
 
 
262
 
    for(curitem = IDL_OP_DCL(tree).context_expr; curitem; curitem = IDL_LIST(curitem).next) {
263
 
      fprintf(ci->fh, "{%lu, \"%s\"},\n", (unsigned long)strlen(IDL_STRING(IDL_LIST(curitem).data).value) + 1,
264
 
              IDL_STRING(IDL_LIST(curitem).data).value);
265
 
    }
266
 
    fprintf(ci->fh, "};\n");
267
 
  }
268
 
 
269
 
  fprintf(ci->fh, "register CORBA_unsigned_long _ORBIT_request_id;\n");
270
 
  fprintf(ci->fh, "register CORBA_char *_ORBIT_system_exception_ex = ex_CORBA_COMM_FAILURE;\n");
271
 
  fprintf(ci->fh, "register CORBA_completion_status _ORBIT_completion_status = CORBA_COMPLETED_NO;\n");
272
 
  fprintf(ci->fh, "register GIOPSendBuffer *_ORBIT_send_buffer = NULL;\n");
273
 
  if(!IDL_OP_DCL(tree).f_oneway)
274
 
    {
275
 
      fprintf(ci->fh, "register GIOPRecvBuffer *_ORBIT_recv_buffer = NULL;\n");
276
 
      fprintf(ci->fh, "GIOPMessageQueueEntry _ORBIT_mqe;\n");
277
 
    }
278
 
  fprintf(ci->fh, "register GIOPConnection *_cnx;\n");
279
 
  fprintf(ci->fh, "register guchar *_ORBIT_buf_end;\n");
280
 
 
281
 
  if(oi->out_stubs) /* Lame hack to ensure we get _ORBIT_retval available */
282
 
    orbit_cbe_alloc_tmpvars(oi->out_stubs, ci);
283
 
 
284
 
  /* Check if we can do a direct call, and if so, do it */
285
 
  {
286
 
    IDL_tree curitem;
287
 
    char *id;
288
 
 
289
 
    curitem = IDL_get_parent_node(tree, IDLN_INTERFACE, 0);
290
 
    g_assert(curitem);
291
 
    id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident),
292
 
                                 "_", 0);
293
 
    fprintf(ci->fh, "if(ORBIT_STUB_IsBypass(_obj,%s__classid))\n{\n", id);
294
 
#if 0
295
 
    fprintf(ci->fh, "ORBit_POAInvocation invoke_rec;\n");
296
 
#endif
297
 
 
298
 
    fprintf(ci->fh, "POA_%s__epv *_epv=(POA_%s__epv*)ORBIT_STUB_GetEpv(_obj,%s__classid);\n",
299
 
            id, id, id);
300
 
    fprintf(ci->fh, "ORBit_POAInvocation _invoke_rec;\n");
301
 
    fprintf(ci->fh, "ORBIT_STUB_PreCall(_obj, _invoke_rec);\n");
302
 
    fprintf(ci->fh, "%s _epv->%s(ORBIT_STUB_GetServant(_obj), ",
303
 
            IDL_OP_DCL(tree).op_type_spec?"_ORBIT_retval = ":"",
304
 
            IDL_IDENT(IDL_OP_DCL(tree).ident).str);
305
 
    g_free(id);
306
 
    for(curitem = IDL_OP_DCL(tree).parameter_dcls; curitem;
307
 
        curitem = IDL_LIST(curitem).next) {
308
 
      fprintf(ci->fh, "%s, ",
309
 
              IDL_IDENT(IDL_PARAM_DCL(IDL_LIST(curitem).data).simple_declarator).str);
310
 
    }
311
 
    if(IDL_OP_DCL(tree).context_expr)
312
 
      fprintf(ci->fh, "_ctx, ");
313
 
 
314
 
    fprintf(ci->fh, "ev);\n");
315
 
 
316
 
    fprintf(ci->fh, "ORBIT_STUB_PostCall(_obj, _invoke_rec);\n");
317
 
    fprintf(ci->fh, "return %s;\n}\n", IDL_OP_DCL(tree).op_type_spec?"_ORBIT_retval":"");
318
 
  }
319
 
 
320
 
  fprintf(ci->fh, "_cnx = ORBit_object_get_connection(_obj);\n");
321
 
  fprintf(ci->fh, "if(!_cnx) goto _ORBIT_system_exception;\n");
322
 
 
323
 
  if(!IDL_OP_DCL(tree).f_oneway) /* For location forwarding */
324
 
    {
325
 
      fprintf(ci->fh, "_ORBIT_retry_request:\n");
326
 
      fprintf(ci->fh, "_ORBIT_recv_buffer = NULL;\n");
327
 
    }
328
 
 
329
 
  fprintf(ci->fh, "_ORBIT_send_buffer = NULL;\n");
330
 
  fprintf(ci->fh, "_ORBIT_completion_status = CORBA_COMPLETED_NO;\n");
331
 
 
332
 
  if(sizeof(gpointer) > sizeof(CORBA_unsigned_long))
333
 
    fprintf(ci->fh, "_ORBIT_request_id = giop_get_request_id();\n");
334
 
  else
335
 
    fprintf(ci->fh, "_ORBIT_request_id = GPOINTER_TO_UINT(g_alloca(0));\n");
336
 
 
337
 
  fprintf(ci->fh, "{ /* marshalling */\n");
338
 
  fprintf(ci->fh, "static const struct { CORBA_unsigned_long len; char opname[%lu]; } _ORBIT_operation_name_data = { %lu, \"%s\" };\n",
339
 
          /* We align it now instead of at runtime */
340
 
          ALIGN_VALUE(strlen(IDL_IDENT(IDL_OP_DCL(tree).ident).str) + 1, sizeof(CORBA_unsigned_long)),
341
 
          (unsigned long)strlen(IDL_IDENT(IDL_OP_DCL(tree).ident).str) + 1,
342
 
          IDL_IDENT(IDL_OP_DCL(tree).ident).str);
343
 
  fprintf(ci->fh, "const struct iovec _ORBIT_operation_vec = {(gpointer)&_ORBIT_operation_name_data, %lu};\n",
344
 
          sizeof(CORBA_unsigned_long) +
345
 
          ALIGN_VALUE(strlen(IDL_IDENT(IDL_OP_DCL(tree).ident).str) + 1,
346
 
                      sizeof(CORBA_unsigned_long)));
347
 
 
348
 
  orbit_cbe_alloc_tmpvars(oi->in_stubs, ci);
349
 
 
350
 
  fprintf(ci->fh, "_ORBIT_send_buffer = \n");
351
 
  fprintf(ci->fh, "giop_send_buffer_use_request(_cnx->giop_version, _ORBIT_request_id, %s,\n",
352
 
          IDL_OP_DCL(tree).f_oneway?"CORBA_FALSE":"CORBA_TRUE");
353
 
  fprintf(ci->fh, "&(_obj->oki->object_key_vec), &_ORBIT_operation_vec, NULL /* &ORBit_default_principal_iovec */);\n\n");
354
 
  fprintf(ci->fh, "_ORBIT_system_exception_ex = ex_CORBA_COMM_FAILURE;\n");
355
 
  fprintf(ci->fh, "if(!_ORBIT_send_buffer) goto _ORBIT_system_exception;\n");
356
 
 
357
 
  c_marshalling_generate(oi->in_stubs, ci, TRUE);
358
 
 
359
 
  if(!IDL_OP_DCL(tree).f_oneway)
360
 
    {
361
 
      fprintf(ci->fh, "giop_recv_list_setup_queue_entry(&_ORBIT_mqe, _cnx, GIOP_REPLY, _ORBIT_request_id);\n");
362
 
      fprintf(ci->fh, "if(giop_send_buffer_write(_ORBIT_send_buffer, _cnx)) { giop_recv_list_destroy_queue_entry(&_ORBIT_mqe); goto _ORBIT_system_exception; }\n");
363
 
    }
364
 
  else
365
 
    fprintf(ci->fh, "if(giop_send_buffer_write(_ORBIT_send_buffer, _cnx)) goto _ORBIT_system_exception;\n");
366
 
  fprintf(ci->fh, "_ORBIT_completion_status = CORBA_COMPLETED_MAYBE;\n");
367
 
  fprintf(ci->fh, "giop_send_buffer_unuse(_ORBIT_send_buffer); _ORBIT_send_buffer = NULL;\n");
368
 
  fprintf(ci->fh, "}\n");
369
 
 
370
 
  if(!IDL_OP_DCL(tree).f_oneway) {
371
 
    /* free inout params as needed */
372
 
    cs_free_inout_params(tree, ci);
373
 
 
374
 
    fprintf(ci->fh, "{ /* demarshalling */\n");
375
 
 
376
 
    if(oi->out_stubs)
377
 
      fprintf(ci->fh, "register guchar *_ORBIT_curptr G_GNUC_UNUSED;\n");
378
 
 
379
 
    fprintf(ci->fh, "_ORBIT_recv_buffer = giop_recv_buffer_get(&_ORBIT_mqe, TRUE);\n");
380
 
 
381
 
    fprintf(ci->fh, "if(!_ORBIT_recv_buffer) goto _ORBIT_system_exception;\n");
382
 
    fprintf(ci->fh, "_ORBIT_buf_end = _ORBIT_recv_buffer->end;\n");
383
 
    fprintf(ci->fh, "_ORBIT_completion_status = CORBA_COMPLETED_YES;\n");
384
 
 
385
 
    fprintf(ci->fh, "if(giop_recv_buffer_reply_status(_ORBIT_recv_buffer) != GIOP_NO_EXCEPTION) goto _ORBIT_msg_exception;\n");
386
 
 
387
 
    cs_stub_alloc_params(tree, ci);
388
 
 
389
 
    c_demarshalling_generate(oi->out_stubs, ci, FALSE, FALSE);
390
 
 
391
 
    fprintf(ci->fh, "giop_recv_buffer_unuse(_ORBIT_recv_buffer);\n");
392
 
    cs_stub_print_return (tree, ci);
393
 
 
394
 
  } else
395
 
    fprintf(ci->fh, "return;\n");
396
 
 
397
 
  if(!IDL_OP_DCL(tree).f_oneway) {
398
 
    IDL_tree curitem;
399
 
 
400
 
    for(curitem = IDL_list_nth(IDL_OP_DCL(tree).parameter_dcls, IDL_list_length(IDL_OP_DCL(tree).parameter_dcls) - 1);
401
 
        curitem; curitem = IDL_LIST(curitem).prev)
402
 
      {
403
 
        IDL_tree param;
404
 
 
405
 
        param = IDL_LIST(curitem).data;
406
 
        if(IDL_PARAM_DCL(param).attr != IDL_PARAM_IN)
407
 
          {
408
 
            fprintf(ci->fh, "%s_demarshal_error:\n", IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str);
409
 
            cbe_op_param_free(param, ci, FALSE);
410
 
          }
411
 
      }    
412
 
 
413
 
    if(IDL_OP_DCL(tree).op_type_spec)
414
 
      {
415
 
        fprintf(ci->fh, "%s_demarshal_error:\n", ORBIT_RETVAL_VAR_NAME);
416
 
        cbe_op_retval_free(IDL_OP_DCL(tree).op_type_spec, ci);
417
 
      }
418
 
 
419
 
    fprintf(ci->fh, "_ORBIT_demarshal_error:\n");
420
 
    fprintf(ci->fh, "_ORBIT_system_exception_ex = ex_CORBA_MARSHAL;\n");
421
 
  }
422
 
  fprintf(ci->fh, "_ORBIT_system_exception:\n");
423
 
#ifdef BACKWARDS_COMPAT_0_4
424
 
  fprintf(ci->fh, "CORBA_exception_set_system(ev, _ORBIT_system_exception_ex, _ORBIT_completion_status);\n");
425
 
  fprintf(ci->fh, "giop_recv_buffer_unuse(_ORBIT_recv_buffer);\n");
426
 
  fprintf(ci->fh, "giop_send_buffer_unuse(_ORBIT_send_buffer);\n");
427
 
#else
428
 
  fprintf(ci->fh, "ORBit_handle_system_exception(ev, _ORBIT_system_exception_ex, _ORBIT_completion_status, %s, _ORBIT_send_buffer);\n",
429
 
          IDL_OP_DCL(tree).f_oneway?"NULL":"_ORBIT_recv_buffer");
430
 
#endif
431
 
  if(IDL_OP_DCL(tree).op_type_spec)
432
 
    /* This will avoid warning about uninitialized memory while
433
 
     * compiling the stubs with no extra code size cost */
434
 
    fprintf(ci->fh, "#if defined(__GNUC__) && defined(__OPTIMIZE__)\n"
435
 
            "if(&%s);\n"
436
 
            "#endif\n", ORBIT_RETVAL_VAR_NAME);
437
 
 
438
 
  cs_stub_print_return (tree, ci);
439
 
 
440
 
  if(!IDL_OP_DCL(tree).f_oneway) {
441
 
    fprintf(ci->fh, "_ORBIT_msg_exception:\n");
442
 
    /* deal with LOCATION_FORWARD exceptions */
443
 
    fprintf(ci->fh, "if(giop_recv_buffer_reply_status(_ORBIT_recv_buffer) == GIOP_LOCATION_FORWARD) {\n");
444
 
#ifdef BACKWARDS_COMPAT_0_4
445
 
    fprintf(ci->fh, "if (_obj->forward_locations != NULL) ORBit_delete_profiles(_obj->forward_locations);\n");
446
 
    fprintf(ci->fh, "_obj->forward_locations = ORBit_demarshal_IOR(_ORBIT_recv_buffer);\n");
447
 
    fprintf(ci->fh, "_cnx = ORBit_object_get_forwarded_connection(_obj);\n");
448
 
    fprintf(ci->fh, "giop_recv_buffer_unuse(_ORBIT_recv_buffer);\n");
449
 
#else
450
 
    fprintf(ci->fh, "_cnx = ORBit_handle_location_forward(_ORBIT_recv_buffer, _obj);\n");
451
 
#endif
452
 
    fprintf(ci->fh, "\ngoto _ORBIT_retry_request;\n");
453
 
    fprintf(ci->fh, "} else {\n");
454
 
 
455
 
    fprintf(ci->fh, "ORBit_handle_exception(_ORBIT_recv_buffer, ev, %s, _obj->orb);\n",
456
 
            IDL_OP_DCL(tree).raises_expr?"_ORBIT_user_exceptions":"NULL");
457
 
    fprintf(ci->fh, "giop_recv_buffer_unuse(_ORBIT_recv_buffer);\n");
458
 
    cs_stub_print_return (tree, ci);
459
 
    fprintf(ci->fh, "}\n}\n");
460
 
  }
461
 
 
462
 
  fprintf(ci->fh, "}\n");
463
 
}
464
 
    
465
 
static void cs_stub_print_return(IDL_tree tree, OIDL_C_Info *ci)
466
 
{
467
 
  if(IDL_OP_DCL(tree).op_type_spec)
468
 
    fprintf(ci->fh, "return %s;\n", ORBIT_RETVAL_VAR_NAME);
469
 
  else
470
 
    fprintf(ci->fh, "return;\n");
471
 
}
472
 
 
473
 
static void
474
 
cbe_stub_op_param_alloc(FILE *of, IDL_tree node, GString *tmpstr)
475
 
{
476
 
  int n, i;
477
 
  char *id;
478
 
  IDL_tree ts = orbit_cbe_get_typespec(node);
479
 
  gboolean isSlice;
480
 
 
481
 
  n = oidl_param_info(node, 
482
 
                         oidl_attr_to_paramrole(IDL_PARAM_DCL(node).attr),
483
 
                         &isSlice);
484
 
  if ( isSlice )
485
 
        n -= 1;
486
 
 
487
 
  if(((n - 1) <= 0) && IDL_NODE_TYPE(ts) != IDLN_TYPE_ARRAY)
488
 
    return;
489
 
 
490
 
  switch(IDL_NODE_TYPE(ts)) {
491
 
  case IDLN_TYPE_ARRAY:
492
 
    if((IDL_PARAM_DCL(node).attr != IDL_PARAM_OUT)
493
 
       || orbit_cbe_type_is_fixed_length(ts))
494
 
      return;
495
 
    n++;
496
 
    break;
497
 
  case IDLN_TYPE_SEQUENCE:
498
 
  case IDLN_TYPE_ANY:
499
 
    if(IDL_PARAM_DCL(node).attr == IDL_PARAM_INOUT)
500
 
      return;
501
 
    break;
502
 
  case IDLN_TYPE_UNION:
503
 
  case IDLN_TYPE_STRUCT:
504
 
    if(orbit_cbe_type_is_fixed_length(ts))
505
 
      return;
506
 
  default:
507
 
    break;
508
 
  }
509
 
 
510
 
  g_string_assign(tmpstr, "");
511
 
  for(i = 0; i < n - 1; i++)
512
 
    g_string_append_c(tmpstr, '*');
513
 
 
514
 
  g_string_append_printf(tmpstr, "%s",
515
 
                    IDL_IDENT(IDL_PARAM_DCL(node).simple_declarator).str);
516
 
 
517
 
  id = orbit_cbe_get_typespec_str(IDL_PARAM_DCL(node).param_type_spec);
518
 
  fprintf(of, "%s = %s__alloc();\n", tmpstr->str, id);
519
 
  g_free(id);
 
137
                        cs_output_stubs (ai->op1, ci, idx);
 
138
 
 
139
                        if (ai->op2)
 
140
                                cs_output_stubs (ai->op2, ci, idx);
 
141
                }
 
142
                break;
 
143
                }
 
144
        case IDLN_INTERFACE: {
 
145
                int real_idx = 0;
 
146
 
 
147
                cs_output_stubs (IDL_INTERFACE (tree).body, ci, &real_idx);
 
148
                break;
 
149
                }
 
150
        case IDLN_OP_DCL:
 
151
                cs_output_stub (tree, ci, idx);
 
152
                break;
 
153
        default:
 
154
                break;
 
155
        }
520
156
}
521
157
 
522
158
void
523
 
cbe_stub_op_retval_alloc(FILE *of, IDL_tree node, GString *tmpstr)
524
 
{
525
 
  int n;
526
 
  char *id;
527
 
  IDL_tree ts = orbit_cbe_get_typespec(node);
528
 
 
529
 
  n = oidl_param_numptrs(node, DATA_RETURN);
530
 
 
531
 
  if((n <= 0)
532
 
     && (IDL_NODE_TYPE(ts) != IDLN_TYPE_ARRAY))
533
 
    return;
534
 
 
535
 
  g_string_assign(tmpstr, ORBIT_RETVAL_VAR_NAME );
536
 
 
537
 
  switch(IDL_NODE_TYPE(ts)) {
538
 
  case IDLN_TYPE_UNION:
539
 
  case IDLN_TYPE_STRUCT:
540
 
    if(orbit_cbe_type_is_fixed_length(ts))
541
 
      return;
542
 
  case IDLN_TYPE_ANY:
543
 
  case IDLN_TYPE_SEQUENCE:
544
 
  case IDLN_TYPE_ARRAY:
545
 
    break;
546
 
  default:
547
 
    return;
548
 
  }
549
 
 
550
 
  id = orbit_cbe_get_typespec_str(node);
551
 
  fprintf(of, "%s = %s__alloc();\n", tmpstr->str, id);
552
 
  g_free(id);
553
 
}
554
 
 
555
 
static void
556
 
cs_stub_alloc_params(IDL_tree tree, OIDL_C_Info *ci)
557
 
{
558
 
  IDL_tree curitem, param;
559
 
  GString *tmpstr = g_string_new(NULL);
560
 
 
561
 
  if(IDL_OP_DCL(tree).op_type_spec)
562
 
    cbe_stub_op_retval_alloc(ci->fh, IDL_OP_DCL(tree).op_type_spec,
563
 
                             tmpstr);
564
 
 
565
 
  for(curitem = IDL_OP_DCL(tree).parameter_dcls; curitem;
566
 
      curitem = IDL_LIST(curitem).next) {
567
 
 
568
 
    param = IDL_LIST(curitem).data;
569
 
 
570
 
    if(IDL_PARAM_DCL(param).attr == IDL_PARAM_INOUT
571
 
       || IDL_PARAM_DCL(param).attr == IDL_PARAM_OUT)
572
 
      cbe_stub_op_param_alloc(ci->fh, param, tmpstr);
573
 
  }
574
 
 
575
 
  g_string_free(tmpstr, TRUE);
576
 
}
577
 
 
578
 
/* This param freeing stuff really could be done better - perhaps shared code with the skels generation. */
579
 
static void
580
 
cbe_stub_op_param_free(FILE *of, IDL_tree node, GString *tmpstr)
581
 
{
582
 
  int n, i;
583
 
  IDL_tree ts;
584
 
  char *id;
585
 
 
586
 
  ts = orbit_cbe_get_typespec(IDL_PARAM_DCL(node).param_type_spec);
587
 
  n = oidl_param_numptrs(node, DATA_INOUT);
588
 
  g_string_assign(tmpstr, "");
589
 
 
590
 
  if(IDL_NODE_TYPE(ts) == IDLN_TYPE_STRUCT
591
 
     || IDL_NODE_TYPE(ts) == IDLN_TYPE_UNION)
592
 
    n--;
593
 
 
594
 
  for(i = 0; i < n; i++)
595
 
    g_string_append_c(tmpstr, '*');
596
 
  
597
 
  g_string_append_printf(tmpstr, "%s",
598
 
                    IDL_IDENT(IDL_PARAM_DCL(node).simple_declarator).str);
599
 
  switch(IDL_NODE_TYPE(ts)) {
600
 
  case IDLN_TYPE_ANY:
601
 
    fprintf(of, "if((%s)._release) CORBA_free((%s)._value);\n",
602
 
            tmpstr->str, tmpstr->str);
603
 
    fprintf(of, "CORBA_Object_release((%s)._type, ev);\n", tmpstr->str);
604
 
    break;
605
 
  case IDLN_TYPE_SEQUENCE:
606
 
    fprintf(of, "if((%s)._release) CORBA_free((%s)._buffer);\n",
607
 
            tmpstr->str, tmpstr->str);
608
 
    break;
609
 
  case IDLN_TYPE_STRUCT:
610
 
  case IDLN_TYPE_UNION:
611
 
  case IDLN_TYPE_ARRAY:
612
 
    if(orbit_cbe_type_is_fixed_length(ts))
613
 
      break;
614
 
    id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(ts).ident), "_", 0);
615
 
    fprintf(of, "%s__freekids(%s, NULL);\n", id, tmpstr->str);
616
 
    g_free(id);
617
 
    break;
618
 
  case IDLN_TYPE_STRING:
619
 
    fprintf(of, "CORBA_free(%s);\n", tmpstr->str);
620
 
    break;
621
 
  case IDLN_INTERFACE:
622
 
  case IDLN_FORWARD_DCL:
623
 
  case IDLN_TYPE_OBJECT:
624
 
  case IDLN_TYPE_TYPECODE:
625
 
    fprintf(of, "CORBA_Object_release(%s, ev);\n", tmpstr->str);
626
 
    break;
627
 
  default:
628
 
    g_assert(orbit_cbe_type_is_fixed_length(node));
629
 
    break;
630
 
  }
631
 
}
632
 
 
633
 
static void
634
 
cs_free_inout_params(IDL_tree tree, OIDL_C_Info *ci)
635
 
{
636
 
  IDL_tree curitem;
637
 
  GString *tmpstr;
638
 
 
639
 
  tmpstr = g_string_new(NULL);
640
 
  for(curitem = IDL_OP_DCL(tree).parameter_dcls; curitem; curitem = IDL_LIST(curitem).next) {
641
 
    IDL_tree curparam;
642
 
 
643
 
    curparam = IDL_LIST(curitem).data;
644
 
 
645
 
    if(IDL_PARAM_DCL(curparam).attr != IDL_PARAM_INOUT) continue;
646
 
 
647
 
    cbe_stub_op_param_free(ci->fh, curparam, tmpstr);
648
 
  }
649
 
  g_string_free(tmpstr, TRUE);
650
 
}
651
 
 
652
 
static void
653
 
cs_output_except(IDL_tree tree, OIDL_C_Info *ci)
654
 
{
655
 
  char *id;
656
 
  OIDL_Except_Info *ei;
657
 
 
658
 
  if ( oidl_tree_is_pidl(tree) )
659
 
        return;
660
 
 
661
 
  ei = tree->data;
662
 
  g_assert(ei);
663
 
 
664
 
  id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_EXCEPT_DCL(tree).ident), "_", 0);
665
 
 
666
 
  fprintf(ci->fh, "gboolean\n_ORBIT_%s_demarshal(GIOPRecvBuffer *_ORBIT_recv_buffer, CORBA_Environment *ev)\n", id);
667
 
  fprintf(ci->fh, "{\n");
668
 
  if(IDL_EXCEPT_DCL(tree).members) {
669
 
    fprintf(ci->fh, "register guchar *_ORBIT_curptr;\n");
670
 
    fprintf(ci->fh, "register guchar *_ORBIT_buf_end = _ORBIT_recv_buffer->end;\n");
671
 
    orbit_cbe_alloc_tmpvars(ei->demarshal, ci);
672
 
    fprintf(ci->fh, "%s *_ORBIT_exdata;\n", id);
673
 
    c_demarshalling_generate(ei->demarshal, ci, FALSE, FALSE);
674
 
  }
675
 
 
676
 
  fprintf(ci->fh, "CORBA_exception_set(ev, CORBA_USER_EXCEPTION, TC_%s_struct.repo_id, %s);\n",
677
 
          id, IDL_EXCEPT_DCL(tree).members?"_ORBIT_exdata":"NULL");
678
 
 
679
 
  fprintf(ci->fh, "return FALSE;");
680
 
 
681
 
  fprintf(ci->fh, "_ORBIT_demarshal_error:\nreturn TRUE;\n");
682
 
 
683
 
  fprintf(ci->fh, "}\n");
 
159
orbit_idl_output_c_stubs (IDL_tree       tree,
 
160
                          OIDL_Run_Info *rinfo,
 
161
                          OIDL_C_Info   *ci)
 
162
{
 
163
        fprintf (ci->fh, OIDL_C_WARNING);
 
164
        fprintf (ci->fh, "#include <string.h>\n");
 
165
        fprintf (ci->fh, "#define ORBIT2_STUBS_API\n");
 
166
        fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
 
167
 
 
168
        cs_output_stubs (tree, ci, NULL);
684
169
}