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

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

rtai: convert to vfile

---

 include/rtai/Makefile.am |    1 -
 include/rtai/Makefile.in |    1 -
 ksrc/skins/rtai/fifo.c   |   78 ++++++++++++++++++++++++++------------------
 ksrc/skins/rtai/module.c |    9 +----
 ksrc/skins/rtai/shm.c    |   81 +++++++++++++++++++++++++++-------------------
 5 files changed, 95 insertions(+), 75 deletions(-)

diff --git a/include/rtai/Makefile.am b/include/rtai/Makefile.am
index 4976589..75bb86a 100644
--- a/include/rtai/Makefile.am
+++ b/include/rtai/Makefile.am
@@ -8,7 +8,6 @@ includesub_HEADERS = \
        rtai_fifos.h \
        rtai_hal.h \
        rtai_nam2num.h \
-       rtai_proc_fs.h \
        rtai_sched.h \
        rtai_sem.h \
        rtai_shm.h \
diff --git a/include/rtai/Makefile.in b/include/rtai/Makefile.in
index 2f525d0..1379296 100644
--- a/include/rtai/Makefile.in
+++ b/include/rtai/Makefile.in
@@ -233,7 +233,6 @@ includesub_HEADERS = \
        rtai_fifos.h \
        rtai_hal.h \
        rtai_nam2num.h \
-       rtai_proc_fs.h \
        rtai_sched.h \
        rtai_sem.h \
        rtai_shm.h \
diff --git a/ksrc/skins/rtai/fifo.c b/ksrc/skins/rtai/fifo.c
index d2724ff..7ce79a7 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_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_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_snapshot __fifo_pnode = {
+       .node = {
+               .dirname = "fifo",
+               .root = &__rtai_ptree,
+               .ops = &xnregistry_vfsnap_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .ops = &vfile_ops,
+       },
 };
 
 #else /* !CONFIG_PROC_FS */
 
-static xnpnode_t __fifo_pnode = {
-
-       .type = "fifo"
+static struct xnpnode_snapshot __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..72f16d9 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_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_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_snapshot __shm_pnode = {
+       .node = {
+               .dirname = "shm",
+               .root = &__rtai_ptree,
+               .ops = &xnregistry_vfsnap_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .ops = &vfile_ops,
+       },
+};
 
-static xnpnode_t __shm_pnode = {
+#else /* !CONFIG_PROC_FS */
 
-       .type = "fifo"
+static struct xnpnode_snapshot __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