Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
LabComm
Commits
366de880
Commit
366de880
authored
11 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Use ioctl's instead of access to labcomm_dynamic_buffer_writer internal fields.
parent
5f2c6643
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/c/Makefile
+3
-2
3 additions, 2 deletions
lib/c/Makefile
lib/c/labcomm.c
+31
-14
31 additions, 14 deletions
lib/c/labcomm.c
lib/c/labcomm_dynamic_buffer_writer.c
+41
-3
41 additions, 3 deletions
lib/c/labcomm_dynamic_buffer_writer.c
with
75 additions
and
19 deletions
lib/c/Makefile
+
3
−
2
View file @
366de880
...
...
@@ -51,14 +51,15 @@ $(CREATED_DIRS):
mkdir
-p
$@
## NB! the tests need CUnit to be installed
run-test
:
$(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR)
run-test
:
$(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors
\
| $(TEST_DIR)
test
/test_labcomm
test
/test_labcomm_errors
$(TEST_DIR)/%.o
:
$(TEST_DIR)/%.c
$(
CC
)
$(
CFLAGS
)
-o
$@
-c
$<
$(TEST_DIR)/%
:
$(TEST_DIR)/%.o
$(TEST_DIR)/%
:
$(TEST_DIR)/%.o
| liblabcomm.a
$(
CC
)
$(
LDFLAGS
)
-o
$@
$^
$(
LDLIBS
)
$(
LDLIBS_TEST
)
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h
:
$(TESTDATA_DIR)/%.lc
\
...
...
This diff is collapsed.
Click to expand it.
lib/c/labcomm.c
+
31
−
14
View file @
366de880
...
...
@@ -432,38 +432,53 @@ static int do_decode_one(labcomm_decoder_t *d)
result
=
labcomm_decode_packed32
(
d
);
// printf("do_decode_one: result(2) = %x\n", result);
if
(
result
==
LABCOMM_TYPEDEF
||
result
==
LABCOMM_SAMPLE
)
{
/* TODO: should the labcomm_dynamic_buffer_writer be
a permanent part of labcomm_decoder? */
labcomm_encoder_t
*
e
=
labcomm_encoder_new
(
labcomm_dynamic_buffer_writer
,
0
);
labcomm_signature_t
signature
;
labcomm_sample_entry_t
*
entry
;
int
index
;
labcomm_sample_entry_t
*
entry
=
NULL
;
int
index
,
err
;
e
->
writer
.
write
(
&
e
->
writer
,
labcomm_writer_start
);
signature
.
type
=
result
;
index
=
labcomm_decode_packed32
(
d
);
//int
signature
.
name
=
labcomm_decode_string
(
d
);
// printf("do_decode_one: result = %x, index = %x, name=%s\n", result, index, signature.name);
signature
.
type
=
result
;
e
->
writer
.
write
(
&
e
->
writer
,
labcomm_writer_start
);
/* printf("do_decode_one: result = %x, index = %x, name=%s\n",
result, index, signature.name); */
collect_flat_signature
(
d
,
e
);
signature
.
size
=
e
->
writer
.
pos
;
signature
.
signature
=
e
->
writer
.
data
;
e
->
writer
.
write
(
&
e
->
writer
,
labcomm_writer_end
);
err
=
labcomm_encoder_ioctl
(
e
,
LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN
,
&
signature
.
size
);
if
(
err
<
0
)
{
printf
(
"Failed to get size: %s
\n
"
,
strerror
(
-
err
));
goto
free_signature_name
;
}
err
=
labcomm_encoder_ioctl
(
e
,
LABCOMM_IOCTL_WRITER_GET_BYTE_POINTER
,
&
signature
.
signature
);
if
(
err
<
0
)
{
printf
(
"Failed to get pointer: %s
\n
"
,
strerror
(
-
err
));
goto
free_signature_name
;
}
entry
=
get_sample_by_signature_value
(
context
->
sample
,
&
signature
);
if
(
!
entry
)
{
// Unknown datatype, bail out
/*d->on_error(LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE, 4, "%s(): unknown datatype '%s' (id=0x%x)\n", __FUNCTION__, signature.name, index);*/
d
->
on_new_datatype
(
d
,
&
signature
);
/* Unknown datatype, bail out */
d
->
on_new_datatype
(
d
,
&
signature
);
}
else
if
(
entry
->
index
&&
entry
->
index
!=
index
)
{
d
->
on_error
(
LABCOMM_ERROR_DEC_INDEX_MISMATCH
,
5
,
"%s(): index mismatch '%s' (id=0x%x != 0x%x)
\n
"
,
__FUNCTION__
,
signature
.
name
,
entry
->
index
,
index
);
d
->
on_error
(
LABCOMM_ERROR_DEC_INDEX_MISMATCH
,
5
,
"%s(): index mismatch '%s' (id=0x%x != 0x%x)
\n
"
,
__FUNCTION__
,
signature
.
name
,
entry
->
index
,
index
);
}
else
{
// TODO unnessesary, since entry->index == index in above if statement
// TODO unnessesary, since entry->index == index in above if statement
entry
->
index
=
index
;
}
free_signature_name:
free
(
signature
.
name
);
e
->
writer
.
write
(
&
e
->
writer
,
labcomm_writer_end
);
labcomm_encoder_free
(
e
);
if
(
!
entry
)
{
// No handler for found type, bail out (after cleanup)
result
=
-
ENOENT
;
}
labcomm_encoder_free
(
e
);
}
else
{
labcomm_sample_entry_t
*
entry
;
...
...
@@ -479,6 +494,8 @@ static int do_decode_one(labcomm_decoder_t *d)
}
}
d
->
reader
.
read
(
&
d
->
reader
,
labcomm_reader_end
);
/* TODO: should we really loop, or is it OK to
return after a typedef/sample */
}
while
(
result
>
0
&&
result
<
LABCOMM_USER
);
return
result
;
}
...
...
This diff is collapsed.
Click to expand it.
lib/c/labcomm_dynamic_buffer_writer.c
+
41
−
3
View file @
366de880
#include
<errno.h>
#include
"labcomm_ioctl.h"
#include
"labcomm_dynamic_buffer_writer.h"
static
int
labcomm_dynamic_buffer_writer_ioctl
(
struct
labcomm_writer
*
w
,
int
action
,
va_list
arg
)
{
int
result
=
-
ENOTSUP
;
switch
(
action
)
{
case
LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN
:
{
int
*
value
=
va_arg
(
arg
,
int
*
);
*
value
=
w
->
pos
;
result
=
0
;
}
break
;
case
LABCOMM_IOCTL_WRITER_GET_BYTE_POINTER
:
{
void
**
value
=
va_arg
(
arg
,
void
**
);
*
value
=
w
->
data
;
result
=
0
;
}
break
;
}
return
result
;
}
int
labcomm_dynamic_buffer_writer
(
labcomm_writer_t
*
w
,
labcomm_writer_action_t
action
,
...
...
@@ -10,20 +31,37 @@ int labcomm_dynamic_buffer_writer(
w
->
data_size
=
1000
;
w
->
count
=
w
->
data_size
;
w
->
data
=
malloc
(
w
->
data_size
);
if
(
w
->
data
==
NULL
)
{
w
->
error
=
-
ENOMEM
;
}
w
->
pos
=
0
;
w
->
ioctl
=
labcomm_dynamic_buffer_writer_ioctl
;
}
break
;
case
labcomm_writer_start
:
case
labcomm_writer_start_signature
:
{
void
*
tmp
;
w
->
data_size
=
1000
;
w
->
count
=
w
->
data_size
;
w
->
data
=
realloc
(
w
->
data
,
w
->
data_size
);
tmp
=
realloc
(
w
->
data
,
w
->
data_size
);
if
(
tmp
!=
NULL
)
{
w
->
data
=
tmp
;
w
->
error
=
0
;
}
else
{
w
->
error
=
-
ENOMEM
;
}
w
->
pos
=
0
;
}
break
;
case
labcomm_writer_continue
:
case
labcomm_writer_continue_signature
:
{
void
*
tmp
;
w
->
data_size
+=
1000
;
w
->
count
=
w
->
data_size
;
w
->
data
=
realloc
(
w
->
data
,
w
->
data_size
);
tmp
=
realloc
(
w
->
data
,
w
->
data_size
);
if
(
tmp
!=
NULL
)
{
w
->
data
=
tmp
;
}
else
{
w
->
error
=
-
ENOMEM
;
}
}
break
;
case
labcomm_writer_end
:
case
labcomm_writer_end_signature
:
{
...
...
@@ -36,6 +74,6 @@ int labcomm_dynamic_buffer_writer(
w
->
pos
=
0
;
}
break
;
}
return
0
;
return
w
->
error
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment