[svn-commits] tzafrir: branch tzafrir/sysfs r2951 - /team/tzafrir/sysfs/zaptel-base.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 24 19:00:26 CDT 2007


Author: tzafrir
Date: Fri Aug 24 19:00:26 2007
New Revision: 2951

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2951
Log:
* span_add_attribute(): A macro for adding an attribute.
* Span properties for digital_coding and digital_framing: taken from
  lineconfig - those were probably the last values set in the ioctl
  SPANCONFIG (by ztcfg, typiclly).

Modified:
    team/tzafrir/sysfs/zaptel-base.c

Modified: team/tzafrir/sysfs/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-base.c?view=diff&rev=2951&r1=2950&r2=2951
==============================================================================
--- team/tzafrir/sysfs/zaptel-base.c (original)
+++ team/tzafrir/sysfs/zaptel-base.c Fri Aug 24 19:00:26 2007
@@ -789,6 +789,41 @@
 }
 
 /*--------- Sysfs Device handling ----*/
+static DEVICE_ATTR_FUNC(digital_coding_show, dev, buf)
+{
+	struct	zt_span *span = dev_to_span(dev);
+	int	lineconfig = span->lineconfig;
+	char*	name;
+
+	lineconfig &= ~(ZT_CONFIG_AMI | ZT_CONFIG_B8ZS | ZT_CONFIG_HDB3 );
+	switch (lineconfig) {
+		case ZT_CONFIG_AMI: name="ami"; break;
+		case ZT_CONFIG_B8ZS: name="b8zf"; break;
+		case ZT_CONFIG_HDB3: name="hdb3"; break;
+		default: name="unknown"; break;
+	}
+	return snprintf(buf, PAGE_SIZE, "%s\n", name);
+}
+static	DEVICE_ATTR(digital_coding, S_IRUGO, digital_coding_show, NULL);
+
+static DEVICE_ATTR_FUNC(digital_framing_show, dev, buf)
+{
+	struct	zt_span *span = dev_to_span(dev);
+	int	lineconfig = span->lineconfig;
+	char*	name;
+
+	lineconfig &= ~(ZT_CONFIG_D4 | ZT_CONFIG_ESF | ZT_CONFIG_CCS);
+	switch (lineconfig) {
+		case 0: name="cas"; break;
+		case ZT_CONFIG_D4: name="d4"; break;
+		case ZT_CONFIG_ESF: name="esf"; break;
+		case ZT_CONFIG_CCS: name="ccs"; break;
+		default: name="unknown"; break;
+	}
+	return snprintf(buf, PAGE_SIZE, "%s\n", name);
+}
+static	DEVICE_ATTR(digital_framing, S_IRUGO, digital_framing_show, NULL);
+
 static DEVICE_ATTR_FUNC(flags_show, dev, buf)
 {
 	struct zt_span *span = dev_to_span(dev);
@@ -803,14 +838,12 @@
 }
 static	DEVICE_ATTR(name, S_IRUGO, name_show, NULL);
 
-/* FIXME: replace this attribute with something more useful */
 static DEVICE_ATTR_FUNC(sync_master_show, dev, buf)
 {
 	struct zt_span *span = dev_to_span(dev);
 	return snprintf(buf, PAGE_SIZE, "%s\n", (span == master) ? "Y":"N");
 }
 static	DEVICE_ATTR(sync_master, S_IRUGO, sync_master_show, NULL);
-
 
 static void span_sysfs_remove(struct zt_span *span)
 {
@@ -820,12 +853,20 @@
 	zap_dbg_span(span, "\n");
 	device = &span->device;
 	BUG_ON(!device);
+	device_remove_file(&span->device, &dev_attr_digital_coding);
+	device_remove_file(&span->device, &dev_attr_digital_framing);
 	device_remove_file(&span->device, &dev_attr_flags);
 	device_remove_file(&span->device, &dev_attr_name);
 	device_remove_file(&span->device, &dev_attr_sync_master);
 	device_unregister(&span->device);
 }
 
+#define span_add_attribute(name) \
+	ret = device_create_file(device, &dev_attr_##name); \
+	if(ret) { \
+		zap_err_span(span, "%s: device_create_file failed (flags): %d\n", __FUNCTION__, ret); \
+		goto out; \
+	}
 static int span_sysfs_create(struct zt_span *span)
 {
 	struct device	*device;
@@ -846,21 +887,11 @@
 		zap_err_span(span, "%s: device_add failed: %d\n", __FUNCTION__, ret);
 		goto out;
 	}
-	ret = device_create_file(device, &dev_attr_flags);
-	if(ret) {
-		zap_err_span(span, "%s: device_create_file failed (flags): %d\n", __FUNCTION__, ret);
-		goto out;
-	}
-	ret = device_create_file(device, &dev_attr_name);
-	if(ret) {
-		zap_err_span(span, "%s: device_create_file failed (name): %d\n", __FUNCTION__, ret);
-		goto out;
-	}
-	ret = device_create_file(device, &dev_attr_sync_master);
-	if(ret) {
-		zap_err_span(span, "%s: device_create_file failed (sync_master): %d\n", __FUNCTION__, ret);
-		goto out;
-	}
+	span_add_attribute(digital_coding);
+	span_add_attribute(digital_framing);
+	span_add_attribute(flags);
+	span_add_attribute(name);
+	span_add_attribute(sync_master);
 out:
 	return ret;
 }




More information about the svn-commits mailing list