[Kst] dirfile error reporting

Matthew D Truch matt at truch.net
Wed Apr 12 19:19:10 CEST 2006


So I got this far yesterday (when other people were discussing
implementation of [go]nads) with having the dirfile datasource tell the
user about errors as indicated by getdata.  See attached patch.  

My main problem is that since kst keeps trying to read anything that is
borked every update cycle, the error is repeated every 250ms (or
whatever the update timer is).  This can't be what we want.  Should the
datasource keep track of if it's reported a specific error before and
only report it once, or should KstDebug take care of that, or should we
not deal with this?  

-- 
"Party on Wayne; Party on Garth. -- Wayne's World"
--------------------------
Matthew Truch
Department of Physics
Brown University
matt at truch.net
http://matt.truch.net/
-------------- next part --------------
Index: kst/src/datasources/dirfile/dirfile.cpp
===================================================================
--- kst/src/datasources/dirfile/dirfile.cpp	(revision 529160)
+++ kst/src/datasources/dirfile/dirfile.cpp	(working copy)
@@ -19,6 +19,8 @@
 #include "getdata.h"
 #include "getdata_struct.h"
 
+#include "kstdebug.h"
+#define ERRLEN 1000
 
 DirFileSource::DirFileSource(KConfig *cfg, const QString& filename, const QString& type)
 : KstDataSource(cfg, filename, type) {
@@ -41,11 +43,14 @@
 
 bool DirFileSource::init() {
   int err = 0;
+  char err_str[ERRLEN];
 
   _frameCount = 0;
   FormatType *ft = GetFormat(_filename.latin1(), &err);
 
-  if (err == GD_E_OK) {
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  } else {
     _fieldList.append("INDEX");
     for (int i = 0; i < ft->n_lincom; i++) {
       _fieldList.append(ft->lincomEntries[i].field);
@@ -88,34 +93,50 @@
 
 
 int DirFileSource::readField(double *v, const QString& field, int s, int n) {
+  int samples;
   int err = 0;
+  char err_str[ERRLEN];
 
   if (n < 0) {
-    return GetData(_filename.latin1(), field.left(FIELD_LENGTH).latin1(),
+    samples = GetData(_filename.latin1(), field.left(FIELD_LENGTH).latin1(),
                    s, 0, /* 1st sframe, 1st samp */
                    0, 1, /* num sframes, num samps */
                    'd', (void*)v,
                    &err);
   } else {
-    return GetData(_filename.latin1(), field.left(FIELD_LENGTH).latin1(),
+    samples = GetData(_filename.latin1(), field.left(FIELD_LENGTH).latin1(),
                    s, 0, /* 1st sframe, 1st samp */
                    n, 0, /* num sframes, num samps */
                    'd', (void*)v,
                    &err);
   }
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  }
+  return samples;
 }
 
 
 bool DirFileSource::isValidField(const QString& field) const {
   int err = 0;
+  char err_str[ERRLEN];
   GetSamplesPerFrame(_filename.latin1(), field.left(FIELD_LENGTH).latin1(), &err);
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  }
   return err == 0;
 }
 
 
 int DirFileSource::samplesPerFrame(const QString &field) {
+  int samples;
   int err = 0;
-  return GetSamplesPerFrame(_filename.latin1(), field.left(FIELD_LENGTH).latin1(), &err);
+  char err_str[ERRLEN];
+  samples = GetSamplesPerFrame(_filename.latin1(), field.left(FIELD_LENGTH).latin1(), &err);
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  }
+  return samples;
 }
 
 
@@ -169,7 +190,11 @@
 QStringList fieldList_dirfile(KConfig*, const QString& filename, const QString& type, QString *typeSuggestion, bool *complete) {
   Q_UNUSED(type)
   int err = 0;
+  char err_str[ERRLEN];
   struct FormatType *ft = GetFormat(filename.latin1(), &err);
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  }
   QStringList fieldList;
 
   if (complete) {
@@ -180,7 +205,9 @@
     *typeSuggestion = "Directory of Binary Files";
   }
 
-  if (err == GD_E_OK) {
+  if (err != GD_E_OK) {
+    KstDebug::self()->log(GetDataErrorString(err_str, ERRLEN), KstDebug::Error);
+  } else {
     fieldList.append("INDEX");
     for (int i = 0; i < ft->n_lincom; i++) {
       fieldList.append(ft->lincomEntries[i].field);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kst/attachments/20060412/decdf24c/attachment.pgp 


More information about the Kst mailing list