l4-hurd
[Top][All Lists]
Advanced

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

Re: Hurd IPC (client side)


From: Neal H. Walfield
Subject: Re: Hurd IPC (client side)
Date: 03 Nov 2002 17:19:45 -0500
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2

> I think using macro for this is probably not a good idea.  A simple
> example is that something like

If you do have bad macros, then yes.  But we can always do:

#define file_chown(uh, owner, group) \
        ({ \
          user_handle_t t = (uh); \
          frob_file_chown (t.server, t.handle, (owner), (group)); \
        })

This can of course be abstracted a bit so we do not have to code this
type of stub for every rpc.

> Having a library in between the client code and the actual RPCs could avoid
> that.  What do you think would be the best way to unify client code for the
> various Hurd implementations?

But, what does it buy us other than overhead of remarshaling the
parameters?

This is the type of magic that we will use on the server side when
doing the mutations (I have not written the client side stuff):

/* RPC magic transformations.
   Copyright (C) 2002 Free Software Foundation, Inc.
   Written by Neal H. Walfield.

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */


/* Input:

     Macro RPC_PREFIX:   Must be defined; prefix for the C stub.
     Macro RPC_POSTFIX:  Must be defined; postfix for the C stub.
     Macro RPC_SEQNO:    If defined, stubs will be called with the
                         sequence number of the rpc.

*/

#include "server-handles.h"
#include <idl4/interface_v4.h>

#undef _RPC_PARAMETERS_SEQNO
#ifdef RPC_SEQNO
#define _RPC_PARAMETERS_SEQNO , msg_seqno_t seqno
#else
#define _RPC_PARAMETERS_SEQNO
#endif

#undef _RPC_ARGS_SEQNO
#ifdef RPC_SEQNO
#define _RPC_ARGS_SEQNO , shi->seqno
#else
#define _RPC_ARGS_SEQNO
#endif

#ifndef __HURD_L4_RPC_MAGIC_H__
#define __HURD_L4_RPC_MAGIC_H__

/* Thread local variables set by the manager thread.  */
#if 0
extern __thread struct server_handle_bucket *manager_bucket;
extern __thread int (*manager_dispatcher) (int (*callback) (void *));
extern __thread msg_id_t manager_current_msg_id;
#else
extern struct server_handle_bucket *manager_bucket;
extern int (*manager_dispatcher) (int (*callback) (void *));
extern msg_id_t manager_current_msg_id;
#endif

extern task_t thread_to_task (L4_ThreadId_t);

/* Generate an rpc stub.  FUNCTION is the rpc name; ARGTYPES the
   parameter list as returned from RPC_TYPES(); and args the argument
   list as returned from RPC_ARGS().  Makes the following assumptions:
   the rpc returns an error_t and the first argument is a
   user_handle_id_t on the wire and a struct server_handle_info * in
   the stub.  */
#define RPC_GEN(function, argtypes, args) _RPC_GEN(function, argtypes, args)
#define _RPC_GEN(function, argtypes, realstub_argtypes, args) \
  extern error_t RPCNAME(function) realstub_argtypes; \
  extern inline error_t \
  RPCNAME(_frob_ ## function) argtypes \
  { \
    error_t err; \
    struct rpc_info info; \
    server_handle_t sh \
      = { uhid, thread_to_task (* (L4_ThreadId_t *) &caller) }; \
    struct server_handle_info *shi \
      = server_handle_lookup (manager_bucket, sh, 0); \
    \
    int invoke (void *x) \
      { \
        return RPCNAME (function) args; \
      } \
    \
    if (! shi) \
      return EOPNOTSUPP; \
    \
    err = server_handle_begin_rpc (shi, sh, manager_current_msg_id, \
                                   &info); \
    if (! err) \
      { \
        if (manager_dispatcher) \
          err = manager_dispatcher (invoke); \
        else \
          err = invoke (0); \
        \
        server_handle_end_rpc (shi, &info); \
      } \
    server_handle_deref (shi); \
    return err; \
  } \
  \
  IDL4_PUBLISH_ ## function (RPCNAME(_frob_ ## function));

/* Return the C name for the rpc NAME by prepending RPC_PREFIX and
   appending RPC_POSTFIX.  */
#define RPCNAME(name) _RPCNAME1(RPC_PREFIX, name, RPC_POSTFIX)
#define _RPCNAME1(a, b, c) _RPCNAME2(a, b, c)
#define _RPCNAME2(a, b, c) a ## b ## c

/* Massage the parameter list.  */
#define RPC_PARAMETERS(argtypes...) \
  (CORBA_Object caller, \
   const user_handle_id_t uhid , ## argtypes, \
   idl4_server_environment *env) , \
  (CORBA_Object caller, \
   struct server_handle_info *shi _RPC_PARAMETERS_SEQNO , ## argtypes, \
   idl4_server_environment *env)

/* Massages the argument list.  Must parallel the TYPES function.  */
#define RPC_ARGS(args...) (caller, shi _RPC_ARGS_SEQNO , ## args, env)

#endif /*  __HURD_L4_RPC_MAGIC_H__ */


And here is an example file idl file and stub file:

/* -*- Mode: c -*- */
#include <hurd/l4/interfaces.h>

[uuid(RPC_INTERFACE_ID)]
interface rpc
{
  import "hurd/l4/types.h";

  /* Interrupt all pending rpcs on USER_HANDLE and force them to
     return immediately.  */
  error_t interrupt (in user_handle_id_t handle);
};
  
/* RPC interface.
   Copyright (C) 2002 Free Software Foundation, Inc.
   Written by Neal H. Walfield.

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */

#include <rpc_server.h>

#ifndef RPC_PREFIX
#define RPC_PREFIX S_
#endif

#ifndef RPC_PREFIX
#define RPC_POSTFIX
#endif

#include <hurd/l4/rpc-magic.h>

RPC_GEN (rpc_interrupt, RPC_PARAMETERS (), RPC_ARGS ());

#undef RPC_PREFIX
#undef RPC_POSTFIX




reply via email to

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