Extend RPC parameters
The RPC model is extended to include parameters for identifying
an RPC interface instance at an endpoint and another for
identifying the parameter encoding. The interface ID parameter
allows multiple service interfaces to be co-located. The encoding
parameter allows clients to use different parameter serialization
schemes and to specify the format in each RPC request.
Signed-off-by: julhal01 <julian.hall@arm.com>
Change-Id: I201b3417dc0e9f655113b9931db3494e41f1d74b
diff --git a/components/rpc/common/caller/rpc_caller.c b/components/rpc/common/caller/rpc_caller.c
index 4fd1e5a..00b559c 100644
--- a/components/rpc/common/caller/rpc_caller.c
+++ b/components/rpc/common/caller/rpc_caller.c
@@ -1,11 +1,25 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <rpc_caller.h>
#include <stdint.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
+
+void rpc_caller_init(struct rpc_caller *s, void *context)
+{
+ s->context = context;
+
+ /* The default encoding scheme - may be overridden by a client */
+ s->encoding = TS_RPC_ENCODING_PACKED_C;
+}
+
+void rpc_caller_set_encoding_scheme(struct rpc_caller *s, uint32_t encoding)
+{
+ s->encoding = encoding;
+}
rpc_call_handle rpc_caller_begin(struct rpc_caller *s,
uint8_t **req_buf, size_t req_len)
diff --git a/components/rpc/common/endpoint/call_ep.h b/components/rpc/common/endpoint/rpc_interface.h
similarity index 65%
rename from components/rpc/common/endpoint/call_ep.h
rename to components/rpc/common/endpoint/rpc_interface.h
index 1b5d03d..44e5783 100644
--- a/components/rpc/common/endpoint/call_ep.h
+++ b/components/rpc/common/endpoint/rpc_interface.h
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#ifndef CALL_EP_H
-#define CALL_EP_H
+#ifndef RPC_INTERFACE_H
+#define RPC_INTERFACE_H
#include <stddef.h>
#include <stdint.h>
@@ -51,16 +51,6 @@
return v;
}
-/** \brief Serializer for handling call parameters
- *
- * An abstract serializer pointer, used for attaching a concrete
- * serializer to a call request for serializing/deserializing call
- * parameters. The strategy for selecting an appropriate serializer
- * could be hard-coded or dynamic, based on a content type identifier
- * carried by a concrete rpc.
- */
-typedef const void* call_param_serializer_ptr;
-
/** \brief Call request
*
* A call request object represents a request from a client that will
@@ -68,9 +58,10 @@
*/
struct call_req {
uint32_t caller_id;
+ uint32_t interface_id;
uint32_t opcode;
+ uint32_t encoding;
int opstatus;
- call_param_serializer_ptr serializer;
struct call_param_buf req_buf;
struct call_param_buf resp_buf;
};
@@ -80,11 +71,21 @@
return req->caller_id;
}
+static inline uint32_t call_req_get_interface_id(const struct call_req *req)
+{
+ return req->interface_id;
+}
+
static inline uint32_t call_req_get_opcode(const struct call_req *req)
{
return req->opcode;
}
+static inline uint32_t call_req_get_encoding(const struct call_req *req)
+{
+ return req->encoding;
+}
+
static inline int call_req_get_opstatus(const struct call_req *req)
{
return req->opstatus;
@@ -95,11 +96,6 @@
req->opstatus = opstatus;
}
-static inline call_param_serializer_ptr call_req_get_serializer(const struct call_req *req)
-{
- return req->serializer;
-}
-
static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req)
{
return &req->req_buf;
@@ -110,25 +106,25 @@
return &req->resp_buf;
}
-/** \brief Call endpoint
+/** \brief RPC interface
*
- * A generalized call endpoint. Provides a standard interface for a
+ * A generalized RPC interface. Provides a standard interface for a
* call endpoint that handles incoming call requests.
*/
-struct call_ep
+struct rpc_interface
{
void *context;
- rpc_status_t (*receive)(struct call_ep *ep, struct call_req *req);
+ rpc_status_t (*receive)(struct rpc_interface *iface, struct call_req *req);
};
-static inline rpc_status_t call_ep_receive(struct call_ep *ep,
+static inline rpc_status_t rpc_interface_receive(struct rpc_interface *iface,
struct call_req *req)
{
- return ep->receive(ep, req);
+ return iface->receive(iface, req);
}
#ifdef __cplusplus
}
#endif
-#endif /* CALL_EP_H */
+#endif /* RPC_INTERFACE_H */
diff --git a/components/rpc/common/interface/rpc_caller.h b/components/rpc/common/interface/rpc_caller.h
index a75bdd9..879d2cb 100644
--- a/components/rpc/common/interface/rpc_caller.h
+++ b/components/rpc/common/interface/rpc_caller.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -36,6 +36,7 @@
struct rpc_caller
{
void *context;
+ uint32_t encoding;
/* A concrete rpc_caller implements these methods */
rpc_call_handle (*call_begin)(void *context, uint8_t **req_buf, size_t req_len);
@@ -47,6 +48,19 @@
};
/*
+ * Called by a concrete rpc_caller to initialise the base rpc_caller.
+ */
+void rpc_caller_init(struct rpc_caller *s, void *context);
+
+/*
+ * Allows a client to specify the parameter encoding scheme that the client
+ * intends to use during an RPC session. It is the client's responsiblity
+ * to choose an encoding scheme that is supported by the remote interface.
+ */
+RPC_CALLER_EXPORTED void rpc_caller_set_encoding_scheme(struct rpc_caller *s,
+ uint32_t encoding);
+
+/*
* Starts a call transaction. The returned handle is an identifier for the
* transaction and must be passed as a parameter to call_invoke() and
* call_end(). A concrete rpc_caller may perform resource allocation during