Module: xenomai-rpm
Branch: queue/vfile
Commit: 269bf7db68d667eca7ae672f21a970d58fb46c5c
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=269bf7db68d667eca7ae672f21a970d58fb46c5c

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jun  7 19:41:15 2010 +0200

rtai: convert to vfile

---

 ksrc/skins/rtai/fifo.c   |   78 ++++++++++++++++++++++++++------------------
 ksrc/skins/rtai/module.c |    9 +----
 ksrc/skins/rtai/shm.c    |   81 +++++++++++++++++++++++++++-------------------
 3 files changed, 95 insertions(+), 73 deletions(-)

diff --git a/ksrc/skins/rtai/fifo.c b/ksrc/skins/rtai/fifo.c
index d2724ff..49d6f27 100644
--- a/ksrc/skins/rtai/fifo.c
+++ b/ksrc/skins/rtai/fifo.c
@@ -27,49 +27,63 @@ static RT_FIFO __fifo_table[CONFIG_XENO_OPT_PIPE_NRDEV];
 
 #ifdef CONFIG_PROC_FS
 
-extern xnptree_t __rtai_ptree;
+struct vfile_priv {
+       size_t bufsz;
+       size_t fillsz;
+       void *handler;
+       int refcnt;
+};
 
-static int __fifo_read_proc(char *page,
-                           char **start,
-                           off_t off, int count, int *eof, void *data)
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
 {
-       RT_FIFO *p = data;
-       char *ptrW = page;
-       int len;
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       RT_FIFO *fifo = xnvfile_priv(it->vfile);
+
+       priv->bufsz = fifo->bufsz;
+       priv->fillsz = fifo->fillsz;
+       priv->handler = fifo->handler;
+       priv->refcnt = fifo->refcnt;
+
+       return 0;
+}
 
-       ptrW += sprintf(ptrW, "Size     - Written  - F - Handler  - Ref\n");
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
 
+       xnvfile_printf(it, "Size     - Written  - F - Handler  - Ref\n");
        /* Output buffer:  xnpipe_mh_t *buffer; */
-       ptrW += sprintf(ptrW, "%08zX - %08zX - %p - %i\n",
-                       p->bufsz, p->fillsz, p->handler, p->refcnt);
-
-       len = ptrW - page - off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-
-       return len;
+       xnvfile_printf(it, "%08zX - %08zX - %p - %i\n",
+                      priv->bufsz, priv->fillsz, priv->handler, priv->refcnt);
+
+       return 0;
 }
 
-static xnpnode_t __fifo_pnode = {
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .show = vfile_show,
+};
 
-       .dir = NULL,
-       .type = "fifo",
-       .entries = 0,
-       .read_proc = &__fifo_read_proc,
-       .write_proc = NULL,
-       .root = &__rtai_ptree,
+extern struct xnptree __rtai_ptree;
+
+static struct xnpnode_file __fifo_pnode = {
+       .node = {
+               .dirname = "fifo",
+               .root = &__rtai_ptree,
+               .ops = &xnregistry_vfile_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .ops = &vfile_ops,
+       },
 };
 
 #else /* !CONFIG_PROC_FS */
 
-static xnpnode_t __fifo_pnode = {
-
-       .type = "fifo"
+static struct xnpnode_file __fifo_pnode = {
+       .node = {
+               .dirname = "fifo",
+       },
 };
 
 #endif /* !CONFIG_PROC_FS */
@@ -240,7 +254,7 @@ int rtf_create(unsigned minor, int size)
 
        fifo->handle = 0;
        snprintf(fifo->name, sizeof(fifo->name), "rtf%u", minor);
-       xnregistry_enter(fifo->name, fifo, &fifo->handle, &__fifo_pnode);
+       xnregistry_enter(fifo->name, fifo, &fifo->handle, &__fifo_pnode.node);
 
        return minor;
 
diff --git a/ksrc/skins/rtai/module.c b/ksrc/skins/rtai/module.c
index 13367b5..32e35bb 100644
--- a/ksrc/skins/rtai/module.c
+++ b/ksrc/skins/rtai/module.c
@@ -42,14 +42,7 @@ MODULE_PARM_DESC(sync_time, "Set non-zero to synchronize on 
master time base");
 
 xntbase_t *rtai_tbase;
 
-#ifdef CONFIG_PROC_FS
-xnptree_t __rtai_ptree = {
-
-       .dir = NULL,
-       .name = "rtai",
-       .entries = 0,
-};
-#endif /* CONFIG_PROC_FS */
+DEFINE_XNPTREE(__rtai_ptree, "rtai");
 
 static void rtai_shutdown(int xtype)
 {
diff --git a/ksrc/skins/rtai/shm.c b/ksrc/skins/rtai/shm.c
index 96b7ae1..9c1c026 100644
--- a/ksrc/skins/rtai/shm.c
+++ b/ksrc/skins/rtai/shm.c
@@ -55,47 +55,62 @@ xnqueue_t xnshm_allocq;
 
 #ifdef CONFIG_PROC_FS
 
-extern xnptree_t __rtai_ptree;
+struct vfile_priv {
+       int size;
+       char szName[6];
+       unsigned long name;
+       unsigned int refcnt;
+};
 
-static int __shm_read_proc(char *page,
-                          char **start,
-                          off_t off, int count, int *eof, void *data)
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
 {
-       xnshm_a_t *p = data;
-       char *ptrW = page;
-       int len;
-
-       ptrW += sprintf(ptrW, "Name   - Ptr      - Size     - Ref\n");
-       ptrW += sprintf(ptrW, "%s - %08lX - %08X - %i\n",
-                       p->szName, p->name, p->size, p->ref);
-
-       len = ptrW - page - off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-
-       return len;
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       xnshm_a_t *shm = xnvfile_priv(it->vfile);
+
+       priv->size = shm->size;
+       memcpy(priv->szName, shm->szName, sizeof(priv->szName));
+       priv->name = shm->name;
+       priv->refcnt = shm->ref;
+
+       return 0;
 }
 
-static xnpnode_t __shm_pnode = {
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
 
-       .dir = NULL,
-       .type = "shm",
-       .entries = 0,
-       .read_proc = &__shm_read_proc,
-       .write_proc = NULL,
-       .root = &__rtai_ptree,
+       xnvfile_printf(it, "Name   - Ptr      - Size     - Ref\n");
+       xnvfile_printf(it, "%s - %08lX - %08X - %i\n",
+                      priv->szName, priv->name, priv->size, priv->refcnt);
+
+       return 0;
+}
+
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .show = vfile_show,
 };
 
-#else /* !CONFIG_PROC_FS */
+extern struct xnptree __rtai_ptree;
+
+static struct xnpnode_file __shm_pnode = {
+       .node = {
+               .dirname = "shm",
+               .root = &__rtai_ptree,
+               .ops = &xnregistry_vfile_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .ops = &vfile_ops,
+       },
+};
 
-static xnpnode_t __shm_pnode = {
+#else /* !CONFIG_PROC_FS */
 
-       .type = "fifo"
+static struct xnpnode_file __shm_pnode = {
+       .node = {
+               .dirname = "shm",
+       },
 };
 
 #endif /* !CONFIG_PROC_FS */
@@ -236,7 +251,7 @@ void *_shm_alloc(unsigned long name, int size, int suprt, 
int in_kheap,
 
        p->handle = 0;
        num2nam(p->name, p->szName);
-       xnregistry_enter(p->szName, p, &p->handle, &__shm_pnode);
+       xnregistry_enter(p->szName, p, &p->handle, &__shm_pnode.node);
 
        ret = p->chunk;
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to