Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
RobotAPI
Commits
112f6117
Commit
112f6117
authored
3 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add owning component (for use with dependency).
Add useReader() and useWriter() Improve doc
parent
980a1a6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/RobotAPI/libraries/armem/mns/Client.cpp
+66
-7
66 additions, 7 deletions
source/RobotAPI/libraries/armem/mns/Client.cpp
source/RobotAPI/libraries/armem/mns/Client.h
+43
-10
43 additions, 10 deletions
source/RobotAPI/libraries/armem/mns/Client.h
with
109 additions
and
17 deletions
source/RobotAPI/libraries/armem/mns/Client.cpp
+
66
−
7
View file @
112f6117
...
...
@@ -16,7 +16,8 @@ namespace armarx::armem::mns
}
Client
::
Client
(
MemoryNameSystemInterfacePrx
mns
)
:
mns
(
mns
)
Client
::
Client
(
MemoryNameSystemInterfacePrx
mns
,
ManagedIceObject
*
component
)
:
mns
(
mns
),
component
(
component
)
{
}
...
...
@@ -24,12 +25,11 @@ namespace armarx::armem::mns
void
Client
::
update
()
{
ARMARX_CHECK_NOT_NULL
(
mns
);
data
::
GetAllRegisteredMemoriesResult
result
=
mns
->
getAllRegisteredMemories
();
if
(
result
.
success
)
{
this
->
memoryMap
=
result
.
proxies
;
this
->
servers
=
result
.
proxies
;
}
else
{
...
...
@@ -40,14 +40,14 @@ namespace armarx::armem::mns
server
::
MemoryInterfacePrx
Client
::
resolveServer
(
const
MemoryID
&
memoryID
)
{
if
(
auto
it
=
memoryMap
.
find
(
memoryID
.
memoryName
);
it
!=
memoryMap
.
end
())
if
(
auto
it
=
servers
.
find
(
memoryID
.
memoryName
);
it
!=
servers
.
end
())
{
return
it
->
second
;
}
else
{
update
();
if
(
auto
it
=
memoryMap
.
find
(
memoryID
.
memoryName
);
it
!=
memoryMap
.
end
())
if
(
auto
it
=
servers
.
find
(
memoryID
.
memoryName
);
it
!=
servers
.
end
())
{
return
it
->
second
;
}
...
...
@@ -61,7 +61,7 @@ namespace armarx::armem::mns
server
::
MemoryInterfacePrx
Client
::
waitForServer
(
const
MemoryID
&
memoryID
,
Time
timeout
)
{
if
(
auto
it
=
memoryMap
.
find
(
memoryID
.
memoryName
);
it
!=
memoryMap
.
end
())
if
(
auto
it
=
servers
.
find
(
memoryID
.
memoryName
);
it
!=
servers
.
end
())
{
return
it
->
second
;
}
...
...
@@ -71,6 +71,7 @@ namespace armarx::armem::mns
input
.
name
=
memoryID
.
memoryName
;
input
.
timeoutMilliSeconds
=
timeout
.
toMilliSeconds
();
ARMARX_CHECK_NOT_NULL
(
mns
);
armem
::
data
::
WaitForMemoryResult
result
=
mns
->
waitForMemory
(
input
);
if
(
result
.
success
)
{
...
...
@@ -83,6 +84,17 @@ namespace armarx::armem::mns
}
}
server
::
MemoryInterfacePrx
Client
::
useServer
(
const
MemoryID
&
memoryID
)
{
ARMARX_CHECK_NOT_NULL
(
component
)
<<
"Owning component not set when using a memory server.
\n
"
<<
"When calling `armem::mns::Client::useServer()`, the owning component which should "
<<
"receive the dependency to the memory server must be set beforehand.
\n\n
"
<<
"Use `armem::mns::Client::setComponent()` or pass the component on construction "
<<
"before calling useServer()."
;
return
useServer
(
memoryID
,
*
component
);
}
server
::
MemoryInterfacePrx
Client
::
useServer
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
)
{
...
...
@@ -97,12 +109,32 @@ namespace armarx::armem::mns
return
client
::
Reader
(
resolveServer
(
memoryID
));
}
client
::
Reader
Client
::
useReader
(
const
MemoryID
&
memoryID
)
{
return
client
::
Reader
(
useServer
(
memoryID
));
}
client
::
Reader
Client
::
useReader
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
)
{
return
client
::
Reader
(
useServer
(
memoryID
,
component
));
}
client
::
Reader
Client
::
useReader
(
const
std
::
string
&
memoryName
)
{
return
useReader
(
MemoryID
().
withMemoryName
(
memoryName
));
}
client
::
Reader
Client
::
useReader
(
const
std
::
string
&
memoryName
,
ManagedIceObject
&
component
)
{
return
useReader
(
MemoryID
().
withMemoryName
(
memoryName
),
component
);
}
template
<
class
ClientT
>
std
::
map
<
std
::
string
,
ClientT
>
Client
::
_getAllClients
()
const
{
std
::
map
<
std
::
string
,
ClientT
>
result
;
for
(
const
auto
&
[
name
,
server
]
:
memoryMap
)
for
(
const
auto
&
[
name
,
server
]
:
servers
)
{
result
[
name
]
=
ClientT
(
server
);
}
...
...
@@ -138,6 +170,26 @@ namespace armarx::armem::mns
return
client
::
Writer
(
resolveServer
(
memoryID
));
}
client
::
Writer
Client
::
useWriter
(
const
MemoryID
&
memoryID
)
{
return
client
::
Writer
(
useServer
(
memoryID
));
}
client
::
Writer
Client
::
useWriter
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
)
{
return
client
::
Writer
(
useServer
(
memoryID
,
component
));
}
client
::
Writer
Client
::
useWriter
(
const
std
::
string
&
memoryName
)
{
return
useWriter
(
MemoryID
().
withMemoryName
(
memoryName
));
}
client
::
Writer
Client
::
useWriter
(
const
std
::
string
&
memoryName
,
ManagedIceObject
&
component
)
{
return
useWriter
(
MemoryID
().
withMemoryName
(
memoryName
),
component
);
}
std
::
map
<
std
::
string
,
client
::
Writer
>
Client
::
getAllWriters
(
bool
update
)
{
...
...
@@ -158,6 +210,7 @@ namespace armarx::armem::mns
input
.
proxy
=
proxy
;
ARMARX_CHECK_NOT_NULL
(
input
.
proxy
);
ARMARX_CHECK_NOT_NULL
(
mns
);
data
::
RegisterMemoryResult
result
=
mns
->
registerMemory
(
input
);
if
(
!
result
.
success
)
{
...
...
@@ -171,6 +224,7 @@ namespace armarx::armem::mns
data
::
RemoveMemoryInput
input
;
input
.
name
=
memoryID
.
memoryName
;
ARMARX_CHECK_NOT_NULL
(
mns
);
data
::
RemoveMemoryResult
result
=
mns
->
removeMemory
(
input
);
if
(
!
result
.
success
)
{
...
...
@@ -190,6 +244,11 @@ namespace armarx::armem::mns
this
->
mns
=
mns
;
}
void
Client
::
setComponent
(
ManagedIceObject
*
component
)
{
this
->
component
=
component
;
}
}
...
...
This diff is collapsed.
Click to expand it.
source/RobotAPI/libraries/armem/mns/Client.h
+
43
−
10
View file @
112f6117
...
...
@@ -44,25 +44,40 @@ namespace armarx::armem::mns
/**
* @brief The memory name system (MNS) client.
*
* This client class has a proxy to the MNS and can be used to construct
* (single) Memory Clients as well as fetch the data for any Memory IDs.
* Like in DNS, it stores a map from memory names to proxies which is used
* if the respective entry exists. Otherwise, it queries the MNS.
* Provides the other interface functions of the MNS.
* Can be used to query arbitrary Memory IDs (resolving the memory name,
* then sending a query to that memory, returning the result).
* This client class serves provides the MNS interface and is a local cache
* of the MNS registry. It can be used to resolve memory servers by their
* memory ID and to construct `client::Readers` and `client::Writers`.
*
* During server resolution, it first consults the locally cached registry.
* If the memory server is not known locally, the local registry is
* updated to that of the remote MNS before trying again.
*
* In addition, the MNS client can be used to send queries over multiple
* memory servers, as well as retrieving the data for arbitrary entity or
* entity snapshot IDs.
*/
class
Client
{
public:
Client
();
Client
(
MemoryNameSystemInterfacePrx
mns
);
/**
* @brief Construct an MNS client.
*
* @param mns The MNS proxy.
* @param component The owning component. When `using` a memory server,
* dependencies will be added to this component.
*/
Client
(
MemoryNameSystemInterfacePrx
mns
,
ManagedIceObject
*
component
=
nullptr
);
mns
::
MemoryNameSystemInterfacePrx
getMemoryNameSystem
()
const
;
void
getMemoryNameSystem
(
mns
::
MemoryNameSystemInterfacePrx
mns
);
void
setComponent
(
ManagedIceObject
*
component
);
// Name Resolution
...
...
@@ -103,6 +118,7 @@ namespace armarx::armem::mns
*
* @throw `error::CouldNotResolveMemoryServer` If the memory name could not be resolved.
*/
server
::
MemoryInterfacePrx
useServer
(
const
MemoryID
&
memoryID
);
server
::
MemoryInterfacePrx
useServer
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
);
...
...
@@ -118,6 +134,11 @@ namespace armarx::armem::mns
*/
client
::
Reader
getReader
(
const
MemoryID
&
memoryID
);
client
::
Reader
useReader
(
const
MemoryID
&
memoryID
);
client
::
Reader
useReader
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
);
client
::
Reader
useReader
(
const
std
::
string
&
memoryName
);
client
::
Reader
useReader
(
const
std
::
string
&
memoryName
,
ManagedIceObject
&
component
);
/**
* @brief Get Readers for all registered servers.
*
...
...
@@ -144,6 +165,11 @@ namespace armarx::armem::mns
*/
client
::
Writer
getWriter
(
const
MemoryID
&
memoryID
);
client
::
Writer
useWriter
(
const
MemoryID
&
memoryID
);
client
::
Writer
useWriter
(
const
MemoryID
&
memoryID
,
ManagedIceObject
&
component
);
client
::
Writer
useWriter
(
const
std
::
string
&
memoryName
);
client
::
Writer
useWriter
(
const
std
::
string
&
memoryName
,
ManagedIceObject
&
component
);
/**
* @brief Get Writers for all registered servers.
*
...
...
@@ -159,6 +185,10 @@ namespace armarx::armem::mns
std
::
map
<
std
::
string
,
client
::
Writer
>
getAllWriters
()
const
;
// ToDo: commit() and query()
// Registration - only for memory servers
/**
...
...
@@ -199,10 +229,13 @@ namespace armarx::armem::mns
std
::
map
<
std
::
string
,
ClientT
>
_getAllClients
()
const
;
/// The MNS proxy.
MemoryNameSystemInterfacePrx
mns
=
nullptr
;
/// The component to which dependencies will be added.
ManagedIceObject
*
component
=
nullptr
;
std
::
map
<
std
::
string
,
server
::
MemoryInterfacePrx
>
memoryMap
;
/// The registered memory servers.
std
::
map
<
std
::
string
,
server
::
MemoryInterfacePrx
>
servers
;
};
...
...
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