Rename 'direction' to 'type' in remote_message_header

The 'remote_message_header' struct has a mis-leadingly named
field 'direction'. It is really a reflection of the type of
message, and some types can be sent in either direction. Thus
the field is more accurately named 'type'. No function change.

* qemud/remote_protocol.x: Rename 'direction' to 'type' in
  'remote_message_header. Write better docs describing the
  message header field semantics & usage
* qemud/remote_protocol.c, qemud/remote_protocol.h: Regenerate
* qemud/remote.c, qemud/dispatch.c, src/remote_internal.c
  Update to reflect rename of 'direction' to 'type'
This commit is contained in:
Daniel P. Berrange 2009-07-10 13:02:08 +01:00
parent caaa1b8f13
commit 27944fac9c
6 changed files with 67 additions and 35 deletions

View File

@ -129,7 +129,7 @@ remoteSerializeError(struct qemud_client *client,
int program,
int version,
int procedure,
int direction,
int type,
int serial)
{
XDR xdr;
@ -143,7 +143,7 @@ remoteSerializeError(struct qemud_client *client,
msg->hdr.prog = program;
msg->hdr.vers = version;
msg->hdr.proc = procedure;
msg->hdr.direction = direction;
msg->hdr.type = type;
msg->hdr.serial = serial;
msg->hdr.status = REMOTE_ERROR;
@ -354,13 +354,13 @@ remoteDispatchClientRequest (struct qemud_server *server,
goto error;
}
switch (msg->hdr.direction) {
switch (msg->hdr.type) {
case REMOTE_CALL:
return remoteDispatchClientCall(server, client, msg);
default:
remoteDispatchFormatError (&rerr, _("direction (%d) != REMOTE_CALL"),
(int) msg->hdr.direction);
remoteDispatchFormatError (&rerr, _("type (%d) != REMOTE_CALL"),
(int) msg->hdr.type);
}
error:
@ -468,11 +468,11 @@ remoteDispatchClientCall (struct qemud_server *server,
goto rpc_error;
/* Return header. We're re-using same message object, so
* only need to tweak direction/status fields */
* only need to tweak type/status fields */
/*msg->hdr.prog = msg->hdr.prog;*/
/*msg->hdr.vers = msg->hdr.vers;*/
/*msg->hdr.proc = msg->hdr.proc;*/
msg->hdr.direction = REMOTE_REPLY;
msg->hdr.type = REMOTE_REPLY;
/*msg->hdr.serial = msg->hdr.serial;*/
msg->hdr.status = REMOTE_OK;

View File

@ -4422,7 +4422,7 @@ remoteDispatchDomainEventSend (struct qemud_client *client,
msg->hdr.prog = REMOTE_PROGRAM;
msg->hdr.vers = REMOTE_PROTOCOL_VERSION;
msg->hdr.proc = REMOTE_PROC_DOMAIN_EVENT;
msg->hdr.direction = REMOTE_MESSAGE;
msg->hdr.type = REMOTE_MESSAGE;
msg->hdr.serial = 1;
msg->hdr.status = REMOTE_OK;

View File

@ -2514,7 +2514,7 @@ xdr_remote_procedure (XDR *xdrs, remote_procedure *objp)
}
bool_t
xdr_remote_message_direction (XDR *xdrs, remote_message_direction *objp)
xdr_remote_message_type (XDR *xdrs, remote_message_type *objp)
{
if (!xdr_enum (xdrs, (enum_t *) objp))
@ -2541,7 +2541,7 @@ xdr_remote_message_header (XDR *xdrs, remote_message_header *objp)
return FALSE;
if (!xdr_remote_procedure (xdrs, &objp->proc))
return FALSE;
if (!xdr_remote_message_direction (xdrs, &objp->direction))
if (!xdr_remote_message_type (xdrs, &objp->type))
return FALSE;
if (!xdr_u_int (xdrs, &objp->serial))
return FALSE;

View File

@ -1551,12 +1551,12 @@ enum remote_procedure {
};
typedef enum remote_procedure remote_procedure;
enum remote_message_direction {
enum remote_message_type {
REMOTE_CALL = 0,
REMOTE_REPLY = 1,
REMOTE_MESSAGE = 2,
};
typedef enum remote_message_direction remote_message_direction;
typedef enum remote_message_type remote_message_type;
enum remote_message_status {
REMOTE_OK = 0,
@ -1569,7 +1569,7 @@ struct remote_message_header {
u_int prog;
u_int vers;
remote_procedure proc;
remote_message_direction direction;
remote_message_type type;
u_int serial;
remote_message_status status;
};
@ -1808,7 +1808,7 @@ extern bool_t xdr_remote_domain_xml_from_native_ret (XDR *, remote_domain_xml_f
extern bool_t xdr_remote_domain_xml_to_native_args (XDR *, remote_domain_xml_to_native_args*);
extern bool_t xdr_remote_domain_xml_to_native_ret (XDR *, remote_domain_xml_to_native_ret*);
extern bool_t xdr_remote_procedure (XDR *, remote_procedure*);
extern bool_t xdr_remote_message_direction (XDR *, remote_message_direction*);
extern bool_t xdr_remote_message_type (XDR *, remote_message_type*);
extern bool_t xdr_remote_message_status (XDR *, remote_message_status*);
extern bool_t xdr_remote_message_header (XDR *, remote_message_header*);
@ -2043,7 +2043,7 @@ extern bool_t xdr_remote_domain_xml_from_native_ret ();
extern bool_t xdr_remote_domain_xml_to_native_args ();
extern bool_t xdr_remote_domain_xml_to_native_ret ();
extern bool_t xdr_remote_procedure ();
extern bool_t xdr_remote_message_direction ();
extern bool_t xdr_remote_message_type ();
extern bool_t xdr_remote_message_status ();
extern bool_t xdr_remote_message_header ();

View File

@ -1409,23 +1409,55 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_XML_TO_NATIVE = 136
};
/* Custom RPC structure. */
/* Each message consists of:
* int length Number of bytes in message _including_ length.
* remote_message_header Header.
* then either: args Arguments (for REMOTE_CALL).
* or: ret Return (for REMOTE_REPLY, status = REMOTE_OK)
* or: remote_error Error (for REMOTE_REPLY, status = REMOTE_ERROR)
*
* The first two words (length, program number) are meant to be compatible
* with the qemud protocol (qemud/protocol.x), although the rest of the
* messages are completely different.
*/
enum remote_message_direction {
REMOTE_CALL = 0, /* client -> server */
REMOTE_REPLY = 1, /* server -> client */
REMOTE_MESSAGE = 2 /* server -> client, asynchronous [NYI] */
/*
* RPC wire format
*
* Each message consists of:
*
* Name | Type | Description
* -----------+-----------------------+------------------
* Length | int | Total number of bytes in message _including_ length.
* Header | remote_message_header | Control information about procedure call
* Payload | - | Variable payload data per procedure
*
* In header, the 'serial' field varies according to:
*
* - type == REMOTE_CALL
* * serial is set by client, incrementing by 1 each time
*
* - type == REMOTE_REPLY
* * serial matches that from the corresponding REMOTE_CALL
*
* - type == REMOTE_MESSAGE
* * serial matches that from the corresponding REMOTE_CALL, or zero
*
*
* Payload varies according to type and status:
*
* - type == REMOTE_CALL
* XXX_args for procedure
*
* - type == REMOTE_REPLY
* * status == REMOTE_OK
* XXX_ret for procedure
* * status == REMOTE_ERROR
* remote_error Error information
*
* - type == REMOTE_MESSAGE
* * status == REMOTE_OK
* XXX_args for procedure
* * status == REMOTE_ERROR
* remote_error Error information
*
*/
enum remote_message_type {
/* client -> server. args from a method call */
REMOTE_CALL = 0,
/* server -> client. reply/error from a method call */
REMOTE_REPLY = 1,
/* either direction. async notification */
REMOTE_MESSAGE = 2
};
enum remote_message_status {
@ -1447,7 +1479,7 @@ struct remote_message_header {
unsigned prog; /* REMOTE_PROGRAM */
unsigned vers; /* REMOTE_PROTOCOL_VERSION */
remote_procedure proc; /* REMOTE_PROC_x */
remote_message_direction direction;
remote_message_type type;
unsigned serial; /* Serial number of message. */
remote_message_status status;
};

View File

@ -6269,7 +6269,7 @@ prepareCall(virConnectPtr conn,
hdr.prog = REMOTE_PROGRAM;
hdr.vers = REMOTE_PROTOCOL_VERSION;
hdr.proc = proc_nr;
hdr.direction = REMOTE_CALL;
hdr.type = REMOTE_CALL;
hdr.serial = rv->serial;
hdr.status = REMOTE_OK;
@ -6664,14 +6664,14 @@ processCallRecvMsg(virConnectPtr conn, struct private_data *priv,
}
/* Async events from server need special handling */
if (hdr.direction == REMOTE_MESSAGE) {
if (hdr.type == REMOTE_MESSAGE) {
processCallAsyncEvent(conn, priv, in_open,
&hdr, &xdr);
xdr_destroy(&xdr);
return 0;
}
if (hdr.direction != REMOTE_REPLY) {
if (hdr.type != REMOTE_REPLY) {
virRaiseError (in_open ? NULL : conn,
NULL, NULL, VIR_FROM_REMOTE,
VIR_ERR_RPC, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,