/***** In main program ******/
....
BtoC(NODE_TYPE *node_from_a)
{
NODE_TYPE *node_to_c; /* use node_alloc() to create this */
/* THIS IS WHERE I NEED HELP */
node_to_c = node_alloc();
/* create b_node: use node_alloc() - THIS IS WHERE I NEED HELP */
b_node = node_alloc(); //CORRECT?????
/* Fill the fields of b_node - THIS IS WHERE I NEED HELP */
b_node->u->a_node = &node_from_a; //CORRECT?????
b_node->type = TYPE_B_NODE; //CORRECT?????
node_to_c->u->b_node = &b_node; //????
node_to_c->type = TYPE_C_NODE; //????
/* send to c */
send_node_to_c(node_to_c);
return 0;
}
....
/***** In .h file ******/
....
/* data unit between A and B */
typedef struct {
int snode; /* source node address */
int dnode; /* destination node address */
char data[DATASIZE]; /* message */
} A_TYPE;
/* data unit between B and C */
typedef struct {
int curr_node; /* address of this node */
int next_node; /* address of next node */
A_TYPE a_node;
enum boolean error; /* YES or NO */
} B_TYPE;
/* data unit between C layers */
typedef struct {
int type;
B_TYPE b_node;
} C_TYPE;
/* Values for the type field in NODE_TYPE */
#define TYPE_A_NODE 0
#define TYPE_B_NODE 1
#define TYPE_C_NODE 2
typedef struct {
union {
A_TYPE a_node;
B_TYPE b_node;
C_TYPE c_node;
} u;
int type; /* One of TYPE_A_NODE, TYPE_B_NODE, TYPE_C_NODE */
} NODE_TYPE;
int node_init(); /* Initialize the pool of nodes. Returns 0 for failure. */
NODE_TYPE *node_alloc(); /* Allocates a node and returns a pointer */
....
|