Commit d4d7a74e authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

moved version to labcomm.h and added check (sketch) in reader and writer

parent 2b1728f7
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
#include "labcomm2006_ioctl.h" #include "labcomm2006_ioctl.h"
#include "labcomm2006_dynamic_buffer_writer.h" #include "labcomm2006_dynamic_buffer_writer.h"
#define LABCOMM_VERSION "LabComm2006"
/* Unwrapping reader/writer functions */ /* Unwrapping reader/writer functions */
#define UNWRAP_ac(rw, ac, ...) ac #define UNWRAP_ac(rw, ac, ...) ac
#define UNWRAP(func, ...) \ #define UNWRAP(func, ...) \
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#ifndef _LABCOMM_H_ #ifndef _LABCOMM_H_
#define _LABCOMM_H_ #define _LABCOMM_H_
#define LABCOMM_VERSION "LabComm2006"
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define LABCOMM_VERSION "LabComm2006"
#include <errno.h> #include <errno.h>
#include "labcomm2006.h" #include "labcomm2006.h"
#include "labcomm2006_private.h" #include "labcomm2006_private.h"
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define LABCOMM_VERSION "LabComm2006"
#include <errno.h> #include <errno.h>
#include "labcomm2006.h" #include "labcomm2006.h"
#include "labcomm2006_private.h" #include "labcomm2006_private.h"
......
...@@ -40,6 +40,15 @@ static int fd_alloc(struct labcomm2006_reader *r, ...@@ -40,6 +40,15 @@ static int fd_alloc(struct labcomm2006_reader *r,
char *version) char *version)
{ {
int result = 0; int result = 0;
// in-band version is not included in version 2006.
// This may be a place for version checking and/or printing
// a warning message
if (version && version[0]) {
if (strcmp(LABCOMM_VERSION, version) != 0) {
fprintf(stderr, "ERROR: version mismatch: %s != %s\n", version, LABCOMM_VERSION);
return -EINVAL;
}
}
r->count = 0; r->count = 0;
r->pos = 0; r->pos = 0;
...@@ -51,22 +60,6 @@ static int fd_alloc(struct labcomm2006_reader *r, ...@@ -51,22 +60,6 @@ static int fd_alloc(struct labcomm2006_reader *r,
r->data_size = BUFFER_SIZE; r->data_size = BUFFER_SIZE;
result = r->data_size; result = r->data_size;
#if 0
// in-band version is not included in version 2006.
// This may be a place for version checking and/or printing
// a warning message
if (version && version[0]) {
char *tmp;
tmp = labcomm2006_read_string(r);
if (strcmp(tmp, version) != 0) {
result = -EINVAL;
} else {
result = r->data_size;
}
labcomm2006_memory_free(r->memory, 1, tmp);
}
#endif
} }
return result; return result;
} }
......
...@@ -43,6 +43,16 @@ static int fd_alloc(struct labcomm2006_writer *w, ...@@ -43,6 +43,16 @@ static int fd_alloc(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context, struct labcomm2006_writer_action_context *action_context,
char *version) char *version)
{ {
// in-band version is not included in version 2006.
// This may be a place for version checking and/or printing
// a warning message
if (version && version[0]) {
if (strcmp(LABCOMM_VERSION, version) != 0) {
fprintf(stderr, "ERROR: version mismatch: %s != %s\n", version, LABCOMM_VERSION);
return -EINVAL;
}
}
w->data = labcomm2006_memory_alloc(w->memory, 0, BUFFER_SIZE); w->data = labcomm2006_memory_alloc(w->memory, 0, BUFFER_SIZE);
if (! w->data) { if (! w->data) {
w->error = -ENOMEM; w->error = -ENOMEM;
...@@ -53,12 +63,6 @@ static int fd_alloc(struct labcomm2006_writer *w, ...@@ -53,12 +63,6 @@ static int fd_alloc(struct labcomm2006_writer *w,
w->data_size = BUFFER_SIZE; w->data_size = BUFFER_SIZE;
w->count = BUFFER_SIZE; w->count = BUFFER_SIZE;
w->pos = 0; w->pos = 0;
if (version && version[0]) {
#if 0
labcomm2006_write_string(w, version);
fd_flush(w, action_context);
#endif
}
} }
return w->error; return w->error;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment