qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 2/9] net: introduce one net host device class


From: zwu . kernel
Subject: [Qemu-devel] [RFC 2/9] net: introduce one net host device class
Date: Mon, 26 Mar 2012 13:40:16 +0800

From: Zhi Yong Wu <address@hidden>

Signed-off-by: Zhi Yong Wu <address@hidden>
---
 net.c |   35 +++++++++++++++++++++++++++++++++++
 net.h |   27 +++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index dd67d16..608c090 100644
--- a/net.c
+++ b/net.c
@@ -1231,3 +1231,38 @@ int net_client_parse(QemuOptsList *opts_list, const char 
*optarg)
     default_net = 0;
     return 0;
 }
+
+static int net_dev_init(HOSTDevice *host_dev)
+{
+    NETDevice *net_dev = NET_DEVICE(host_dev);
+    NETDeviceClass *dc = NETDEV_GET_CLASS(host_dev);
+
+    if (dc->init) {
+        return dc->init(net_dev);
+    }
+
+    return 0;
+}
+
+static void net_class_init(ObjectClass *klass, void *data)
+{
+
+    HOSTDeviceClass *k = HOSTDEV_CLASS(klass);
+
+    k->init = net_dev_init;
+}
+
+static TypeInfo net_type = {
+    .name          = TYPE_NETDEV,
+    .parent        = TYPE_HOSTDEV,
+    .instance_size = sizeof(NETDevice),
+    .class_init    = net_class_init,
+};
+
+static void net_register_types(void)
+{
+    type_register_static(&net_type);
+}
+
+type_init(net_register_types)
+
diff --git a/net.h b/net.h
index 60837ab..912fa2d 100644
--- a/net.h
+++ b/net.h
@@ -7,6 +7,33 @@
 #include "qemu-option.h"
 #include "net/queue.h"
 #include "vmstate.h"
+#include "qemu/hostdev.h"
+
+typedef struct NETDevice NETDevice;
+
+#define TYPE_NETDEV "net-dev"
+#define NET_DEVICE(obj) \
+     OBJECT_CHECK(NETDevice, (obj), TYPE_NETDEV)
+#define NETDEV_CLASS(klass) \
+     OBJECT_CLASS_CHECK(NETDeviceClass, (klass), TYPE_NETDEV)
+#define NETDEV_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(NETDeviceClass, (obj), TYPE_NETDEV)
+
+typedef struct NETDeviceClass {
+    HOSTDeviceClass parent_class;
+    int (*init)(NETDevice *net_dev);
+} NETDeviceClass;
+
+struct NETDevice {
+    /*< private >*/
+    HOSTDevice host_dev;
+
+    /*< public >*/
+    QemuOpts *opts;
+    Monitor *mon;
+    const char *name;
+    NetClientState *peer;
+};
 
 struct MACAddr {
     uint8_t a[6];
-- 
1.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]