Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tommy Olofsson
LabComm
Commits
d3e25d39
Commit
d3e25d39
authored
Oct 15, 2014
by
Anders Blomdell
Browse files
Version string encapsulated with tag and length, hence version string not
passed to labcomm_writer_alloc any more.
parent
10bbd93d
Changes
27
Hide whitespace changes
Inline
Side-by-side
examples/twoway/decimating.c
View file @
d3e25d39
...
...
@@ -62,14 +62,13 @@ static void set_decimation(
static
int
wrap_reader_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_reader_action_context
*
action_context
)
{
struct
decimating_private
*
decimating
=
action_context
->
context
;
labcomm_decoder_register_decimating_messages_set_decimation
(
r
->
decoder
,
set_decimation
,
decimating
);
return
labcomm_reader_alloc
(
r
,
action_context
->
next
,
labcomm_version
);
return
labcomm_reader_alloc
(
r
,
action_context
->
next
);
}
struct
send_set_decimation
{
...
...
@@ -186,14 +185,13 @@ static void register_signatures(void *context)
static
int
wrap_writer_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_writer_action_context
*
action_context
)
{
struct
decimating_private
*
decimating
=
action_context
->
context
;
labcomm_scheduler_enqueue
(
decimating
->
scheduler
,
0
,
register_signatures
,
decimating
);
return
labcomm_writer_alloc
(
w
,
action_context
->
next
,
labcomm_version
);
return
labcomm_writer_alloc
(
w
,
action_context
->
next
);
}
static
int
wrap_writer_start
(
...
...
@@ -206,20 +204,22 @@ static int wrap_writer_start(
struct
decimation
*
decimation
;
int
result
;
labcomm_scheduler_data_lock
(
decimating
->
scheduler
);
decimation
=
LABCOMM_SIGNATURE_ARRAY_REF
(
decimating
->
memory
,
decimating
->
writer_decimation
,
struct
decimation
,
index
);
decimation
->
current
++
;
if
(
decimation
->
current
<
decimation
->
n
)
{
result
=
-
EALREADY
;
}
else
{
decimation
->
current
=
0
;
if
(
index
<
LABCOMM_USER
)
{
result
=
0
;
}
else
{
labcomm_scheduler_data_lock
(
decimating
->
scheduler
);
decimation
=
LABCOMM_SIGNATURE_ARRAY_REF
(
decimating
->
memory
,
decimating
->
writer_decimation
,
struct
decimation
,
index
);
decimation
->
current
++
;
if
(
decimation
->
current
<
decimation
->
n
)
{
result
=
-
EALREADY
;
}
else
{
decimation
->
current
=
0
;
result
=
0
;
}
labcomm_scheduler_data_unlock
(
decimating
->
scheduler
);
}
labcomm_scheduler_data_unlock
(
decimating
->
scheduler
);
if
(
result
==
0
)
{
result
=
labcomm_writer_start
(
w
,
action_context
->
next
,
index
,
signature
,
value
);
...
...
examples/twoway/introspecting.c
View file @
d3e25d39
...
...
@@ -124,15 +124,14 @@ static void handles_signature(
static
int
wrap_reader_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_reader_action_context
*
action_context
)
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
labcomm_decoder_register_introspecting_messages_handles_signature
(
introspecting
->
introspecting
.
reader
->
decoder
,
handles_signature
,
introspecting
);
return
labcomm_reader_alloc
(
r
,
action_context
->
next
,
labcomm_version
);
return
labcomm_reader_alloc
(
r
,
action_context
->
next
);
}
struct
handles_signature
{
...
...
@@ -213,14 +212,13 @@ static void register_encoder_signatures(void *context)
static
int
wrap_writer_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_writer_action_context
*
action_context
)
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
labcomm_scheduler_enqueue
(
introspecting
->
scheduler
,
0
,
register_encoder_signatures
,
introspecting
);
return
labcomm_writer_alloc
(
w
,
action_context
->
next
,
labcomm_version
);
return
labcomm_writer_alloc
(
w
,
action_context
->
next
);
}
static
int
wrap_writer_start
(
...
...
@@ -231,7 +229,7 @@ static int wrap_writer_start(
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
if
(
value
==
NULL
)
{
if
(
index
>=
LABCOMM_USER
&&
value
==
NULL
)
{
struct
local
*
local
;
labcomm_scheduler_data_lock
(
introspecting
->
scheduler
);
...
...
lib/c/2006/labcomm2006.c
View file @
d3e25d39
...
...
@@ -48,10 +48,9 @@
}
int
labcomm2006_reader_alloc
(
struct
labcomm2006_reader
*
r
,
struct
labcomm2006_reader_action_context
*
action_context
,
char
*
labcomm2006_version
)
struct
labcomm2006_reader_action_context
*
action_context
)
{
UNWRAP
(
alloc
,
r
,
action_context
,
labcomm2006_version
);
UNWRAP
(
alloc
,
r
,
action_context
);
}
int
labcomm2006_reader_free
(
struct
labcomm2006_reader
*
r
,
...
...
@@ -92,10 +91,9 @@ int labcomm2006_reader_ioctl(struct labcomm2006_reader *r,
}
int
labcomm2006_writer_alloc
(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
,
char
*
labcomm2006_version
)
struct
labcomm2006_writer_action_context
*
action_context
)
{
UNWRAP
(
alloc
,
w
,
action_context
,
labcomm2006_version
);
UNWRAP
(
alloc
,
w
,
action_context
);
}
int
labcomm2006_writer_free
(
struct
labcomm2006_writer
*
w
,
...
...
lib/c/2006/labcomm2006_decoder.c
View file @
d3e25d39
...
...
@@ -186,7 +186,7 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
local_signature
=
NULL
;
local_index
=
0
;
labcomm2006_writer_alloc
(
&
writer
,
writer
.
action_context
,
""
);
labcomm2006_writer_alloc
(
&
writer
,
writer
.
action_context
);
labcomm2006_writer_start
(
&
writer
,
writer
.
action_context
,
0
,
NULL
,
NULL
);
remote_index
=
labcomm2006_read_packed32
(
d
->
reader
);
signature
.
name
=
labcomm2006_read_string
(
d
->
reader
);
...
...
@@ -286,8 +286,7 @@ static void reader_alloc(struct labcomm2006_decoder *d)
{
if
(
!
d
->
reader_allocated
)
{
d
->
reader_allocated
=
1
;
labcomm2006_reader_alloc
(
d
->
reader
,
d
->
reader
->
action_context
,
LABCOMM_VERSION
);
labcomm2006_reader_alloc
(
d
->
reader
,
d
->
reader
->
action_context
);
}
}
...
...
lib/c/2006/labcomm2006_dynamic_buffer_writer.c
View file @
d3e25d39
...
...
@@ -28,8 +28,7 @@
#include
"labcomm2006_dynamic_buffer_writer.h"
static
int
dyn_alloc
(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
,
char
*
labcomm2006_version
)
struct
labcomm2006_writer_action_context
*
action_context
)
{
w
->
data_size
=
1000
;
w
->
count
=
w
->
data_size
;
...
...
lib/c/2006/labcomm2006_encoder.c
View file @
d3e25d39
...
...
@@ -53,7 +53,7 @@ struct labcomm2006_encoder *labcomm2006_encoder_new(
result
->
scheduler
=
scheduler
;
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
registered
,
int
);
labcomm2006_writer_alloc
(
result
->
writer
,
result
->
writer
->
action_context
,
LABCOMM_VERSION
);
result
->
writer
->
action_context
);
}
return
result
;
}
...
...
lib/c/2006/labcomm2006_fd_reader.c
View file @
d3e25d39
...
...
@@ -36,19 +36,9 @@ struct labcomm2006_fd_reader {
};
static
int
fd_alloc
(
struct
labcomm2006_reader
*
r
,
struct
labcomm2006_reader_action_context
*
action_context
,
char
*
version
)
struct
labcomm2006_reader_action_context
*
action_context
)
{
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
->
pos
=
0
;
...
...
lib/c/2006/labcomm2006_fd_writer.c
View file @
d3e25d39
...
...
@@ -40,20 +40,9 @@ static int fd_flush(struct labcomm2006_writer *w,
struct
labcomm2006_writer_action_context
*
action_context
);
static
int
fd_alloc
(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
,
char
*
version
)
struct
labcomm2006_writer_action_context
*
action_context
)
{
// 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
)
{
w
->
error
=
-
ENOMEM
;
w
->
data_size
=
0
;
...
...
lib/c/2006/labcomm2006_private.h
View file @
d3e25d39
...
...
@@ -96,17 +96,14 @@ struct labcomm2006_reader_action_context;
struct
labcomm2006_reader_action
{
/* 'alloc' is called at the first invocation of 'labcomm2006_decoder_decode_one'
on the decoder containing the reader. If 'labcomm2006_version' != NULL
and non-empty the transport layer may use it to ensure that
compatible versions are used.
on the decoder containing the reader.
Returned value:
> 0 Number of bytes allocated for buffering
<= 0 Error
*/
int
(
*
alloc
)(
struct
labcomm2006_reader
*
r
,
struct
labcomm2006_reader_action_context
*
action_context
,
char
*
labcomm2006_version
);
struct
labcomm2006_reader_action_context
*
action_context
);
/* 'free' returns the resources claimed by 'alloc' and might have other
reader specific side-effects as well.
...
...
@@ -159,8 +156,7 @@ struct labcomm2006_reader {
};
int
labcomm2006_reader_alloc
(
struct
labcomm2006_reader
*
r
,
struct
labcomm2006_reader_action_context
*
action_context
,
char
*
labcomm2006_version
);
struct
labcomm2006_reader_action_context
*
action_context
);
int
labcomm2006_reader_free
(
struct
labcomm2006_reader
*
r
,
struct
labcomm2006_reader_action_context
*
action_context
);
int
labcomm2006_reader_start
(
struct
labcomm2006_reader
*
r
,
...
...
@@ -299,8 +295,7 @@ struct labcomm2006_writer_action_context;
struct
labcomm2006_writer_action
{
int
(
*
alloc
)(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
,
char
*
labcomm2006_version
);
struct
labcomm2006_writer_action_context
*
action_context
);
int
(
*
free
)(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
);
/* 'start' is called right before a sample is to be sent. In the
...
...
@@ -345,8 +340,7 @@ struct labcomm2006_writer {
};
int
labcomm2006_writer_alloc
(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
,
char
*
labcomm_version
);
struct
labcomm2006_writer_action_context
*
action_context
);
int
labcomm2006_writer_free
(
struct
labcomm2006_writer
*
w
,
struct
labcomm2006_writer_action_context
*
action_context
);
int
labcomm2006_writer_start
(
struct
labcomm2006_writer
*
w
,
...
...
lib/c/labcomm.c
View file @
d3e25d39
...
...
@@ -37,7 +37,7 @@
#include
"labcomm_ioctl.h"
#include
"labcomm_dynamic_buffer_writer.h"
#define
LABCOMM
_VERSION "LabComm20141009"
#define
CURRENT
_VERSION "LabComm20141009"
/* Unwrapping reader/writer functions */
#define UNWRAP_ac(rw, ac, ...) ac
...
...
@@ -50,10 +50,9 @@
}
int
labcomm_reader_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_reader_action_context
*
action_context
)
{
UNWRAP
(
alloc
,
r
,
action_context
,
labcomm_version
);
UNWRAP
(
alloc
,
r
,
action_context
);
}
int
labcomm_reader_free
(
struct
labcomm_reader
*
r
,
...
...
@@ -94,10 +93,9 @@ int labcomm_reader_ioctl(struct labcomm_reader *r,
}
int
labcomm_writer_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_writer_action_context
*
action_context
)
{
UNWRAP
(
alloc
,
w
,
action_context
,
labcomm_version
);
UNWRAP
(
alloc
,
w
,
action_context
);
}
int
labcomm_writer_free
(
struct
labcomm_writer
*
w
,
...
...
@@ -265,11 +263,6 @@ int labcomm_internal_sizeof(struct labcomm_signature *signature,
void
*
v
)
{
int
length
=
signature
->
encoded_size
(
v
);
fprintf
(
stderr
,
"SIZEOF(%s) = %d %d %d
\n
"
,
signature
->
name
,
labcomm_size_packed32
(
signature
->
index
),
labcomm_size_packed32
(
length
),
length
);
return
(
labcomm_size_packed32
(
signature
->
index
)
+
labcomm_size_packed32
(
length
)
+
length
);
...
...
lib/c/labcomm_decoder.c
View file @
d3e25d39
...
...
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define
LABCOMM
_VERSION "LabComm20141009"
#define
CURRENT
_VERSION "LabComm20141009"
#include
<errno.h>
#include
"labcomm.h"
...
...
@@ -37,6 +37,7 @@ struct sample_entry {
struct
labcomm_decoder
{
struct
labcomm_reader
*
reader
;
int
reader_allocated
;
int
version_ok
;
struct
labcomm_error_handler
*
error
;
struct
labcomm_memory
*
memory
;
struct
labcomm_scheduler
*
scheduler
;
...
...
@@ -64,6 +65,7 @@ struct labcomm_decoder *labcomm_decoder_new(
result
->
reader
->
pos
=
0
;
result
->
reader
->
error
=
0
;
result
->
reader_allocated
=
0
;
result
->
version_ok
=
0
;
result
->
error
=
error
;
result
->
memory
=
memory
;
result
->
scheduler
=
scheduler
;
...
...
@@ -105,7 +107,7 @@ static int decode_sample(struct labcomm_decoder *d, int kind)
signature
.
size
=
labcomm_read_packed32
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
goto
out
;
goto
free_signature_name
;
}
signature
.
signature
=
labcomm_memory_alloc
(
d
->
memory
,
1
,
signature
.
size
);
if
(
d
->
reader
->
error
<
0
)
{
...
...
@@ -184,14 +186,13 @@ static void reader_alloc(struct labcomm_decoder *d)
{
if
(
!
d
->
reader_allocated
)
{
d
->
reader_allocated
=
1
;
labcomm_reader_alloc
(
d
->
reader
,
d
->
reader
->
action_context
,
LABCOMM_VERSION
);
labcomm_reader_alloc
(
d
->
reader
,
d
->
reader
->
action_context
);
}
}
int
labcomm_decoder_decode_one
(
struct
labcomm_decoder
*
d
)
{
int
result
,
remote_index
,
length
__attribute__
((
__unused__
))
;
int
result
,
remote_index
,
length
;
reader_alloc
(
d
);
remote_index
=
labcomm_read_packed32
(
d
->
reader
);
...
...
@@ -204,8 +205,30 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
result
=
d
->
reader
->
error
;
goto
out
;
}
if
(
remote_index
==
LABCOMM_SAMPLE
)
{
if
(
remote_index
==
LABCOMM_VERSION
)
{
char
*
version
=
labcomm_read_string
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
goto
out
;
}
if
(
strcmp
(
version
,
CURRENT_VERSION
)
==
0
)
{
result
=
LABCOMM_VERSION
;
d
->
version_ok
=
1
;
}
else
{
result
=
-
ECONNRESET
;
}
fprintf
(
stderr
,
"VERSION %s %d
\n
"
,
version
,
result
);
labcomm_memory_free
(
d
->
memory
,
1
,
version
);
}
else
if
(
!
d
->
version_ok
)
{
fprintf
(
stderr
,
"No VERSION %d %d
\n
"
,
remote_index
,
length
);
result
=
-
ECONNRESET
;
}
else
if
(
remote_index
==
LABCOMM_SAMPLE
)
{
result
=
decode_sample
(
d
,
remote_index
);
}
else
if
(
remote_index
==
LABCOMM_PRAGMA
&&
0
/* d->pragma_handler*/
)
{
/* d->prama_handler(...); */
}
else
if
(
remote_index
<
LABCOMM_USER
)
{
fprintf
(
stderr
,
"SKIP %d %d
\n
"
,
remote_index
,
length
);
result
=
remote_index
;
}
else
{
int
*
local_index
;
struct
call_handler_context
wrap
=
{
...
...
@@ -244,7 +267,7 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
result
=
-
ENOENT
;
}
}
out:
out:
return
result
;
}
...
...
lib/c/labcomm_dynamic_buffer_writer.c
View file @
d3e25d39
...
...
@@ -28,8 +28,7 @@
#include
"labcomm_dynamic_buffer_writer.h"
static
int
dyn_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_writer_action_context
*
action_context
)
{
w
->
data_size
=
1000
;
w
->
count
=
w
->
data_size
;
...
...
lib/c/labcomm_encoder.c
View file @
d3e25d39
...
...
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define
LABCOMM
_VERSION "LabComm20141009"
#define
CURRENT
_VERSION "LabComm20141009"
#include
<errno.h>
#include
"labcomm.h"
...
...
@@ -43,6 +43,8 @@ struct labcomm_encoder *labcomm_encoder_new(
result
=
labcomm_memory_alloc
(
memory
,
0
,
sizeof
(
*
result
));
if
(
result
)
{
int
length
;
result
->
writer
=
writer
;
result
->
writer
->
encoder
=
result
;
result
->
writer
->
data
=
NULL
;
...
...
@@ -55,7 +57,16 @@ struct labcomm_encoder *labcomm_encoder_new(
result
->
scheduler
=
scheduler
;
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
registered
,
int
);
labcomm_writer_alloc
(
result
->
writer
,
result
->
writer
->
action_context
,
LABCOMM_VERSION
);
result
->
writer
->
action_context
);
labcomm_writer_start
(
result
->
writer
,
result
->
writer
->
action_context
,
LABCOMM_VERSION
,
NULL
,
CURRENT_VERSION
);
labcomm_write_packed32
(
result
->
writer
,
LABCOMM_VERSION
);
length
=
(
labcomm_size_packed32
(
LABCOMM_VERSION
)
+
labcomm_size_string
(
CURRENT_VERSION
));
labcomm_write_packed32
(
result
->
writer
,
length
);
labcomm_write_string
(
result
->
writer
,
CURRENT_VERSION
);
labcomm_writer_end
(
result
->
writer
,
result
->
writer
->
action_context
);
}
return
result
;
}
...
...
lib/c/labcomm_fd_reader.c
View file @
d3e25d39
...
...
@@ -36,8 +36,7 @@ struct labcomm_fd_reader {
};
static
int
fd_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
version
)
struct
labcomm_reader_action_context
*
action_context
)
{
int
result
=
0
;
...
...
@@ -51,17 +50,6 @@ static int fd_alloc(struct labcomm_reader *r,
r
->
data_size
=
BUFFER_SIZE
;
result
=
r
->
data_size
;
if
(
version
&&
version
[
0
])
{
char
*
tmp
;
tmp
=
labcomm_read_string
(
r
);
if
(
strcmp
(
tmp
,
version
)
!=
0
)
{
result
=
-
EINVAL
;
}
else
{
result
=
r
->
data_size
;
}
labcomm_memory_free
(
r
->
memory
,
1
,
tmp
);
}
}
return
result
;
}
...
...
lib/c/labcomm_fd_writer.c
View file @
d3e25d39
...
...
@@ -40,8 +40,7 @@ static int fd_flush(struct labcomm_writer *w,
struct
labcomm_writer_action_context
*
action_context
);
static
int
fd_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
version
)
struct
labcomm_writer_action_context
*
action_context
)
{
w
->
data
=
labcomm_memory_alloc
(
w
->
memory
,
0
,
BUFFER_SIZE
);
if
(
!
w
->
data
)
{
...
...
@@ -53,10 +52,6 @@ static int fd_alloc(struct labcomm_writer *w,
w
->
data_size
=
BUFFER_SIZE
;
w
->
count
=
BUFFER_SIZE
;
w
->
pos
=
0
;
if
(
version
&&
version
[
0
])
{
labcomm_write_string
(
w
,
version
);
fd_flush
(
w
,
action_context
);
}
}
return
w
->
error
;
...
...
lib/c/labcomm_private.h
View file @
d3e25d39
...
...
@@ -37,15 +37,22 @@
#include
"labcomm.h"
/*
*
Predeclared aggregate type indice
s
*
Allowed packet tag
s
*/
#define LABCOMM_
TYPEDEF
0x01
#define LABCOMM_
VERSION
0x01
#define LABCOMM_SAMPLE 0x02
#define LABCOMM_PRAGMA 0x3f
#define LABCOMM_USER 0x40
/* ..0xffffffff */
/*
* Predefined aggregate type indices
*/
#define LABCOMM_ARRAY 0x10
#define LABCOMM_STRUCT 0x11
/*
* Prede
clar
ed primitive type indices
* Prede
fin
ed primitive type indices
*/
#define LABCOMM_BOOLEAN 0x20
#define LABCOMM_BYTE 0x21
...
...
@@ -56,10 +63,6 @@
#define LABCOMM_DOUBLE 0x26
#define LABCOMM_STRING 0x27
/*
* Start index for user defined types
*/
#define LABCOMM_USER 0x40
/*
* Macro to automagically call constructors in modules compiled
...
...
@@ -96,17 +99,14 @@ struct labcomm_reader_action_context;
struct
labcomm_reader_action
{
/* 'alloc' is called at the first invocation of 'labcomm_decoder_decode_one'
on the decoder containing the reader. If 'labcomm_version' != NULL
and non-empty the transport layer may use it to ensure that
compatible versions are used.
on the decoder containing the reader.
Returned value:
> 0 Number of bytes allocated for buffering
<= 0 Error
*/
int
(
*
alloc
)(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
);
struct
labcomm_reader_action_context
*
action_context
);
/* 'free' returns the resources claimed by 'alloc' and might have other
reader specific side-effects as well.
...
...
@@ -159,8 +159,7 @@ struct labcomm_reader {
};
int
labcomm_reader_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
);
struct
labcomm_reader_action_context
*
action_context
);
int
labcomm_reader_free
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
);
int
labcomm_reader_start
(
struct
labcomm_reader
*
r
,
...
...
@@ -299,8 +298,7 @@ struct labcomm_writer_action_context;
struct
labcomm_writer_action
{
int
(
*
alloc
)(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
);
struct
labcomm_writer_action_context
*
action_context
);
int
(
*
free
)(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
);
/* 'start' is called right before a sample is to be sent. In the
...
...
@@ -345,8 +343,7 @@ struct labcomm_writer {
};
int
labcomm_writer_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
);
struct
labcomm_writer_action_context
*
action_context
);
int
labcomm_writer_free
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
);
int
labcomm_writer_start
(
struct
labcomm_writer
*
w
,
...
...
lib/c/test/test_labcomm.c
View file @
d3e25d39
...
...
@@ -33,8 +33,7 @@
static
unsigned
char
buffer
[
512
];
static
int
writer_alloc
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_writer_action_context
*
action_context
)
{
w
->
data
=
buffer
;
w
->
data_size
=
sizeof
(
buffer
);
...
...
@@ -68,8 +67,7 @@ static struct labcomm_writer writer = {
};
static
int
reader_alloc
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
char
*
labcomm_version
)
struct
labcomm_reader_action_context
*
action_context
)
{
r
->
data
=
buffer
;
r
->
data_size
=
sizeof
(
buffer
);
...
...
@@ -127,8 +125,8 @@ int test_decode_one(struct labcomm_decoder *decoder)
for
(
reader
.
count
=
0
;
reader
.
count
<
writer
.
pos
;
reader
.
count
++
)
{
reader
.
error
=
0
;
reader
.
pos
=
0
;
result
=
labcomm_decoder_decode_one
(
decoder
);
if
(
result
>=
0
)
{
result
=
labcomm_decoder_decode_one
(
decoder
);
if
(
result
>=
0
)
{
fprintf
(
stderr
,
"Got result from buffer with bogus length (%d)
\n
"
,
result
);