struct gt_function_backend *function;
struct gt_gadget_backend *gadget;
struct gt_config_backend *config;
+ struct gt_udc_backend *udc;
};
struct gt_backend_ctx {
#include "function.h"
#include "gadget.h"
#include "configuration.h"
+#include "udc.h"
struct gt_backend_ctx backend_ctx = {
.backend_type = GT_BACKEND_AUTO,
.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)
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} )
#include "command.h"
+struct gt_udc_backend {
+ int (*udc)(void *);
+};
+
/**
* @brief Help function which should be used if invalid
* syntax for udc was entered.
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__
#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)
{
{
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);
--- /dev/null
+/*
+ * 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,
+};
--- /dev/null
+/*
+ * 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,
+};
--- /dev/null
+/*
+ * 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,
+};