Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
etherlabmaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
ICS Control System Infrastructure
etherlabmaster
Commits
648880d9
Commit
648880d9
authored
14 years ago
by
Florian Pose
Browse files
Options
Downloads
Plain Diff
merge
parents
db0e84aa
c5782a25
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tool/Command.cpp
+74
-56
74 additions, 56 deletions
tool/Command.cpp
tool/NumberListParser.cpp
+2
-1
2 additions, 1 deletion
tool/NumberListParser.cpp
with
76 additions
and
57 deletions
tool/Command.cpp
+
74
−
56
View file @
648880d9
...
...
@@ -38,6 +38,11 @@ using namespace std;
/*****************************************************************************/
typedef
map
<
uint16_t
,
ec_ioctl_config_t
>
AliasMap
;
typedef
map
<
uint16_t
,
AliasMap
>
ConfigMap
;
/*****************************************************************************/
class
MasterIndexParser
:
public
NumberListParser
{
...
...
@@ -85,27 +90,14 @@ class ConfigAliasParser:
public
NumberListParser
{
public:
ConfigAliasParser
(
ec_ioctl_master_
t
&
ma
ster
,
MasterDevice
&
dev
)
:
ma
ster
(
master
),
dev
(
dev
)
{}
ConfigAliasParser
(
unsigned
in
t
ma
xAlias
)
:
ma
xAlias
(
maxAlias
)
{}
protected
:
int
getMax
()
{
unsigned
int
i
;
uint16_t
maxAlias
=
0
;
for
(
i
=
0
;
i
<
master
.
config_count
;
i
++
)
{
ec_ioctl_config_t
config
;
dev
.
getConfig
(
&
config
,
i
);
if
(
config
.
alias
>
maxAlias
)
{
maxAlias
=
config
.
alias
;
}
}
return
maxAlias
?
maxAlias
:
-
1
;
};
int
getMax
()
{
return
maxAlias
;
};
private
:
ec_ioctl_master_t
&
master
;
MasterDevice
&
dev
;
unsigned
int
maxAlias
;
};
/*****************************************************************************/
...
...
@@ -128,6 +120,33 @@ class PositionParser:
/*****************************************************************************/
class
AliasPositionParser
:
public
NumberListParser
{
public:
AliasPositionParser
(
const
AliasMap
&
aliasMap
)
:
aliasMap
(
aliasMap
)
{}
protected
:
int
getMax
()
{
AliasMap
::
const_iterator
i
;
int
maxPos
=
-
1
;
for
(
i
=
aliasMap
.
begin
();
i
!=
aliasMap
.
end
();
i
++
)
{
if
(
i
->
first
>
maxPos
)
{
maxPos
=
i
->
first
;
}
}
return
maxPos
;
};
private
:
const
AliasMap
&
aliasMap
;
};
/*****************************************************************************/
Command
::
Command
(
const
string
&
name
,
const
string
&
briefDesc
)
:
name
(
name
),
briefDesc
(
briefDesc
),
...
...
@@ -293,11 +312,13 @@ Command::MasterIndexList Command::getMasterIndices() const
unsigned
int
Command
::
getSingleMasterIndex
()
const
{
MasterIndexList
masterIndices
=
getMasterIndices
();
if
(
masterIndices
.
size
()
!=
1
)
{
stringstream
err
;
err
<<
getName
()
<<
" requires to select a single master!"
;
throwInvalidUsageException
(
err
);
}
return
masterIndices
.
front
();
}
...
...
@@ -316,9 +337,12 @@ Command::SlaveList Command::selectedSlaves(MasterDevice &m)
PositionParser
pp
(
master
.
slave_count
);
NumberListParser
::
List
posList
=
pp
.
parse
(
positions
.
c_str
());
NumberListParser
::
List
::
const_iterator
pi
;
for
(
pi
=
posList
.
begin
();
pi
!=
posList
.
end
();
pi
++
)
{
m
.
getSlave
(
&
slave
,
*
pi
);
list
.
push_back
(
slave
);
if
(
*
pi
<
master
.
slave_count
)
{
m
.
getSlave
(
&
slave
,
*
pi
);
list
.
push_back
(
slave
);
}
}
}
else
{
// aliases given
SlaveAliasParser
ap
(
master
,
m
);
...
...
@@ -353,11 +377,6 @@ Command::SlaveList Command::selectedSlaves(MasterDevice &m)
for
(
pi
=
posList
.
begin
();
pi
!=
posList
.
end
();
pi
++
)
{
if
(
*
pi
<
aliasSlaves
.
size
())
{
list
.
push_back
(
aliasSlaves
[
*
pi
]);
}
else
{
stringstream
err
;
err
<<
"Warning: Slave "
<<
*
ai
<<
":"
<<
*
pi
<<
" does not exist on master "
<<
m
.
getIndex
();
throwCommandException
(
err
);
}
}
}
...
...
@@ -389,50 +408,47 @@ Command::ConfigList Command::selectedConfigs(MasterDevice &m)
m
.
getMaster
(
&
master
);
if
(
aliases
==
"-"
)
{
// no alias given
PositionParser
pp
(
master
.
config_count
);
NumberListParser
::
List
posList
=
pp
.
parse
(
positions
.
c_str
());
NumberListParser
::
List
::
const_iterator
pi
;
for
(
pi
=
posList
.
begin
();
pi
!=
posList
.
end
();
pi
++
)
{
m
.
getConfig
(
&
config
,
*
pi
);
// FIXME use sorted list
if
(
aliases
==
"-"
&&
positions
==
"-"
)
{
// shortcut
for
(
i
=
0
;
i
<
master
.
config_count
;
i
++
)
{
m
.
getConfig
(
&
config
,
i
);
list
.
push_back
(
config
);
}
}
else
{
// alias given
ConfigAliasParser
ap
(
master
,
m
);
}
else
{
// take the long way home...
ConfigMap
configs
;
uint16_t
maxAlias
=
0
;
// fill cascaded map structure with all configs
for
(
i
=
0
;
i
<
master
.
config_count
;
i
++
)
{
m
.
getConfig
(
&
config
,
i
);
AliasMap
&
aliasMap
=
configs
[
config
.
alias
];
aliasMap
[
config
.
position
]
=
config
;
if
(
config
.
alias
>
maxAlias
)
{
maxAlias
=
config
.
alias
;
}
}
ConfigAliasParser
ap
(
maxAlias
);
NumberListParser
::
List
aliasList
=
ap
.
parse
(
aliases
.
c_str
());
NumberListParser
::
List
::
const_iterator
ai
;
for
(
ai
=
aliasList
.
begin
();
ai
!=
aliasList
.
end
();
ai
++
)
{
// gather configs with that alias
map
<
uint16_t
,
ec_ioctl_config_t
>
aliasConfigs
;
int
maxPos
=
-
1
;
for
(
i
=
0
;
i
<
master
.
config_count
;
i
++
)
{
m
.
getConfig
(
&
config
,
i
);
if
(
config
.
alias
==
*
ai
)
{
aliasConfigs
[
config
.
position
]
=
config
;
if
(
config
.
position
>
maxPos
)
{
maxPos
=
config
.
position
;
}
}
ConfigMap
::
iterator
ci
=
configs
.
find
(
*
ai
);
if
(
ci
==
configs
.
end
())
{
continue
;
}
PositionParser
pp
(
maxPos
+
1
);
AliasMap
&
aliasMap
=
configs
[
*
ai
];
AliasPositionParser
pp
(
aliasMap
);
NumberListParser
::
List
posList
=
pp
.
parse
(
positions
.
c_str
());
NumberListParser
::
List
::
const_iterator
pi
;
for
(
pi
=
posList
.
begin
();
pi
!=
posList
.
end
();
pi
++
)
{
map
<
uint16_t
,
ec_ioctl_config_t
>::
const_iterator
ci
;
ci
=
aliasConfigs
.
find
(
*
pi
);
AliasMap
::
const_iterator
ci
;
if
(
ci
!=
aliasConfigs
.
end
())
{
ci
=
aliasMap
.
find
(
*
pi
);
if
(
ci
!=
aliasMap
.
end
())
{
list
.
push_back
(
ci
->
second
);
}
else
{
stringstream
err
;
err
<<
"Warning: Config "
<<
*
ai
<<
":"
<<
*
pi
<<
" does not exist on master "
<<
m
.
getIndex
();
throwCommandException
(
err
);
}
}
}
...
...
@@ -456,9 +472,11 @@ Command::DomainList Command::selectedDomains(MasterDevice &m)
NumberListParser
::
List
::
const_iterator
di
;
for
(
di
=
domList
.
begin
();
di
!=
domList
.
end
();
di
++
)
{
ec_ioctl_domain_t
d
;
m
.
getDomain
(
&
d
,
*
di
);
list
.
push_back
(
d
);
if
(
*
di
<
master
.
domain_count
)
{
ec_ioctl_domain_t
d
;
m
.
getDomain
(
&
d
,
*
di
);
list
.
push_back
(
d
);
}
}
return
list
;
...
...
This diff is collapsed.
Click to expand it.
tool/NumberListParser.cpp
+
2
−
1
View file @
648880d9
...
...
@@ -109,7 +109,8 @@ NumberListParser::List NumberListParser::parse(const char *data)
case
Range
:
if
(
i
>=
size
)
{
int
max
=
maximum
();
if
(
max
>=
0
)
{
// only increasing ranges if second number omitted
if
(
max
>=
0
&&
firstNum
<=
(
unsigned
int
)
max
)
{
List
r
=
range
(
firstNum
,
max
);
ret
.
splice
(
ret
.
end
(),
r
);
}
...
...
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