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
f1cf1aa5
Commit
f1cf1aa5
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
refactored c pragma. still TODO: share decoder registry
parent
5340978e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/c/labcomm.h
+3
-3
3 additions, 3 deletions
lib/c/labcomm.h
lib/c/labcomm_decoder.c
+23
-8
23 additions, 8 deletions
lib/c/labcomm_decoder.c
with
26 additions
and
11 deletions
lib/c/labcomm.h
+
3
−
3
View file @
f1cf1aa5
...
...
@@ -117,7 +117,7 @@ void labcomm_decoder_free(
struct
labcomm_decoder
*
decoder
);
int
labcomm_decoder_decode_one
(
struct
labcomm_decoder
*
decoder
);
void
labcomm_decoder_run
(
int
labcomm_decoder_run
(
struct
labcomm_decoder
*
decoder
);
/* See labcomm_ioctl.h for predefined ioctl_action values */
...
...
@@ -137,12 +137,12 @@ struct labcomm_pragma_handler {
int
foo
;
};
typedef
int
(
*
labcomm_
handle_pragma
_callback
)(
typedef
int
(
*
labcomm_
pragma_handler
_callback
)(
struct
labcomm_decoder
*
decoder
,
char
*
pragma_type
);
void
labcomm_decoder_register_pragma_handler
(
struct
labcomm_decoder
*
d
,
labcomm_
handle_pragma
_callback
pragma_dispatcher
);
labcomm_
pragma_handler
_callback
pragma_dispatcher
);
/*
* Encoder
...
...
This diff is collapsed.
Click to expand it.
lib/c/labcomm_decoder.c
+
23
−
8
View file @
f1cf1aa5
...
...
@@ -35,6 +35,17 @@ struct sample_entry {
void
*
context
;
};
//XXX move to pragma.ch
//int default_pragma_handler(struct labcomm_decoder *d, char *pragma_type);
int
default_pragma_handler
(
struct
labcomm_decoder
*
d
,
char
*
pragma_type
)
{
printf
(
"Default pragma handler got pragma: %s
\n
"
,
pragma_type
);
int
res
=
labcomm_decoder_run
(
d
);
printf
(
"... %d:%s
\n
"
,
res
,
strerror
(
-
res
));
return
LABCOMM_PRAGMA
;
}
struct
labcomm_decoder
{
struct
labcomm_reader
*
reader
;
int
reader_allocated
;
...
...
@@ -46,6 +57,7 @@ struct labcomm_decoder {
labcomm_handle_new_datatype_callback
on_new_datatype
;
LABCOMM_SIGNATURE_ARRAY_DEF
(
local
,
struct
sample_entry
);
LABCOMM_SIGNATURE_ARRAY_DEF
(
remote_to_local
,
int
);
labcomm_pragma_handler_callback
pragma_handler
;
};
struct
labcomm_decoder
*
labcomm_decoder_new
(
...
...
@@ -73,6 +85,7 @@ struct labcomm_decoder *labcomm_decoder_new(
result
->
on_error
=
on_error_fprintf
;
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
local
,
struct
sample_entry
);
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
remote_to_local
,
int
);
result
->
pragma_handler
=
default_pragma_handler
;
}
return
result
;
}
...
...
@@ -253,8 +266,7 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
}
int
bytes
=
labcomm_size_string
(
pragma_type
);
int
psize
=
len
-
bytes
;
printf
(
"got pragma: %s
\n
"
,
pragma_type
);
if
(
0
/*d->pragma_handler*/
)
{
if
(
d
->
pragma_handler
)
{
//read the entire packet to a buffer and then run
// decode on that through a bytearray_reader.
// (to easily handle multiple labcomm packets in one metadata packet)
...
...
@@ -267,18 +279,19 @@ static int decode_pragma(struct labcomm_decoder *d, int len)
goto
out
;
}
}
printf
(
"read %d bytes
\n
"
,
psize
);
//
printf("read %d bytes\n", psize);
//TODO: add wrapped decoders, and create pragma decoder that does not
// expect a version packet
struct
labcomm_reader
*
pr
=
labcomm_bytearray_reader_new
(
d
->
reader
->
memory
,
pragma_data
,
psize
);
struct
labcomm_decoder
*
pd
=
labcomm_decoder_new
(
pr
,
d
->
error
,
d
->
memory
,
d
->
scheduler
);
/* d->prama_handler(pd, ptype, plen); */
labcomm_decoder_run
(
pd
);
pd
->
version_ok
=
1
;
printf
(
"calling pragma_handler
\n
"
);
result
=
d
->
pragma_handler
(
pd
,
pragma_type
);
printf
(
"returned from pragma_handler
\n
"
);
internal_labcomm_decoder_free
(
pd
);
result
=
0
;
}
else
{
result
=
decoder_skip
(
d
,
psize
,
LABCOMM_PRAGMA
);
}
...
...
@@ -356,10 +369,12 @@ out:
return
result
;
}
void
labcomm_decoder_run
(
struct
labcomm_decoder
*
d
)
int
labcomm_decoder_run
(
struct
labcomm_decoder
*
d
)
{
while
(
labcomm_decoder_decode_one
(
d
)
>
0
)
{
int
res
;
while
(
(
res
=
labcomm_decoder_decode_one
(
d
))
>
0
)
{
}
return
res
;
}
int
labcomm_decoder_ioctl
(
struct
labcomm_decoder
*
d
,
...
...
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