poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] MI: Replace sequence number with ID


From: Mohammad-Reza Nabipoor
Subject: Re: [PATCH v2] MI: Replace sequence number with ID
Date: Tue, 9 Nov 2021 02:42:43 +0330

Hi, Jose.

ping


On Thu, Aug 19, 2021 at 01:27:39PM +0430, Mohammad-Reza Nabipoor wrote:
> Each message kind has its own independent ID. The (msg_kind, ID) pair
> is unique among all messages.
> 
> 2021-08-19  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> 
>       * poke/pk-mi-msg.h (pk_mi_seqnum): Replaced by `pk_mi_id`.
>       (pk_mi_id): New typedef.
>       (pk_mi_make_req): Add new arg (`id`).
>       (pk_mi_make_event): Likewise.
>       (pk_mi_make_resp): Likewise.
>       (pk_mi_msg_number): Replaced by `pk_mi_msg_id`.
>       (pk_mi_set_msg_number): Replaced by `pk_mi_set_msg_id`.
>       (pk_mi_msg_resp_req_number): Replaced by `pk_mi_msg_resp_req_id`.
>       (pk_mi_msg_id): New function declaration.
>       (pk_mi_make_resp_auto): Likewise.
>       (pk_mi_make_event_auto): Likewise.
>       (pk_mi_set_msg_id): Likewise.
>       (pk_mi_msg_resp_req_id): Likewise.
>       * poke/pk-mi-msg.def (INVREQ): s/reqnum/reqid/.
>       * poke/pk-mi-msg.c (PK_MI_MSG_RESP_REQ_NUMBER): Replaced by
>       `PK_MI_MSG_RESP_REQ_ID`.
>       (PK_MI_MSG_NUMBER): Replaced by `PK_MI_MSG_ID`.
>       (PK_MI_MSG_RESP_REQ_ID): New accessor macro.
>       (struct pk_mi_msg_resp): s/req_number/req_id/.
>       (struct pk_mi_msg): s/number/id/.
>       (next_seqnum): Replaced by `next_event_id`.
>       (next_resp_id): New global variable.
>       (next_event_id): Likewise.
>       (PK_MI_MSG_ID): Likewise.
>       (pk_mi_make_msg): Updated.
>       (pk_mi_make_resp): Likewise.
>       (pk_mi_make_event): Likewise.
>       (pk_mi_msg_number): Removed.
>       (pk_mi_set_msg_number): Likewise.
>       (pk_mi_msg_resp_req_number): Likewise.
>       (pk_mi_make_resp_auto): New function definition.
>       (pk_mi_make_event_auto): Likewise.
>       (pk_mi_msg_id): Likewise.
>       (pk_mi_set_msg_id): Likewise.
>       (pk_mi_msg_resp_req_id): Likewise.
>       * poke/pk-mi.c (pk_mi_send_invalid_msg): Updated.
>       (pk_mi_dispatch_msg): Likewise.
>       * poke/pk-mi-json.c (MI Messages): Updated.
>       (pk_mi_msg_to_json_object): Likewise.
>       (pk_mi_json_object_to_msg): Likewise.
>       * doc/poke.texi (The Machine-Interface): Updated.
> ---
> 
> 
> Hi, Jose.
> 
> I changed the patch to use monotonically increasing ID.
> 
> 
> Regards,
> Mohammad-Reza
> 
> 
>  ChangeLog          | 44 +++++++++++++++++++++++++++++++
>  doc/poke.texi      |  6 +++--
>  poke/pk-mi-json.c  | 42 +++++++++++++++---------------
>  poke/pk-mi-msg.c   | 65 ++++++++++++++++++++++++++++------------------
>  poke/pk-mi-msg.def |  6 ++---
>  poke/pk-mi-msg.h   | 39 +++++++++++++++++++---------
>  poke/pk-mi.c       | 20 +++++++-------
>  7 files changed, 149 insertions(+), 73 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index aa41c1bd..abf23c2b 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,47 @@
> +2021-08-19  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * poke/pk-mi-msg.h (pk_mi_seqnum): Replaced by `pk_mi_id`.
> +     (pk_mi_id): New typedef.
> +     (pk_mi_make_req): Add new arg (`id`).
> +     (pk_mi_make_event): Likewise.
> +     (pk_mi_make_resp): Likewise.
> +     (pk_mi_msg_number): Replaced by `pk_mi_msg_id`.
> +     (pk_mi_set_msg_number): Replaced by `pk_mi_set_msg_id`.
> +     (pk_mi_msg_resp_req_number): Replaced by `pk_mi_msg_resp_req_id`.
> +     (pk_mi_msg_id): New function declaration.
> +     (pk_mi_make_resp_auto): Likewise.
> +     (pk_mi_make_event_auto): Likewise.
> +     (pk_mi_set_msg_id): Likewise.
> +     (pk_mi_msg_resp_req_id): Likewise.
> +     * poke/pk-mi-msg.def (INVREQ): s/reqnum/reqid/.
> +     * poke/pk-mi-msg.c (PK_MI_MSG_RESP_REQ_NUMBER): Replaced by
> +     `PK_MI_MSG_RESP_REQ_ID`.
> +     (PK_MI_MSG_NUMBER): Replaced by `PK_MI_MSG_ID`.
> +     (PK_MI_MSG_RESP_REQ_ID): New accessor macro.
> +     (struct pk_mi_msg_resp): s/req_number/req_id/.
> +     (struct pk_mi_msg): s/number/id/.
> +     (next_seqnum): Replaced by `next_event_id`.
> +     (next_resp_id): New global variable.
> +     (next_event_id): Likewise.
> +     (PK_MI_MSG_ID): Likewise.
> +     (pk_mi_make_msg): Updated.
> +     (pk_mi_make_resp): Likewise.
> +     (pk_mi_make_event): Likewise.
> +     (pk_mi_msg_number): Removed.
> +     (pk_mi_set_msg_number): Likewise.
> +     (pk_mi_msg_resp_req_number): Likewise.
> +     (pk_mi_make_resp_auto): New function definition.
> +     (pk_mi_make_event_auto): Likewise.
> +     (pk_mi_msg_id): Likewise.
> +     (pk_mi_set_msg_id): Likewise.
> +     (pk_mi_msg_resp_req_id): Likewise.
> +     * poke/pk-mi.c (pk_mi_send_invalid_msg): Updated.
> +     (pk_mi_dispatch_msg): Likewise.
> +     * poke/pk-mi-json.c (MI Messages): Updated.
> +     (pk_mi_msg_to_json_object): Likewise.
> +     (pk_mi_json_object_to_msg): Likewise.
> +     * doc/poke.texi (The Machine-Interface): Updated.
> +
>  2021-08-06  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * poke/pk-mi-msg.c (pk_mi_make_resp): Prevents `errmsg` to be `NULL`.
> diff --git a/doc/poke.texi b/doc/poke.texi
> index 9acf133a..36f2aa93 100644
> --- a/doc/poke.texi
> +++ b/doc/poke.texi
> @@ -13747,7 +13747,9 @@ the standard input and standard output:
>  
>  @example
>  $ poke --mi
> -^@@^@@^@@G@{"poke_mi":0,"type":2,"data":@{"type":0,"args":@{"version":"0.1-beta"@}@}@}
> +^@@^@@^@@G@{"id":1,"type":2,"data":@{"type":0,"args":@{"mi_version":
> +@{"type":"Integer","value":0,"size":32@},"version":@{"type":"String",
> +"value":"1.3"@}@}@}@}
>  @end example
>  
>  When using sockets, poke prints the number of the socket where it is
> @@ -13786,7 +13788,7 @@ maximum length of a frame message payload is two 
> kilobytes.
>  
>  @dfn{Requests} are initiated by the client.  Once a request is sent,
>  it will trigger a response.  The response is paired with the
> -triggering request by the request's sequence number.
> +triggering request by the request's ID.
>  
>  @dfn{Responses} are initiated by poke, in response to a request
>  received from the client.
> diff --git a/poke/pk-mi-json.c b/poke/pk-mi-json.c
> index a66a65b0..8ffea7f0 100644
> --- a/poke/pk-mi-json.c
> +++ b/poke/pk-mi-json.c
> @@ -132,7 +132,7 @@ jerror (int ok, char **out, const char *fmt, ...)
>  
>  /* Message::
>     {
> -     "seq"  : integer
> +     "id"   : uint64
>       "type" : MessageType
>       "data" : Request | Response | Event
>     }
> @@ -150,7 +150,7 @@ jerror (int ok, char **out, const char *fmt, ...)
>     Response::
>     {
>       "type" : ResponseType
> -     "req_number" : uint32
> +     "req_id" : uint64
>       "success_p: : boolean
>       "errmsg" : string
>       "result"? : null
> @@ -1111,14 +1111,14 @@ pk_mi_msg_to_json_object (pk_mi_msg msg)
>    if (!json)
>      goto out_of_memory;
>  
> -  /* Add the number.  */
> +  /* Add the id.  */
>    {
>      json_object *number
> -      = json_object_new_int (pk_mi_msg_number (msg));
> +      = json_object_new_int (pk_mi_msg_id (msg));
>  
>      if (!number)
>        goto out_of_memory;
> -    json_object_object_add (json, "seq", number);
> +    json_object_object_add (json, "id", number);
>    }
>  
>    /* Add the type.  */
> @@ -1157,7 +1157,7 @@ pk_mi_msg_to_json_object (pk_mi_msg msg)
>    case PK_MI_MSG_RESPONSE:
>      {
>        enum pk_mi_resp_type msg_resp_type = pk_mi_msg_resp_type (msg);
> -      json_object *resp, *resp_type, *success_p, *req_number, *args;
> +      json_object *resp, *resp_type, *success_p, *req_id, *args;
>  
>        resp = json_object_new_object ();
>        if (!resp)
> @@ -1174,9 +1174,8 @@ pk_mi_msg_to_json_object (pk_mi_msg msg)
>          goto out_of_memory;
>        json_object_object_add (resp, "success_p", success_p);
>  
> -      req_number
> -        = json_object_new_int (pk_mi_msg_resp_req_number (msg));
> -      json_object_object_add (resp, "req_number", req_number);
> +      req_id = json_object_new_int (pk_mi_msg_resp_req_id (msg));
> +      json_object_object_add (resp, "req_id", req_id);
>  
>        if (pk_mi_msg_resp_errmsg (msg))
>          {
> @@ -1231,7 +1230,7 @@ static pk_mi_msg
>  pk_mi_json_object_to_msg (json_object *json, char** errmsg)
>  {
>    enum pk_mi_msg_kind msg_kind;
> -  int msg_number;
> +  int msg_id;
>    json_object *obj, *msg_json, *args_json;
>    pk_mi_msg msg = NULL;
>  
> @@ -1239,13 +1238,13 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>      GOTO_ON_JERR (
>        J_NOK, failed, errmsg,"invalid message: expects JSON object");
>  
> -  /* Get the message number.  */
> +  /* Get the message ID.  */
>    {
>      json_object *number;
>  
> -    GOTO_ON_JERR (jexpect (json, "seq", json_type_int, &number, errmsg),
> +    GOTO_ON_JERR (jexpect (json, "id", json_type_int, &number, errmsg),
>                    failed, errmsg, "invalid message");
> -    msg_number = json_object_get_int (number);
> +    msg_id = json_object_get_int (number);
>    }
>  
>    /* Get the message type.  */
> @@ -1271,14 +1270,14 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>          msg_req_type = json_object_get_int (req_type);
>  
>          /* Create the message.   */
> -        msg = pk_mi_make_req (msg_req_type);
> +        msg = pk_mi_make_req (msg_req_type, msg_id);
>          break;
>        }
>      case PK_MI_MSG_RESPONSE:
>        {
>          json_object *obj;
>          enum pk_mi_resp_type resp_type;
> -        pk_mi_seqnum req_number;
> +        pk_mi_id req_id;
>          int success_p;
>          const char *emsg;
>  
> @@ -1287,11 +1286,11 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>                        failed, errmsg, "invalid response message");
>          resp_type = json_object_get_int (obj);
>  
> -        /* Get the request number.  */
> +        /* Get the corresponding request ID.  */
>          GOTO_ON_JERR (
> -          jexpect (msg_json, "req_number", json_type_int, &obj, errmsg),
> +          jexpect (msg_json, "req_id", json_type_int, &obj, errmsg),
>            failed, errmsg, "invalid response message");
> -        req_number = json_object_get_int (obj);
> +        req_id = json_object_get_int (obj);
>  
>          /* Get success_p.  */
>          GOTO_ON_JERR (
> @@ -1312,7 +1311,8 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>  
>          /* Create the message.  */
>          msg = pk_mi_make_resp (resp_type,
> -                               req_number,
> +                               msg_id,
> +                               req_id,
>                                 success_p,
>                                 emsg);
>          break;
> @@ -1328,7 +1328,7 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>          event_type = json_object_get_int (obj);
>  
>          /* Create the message.  */
> -        msg = pk_mi_make_event (event_type);
> +        msg = pk_mi_make_event (event_type, msg_id);
>          break;
>        }
>      default:
> @@ -1346,7 +1346,7 @@ pk_mi_json_object_to_msg (json_object *json, char** 
> errmsg)
>    }
>  
>  done:
> -  pk_mi_set_msg_number (msg, msg_number);
> +  pk_mi_set_msg_id (msg, msg_id);
>    return msg;
>  
>  failed:
> diff --git a/poke/pk-mi-msg.c b/poke/pk-mi-msg.c
> index c8ee2ab6..7b1c33a8 100644
> --- a/poke/pk-mi-msg.c
> +++ b/poke/pk-mi-msg.c
> @@ -83,8 +83,7 @@ struct pk_mi_msg_req
>  /* Responses are initiated by poke, in response to a request received
>     from the client.
>  
> -   REQ_NUMBER is the sequence number of the request for which this is
> -   a response.
> +   REQ_ID is the ID of the request for which this is a response.
>  
>     SUCCESS_P is the outcome of the request.  A value of 0 means the
>     request wasn't successful.  A value other than 0 means the request
> @@ -99,14 +98,14 @@ struct pk_mi_msg_req
>     below.  */
>  
>  #define PK_MI_MSG_RESP_TYPE(MSG) ((MSG)->data.resp.type)
> -#define PK_MI_MSG_RESP_REQ_NUMBER(MSG) ((MSG)->data.resp.req_number)
> +#define PK_MI_MSG_RESP_REQ_ID(MSG) ((MSG)->data.resp.req_id)
>  #define PK_MI_MSG_RESP_SUCCESS_P(MSG) ((MSG)->data.resp.success_p)
>  #define PK_MI_MSG_RESP_ERRMSG(MSG) ((MSG)->data.resp.errmsg)
>  
>  struct pk_mi_msg_resp
>  {
>    enum pk_mi_resp_type type;
> -  pk_mi_seqnum req_number;
> +  pk_mi_id req_id;
>    int success_p;
>    char *errmsg;
>  };
> @@ -128,14 +127,14 @@ struct pk_mi_msg_event
>  
>  /* The message itself.  */
>  
> -#define PK_MI_MSG_NUMBER(MSG) ((MSG)->number)
> +#define PK_MI_MSG_ID(MSG) ((MSG)->id)
>  #define PK_MI_MSG_KIND(MSG) ((MSG)->kind)
>  #define PK_MI_MSG_NUM_ARGS(MSG) ((MSG)->num_args)
>  #define PK_MI_MSG_ARGS(MSG) ((MSG)->args)
>  
>  struct pk_mi_msg
>  {
> -  pk_mi_seqnum number;
> +  pk_mi_id id;
>    enum pk_mi_msg_kind kind;
>  
>    union
> @@ -153,16 +152,17 @@ typedef struct pk_mi_msg *pk_mi_msg;
>  
>  /*** Variables and code  ***/
>  
> -/* Global with the next available message sequence number.  */
> -static pk_mi_seqnum next_seqnum;
> +/* Global with the next available event message ID.  */
> +static pk_mi_id next_resp_id = 1;
> +static pk_mi_id next_event_id = 1;
>  
>  
>  static pk_mi_msg
> -pk_mi_make_msg (enum pk_mi_msg_kind kind)
> +pk_mi_make_msg (enum pk_mi_msg_kind kind, pk_mi_id id)
>  {
>    pk_mi_msg msg = xmalloc (sizeof (struct pk_mi_msg));
>  
> -  PK_MI_MSG_NUMBER (msg) = next_seqnum++;
> +  PK_MI_MSG_ID (msg) = id;
>    PK_MI_MSG_KIND (msg) = kind;
>    PK_MI_MSG_ARGS (msg) = NULL;
>  
> @@ -190,9 +190,9 @@ pk_mi_allocate_msg_args (pk_mi_msg msg,
>  }
>  
>  pk_mi_msg
> -pk_mi_make_req (enum pk_mi_req_type type)
> +pk_mi_make_req (enum pk_mi_req_type type, pk_mi_id id)
>  {
> -  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_REQUEST);
> +  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_REQUEST, id);
>  
>    PK_MI_MSG_REQ_TYPE (msg) = type;
>    pk_mi_allocate_msg_args (msg, req_arginfo, type);
> @@ -202,17 +202,18 @@ pk_mi_make_req (enum pk_mi_req_type type)
>  
>  pk_mi_msg
>  pk_mi_make_resp (enum pk_mi_resp_type type,
> -                 pk_mi_seqnum req_seqnum,
> +                 pk_mi_id id,
> +                 pk_mi_id req_id,
>                   int success_p,
>                   const char *errmsg)
>  {
> -  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_RESPONSE);
> +  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_RESPONSE, id);
>  
>    if (errmsg == NULL)
>      errmsg = "";
>  
>    PK_MI_MSG_RESP_TYPE (msg) = type;
> -  PK_MI_MSG_RESP_REQ_NUMBER (msg) = req_seqnum;
> +  PK_MI_MSG_RESP_REQ_ID (msg) = req_id;
>    PK_MI_MSG_RESP_SUCCESS_P (msg) = success_p;
>    PK_MI_MSG_RESP_ERRMSG (msg) = xstrdup (errmsg);
>    pk_mi_allocate_msg_args (msg, resp_arginfo, type);
> @@ -221,9 +222,18 @@ pk_mi_make_resp (enum pk_mi_resp_type type,
>  }
>  
>  pk_mi_msg
> -pk_mi_make_event (enum pk_mi_event_type type)
> +pk_mi_make_resp_auto (enum pk_mi_resp_type type,
> +                      pk_mi_id req_id,
> +                      int success_p,
> +                      const char *errmsg)
>  {
> -  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_EVENT);
> +  return pk_mi_make_resp (type, next_resp_id++, req_id, success_p, errmsg);
> +}
> +
> +pk_mi_msg
> +pk_mi_make_event (enum pk_mi_event_type type, pk_mi_id id)
> +{
> +  pk_mi_msg msg = pk_mi_make_msg (PK_MI_MSG_EVENT, id);
>  
>    PK_MI_MSG_EVENT_TYPE (msg) = type;
>    pk_mi_allocate_msg_args (msg, event_arginfo, type);
> @@ -231,6 +241,11 @@ pk_mi_make_event (enum pk_mi_event_type type)
>    return msg;
>  }
>  
> +pk_mi_msg
> +pk_mi_make_event_auto (enum pk_mi_event_type type)
> +{
> +  return pk_mi_make_event (type, next_event_id++);
> +}
>  
>  void
>  pk_mi_msg_free (pk_mi_msg msg)
> @@ -324,16 +339,16 @@ pk_mi_msg_kind (pk_mi_msg msg)
>    return PK_MI_MSG_KIND (msg);
>  }
>  
> -pk_mi_seqnum
> -pk_mi_msg_number (pk_mi_msg msg)
> +pk_mi_id
> +pk_mi_msg_id (pk_mi_msg msg)
>  {
> -  return PK_MI_MSG_NUMBER (msg);
> +  return PK_MI_MSG_ID (msg);
>  }
>  
>  void
> -pk_mi_set_msg_number (pk_mi_msg msg, pk_mi_seqnum number)
> +pk_mi_set_msg_id (pk_mi_msg msg, pk_mi_id id)
>  {
> -  PK_MI_MSG_NUMBER (msg) = number;
> +  PK_MI_MSG_ID (msg) = id;
>  }
>  
>  enum pk_mi_req_type
> @@ -354,10 +369,10 @@ pk_mi_msg_event_type (pk_mi_msg msg)
>    return PK_MI_MSG_EVENT_TYPE (msg);
>  }
>  
> -pk_mi_seqnum
> -pk_mi_msg_resp_req_number (pk_mi_msg msg)
> +pk_mi_id
> +pk_mi_msg_resp_req_id (pk_mi_msg msg)
>  {
> -  return PK_MI_MSG_RESP_REQ_NUMBER (msg);
> +  return PK_MI_MSG_RESP_REQ_ID (msg);
>  }
>  
>  int
> diff --git a/poke/pk-mi-msg.def b/poke/pk-mi-msg.def
> index 42e5ab7b..391f7d5f 100644
> --- a/poke/pk-mi-msg.def
> +++ b/poke/pk-mi-msg.def
> @@ -106,14 +106,14 @@ PK_DEF_RESP (PRINTV, PK_DEF_ARGS (PK_DEF_ARG (string, 
> PK_STRING)))
>  
>     Arguments:
>  
> -   reqnum (uint)
> -     Sequence number of the invalid request.
> +   reqid (uint)
> +     ID of the invalid request.
>     errmsg (string)
>       Invalidity reason.
>  */
>  
>  PK_DEF_EVENT (INVREQ,
> -              PK_DEF_ARGS (PK_DEF_ARG (reqnum, PK_UINT),
> +              PK_DEF_ARGS (PK_DEF_ARG (reqid, PK_UINT),
>                             PK_DEF_ARG (errmsg, PK_STRING)))
>  
>  /* Cleanup.  */
> diff --git a/poke/pk-mi-msg.h b/poke/pk-mi-msg.h
> index e2d90831..5f146af9 100644
> --- a/poke/pk-mi-msg.h
> +++ b/poke/pk-mi-msg.h
> @@ -24,10 +24,13 @@
>  
>  #include <libpoke.h> /* For pk_val */
>  
> -/* Each MI message contains a "sequence number".  The protocol uses
> -   this number to univocally identify certain messages.  */
> +/* Each MI message contains an "id".  Every message kind has its own
> +   independent ID.  ID "0" is a special case.
>  
> -typedef uint32_t pk_mi_seqnum;
> +   The protocol uses this number to univocally identify certain
> +   messages.  */
> +
> +typedef uint64_t pk_mi_id;
>  
>  /* MI messages are of three kinds: requests, responses and events.
>  
> @@ -68,12 +71,13 @@ typedef struct pk_mi_msg *pk_mi_msg;
>  /* Build a new request message.
>     Return NULL in case there is an error.  */
>  
> -pk_mi_msg pk_mi_make_req (enum pk_mi_req_type type);
> +pk_mi_msg pk_mi_make_req (enum pk_mi_req_type type, pk_mi_id id);
>  
>  /* Build a new response message.
>  
> -   REQ_SEQNUM is the sequence number of the request that is answered
> -   by this response.
> +   ID is the ID of the new response.
> +
> +   REQ_ID is the ID of the request that is answered by this response.
>  
>     SUCCESS_P should be 0 if the requested operation couldn't be
>     performed for whatever reason.
> @@ -85,14 +89,25 @@ pk_mi_msg pk_mi_make_req (enum pk_mi_req_type type);
>     Return NULL in case there is an error.  */
>  
>  pk_mi_msg pk_mi_make_resp (enum pk_mi_resp_type type,
> -                           pk_mi_seqnum req_seqnum,
> +                           pk_mi_id id,
> +                           pk_mi_id req_id,
>                             int success_p,
>                             const char *errmsg);
>  
> +/* Build a new response message with an auto-assigned ID.
> +
> +   Other parameters are the same as PK_MI_MAKE_RESP function.  */
> +
> +pk_mi_msg pk_mi_make_resp_auto (enum pk_mi_resp_type type,
> +                                pk_mi_id req_id,
> +                                int success_p,
> +                                const char *errmsg);
> +
>  /* Build a new event message.
>     Return NULL in case there is an error.  */
>  
> -pk_mi_msg pk_mi_make_event (enum pk_mi_event_type type);
> +pk_mi_msg pk_mi_make_event (enum pk_mi_event_type type, pk_mi_id id);
> +pk_mi_msg pk_mi_make_event_auto (enum pk_mi_event_type type);
>  
>  /*** Getting and setting message attributes.  */
>  
> @@ -100,10 +115,10 @@ pk_mi_msg pk_mi_make_event (enum pk_mi_event_type type);
>  
>  enum pk_mi_msg_kind pk_mi_msg_kind (pk_mi_msg msg);
>  
> -/* Get and set the sequence number of a given message.  */
> +/* Get and set the ID of a given message.  */
>  
> -pk_mi_seqnum pk_mi_msg_number (pk_mi_msg msg);
> -void pk_mi_set_msg_number (pk_mi_msg msg, pk_mi_seqnum number);
> +pk_mi_id pk_mi_msg_id (pk_mi_msg msg);
> +void pk_mi_set_msg_id (pk_mi_msg msg, pk_mi_id id);
>  
>  /* Get the type of a given message.  Note that the given message
>     should be of the right kind, and this is not checked at
> @@ -115,7 +130,7 @@ enum pk_mi_event_type pk_mi_msg_event_type (pk_mi_msg 
> msg);
>  
>  /* Get attributes of response messages.  */
>  
> -pk_mi_seqnum pk_mi_msg_resp_req_number (pk_mi_msg msg);
> +pk_mi_id pk_mi_msg_resp_req_id (pk_mi_msg msg);
>  int pk_mi_msg_resp_success_p (pk_mi_msg msg);
>  const char *pk_mi_msg_resp_errmsg (pk_mi_msg msg);
>  
> diff --git a/poke/pk-mi.c b/poke/pk-mi.c
> index 39661ae4..30a61da1 100644
> --- a/poke/pk-mi.c
> +++ b/poke/pk-mi.c
> @@ -273,13 +273,13 @@ pk_mi_send (pk_mi_msg msg)
>  static void
>  pk_mi_send_invalid_msg (pk_mi_msg msg, const char* errmsg)
>  {
> -  pk_mi_seqnum seq = msg ? pk_mi_msg_number (msg) : -1;
> -  pk_mi_msg invreq_msg = pk_mi_make_event (PK_MI_EVENT_INVREQ);
> +  pk_mi_id id = msg ? pk_mi_msg_id (msg) : 0;
> +  pk_mi_msg invreq_msg = pk_mi_make_event_auto (PK_MI_EVENT_INVREQ);
>  
>    if (errmsg == NULL)
>      errmsg = "";
>  
> -  pk_mi_set_arg (invreq_msg, "reqnum", pk_make_uint (seq, 64));
> +  pk_mi_set_arg (invreq_msg, "reqid", pk_make_uint (id, 64));
>    pk_mi_set_arg (invreq_msg, "errmsg", pk_make_string (errmsg));
>    pk_mi_send (invreq_msg);
>    pk_mi_msg_free (invreq_msg);
> @@ -301,10 +301,10 @@ pk_mi_dispatch_msg (pk_mi_msg msg)
>      case PK_MI_REQ_EXIT:
>        {
>          pk_mi_msg resp
> -          = pk_mi_make_resp (PK_MI_RESP_EXIT,
> -                             pk_mi_msg_number (msg),
> -                             1 /* success_p */,
> -                             NULL /* errmsg */);
> +          = pk_mi_make_resp_auto (PK_MI_RESP_EXIT,
> +                                  pk_mi_msg_id (msg),
> +                                  1 /* success_p */,
> +                                  NULL /* errmsg */);
>          pk_mi_send (resp);
>          pk_mi_msg_free (resp);
>          pk_mi_exit_p = 1;
> @@ -326,8 +326,8 @@ pk_mi_dispatch_msg (pk_mi_msg msg)
>                                      NULL, &val);
>          assert (ok == PK_OK);
>  
> -        resp = pk_mi_make_resp (PK_MI_RESP_PRINTV, pk_mi_msg_number (msg),
> -                                1 /* success_p */, NULL /* errmsg */);
> +        resp = pk_mi_make_resp_auto (PK_MI_RESP_PRINTV, pk_mi_msg_id (msg),
> +                                     1 /* success_p */, NULL /* errmsg */);
>          pk_mi_set_arg (resp, "string", val);
>          pk_mi_send (resp);
>          pk_mi_msg_free (resp);
> @@ -355,7 +355,7 @@ pk_mi (void)
>  {
>    pk_mi_msg initialized_msg;
>  
> -  initialized_msg = pk_mi_make_event (PK_MI_EVENT_INITIALIZED);
> +  initialized_msg = pk_mi_make_event_auto (PK_MI_EVENT_INITIALIZED);
>    pk_mi_set_arg (initialized_msg, "mi_version", pk_make_int (MI_VERSION, 
> 32));
>    pk_mi_set_arg (initialized_msg, "version", pk_make_string (VERSION));
>  
> -- 
> 2.32.0
> 
> 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]