Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthieu Dorier
codes
Commits
c551f247
Commit
c551f247
authored
Jul 15, 2014
by
Jonathan Jenkins
Browse files
facilities for mapping LP types to used annotations
parent
84879755
Changes
4
Hide whitespace changes
Inline
Side-by-side
codes/codes_mapping.h
View file @
c551f247
...
@@ -48,6 +48,14 @@ const char* codes_mapping_get_annotation_by_name(char *grp_name, char *lp_type_n
...
@@ -48,6 +48,14 @@ const char* codes_mapping_get_annotation_by_name(char *grp_name, char *lp_type_n
* are for convenience */
* are for convenience */
const
char
*
codes_mapping_get_annotation_by_lpid
(
tw_lpid
gid
);
const
char
*
codes_mapping_get_annotation_by_lpid
(
tw_lpid
gid
);
/*
* Returns a mapping of LP name to all annotations used with the type
*
* lp_name - lp name as used in the configuration
*/
const
config_anno_map_t
*
codes_mapping_get_lp_anno_map
(
const
char
*
lp_name
);
/*
/*
* Local variables:
* Local variables:
* c-indent-level: 4
* c-indent-level: 4
...
...
codes/configuration.h
View file @
c551f247
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#define CONFIGURATION_MAX_NAME 256
#define CONFIGURATION_MAX_NAME 256
#define CONFIGURATION_MAX_GROUPS 10
#define CONFIGURATION_MAX_GROUPS 10
#define CONFIGURATION_MAX_TYPES 10
#define CONFIGURATION_MAX_TYPES 10
#define CONFIGURATION_MAX_ANNOS 10
typedef
struct
config_lptype_s
typedef
struct
config_lptype_s
{
{
...
@@ -30,10 +31,26 @@ typedef struct config_lpgroup_s
...
@@ -30,10 +31,26 @@ typedef struct config_lpgroup_s
uint64_t
lptypes_count
;
uint64_t
lptypes_count
;
}
config_lpgroup_t
;
}
config_lpgroup_t
;
// mapping of lp type to the list of annotations used. Used for convenience when
// models are performing configuraiton code
typedef
struct
config_anno_map_s
{
char
lp_name
[
CONFIGURATION_MAX_NAME
];
// only explicit annotations tracked here - use a flag to indicate a
// non-annotated LP type
uint64_t
num_unanno_lps
;
uint64_t
num_annos
;
// maintain the number of lps that have the particular annotation
uint64_t
num_anno_lps
[
CONFIGURATION_MAX_ANNOS
];
char
*
annotations
[
CONFIGURATION_MAX_ANNOS
];
}
config_anno_map_t
;
typedef
struct
config_lpgroups_s
typedef
struct
config_lpgroups_s
{
{
config_lpgroup_t
lpgroups
[
CONFIGURATION_MAX_GROUPS
];
uint64_t
lpgroups_count
;
uint64_t
lpgroups_count
;
config_lpgroup_t
lpgroups
[
CONFIGURATION_MAX_GROUPS
];
uint64_t
lpannos_count
;
config_anno_map_t
lpannos
[
CONFIGURATION_MAX_TYPES
];
}
config_lpgroups_t
;
}
config_lpgroups_t
;
/*
/*
...
...
src/util/codes_mapping.c
View file @
c551f247
...
@@ -410,6 +410,21 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){
...
@@ -410,6 +410,21 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){
return
NULL
;
return
NULL
;
}
}
/*
* Returns a mapping of LP name to all annotations used with the type
*
* lp_name - lp name as used in the configuration
*/
const
config_anno_map_t
*
codes_mapping_get_lp_anno_map
(
const
char
*
lp_name
){
for
(
uint64_t
i
=
0
;
i
<
lpconf
.
lpannos_count
;
i
++
){
if
(
strcmp
(
lp_name
,
lpconf
.
lpannos
[
i
].
lp_name
)
==
0
){
return
&
lpconf
.
lpannos
[
i
];
}
}
return
NULL
;
}
/*
/*
* Local variables:
* Local variables:
* c-indent-level: 4
* c-indent-level: 4
...
...
src/util/configuration.c
View file @
c551f247
...
@@ -263,6 +263,55 @@ int configuration_get_value_double (ConfigHandle *handle,
...
@@ -263,6 +263,55 @@ int configuration_get_value_double (ConfigHandle *handle,
return
rc
;
return
rc
;
}
}
static
void
check_add_anno
(
const
char
*
anno
,
config_anno_map_t
*
map
){
if
(
anno
[
0
]
==
'\0'
){
map
->
num_unanno_lps
++
;
}
else
{
uint64_t
a
=
0
;
for
(;
a
<
map
->
num_annos
;
a
++
){
if
(
strcmp
(
map
->
annotations
[
a
],
anno
)
==
0
){
map
->
num_anno_lps
[
a
]
++
;
break
;
}
}
if
(
a
==
map
->
num_annos
){
// we have a new anno!
assert
(
a
<
CONFIGURATION_MAX_ANNOS
);
map
->
annotations
[
a
]
=
strdup
(
anno
);
map
->
num_annos
++
;
map
->
num_anno_lps
[
a
]
=
1
;
}
// else anno was already there, do nothing
}
}
static
void
check_add_lp_type_anno
(
const
char
*
lp_name
,
const
char
*
anno
,
config_lpgroups_t
*
lpgroups
){
uint64_t
lpt_anno
=
0
;
for
(;
lpt_anno
<
lpgroups
->
lpannos_count
;
lpt_anno
++
){
config_anno_map_t
*
map
=
&
lpgroups
->
lpannos
[
lpt_anno
];
if
(
strcmp
(
map
->
lp_name
,
lp_name
)
==
0
){
check_add_anno
(
anno
,
map
);
}
}
if
(
lpt_anno
==
lpgroups
->
lpannos_count
){
// we haven't seen this lp type before
assert
(
lpt_anno
<
CONFIGURATION_MAX_TYPES
);
config_anno_map_t
*
map
=
&
lpgroups
->
lpannos
[
lpt_anno
];
// initialize this annotation map
strcpy
(
map
->
lp_name
,
lp_name
);
map
->
num_annos
=
0
;
map
->
num_unanno_lps
=
0
;
memset
(
map
->
num_anno_lps
,
0
,
CONFIGURATION_MAX_ANNOS
*
sizeof
(
*
map
->
num_anno_lps
));
check_add_anno
(
anno
,
map
);
lpgroups
->
lpannos_count
++
;
}
}
int
configuration_get_lpgroups
(
ConfigHandle
*
handle
,
int
configuration_get_lpgroups
(
ConfigHandle
*
handle
,
const
char
*
section_name
,
const
char
*
section_name
,
config_lpgroups_t
*
lpgroups
)
config_lpgroups_t
*
lpgroups
)
...
@@ -321,6 +370,8 @@ int configuration_get_lpgroups (ConfigHandle *handle,
...
@@ -321,6 +370,8 @@ int configuration_get_lpgroups (ConfigHandle *handle,
else
{
else
{
anno
[
0
]
=
'\0'
;
anno
[
0
]
=
'\0'
;
}
}
// add to anno map
check_add_lp_type_anno
(
nm
,
anno
,
lpgroups
);
lpgroups
->
lpgroups
[
i
].
lptypes
[
lpt
].
count
=
atoi
(
data
);
lpgroups
->
lpgroups
[
i
].
lptypes
[
lpt
].
count
=
atoi
(
data
);
lpgroups
->
lpgroups
[
i
].
lptypes_count
++
;
lpgroups
->
lpgroups
[
i
].
lptypes_count
++
;
lpt
++
;
lpt
++
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment