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
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Tommy Olofsson
LabComm
Commits
8a72b48b
Commit
8a72b48b
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
sketched pragma handler lookup
parent
a93cdfa7
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_decoder.c
+16
-5
16 additions, 5 deletions
lib/c/labcomm_decoder.c
lib/c/labcomm_pragma.h
+23
-9
23 additions, 9 deletions
lib/c/labcomm_pragma.h
with
39 additions
and
14 deletions
lib/c/labcomm_decoder.c
+
16
−
5
View file @
8a72b48b
...
...
@@ -41,7 +41,8 @@ static int internal_decode_one(struct labcomm_decoder *d,
struct
labcomm_decoder
*
registry
);
int
default_pragma_handler
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
,
char
*
pragma_type
)
char
*
pragma_type
,
void
*
context
)
{
printf
(
"Default pragma handler got pragma: %s
\n
"
,
pragma_type
);
int
res
=
internal_decoder_run
(
d
,
registry
);
...
...
@@ -49,6 +50,13 @@ int default_pragma_handler(struct labcomm_decoder *d,
return
LABCOMM_PRAGMA
;
}
labcomm_pragma_handler_callback
default_pragma_handler_lookup
(
char
*
pragma_type
,
struct
labcomm_decoder
*
d
,
void
*
context
)
{
return
default_pragma_handler
;
}
struct
labcomm_decoder
{
struct
labcomm_reader
*
reader
;
...
...
@@ -61,7 +69,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
;
labcomm_pragma_handler_
lookup
pragma_handler
_lookup
;
};
struct
labcomm_decoder
*
labcomm_decoder_new
(
...
...
@@ -89,7 +97,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
;
result
->
pragma_handler
_lookup
=
default_pragma_handler
_lookup
;
}
return
result
;
}
...
...
@@ -279,6 +287,7 @@ static int decode_pragma(struct labcomm_decoder *d,
{
char
*
pragma_type
;
int
result
;
labcomm_pragma_handler_callback
handler
;
pragma_type
=
labcomm_read_string
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
...
...
@@ -286,7 +295,8 @@ static int decode_pragma(struct labcomm_decoder *d,
}
int
bytes
=
labcomm_size_string
(
pragma_type
);
int
psize
=
len
-
bytes
;
if
(
d
->
pragma_handler
)
{
handler
=
d
->
pragma_handler_lookup
(
pragma_type
,
d
,
0
);
if
(
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)
...
...
@@ -309,8 +319,9 @@ static int decode_pragma(struct labcomm_decoder *d,
struct
labcomm_decoder
*
pd
=
labcomm_decoder_new
(
pr
,
d
->
error
,
d
->
memory
,
d
->
scheduler
);
pd
->
version_ok
=
1
;
void
*
pragma_context
=
0
;
printf
(
"calling pragma_handler
\n
"
);
result
=
d
->
pragma_
handler
(
pd
,
registry
,
pragma_type
);
result
=
handler
(
pd
,
registry
,
pragma_type
,
pragma_context
);
printf
(
"returned from pragma_handler
\n
"
);
internal_labcomm_decoder_free
(
pd
);
...
...
This diff is collapsed.
Click to expand it.
lib/c/labcomm_pragma.h
+
23
−
9
View file @
8a72b48b
...
...
@@ -2,6 +2,7 @@
labcomm_pragma.h -- user interface for handling labcomm pragma packets.
Copyright 2014 Sven Gestegård Robertz <sven.robertz@cs.lth.se>
Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
...
...
@@ -25,24 +26,37 @@
typedef
int
(
*
labcomm_pragma_handler_callback
)(
struct
labcomm_decoder
*
decoder
,
struct
labcomm_decoder
*
registry
,
char
*
pragma_type
);
char
*
pragma_type
,
void
*
context
);
typedef
labcomm_pragma_handler_callback
(
*
labcomm_pragma_handler_lookup
)(
char
*
pragma_type
,
struct
labcomm_decoder
*
d
,
void
*
context
);
void
labcomm_decoder_register_pragma_handler_lookup
(
struct
labcomm_decoder
*
d
,
labcomm_pragma_handler_lookup
pragma_lookup
,
void
*
context
);
/*XXX TODO: rename to _callback? */
void
labcomm_decoder_register_pragma_handler
(
struct
labcomm_decoder
*
d
,
labcomm_pragma_handler_callback
pragma_dispatcher
);
labcomm_pragma_handler_callback
pragma_dispatcher
,
void
*
context
);
/*XXX TODO: rename to _callback? */
int
default_pragma_handler
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
,
char
*
pragma_type
);
char
*
pragma_type
,
void
*
context
);
labcomm_pragma_handler_callback
default_pragma_handler_lookup
(
char
*
pragma_type
,
struct
labcomm_decoder
*
d
,
void
*
context
);
struct
labcomm_encoder
*
labcomm_pragma_builder_new
(
struct
labcomm_encoder
*
e
,
char
*
pragma_type
)
;
int
labcomm_pragma_send
(
struct
labcomm_encoder
*
e
);
struct
labcomm_pragma_handler
{
//struct labcomm_decoder_registry *registry;
//TODO: implement map (char * pragma_type) --> decoder_registry *
//to allow having different sets of handlers for different pragma types
int
foo
;
};
#endif
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