udc: Add consistent backend architecture in udc command
authorPawel Szewczyk <p.szewczyk@samsung.com>
Wed, 15 Jul 2015 13:30:13 +0000 (15:30 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 28 Jul 2015 16:07:11 +0000 (18:07 +0200)
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 <p.szewczyk@samsung.com>
source/base/include/backend.h
source/base/src/backend.c
source/udc/CMakeLists.txt
source/udc/include/udc.h
source/udc/src/udc.c
source/udc/src/udc_gadgetd.c [new file with mode: 0644]
source/udc/src/udc_libusbg.c [new file with mode: 0644]
source/udc/src/udc_not_implemented.c [new file with mode: 0644]

index de3024d..7aac4f4 100644 (file)
@@ -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 {
index f672fe6..7ea611f 100644 (file)
@@ -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 = &gt_function_backend_libusbg,
        .gadget = &gt_gadget_backend_libusbg,
        .config = &gt_config_backend_libusbg,
+       .udc = &gt_udc_backend_libusbg,
 };
 
 struct gt_backend gt_backend_gadgetd = {
        .function = &gt_function_backend_gadgetd,
        .gadget = &gt_gadget_backend_gadgetd,
        .config = &gt_config_backend_gadgetd,
+       .udc = &gt_udc_backend_gadgetd,
 };
 
 int gt_backend_init(const char *program_name, enum gt_option_flags flags)
index 041b15f..84daf80 100644 (file)
@@ -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} )
index 44bb3a1..8438de6 100644 (file)
 
 #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__
index 05d5956..a15e7de 100644 (file)
 #include <stdio.h>
 
 #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 (file)
index 0000000..e3be40f
--- /dev/null
@@ -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 <stdlib.h>
+
+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 (file)
index 0000000..38e7ad5
--- /dev/null
@@ -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 <stdlib.h>
+
+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 (file)
index 0000000..04fe6f5
--- /dev/null
@@ -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 <stdio.h>
+#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,
+};