Author: robert
Date: Sat Jun 30 23:20:34 2007
New Revision: 31
Log:
add getversionstr; let unimplemented functions return -1
Modified:
fddi-20070618-1-trunk/include/osadl/fddi.h
fddi-20070618-1-trunk/src/libfddi.c
Modified: fddi-20070618-1-trunk/include/osadl/fddi.h
==============================================================================
--- fddi-20070618-1-trunk/include/osadl/fddi.h (original)
+++ fddi-20070618-1-trunk/include/osadl/fddi.h Sat Jun 30 23:20:34 2007
@@ -1,3 +1,24 @@
+/*
+ * Copyright (C) 2007 Robert Schwebel <r.schwebel at pengutronix.de>
+ *
+ * This file is part of the OSADL Fieldbus Framework.
+ *
+ * The OSADL Fieldbus Framework is free software; you can redistribute it
+ * and/or modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation. Note that there
+ * is a special link exception; see COPYING for details.
+ *
+ * The OSADL Fieldbus Framework 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 General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the OSADL Fieldbus Framework; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA.
+ */
+
#ifndef OSADL_FDDI_H
#define OSADL_FDDI_H
@@ -80,8 +101,7 @@
struct fddi_iface {
- char *name; /* FIXME: add access functions */
- unsigned long version; /* FIXME: auto generate from configure.ac */
+ char *name;
fddi_state_enum_t state;
fddi_device_t *devlist_head;
fddi_tpu_t *tpulist_head;
@@ -102,11 +122,15 @@
extern int fddi_iface_readconfig(fddi_iface_t *iface, const char *configfile);
extern int fddi_iface_setstate(fddi_iface_t *iface, fddi_state_enum_t state);
extern int fddi_iface_cmd(fddi_iface_t *iface, fddi_cmd_enum_t cmd);
+extern int fddi_iface_getname(fddi_iface_t *iface, char *name, size_t len);
+extern int fddi_iface_setname(fddi_iface_t *iface, char *name);
extern int fddi_iface_getnodev(fddi_iface_t *iface);
extern int fddi_iface_getnotpus(fddi_iface_t *iface);
extern int fddi_iface_getnopvs(fddi_iface_t *iface);
extern int fddi_iface_getdevlist(fddi_iface_t *iface, fddi_device_t **dev);
extern int fddi_iface_gettpulist(fddi_iface_t *iface, fddi_tpu_t **tpu);
+extern int fddi_iface_getversionstr(fddi_iface_t *iface, const char **version);
+extern int fddi_iface_getversion(fddi_iface_t *iface, int *version);
/* fddi_device_t */
extern int fddi_dev_getnext(fddi_device_t **dev);
Modified: fddi-20070618-1-trunk/src/libfddi.c
==============================================================================
--- fddi-20070618-1-trunk/src/libfddi.c (original)
+++ fddi-20070618-1-trunk/src/libfddi.c Sat Jun 30 23:20:34 2007
@@ -1,13 +1,37 @@
+/*
+ * Copyright (C) 2007 Robert Schwebel <r.schwebel at pengutronix.de>
+ *
+ * This file is part of the OSADL Fieldbus Framework.
+ *
+ * The OSADL Fieldbus Framework is free software; you can redistribute it
+ * and/or modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation. Note that there
+ * is a special link exception; see COPYING for details.
+ *
+ * The OSADL Fieldbus Framework 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 General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the OSADL Fieldbus Framework; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA.
+ */
+
#include <errno.h>
#include <ltdl.h>
#include <pthread.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <osadl/fddi.h>
+#include <fddi_config.h>
static pthread_mutex_t lt_dl_mutex = PTHREAD_MUTEX_INITIALIZER;
+const char fddi_version_str[] = VERSION;
/* fddi_iface_attr_t */
int fddi_iface_attr_init(fddi_iface_attr_t *attr)
@@ -52,8 +76,7 @@
return EINVAL;
/* initialize instance variables */
- iface->devlist_head = NULL;
- iface->tpulist_head = NULL;
+ memset(iface, 0, sizeof(fddi_iface_t));
/* attach to backend library */
@@ -101,7 +124,7 @@
pthread_mutex_lock(<_dl_mutex);
lt_dlclose(iface->backend_lib);
pthread_mutex_unlock(<_dl_mutex);
- return EINVAL; // FIXME
+ return EINVAL; /* FIXME better retval? */
}
int fddi_iface_destroy(fddi_iface_t *iface)
@@ -109,6 +132,9 @@
if (!iface)
return EINVAL;
+ if (iface->name != NULL)
+ free(iface->name);
+
pthread_mutex_lock(<_dl_mutex);
lt_dlclose(iface->backend_lib);
pthread_mutex_unlock(<_dl_mutex);
@@ -149,28 +175,55 @@
return iface->backend.cmd(iface, cmd);
}
+int fddi_iface_getname(fddi_iface_t *iface, char *name, size_t len)
+{
+ if ((!iface) || (!name))
+ return EINVAL;
+
+ strncpy(name, iface->name, len);
+
+ return 0;
+}
+
+int fddi_iface_setname(fddi_iface_t *iface, char *name)
+{
+ if ((!iface) || (!name))
+ return EINVAL;
+
+ if (iface->name != NULL)
+ free(iface->name);
+
+ iface->name = malloc(strlen(name)+1);
+ if (!iface->name)
+ return ENOMEM;
+
+ strncpy(iface->name, name, strlen(name)+1);
+
+ return 0;
+}
+
int fddi_iface_getnodev(fddi_iface_t *iface)
{
if (!iface)
return EINVAL;
- /* FIXME */
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_iface_getnotpus(fddi_iface_t *iface)
{
if (!iface)
return EINVAL;
- /* FIXME */
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_iface_getnopvs(fddi_iface_t *iface)
{
if (!iface)
return EINVAL;
- /* FIXME */
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_iface_getdevlist(fddi_iface_t *iface, fddi_device_t **dev)
@@ -191,6 +244,22 @@
return 0;
}
+int fddi_iface_getversionstr(fddi_iface_t *iface, const char **version)
+{
+ if (!iface)
+ return EINVAL;
+
+ *version = fddi_version_str;
+
+ return 0;
+}
+
+int fddi_iface_getversion(fddi_iface_t *iface, int *version)
+{
+ /* FIXME: use the kernel mechanics to get a numerical version here */
+ return 0;
+}
+
/* fddi_device_t */
int fddi_dev_getnext(fddi_device_t **dev)
@@ -233,18 +302,16 @@
{
if (!dev)
return EINVAL;
- /* FIXME */
- *id = 0;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_dev_getlogicalid(fddi_device_t *dev, int *id)
{
if (!dev)
return EINVAL;
- /* FIXME */
- *id = 0;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_dev_getparamlist(fddi_device_t *dev, fddi_param_t **param)
@@ -260,21 +327,24 @@
{
if (!dev)
return EINVAL;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_dev_read_async(fddi_device_t *dev /* FIXME */)
{
if (!dev)
return EINVAL;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_dev_write_async(fddi_device_t *dev /* FIXME */)
{
if (!dev)
return EINVAL;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
@@ -320,8 +390,7 @@
if ((!param) || (!notpus))
return EINVAL;
- *notpus = 0; /* FIXME */
- return 0;
+ return -1; /* FIXME: not implemented yet */
}
@@ -375,7 +444,8 @@
{
if ((!tpu) || (!tpu_callback))
return EINVAL;
- return 0;
+
+ return -1; /* FIXME: not implemented yet */
}
int fddi_tpu_getpvlist(fddi_tpu_t *tpu, fddi_pv_t **pv)
@@ -398,7 +468,7 @@
int fddi_tpu_send(fddi_tpu_t *tpu)
{
- return 0;
+ return -1; /* FIXME: not implemented yet */
}