WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xl: Use command table to store command na

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xl: Use command table to store command name and implementation
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 04 May 2010 13:20:25 -0700
Delivery-date: Tue, 04 May 2010 13:23:10 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1272968886 -3600
# Node ID 35da124fc66a92592395b507bcb25e5b534405f3
# Parent  742311878ae5d32f43480d71b26cdafa68fa03bd
xl: Use command table to store command name and implementation

Signed-off-by: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
---
 tools/libxl/xl.c          |   74 +++++++++++-----------------------------------
 tools/libxl/xl_cmdimpl.c  |    2 -
 tools/libxl/xl_cmdimpl.h  |    2 -
 tools/libxl/xl_cmdtable.h |   46 ++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 57 deletions(-)

diff -r 742311878ae5 -r 35da124fc66a tools/libxl/xl.c
--- a/tools/libxl/xl.c  Tue May 04 11:23:17 2010 +0100
+++ b/tools/libxl/xl.c  Tue May 04 11:28:06 2010 +0100
@@ -29,6 +29,7 @@
 
 #include "libxl.h"
 #include "xl_cmdimpl.h"
+#include "xl_cmdtable.h"
 
 extern struct libxl_ctx ctx;
 extern int logfile;
@@ -43,6 +44,8 @@ void log_callback(void *userdata, int lo
 
 int main(int argc, char **argv)
 {
+    int i;
+
     if (argc < 2) {
         help(NULL);
         exit(1);
@@ -59,60 +62,21 @@ int main(int argc, char **argv)
 
     srand(time(0));
 
-    if (!strcmp(argv[1], "create")) {
-        main_create(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "list")) {
-        main_list(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "list-vm")) {
-        main_list_vm(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "destroy")) {
-        main_destroy(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "pci-attach")) {
-        main_pciattach(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "pci-detach")) {
-        main_pcidetach(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "pci-list")) {
-        main_pcilist(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "pause")) {
-        main_pause(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "unpause")) {
-        main_unpause(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "console")) {
-        main_console(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "save")) {
-        main_save(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "migrate")) {
-        main_migrate(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "restore")) {
-        main_restore(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "migrate-receive")) {
-        main_migrate_receive(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "cd-insert")) {
-        main_cd_insert(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "cd-eject")) {
-        main_cd_eject(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "mem-set")) {
-        main_memset(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "button-press")) {
-        main_button_press(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "vcpu-list")) {
-        main_vcpulist(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "vcpu-pin")) {
-        main_vcpupin(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "vcpu-set")) {
-        main_vcpuset(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "info")) {
-        main_info(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "sched-credit")) {
-        main_sched_credit(argc - 1, argv + 1);
-    } else if (!strcmp(argv[1], "help")) {
-        if (argc > 2)
-            help(argv[2]);
-        else
-            help(NULL);
-        exit(0);
-    } else {
-        fprintf(stderr, "command not implemented\n");
-        exit(1);
+    for (i = 0; i < cmdtable_len; i++) {
+        if (!strcmp(argv[1], cmd_table[i].cmd_name))
+               cmd_table[i].cmd_impl(argc - 1, argv + 1);
+    }
+
+    if (i >= cmdtable_len) {
+        if (!strcmp(argv[1], "help")) {
+            if (argc > 2)
+                help(argv[2]);
+            else
+                help(NULL);
+            exit(0);
+        } else {
+            fprintf(stderr, "command not implemented\n");
+            exit(1);
+        }
     }
 }
diff -r 742311878ae5 -r 35da124fc66a tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue May 04 11:23:17 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue May 04 11:28:06 2010 +0100
@@ -2790,7 +2790,7 @@ static void sched_credit_domain_output(
         scinfo->cap);
 }
 
-void main_sched_credit(int argc, char **argv)
+int main_sched_credit(int argc, char **argv)
 {
     struct libxl_dominfo *info;
     struct libxl_sched_credit scinfo;
diff -r 742311878ae5 -r 35da124fc66a tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h  Tue May 04 11:23:17 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h  Tue May 04 11:28:06 2010 +0100
@@ -34,6 +34,6 @@ int main_vcpupin(int argc, char **argv);
 int main_vcpupin(int argc, char **argv);
 int main_vcpuset(int argc, char **argv);
 int main_memset(int argc, char **argv);
-void main_sched_credit(int argc, char **argv);
+int main_sched_credit(int argc, char **argv);
 
 void help(char *command);
diff -r 742311878ae5 -r 35da124fc66a tools/libxl/xl_cmdtable.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxl/xl_cmdtable.h Tue May 04 11:28:06 2010 +0100
@@ -0,0 +1,46 @@
+/*
+ * Author Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "xl_cmdimpl.h"
+
+struct cmd_spec {
+    char *cmd_name;
+    int (*cmd_impl)(int argc, char **argv);
+};
+
+struct cmd_spec cmd_table[] = {
+    { "create", &main_create },
+    { "list", &main_list },
+    { "destroy", &main_destroy },
+    { "pci-attach", &main_pciattach },
+    { "pci-detach", &main_pcidetach },
+    { "pci-list", &main_pcilist },
+    { "pause", &main_pause },
+    { "unpause", &main_unpause },
+    { "console", &main_console },
+    { "save", &main_save },
+    { "restore", &main_restore },
+    { "cd-insert", &main_cd_insert },
+    { "cd-eject", &main_cd_eject },
+    { "mem-set", &main_memset },
+    { "button-press", &main_button_press },
+    { "vcpu-list", &main_vcpulist },
+    { "vcpu-pin", &main_vcpupin },
+    { "vcpu-set", &main_vcpuset },
+    { "list-vm", &main_list_vm },
+    { "info", &main_info },
+    { "sched-credit", &main_sched_credit },
+};
+
+int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xl: Use command table to store command name and implementation, Xen patchbot-unstable <=