Add direct and dummy RPC caller
Adds two types of RPC caller for testing purposes.
Change-Id: Icba23859ed9db5dc96832b10a985dc670830c4ab
Signed-off-by: Julian Hall <julian.hall@arm.com>
diff --git a/components/rpc/dummy/component.cmake b/components/rpc/dummy/component.cmake
new file mode 100644
index 0000000..19da9de
--- /dev/null
+++ b/components/rpc/dummy/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/dummy_caller.c"
+ )
diff --git a/components/rpc/dummy/dummy_caller.c b/components/rpc/dummy/dummy_caller.c
new file mode 100644
index 0000000..6d40b80
--- /dev/null
+++ b/components/rpc/dummy/dummy_caller.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "dummy_caller.h"
+#include <stdlib.h>
+
+static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
+static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
+ int *opstatus, uint8_t **resp_buf, size_t *resp_len);
+static void call_end(void *context, rpc_call_handle handle);
+
+
+struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
+ rpc_status_t rpc_status, int opstatus)
+{
+ struct rpc_caller *base = &s->rpc_caller;
+
+ base->context = s;
+ base->call_begin = call_begin;
+ base->call_invoke = call_invoke;
+ base->call_end = call_end;
+
+ s->rpc_status = rpc_status;
+ s->opstatus = opstatus;
+ s->req_buf = NULL;
+
+ return base;
+}
+
+void dummy_caller_deinit(struct dummy_caller *s)
+{
+ free(s->req_buf);
+ s->req_buf = NULL;
+}
+
+static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len)
+{
+ struct dummy_caller *this_context = (struct dummy_caller*)context;
+ rpc_call_handle handle = this_context;
+
+ free(this_context->req_buf);
+ this_context->req_buf = malloc(req_len);
+ *req_buf = this_context->req_buf;
+
+ return handle;
+}
+
+static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
+ int *opstatus, uint8_t **resp_buf, size_t *resp_len)
+{
+ struct dummy_caller *this_context = (struct dummy_caller*)context;
+
+ free(this_context->req_buf);
+ this_context->req_buf = NULL;
+
+ *resp_buf = NULL;
+ *resp_len = 0;
+ *opstatus = this_context->opstatus;
+
+ return this_context->rpc_status;
+}
+
+static void call_end(void *context, rpc_call_handle handle)
+{
+ (void)context;
+ (void)handle;
+}
diff --git a/components/rpc/dummy/dummy_caller.h b/components/rpc/dummy/dummy_caller.h
new file mode 100644
index 0000000..215d293
--- /dev/null
+++ b/components/rpc/dummy/dummy_caller.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef DUMMY_CALLER
+#define DUMMY_CALLER
+
+#include <rpc_caller.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * An rpc_caller that is used to return a suitable permanent status
+ * code if an attempt is made to invoke a remote method where an
+ * end-to-end rpc session has failed to be established. Intended
+ * to be used when a session with a real rpc endpoint cant't be
+ * established but a client doesn't wish to treat the condition
+ * as a fatal error.
+ */
+struct dummy_caller
+{
+ struct rpc_caller rpc_caller;
+ rpc_status_t rpc_status;
+ int opstatus;
+ uint8_t *req_buf;
+};
+
+struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
+ rpc_status_t rpc_status, int opstatus);
+void dummy_caller_deinit(struct dummy_caller *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DUMMY_CALLER */