LCOV - code coverage report
Current view: directory - src/shared/srpc - nacl_srpc.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 3 3 100.0 %
Date: 2012-02-16 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2011 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #ifndef NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_
       8                 : #define NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_
       9                 : 
      10                 : /**
      11                 :  * @file
      12                 :  * Defines the API in the
      13                 :  * <a href="group___s_r_p_c.html">Simple RPC (SRPC) library</a>
      14                 :  *
      15                 :  * @addtogroup SRPC
      16                 :  * @{
      17                 :  */
      18                 : 
      19                 : #include <stdarg.h>
      20                 : #include <stdio.h>
      21                 : 
      22                 : /*
      23                 :  * TODO(sehr) break this file into separate files for sdk and service_runtime
      24                 :  * inclusion.
      25                 :  */
      26                 : #ifdef __native_client__
      27                 : #  include <machine/_types.h>
      28                 : 
      29                 : #ifndef DOXYGEN_SHOULD_SKIP_THIS
      30                 : /*
      31                 :  * Avoid emacs' penchant for auto-indenting extern "C" blocks.
      32                 :  */
      33                 : #  ifdef __cplusplus
      34                 : #    define EXTERN_C_BEGIN extern "C" {
      35                 : #    define EXTERN_C_END   }
      36                 : #  else
      37                 : #    define EXTERN_C_BEGIN
      38                 : #    define EXTERN_C_END
      39                 : #  endif  /* __cplusplus */
      40                 : #endif /* DOXYGEN_SHOULD_SKIP_THIS */
      41                 : 
      42                 : /**
      43                 :  * Contains a file descriptor for use as an IMC channel.
      44                 :  */
      45                 : typedef int NaClSrpcImcDescType;
      46                 : #define kNaClSrpcInvalidImcDesc -1
      47                 : #else
      48                 : #  include "native_client/src/include/portability.h"
      49                 : #  include "native_client/src/trusted/service_runtime/include/machine/_types.h"
      50                 : /*
      51                 :  * In trusted code we use a NaClDesc to describe the IMC channel.
      52                 :  * It is this difference between trusted and untrusted code that motivated
      53                 :  * creating a type name.
      54                 :  */
      55                 : typedef struct NaClDesc* NaClSrpcImcDescType;
      56                 : #define kNaClSrpcInvalidImcDesc NULL
      57                 : #endif
      58                 : 
      59                 : EXTERN_C_BEGIN
      60                 : 
      61                 : 
      62                 : /**
      63                 :  * Result codes to be returned from Simple RPC services.
      64                 :  */
      65                 : typedef enum NaClSrpcResultCodes {
      66                 :   /** Invocation was successful. */
      67                 :   NACL_SRPC_RESULT_OK = 256,
      68                 :   /** Invocation was successful, exit the server dispatch loop.
      69                 :    *  When returned from an RPC method, this causes the server to return
      70                 :    *  NACL_SRPC_RESULT_OK and then exit the receive-dispatch-reply loop.
      71                 :    */
      72                 :   NACL_SRPC_RESULT_BREAK,
      73                 :   /** Some or all of a message was not received. */
      74                 :   NACL_SRPC_RESULT_MESSAGE_TRUNCATED,
      75                 :   /** The SRPC runtime system ran out of memory. */
      76                 :   NACL_SRPC_RESULT_NO_MEMORY,
      77                 :   /** The SRPC message layer detected a protocol version difference. */
      78                 :   NACL_SRPC_RESULT_PROTOCOL_MISMATCH,
      79                 :   /** The RPC number was not valid for any method. */
      80                 :   NACL_SRPC_RESULT_BAD_RPC_NUMBER,
      81                 :   /** An unknown type was passed to or returned from an RPC. */
      82                 :   NACL_SRPC_RESULT_BAD_ARG_TYPE,
      83                 :   /** Too few arguments were passed to or returned from an RPC. */
      84                 :   NACL_SRPC_RESULT_TOO_FEW_ARGS,
      85                 :   /** Too many arguments were passed to or returned from an RPC. */
      86                 :   NACL_SRPC_RESULT_TOO_MANY_ARGS,
      87                 :   /** One or more input argument types did not match the expected types. */
      88                 :   NACL_SRPC_RESULT_IN_ARG_TYPE_MISMATCH,
      89                 :   /** One or more output argument types did not match the expected types. */
      90                 :   NACL_SRPC_RESULT_OUT_ARG_TYPE_MISMATCH,
      91                 :   /** An unknown SRPC internal error occurred. */
      92                 :   NACL_SRPC_RESULT_INTERNAL,
      93                 :   /** The application signalled a generic error. */
      94                 :   NACL_SRPC_RESULT_APP_ERROR
      95                 : } NaClSrpcError;
      96                 : 
      97                 : /**
      98                 :  *  Returns a descriptive string for the specified NaClSrpcError value.
      99                 :  *  @param error_val A NaClSrpcError to be translated to a string.
     100                 :  *  @return If error_val is valid, returns a string.  Otherwise returns the
     101                 :  *  string "Unrecognized NaClSrpcError value"
     102                 :  */
     103                 : extern const char* NaClSrpcErrorString(NaClSrpcError error_val);
     104                 : 
     105                 : /**
     106                 :  * Type tag values for NaClSrpcArg unions.
     107                 :  */
     108                 : enum NaClSrpcArgType {
     109                 :   NACL_SRPC_ARG_TYPE_INVALID = 'X',  /**< invalid type */
     110                 :   NACL_SRPC_ARG_TYPE_BOOL = 'b',  /**< scalar bool */
     111                 :   NACL_SRPC_ARG_TYPE_CHAR_ARRAY = 'C',  /**< array of char */
     112                 :   NACL_SRPC_ARG_TYPE_DOUBLE = 'd',  /**< scalar double */
     113                 :   NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY = 'D',  /**< array of double */
     114                 :   NACL_SRPC_ARG_TYPE_HANDLE = 'h',  /**< a descriptor (handle) */
     115                 :   NACL_SRPC_ARG_TYPE_INT = 'i',  /**< scalar int32_t */
     116                 :   NACL_SRPC_ARG_TYPE_INT_ARRAY = 'I',  /**< array of int32_t */
     117                 :   NACL_SRPC_ARG_TYPE_LONG = 'l',  /**< scalar int64_t */
     118                 :   NACL_SRPC_ARG_TYPE_LONG_ARRAY = 'L',  /**< array of int64_t */
     119                 :   NACL_SRPC_ARG_TYPE_STRING = 's',  /**< NUL-terminated string */
     120                 :   NACL_SRPC_ARG_TYPE_OBJECT = 'o',  /**< scriptable object */
     121                 :   NACL_SRPC_ARG_TYPE_VARIANT_ARRAY = 'A'  /**< array of NaClSrpcArg structs */
     122                 : };
     123                 : 
     124                 : #ifdef __cplusplus
     125                 : namespace nacl_srpc {
     126                 : class ScriptableHandleBase;
     127                 : }
     128                 : #endif
     129                 : 
     130                 : #define NACL_SRPC_ARG_SERIALIZED_FIELDS                                    \
     131                 :   /**                                                                      \
     132                 :    * Determines which type this argument contains.  Its value determines   \
     133                 :    * which element of union <code>u</code> may be validly referred to.     \
     134                 :    */                                                                      \
     135                 :   enum NaClSrpcArgType  tag;                                               \
     136                 :   /**                                                                      \
     137                 :    * Padding (unused) to ensure 8-byte alignment of the union u.           \
     138                 :    */                                                                      \
     139                 :   uint32_t              reserved_pad;                                      \
     140                 :   /*                                                                       \
     141                 :    * For efficiency, doubles should be 8-byte aligned so that              \
     142                 :    * loading them would require a single bus cycle, and arrays of          \
     143                 :    * NaClSrpcArgs will have to be 8-byte aligned as well, so it's          \
     144                 :    * either a 4 byte padding between the tag and the union or              \
     145                 :    * (implicitly) at the end.  gcc does not (by default) enforce           \
     146                 :    * 8-byte alignment but visual studio does, so we explicitly pad         \
     147                 :    * so that both compilers will use the same memory layout, even if       \
     148                 :    * the gcc -malign-double flag were omitted.                             \
     149                 :    */                                                                      \
     150                 :   /**                                                                      \
     151                 :    * A union containing the value of the argument.  The element containing \
     152                 :    * the valid data is determined by <code>tag</code>.                     \
     153                 :    */                                                                      \
     154                 :   union {                                                                  \
     155                 :     /** A boolean scalar value */                                          \
     156                 :     int                 bval;                                              \
     157                 :     /** An array size (count) value */                                     \
     158                 :     nacl_abi_size_t     count;                                             \
     159                 :     /** A double-precision floating point scalar value */                  \
     160                 :     double              dval;                                              \
     161                 :     /** A handle used to pass descriptors */                               \
     162                 :     NaClSrpcImcDescType hval;                                              \
     163                 :     /** An integer scalar value */                                         \
     164                 :     int32_t             ival;                                              \
     165                 :     /** A int64_t scalar value */                                          \
     166                 :     int64_t             lval;                                              \
     167                 :     /** An object value that can be exported to the browser as is */       \
     168                 :   } u
     169                 : 
     170                 : /**
     171                 :  *  Used to convey parameters to and from RPC invocations.  It is a variant
     172                 :  *  type, with the <code>tag</code> telling whether to treat the parameter as
     173                 :  *  a bool or an array of characters, etc.
     174                 :  */
     175                 : struct NaClSrpcArg {
     176                 :   /* Data that is serialized for a value or template, regardless of type. */
     177                 :   NACL_SRPC_ARG_SERIALIZED_FIELDS;
     178                 :   /* Data that used to represent an array value, but is not serialized. */
     179                 :   union {
     180                 :     char                *carr;
     181                 :     double              *darr;
     182                 :     int32_t             *iarr;
     183                 :     int64_t             *larr;
     184                 :     /** This field is ordinarily used with predeclared methods, and is never
     185                 :      *  used directly for communicating with nexes.  It usually points to an
     186                 :      *  object scriptable by the browser, i.e.  NPAPI's NPObject or PPAPI's
     187                 :      *  ScriptableObject.  Declaring it as void* to avoid including browser
     188                 :      *  specific types here.
     189                 :      *  TODO(polina): where can one assert for this?
     190                 :      *  Also, as these pointers are overlaid, oval is used in array object
     191                 :      *  serialization to avoid repeated type checks.
     192                 :      */
     193                 :     void                *oval;
     194                 :     char                *str;
     195                 :     struct NaClSrpcArg  *varr;
     196                 :   } arrays;
     197                 : };
     198                 : 
     199                 : /**
     200                 :  * A typedef for struct NaClSrpcArg for use in C.
     201                 :  */
     202                 : typedef struct NaClSrpcArg NaClSrpcArg;
     203                 : 
     204                 : /**
     205                 :  * A constructor that ensures argument memory is properly initialized.
     206                 :  */
     207                 : void NaClSrpcArgCtor(NaClSrpcArg* arg);
     208                 : 
     209                 : #define NACL_SRPC_RPC_SERIALIZED_FIELDS        \
     210                 :   uint32_t                  protocol_version;  \
     211                 :   uint32_t                  request_id;        \
     212                 :   uint32_t                  is_request;        \
     213                 :   uint32_t                  rpc_number;        \
     214                 :   NaClSrpcError             result;            \
     215                 :   uint32_t                  value_len;         \
     216                 :   uint32_t                  template_len
     217                 : 
     218                 : /**
     219                 :  * Remote procedure call state structure.
     220                 :  */
     221                 : struct NaClSrpcRpc {
     222                 :   /* State that is serialized. */
     223                 :   NACL_SRPC_RPC_SERIALIZED_FIELDS;
     224                 :   /* State maintained for transmission/reception, but not serialized */
     225                 :   struct NaClSrpcChannel*   channel;
     226                 :   const char*               ret_types;
     227                 :   NaClSrpcArg**             rets;
     228                 :   uint8_t                   ret_send_succeeded;
     229                 :   uint8_t                   dispatch_loop_should_continue;
     230                 : };
     231                 : 
     232                 : /**
     233                 :  * A typedef for struct NaClSrpcRpc for use in C.
     234                 :  */
     235                 : typedef struct NaClSrpcRpc NaClSrpcRpc;
     236                 : 
     237                 : /* TODO(gregoryd) - duplicate string? */
     238                 : /**
     239                 :  * A utility macro to set a string-typed argument.
     240                 :  */
     241                 : #define STRINGZ_TO_SRPCARG(val, arg) do { \
     242                 :     (arg).tag = NACL_SRPC_ARG_TYPE_STRING; \
     243                 :     (arg).u.sval.str = (val); } while (0)
     244                 : 
     245                 : /**
     246                 :  * The maximum number of arguments per SRPC routine.
     247                 :  */
     248                 : #define NACL_SRPC_MAX_ARGS                     128
     249                 : 
     250                 : /**
     251                 :  * The maximum number of characters returnable from service discovery.
     252                 :  */
     253                 : #define NACL_SRPC_MAX_SERVICE_DISCOVERY_CHARS  4000
     254                 : 
     255                 : /** A pointer to an SRPC channel data structure. */
     256                 : typedef struct NaClSrpcChannel *NaClSrpcChannelPtr;
     257                 : 
     258                 : /**
     259                 :  * The closure used to send responses from a method.
     260                 :  */
     261                 : struct NaClSrpcClosure {
     262                 :   void (*Run)(struct NaClSrpcClosure* self);
     263                 : };
     264                 : 
     265                 : #ifdef __cplusplus
     266                 : /**
     267                 :  * An RAII helper class for using NaClSrpcClosures in C++.
     268                 :  */
     269                 : class NaClSrpcClosureRunner {
     270                 :  public:
     271               9 :   explicit NaClSrpcClosureRunner(NaClSrpcClosure* closure) :
     272               9 :     closure_(closure) { }
     273               9 :   ~NaClSrpcClosureRunner() { closure_->Run(closure_); }
     274                 : 
     275                 :  private:
     276                 :   NaClSrpcClosure* closure_;
     277                 : };
     278                 : #endif
     279                 : 
     280                 : /**
     281                 :  * A typedef for struct NaClSrpcClosure for use in C.
     282                 :  */
     283                 : typedef struct NaClSrpcClosure NaClSrpcClosure;
     284                 : 
     285                 : /**
     286                 :  * Methods used to implement SRPC services have this type signature.
     287                 :  */
     288                 : typedef void (*NaClSrpcMethod)(NaClSrpcRpc* rpc,
     289                 :                                NaClSrpcArg* args[],
     290                 :                                NaClSrpcArg* rets[],
     291                 :                                NaClSrpcClosure* done);
     292                 : 
     293                 : /**
     294                 :  * Binaries that implement SRPC methods (servers) describe their services
     295                 :  * using these structures.
     296                 :  */
     297                 : struct NaClSrpcHandlerDesc {
     298                 :   /**
     299                 :    * a string containing "name:input_types:output_types"
     300                 :    */
     301                 :   char const *entry_fmt;
     302                 :   /**
     303                 :    * function pointer used to process calls to the named method
     304                 :    */
     305                 :   NaClSrpcMethod handler;
     306                 : };
     307                 : 
     308                 : /**
     309                 :  * A typedef for struct NaClSrpcHandlerDesc for use in C.
     310                 :  */
     311                 : typedef struct NaClSrpcHandlerDesc NaClSrpcHandlerDesc;
     312                 : 
     313                 : /**
     314                 :  * A private structure type used to describe methods within NaClSrpcService.
     315                 :  */
     316                 : struct NaClSrpcMethodDesc;
     317                 : 
     318                 : /**
     319                 :  * A description of the services available on a channel.
     320                 :  */
     321                 : struct NaClSrpcService {
     322                 :   /**
     323                 :    * A pointer to an array of RPC service descriptors used to type check and
     324                 :    * dispatch RPC requests.
     325                 :    */
     326                 :   struct NaClSrpcMethodDesc*  rpc_descr;
     327                 :   /** The number of elements in the <code>rpc_descr</code> array. */
     328                 :   uint32_t                    rpc_count;
     329                 :   /**
     330                 :    * A zero terminated string containing name:ins:outs triples used to respond
     331                 :    * to service_discovery RPCs.
     332                 :    */
     333                 :   const char*                 service_string;
     334                 :   /** The length of <code>service_string</code> in bytes */
     335                 :   nacl_abi_size_t             service_string_length;
     336                 : };
     337                 : 
     338                 : /**
     339                 :  *  A typedef for struct NaClSrpcService for use in C.
     340                 :  */
     341                 : typedef struct NaClSrpcService NaClSrpcService;
     342                 : 
     343                 : /**
     344                 :  *  Constructs an SRPC service object from an array of handlers.
     345                 :  *  @param service The service to be constructed.
     346                 :  *  @param imc_desc handler_desc The handlers for each of the methods.
     347                 :  *  @return On success, 1; on failure, 0.
     348                 :  */
     349                 : int NaClSrpcServiceHandlerCtor(NaClSrpcService* service,
     350                 :                                const NaClSrpcHandlerDesc* handler_desc);
     351                 : 
     352                 : /**
     353                 :  *  Constructs an SRPC service object from a service discovery string.
     354                 :  *  @param service The service to be constructed.
     355                 :  *  @param imc_desc handler_desc The string returned from a service discovery
     356                 :  *  call.
     357                 :  *  @return On success, 1; on failure, 0.
     358                 :  */
     359                 : int NaClSrpcServiceStringCtor(NaClSrpcService* service,
     360                 :                               const char* service_discovery_string);
     361                 : 
     362                 : /**
     363                 :  *  Destroys an SRPC service object.
     364                 :  *  @param service The service to be destroyed.
     365                 :  */
     366                 : void NaClSrpcServiceDtor(NaClSrpcService* service);
     367                 : 
     368                 : /**
     369                 :  *  Prints the methods available from the specified service to stdout.
     370                 :  *  @param service A service.
     371                 :  */
     372                 : void NaClSrpcServicePrint(const NaClSrpcService *service);
     373                 : 
     374                 : /**
     375                 :  *  Obtains the count of methods exported by the service.
     376                 :  *  @param service The service to be examined.
     377                 :  *  @return The number of methods exported by the service.
     378                 :  */
     379                 : uint32_t NaClSrpcServiceMethodCount(const NaClSrpcService *service);
     380                 : 
     381                 : 
     382                 : #define kNaClSrpcInvalidMethodIndex ((uint32_t) ~0)
     383                 : /**
     384                 :  *  Obtains the index of the specified RPC name.
     385                 :  *  @param service The service to be searched.
     386                 :  *  @param signature The exported signature of the method.
     387                 :  *  @return A non-negative index if the name was found in the channel's set of
     388                 :  *  methods.  If the name was not found, it returns kNaClSrpcInvalidMethodIndex.
     389                 :  */
     390                 : uint32_t NaClSrpcServiceMethodIndex(const NaClSrpcService *service,
     391                 :                                     char const *signature);
     392                 : 
     393                 : /**
     394                 :  *  Obtains the name, input types, and output types of the specified RPC
     395                 :  *  number.
     396                 :  *  @param service The service to be searched.
     397                 :  *  @param rpc_number The number of the rpc to be looked up.
     398                 :  *  @param name The exported name of the method.
     399                 :  *  @param input_types The types of the inputs of the method.
     400                 :  *  @param output_types The types of the outputs of the method.
     401                 :  *  @return On success, 1; on failure, 0.
     402                 :  */
     403                 : extern int NaClSrpcServiceMethodNameAndTypes(const NaClSrpcService* service,
     404                 :                                              uint32_t rpc_number,
     405                 :                                              const char** name,
     406                 :                                              const char** input_types,
     407                 :                                              const char** output_types);
     408                 : 
     409                 : /**
     410                 :  *  Obtains the function pointer used to handle invocations of a given
     411                 :  *  method number.
     412                 :  *  @param service The service to be searched.
     413                 :  *  @param rpc_number The number of the rpc to be looked up.
     414                 :  *  @return On success, a pointer to the handler; on failure, NULL.
     415                 :  */
     416                 : extern NaClSrpcMethod NaClSrpcServiceMethod(const NaClSrpcService* service,
     417                 :                                             uint32_t rpc_number);
     418                 : 
     419                 : /**
     420                 :  * The encapsulation of all the data necessary for an RPC connection,
     421                 :  * either client or server.
     422                 :  */
     423                 : struct NaClSrpcChannel {
     424                 :   /** A pointer to the message channel used to send and receive RPCs */
     425                 :   struct NaClSrpcMessageChannel *message_channel;
     426                 :   /**
     427                 :    * The services implemented by this server.
     428                 :    */
     429                 :   NaClSrpcService               *server;
     430                 :   /**
     431                 :    * The services available to this client.
     432                 :    */
     433                 :   NaClSrpcService               *client;
     434                 :   /**
     435                 :    * A pointer to channel-specific data.  This allows RPC method
     436                 :    * implementations to be used across multiple services while still
     437                 :    * maintaining reentrancy
     438                 :    */
     439                 :   void                          *server_instance_data;
     440                 : };
     441                 : 
     442                 : /**
     443                 :  *  A typedef for struct NaClSrpcChannel for use in C.
     444                 :  */
     445                 : typedef struct NaClSrpcChannel NaClSrpcChannel;
     446                 : 
     447                 : /**
     448                 :  *  Initialize an SRPC channel so that its pointers are NULL.  This makes it
     449                 :  *  safe to call a Dtor on the channel, even if the Ctor has not been called.
     450                 :  */
     451                 : void NaClSrpcChannelInitialize(NaClSrpcChannel* channel);
     452                 : 
     453                 : /**
     454                 :  *  Constructs an SRPC client object communicating over an IMC descriptor.
     455                 :  *  Clients issue RPC requests and receive responses.
     456                 :  *  @param channel The channel descriptor to be constructed.
     457                 :  *  @param imc_desc The NaClSrpcImcDescType describing the IMC channel to
     458                 :  *  communicate over.
     459                 :  *  @return On success, 1; on failure, 0.
     460                 :  */
     461                 : int NaClSrpcClientCtor(NaClSrpcChannel *channel, NaClSrpcImcDescType imc_desc);
     462                 : 
     463                 : /**
     464                 :  *  Constructs an SRPC server object communicating over an IMC descriptor.
     465                 :  *  Servers wait for RPC requests, dispatch them to implementations, and return
     466                 :  *  responses.
     467                 :  *  @param channel The channel descriptor to be constructed.
     468                 :  *  @param imc_desc The NaClSrpcImcDescType describing the IMC channel to
     469                 :  *  communicate over.
     470                 :  *  @param service A NaClSrpcService structure describing the service
     471                 :  *  handled by this server.
     472                 :  *  @param instance_data A value to be stored on the channel descriptor
     473                 :  *  for conveying data specific to this particular server instance.
     474                 :  *  @return On success, 1; on failure, 0.
     475                 :  */
     476                 : int NaClSrpcServerCtor(NaClSrpcChannel           *channel,
     477                 :                        NaClSrpcImcDescType       imc_desc,
     478                 :                        NaClSrpcService           *service,
     479                 :                        void*                     instance_data);
     480                 : 
     481                 : /**
     482                 :  *  Destroys the specified client or server channel.
     483                 :  *  @param channel The channel to be destroyed.
     484                 :  */
     485                 : void NaClSrpcDtor(NaClSrpcChannel *channel);
     486                 : 
     487                 : /**
     488                 :  *  Runs an SRPC receive-dispatch-respond loop on the specified
     489                 :  *  NaClSrpcImcDescType object.
     490                 :  *  @param imc_socket_desc A NaClSrpcImcDescType object that RPCs will
     491                 :  *  communicate over.
     492                 :  *  @param methods An array of NaClSrpcHandlerDesc structures
     493                 :  *  describing the set of services handled by this server.
     494                 :  *  @param instance_data A value to be stored on the channel
     495                 :  *  descriptor for conveying data specific to this particular server
     496                 :  *  instance.
     497                 :  *  @return On success, 1; on failure, 0.
     498                 :  */
     499                 : int NaClSrpcServerLoop(NaClSrpcImcDescType              imc_socket_desc,
     500                 :                        const struct NaClSrpcHandlerDesc methods[],
     501                 :                        void                             *instance_data);
     502                 : 
     503                 : /**
     504                 :  *  Initializes the SRPC module.
     505                 :  *  @return Returns one on success, zero otherwise.
     506                 :  */
     507                 : int NaClSrpcModuleInit();
     508                 : 
     509                 : /**
     510                 :  *  Shuts down the SRPC module.
     511                 :  */
     512                 : void NaClSrpcModuleFini();
     513                 : 
     514                 : /**
     515                 :  *  @serverSrpc Waits for a connection from a client.  When a client
     516                 :  *  connects, the server starts responding to RPC requests.
     517                 :  *  @param methods The array of methods exported.
     518                 :  *  @return Returns one on success, zero otherwise.
     519                 :  */
     520                 : int NaClSrpcAcceptClientConnection(const struct NaClSrpcHandlerDesc *methods);
     521                 : 
     522                 : /**
     523                 :  *  @serverSrpc Waits for a connection from a client.  When a client
     524                 :  *  connects, spawns a new thread with a server responding to RPC requests.
     525                 :  *  @param methods The array of methods exported.
     526                 :  *  @return Returns one on success, zero otherwise.
     527                 :  */
     528                 : int NaClSrpcAcceptClientOnThread(const struct NaClSrpcHandlerDesc *methods);
     529                 : 
     530                 : /**
     531                 :  *  @clientSrpc Invokes a specified RPC on the given channel.  Parameters
     532                 :  *  are passed by stdarg conventions and determined from the types specified
     533                 :  *  in the method tables.
     534                 :  *  @param channel The channel descriptor to use to invoke the RPC.
     535                 :  *  @param rpc_name The name of the RPC to be invoked.
     536                 :  *  @return A NaClSrpcResultCodes indicating success (NACL_SRPC_RESULT_OK)
     537                 :  *  or failure.
     538                 :  *  @see NaClSrpcResultCodes
     539                 :  */
     540                 : extern NaClSrpcError NaClSrpcInvokeBySignature(NaClSrpcChannel  *channel,
     541                 :                                                const char       *rpc_name,
     542                 :                                                ...);
     543                 : /**
     544                 :  *  @clientSrpc  Invokes a specified RPC on the given channel.  Parameters
     545                 :  *  are passed by stdarg conventions and determined from the types specified
     546                 :  *  in the method tables stored in channel.
     547                 :  *  @param channel The channel descriptor to use to invoke the RPC.
     548                 :  *  @param rpc_num The index of the RPC to be invoked.
     549                 :  *  @return A NaClSrpcResultCodes indicating success (NACL_SRPC_RESULT_OK)
     550                 :  *  or failure.
     551                 :  *  @see NaClSrpcResultCodes
     552                 :  */
     553                 : extern NaClSrpcError NaClSrpcInvoke(NaClSrpcChannel  *channel,
     554                 :                                     uint32_t         rpc_num,
     555                 :                                     ...);
     556                 : /**
     557                 :  *  @clientSrpc Invokes a specified RPC on the given channel.  Parameters are
     558                 :  *  passed in arrays and are type-checked against the types specified in the
     559                 :  *  method tables stored in channel.
     560                 :  *  @param channel The channel descriptor to use to invoke the RPC.
     561                 :  *  @param rpc_num The index of the RPC to be invoked.
     562                 :  *  @param args The array of parameter pointers to arguments to be passed in.
     563                 :  *  @param rets The array of parameter pointers to arguments to be returned.
     564                 :  *  @return A NaClSrpcResultCodes indicating success (NACL_SRPC_RESULT_OK)
     565                 :  *  or failure.
     566                 :  *  @see NaClSrpcResultCodes
     567                 :  */
     568                 : extern NaClSrpcError NaClSrpcInvokeV(NaClSrpcChannel *channel,
     569                 :                                      uint32_t        rpc_num,
     570                 :                                      NaClSrpcArg     *args[],
     571                 :                                      NaClSrpcArg     *rets[]);
     572                 : /**
     573                 :  *  @clientSrpc Invokes a specified RPC on the given channel.  Parameters are
     574                 :  *  passed in and returned through pointers to stdargs.  They are type-checked
     575                 :  *  against the types specified in the method tables stored in channel.
     576                 :  *  @param channel The channel descriptor to use to invoke the RPC.
     577                 :  *  @param rpc_num The index of the RPC to be invoked.
     578                 :  *  @param in_va The pointer to stdargs list of arguments to be passed in.
     579                 :  *  @param out_va The pointer to stdargs list of arguments to be returned.
     580                 :  *  @return A NaClSrpcResultCodes indicating success (NACL_SRPC_RESULT_OK)
     581                 :  *  or failure.
     582                 :  *  @see NaClSrpcResultCodes
     583                 :  */
     584                 : extern NaClSrpcError NaClSrpcInvokeVaList(NaClSrpcChannel *channel,
     585                 :                                         uint32_t          rpc_num,
     586                 :                                         va_list           in_va,
     587                 :                                         va_list           out_va);
     588                 : 
     589                 : /**
     590                 :  * The current protocol (version) number used to send and receive RPCs.
     591                 :  */
     592                 : static const uint32_t kNaClSrpcProtocolVersion = 0xc0da0002;
     593                 : 
     594                 : /**
     595                 :  * Send an RPC request on the given channel.
     596                 :  */
     597                 : extern int NaClSrpcRequestWrite(NaClSrpcChannel* channel,
     598                 :                                 NaClSrpcRpc* rpc,
     599                 :                                 NaClSrpcArg* args[],
     600                 :                                 NaClSrpcArg* rets[]);
     601                 : 
     602                 : /**
     603                 :  * Wait for a sent RPC to receive a response.
     604                 :  */
     605                 : extern void NaClSrpcRpcWait(NaClSrpcChannel* channel,
     606                 :                             NaClSrpcRpc* rpc);
     607                 : 
     608                 : /**
     609                 :  *  @serverSrpc  Returns whether the srpc server is being run "standalone";
     610                 :  *  that is, not as a subprocess of sel_universal, the browser plugin, etc.
     611                 :  */
     612                 : int NaClSrpcIsStandalone();
     613                 : 
     614                 : /**
     615                 :  * Runs a text-based interpreter given a list of SRPC methods.  This
     616                 :  * calls NaClSrpcCommandLoop().
     617                 :  * @return Returns zero on success, non-zero otherwise.
     618                 :  */
     619                 : int NaClSrpcCommandLoopMain(const struct NaClSrpcHandlerDesc *methods);
     620                 : 
     621                 : EXTERN_C_END
     622                 : 
     623                 : /**
     624                 :  * @}
     625                 :  * End of System Calls group
     626                 :  */
     627                 : 
     628                 : #endif  /* NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ */

Generated by: LCOV version 1.7