From 1707b6d708b1bd61c9b2dd97751aa9c5cd76afe4 Mon Sep 17 00:00:00 2001
From: Pawel Szewczyk
Date: Wed, 15 Jul 2015 15:30:13 +0200
Subject: [PATCH] udc: Add consistent backend architecture in udc command
Even if udc command has trivial syntax, backends are handled similarly
to other, bigger commands, just for consistency.
Change-Id: I99392995f859771e1d0f22c1fc04e6a8bf2d15a0
Signed-off-by: Pawel Szewczyk
---
source/base/include/backend.h | 1 +
source/base/src/backend.c | 3 +++
source/udc/CMakeLists.txt | 3 +++
source/udc/include/udc.h | 8 ++++++++
source/udc/src/udc.c | 12 ++++++------
source/udc/src/udc_gadgetd.c | 22 ++++++++++++++++++++++
source/udc/src/udc_libusbg.c | 23 +++++++++++++++++++++++
source/udc/src/udc_not_implemented.c | 28 ++++++++++++++++++++++++++++
8 files changed, 94 insertions(+), 6 deletions(-)
create mode 100644 source/udc/src/udc_gadgetd.c
create mode 100644 source/udc/src/udc_libusbg.c
create mode 100644 source/udc/src/udc_not_implemented.c
diff --git a/source/base/include/backend.h b/source/base/include/backend.h
index de3024d..7aac4f4 100644
--- a/source/base/include/backend.h
+++ b/source/base/include/backend.h
@@ -46,6 +46,7 @@ struct gt_backend {
struct gt_function_backend *function;
struct gt_gadget_backend *gadget;
struct gt_config_backend *config;
+ struct gt_udc_backend *udc;
};
struct gt_backend_ctx {
diff --git a/source/base/src/backend.c b/source/base/src/backend.c
index f672fe6..7ea611f 100644
--- a/source/base/src/backend.c
+++ b/source/base/src/backend.c
@@ -24,6 +24,7 @@
#include "function.h"
#include "gadget.h"
#include "configuration.h"
+#include "udc.h"
struct gt_backend_ctx backend_ctx = {
.backend_type = GT_BACKEND_AUTO,
@@ -33,12 +34,14 @@ struct gt_backend gt_backend_libusbg = {
.function = >_function_backend_libusbg,
.gadget = >_gadget_backend_libusbg,
.config = >_config_backend_libusbg,
+ .udc = >_udc_backend_libusbg,
};
struct gt_backend gt_backend_gadgetd = {
.function = >_function_backend_gadgetd,
.gadget = >_gadget_backend_gadgetd,
.config = >_config_backend_gadgetd,
+ .udc = >_udc_backend_gadgetd,
};
int gt_backend_init(const char *program_name, enum gt_option_flags flags)
diff --git a/source/udc/CMakeLists.txt b/source/udc/CMakeLists.txt
index 041b15f..84daf80 100644
--- a/source/udc/CMakeLists.txt
+++ b/source/udc/CMakeLists.txt
@@ -3,6 +3,9 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
SET( UDC_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/udc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/udc_libusbg.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/udc_gadgetd.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/udc_not_implemented.c
)
add_library(udc STATIC ${UDC_SRC} )
diff --git a/source/udc/include/udc.h b/source/udc/include/udc.h
index 44bb3a1..8438de6 100644
--- a/source/udc/include/udc.h
+++ b/source/udc/include/udc.h
@@ -19,6 +19,10 @@
#include "command.h"
+struct gt_udc_backend {
+ int (*udc)(void *);
+};
+
/**
* @brief Help function which should be used if invalid
* syntax for udc was entered.
@@ -38,4 +42,8 @@ int udc_help_func(void *data);
void udc_parse(const Command *cmd, int argc, char **argv,
ExecutableCommand *exec, void * data);
+extern struct gt_udc_backend gt_udc_backend_libusbg;
+extern struct gt_udc_backend gt_udc_backend_gadgetd;
+extern struct gt_udc_backend gt_udc_backend_not_implemented;
+
#endif //__GADGET_TOOL_UDC_UDC_PARSE_H__
diff --git a/source/udc/src/udc.c b/source/udc/src/udc.c
index 05d5956..a15e7de 100644
--- a/source/udc/src/udc.c
+++ b/source/udc/src/udc.c
@@ -17,12 +17,12 @@
#include
#include "udc.h"
+#include "backend.h"
-static int udc_func(void *data)
-{
- printf("gt udc called successfully. Not implemented yet.\n");
- return 0;
-}
+#define GET_EXECUTABLE(func) \
+ (backend_ctx.backend->udc->func ? \
+ backend_ctx.backend->udc->func : \
+ gt_udc_backend_not_implemented.func)
int udc_help_func(void *data)
{
@@ -35,7 +35,7 @@ void udc_parse(const Command *cmd, int argc, char **argv,
{
if(argc == 0)
// udc should be run without args
- executable_command_set(exec, udc_func, data, NULL);
+ executable_command_set(exec, GET_EXECUTABLE(udc), data, NULL);
else
// Wrong syntax for udc command, let's print help
executable_command_set(exec, cmd->printHelp, data, NULL);
diff --git a/source/udc/src/udc_gadgetd.c b/source/udc/src/udc_gadgetd.c
new file mode 100644
index 0000000..e3be40f
--- /dev/null
+++ b/source/udc/src/udc_gadgetd.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "udc.h"
+#include
+
+struct gt_udc_backend gt_udc_backend_gadgetd = {
+ .udc = NULL,
+};
diff --git a/source/udc/src/udc_libusbg.c b/source/udc/src/udc_libusbg.c
new file mode 100644
index 0000000..38e7ad5
--- /dev/null
+++ b/source/udc/src/udc_libusbg.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "udc.h"
+#include
+
+struct gt_udc_backend gt_udc_backend_libusbg = {
+ .udc = NULL,
+};
diff --git a/source/udc/src/udc_not_implemented.c b/source/udc/src/udc_not_implemented.c
new file mode 100644
index 0000000..04fe6f5
--- /dev/null
+++ b/source/udc/src/udc_not_implemented.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include "udc.h"
+
+static int udc_func(void *data)
+{
+ printf("gt udc called successfully. Not implemented yet.\n");
+ return 0;
+}
+
+struct gt_udc_backend gt_udc_backend_not_implemented = {
+ .udc = udc_func,
+};
--
2.7.4