#include <nidl.h>
#include <ast.h>
#include <bedeck.h>
#include <cspell.h>
#include <ddbe.h>
#include <dutils.h>
#include <nametbl.h>
#include <mtspipes.h>
static void BE_get_next_pipe_index
(
AST_parameter_n_t *p_parameter,
unsigned int ast_in_or_out,
int curr_pipe_index,
int *p_next_pipe_index
)
{
for ( p_parameter = p_parameter->next;
p_parameter != NULL;
p_parameter = p_parameter->next )
{
if ( (p_parameter->type->kind == AST_pipe_k)
|| ((p_parameter->type->kind == AST_pointer_k)
&& (p_parameter->type->type_structure.pointer->pointee_type
->kind == AST_pipe_k)) )
{
curr_pipe_index++;
if (ast_in_or_out & (p_parameter->flags))
{
*p_next_pipe_index = curr_pipe_index;
return;
}
}
}
*p_next_pipe_index = 0;
}
static void BE_get_pipe_type_name
(
AST_parameter_n_t *p_parameter,
char **p_p_name
)
{
if (p_parameter->type->kind == AST_pipe_k)
{
NAMETABLE_id_to_string( p_parameter->type->name, p_p_name );
}
else
{
NAMETABLE_id_to_string( p_parameter->type->type_structure.pointer
->pointee_type->name, p_p_name );
}
}
void DDBE_init_server_pipes
(
FILE *fid,
AST_operation_n_t *p_operation,
int *p_first_pipe
)
{
int first_in_pipe;
int first_out_pipe;
int curr_pipe_index;
int next_in_pipe_index;
int next_out_pipe_index;
AST_parameter_n_t *p_parameter;
char *p_pipe_type_name;
first_in_pipe = 0;
first_out_pipe = 0;
curr_pipe_index = 0;
for ( p_parameter = p_operation->parameters;
p_parameter != NULL;
p_parameter = p_parameter->next )
{
if ( (p_parameter->type->kind == AST_pipe_k)
|| ((p_parameter->type->kind == AST_pointer_k)
&& (p_parameter->type->type_structure.pointer->pointee_type
->kind == AST_pipe_k)) )
{
curr_pipe_index++;
if ( AST_IN_SET(p_parameter) )
{
if (first_in_pipe == 0) first_in_pipe = curr_pipe_index;
}
if ( AST_OUT_SET(p_parameter) )
{
if (first_out_pipe == 0) first_out_pipe = curr_pipe_index;
}
}
}
if ( first_in_pipe != 0 ) *p_first_pipe = first_in_pipe;
else *p_first_pipe = -first_out_pipe;
curr_pipe_index = 0;
for ( p_parameter = p_operation->parameters;
p_parameter != NULL;
p_parameter = p_parameter->next )
{
if ( (p_parameter->type->kind == AST_pipe_k)
|| ((p_parameter->type->kind == AST_pointer_k)
&& (p_parameter->type->type_structure.pointer->pointee_type
->kind == AST_pipe_k)) )
{
AST_type_n_t *pipe_t = p_parameter->type;
if (pipe_t->kind == AST_pointer_k)
pipe_t = pipe_t->type_structure.pointer->pointee_type;
curr_pipe_index++;
BE_get_pipe_type_name( p_parameter, &p_pipe_type_name );
fprintf( fid, "%s.push=(",BE_get_name(p_parameter->name) );
CSPELL_pipe_struct_routine_decl(fid, pipe_t, BE_pipe_push_k, TRUE);
fprintf( fid, ")rpc_ss_ndr_ee_marsh_pipe_chunk;\n");
fprintf( fid, "%s.pull=(",BE_get_name(p_parameter->name) );
CSPELL_pipe_struct_routine_decl(fid, pipe_t, BE_pipe_pull_k, TRUE);
fprintf( fid, ")rpc_ss_ndr_ee_unmar_pipe_chunk;\n");
next_in_pipe_index = 0;
next_out_pipe_index = 0;
if ( AST_IN_SET(p_parameter) )
{
BE_get_next_pipe_index( p_parameter, AST_IN, curr_pipe_index,
&next_in_pipe_index );
if (next_in_pipe_index == 0)
{
if (first_out_pipe != 0)
next_in_pipe_index = -first_out_pipe;
else next_in_pipe_index = BE_FINISHED_WITH_PIPES;
}
}
if ( AST_OUT_SET(p_parameter) )
{
BE_get_next_pipe_index( p_parameter, AST_OUT, curr_pipe_index,
&next_out_pipe_index );
if (next_out_pipe_index == 0 )
next_out_pipe_index = BE_FINISHED_WITH_PIPES;
else
next_out_pipe_index = -next_out_pipe_index;
}
fprintf( fid,
"rpc_ss_mts_init_callee_pipe(%d,%d,%d,&IDL_current_pipe,&IDL_ms,\n",
curr_pipe_index, next_in_pipe_index, next_out_pipe_index );
fprintf( fid, "%d,(rpc_ss_mts_ee_pipe_state_t**)&%s.state);\n",
(p_parameter->type->kind == AST_pipe_k)
? p_parameter->type->be_info.dd_type->type_vec_p->index
: p_parameter->type->type_structure.pointer->pointee_type
->be_info.dd_type->type_vec_p->index,
BE_get_name(p_parameter->name) );
}
}
}