Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
ChimeraTK Mirror
ApplicationCore
Commits
6fa95cd7
Commit
6fa95cd7
authored
5 years ago
by
Tomasz Kozak
Browse files
Options
Downloads
Patches
Plain Diff
Start of implementation for issue #80
parent
8ab22387
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/ExceptionHandlingDecorator.h
+5
-3
5 additions, 3 deletions
include/ExceptionHandlingDecorator.h
src/Application.cc
+2
-2
2 additions, 2 deletions
src/Application.cc
src/ExceptionHandlingDecorator.cc
+29
-13
29 additions, 13 deletions
src/ExceptionHandlingDecorator.cc
with
36 additions
and
18 deletions
include/ExceptionHandlingDecorator.h
+
5
−
3
View file @
6fa95cd7
...
@@ -19,8 +19,8 @@ namespace ChimeraTK {
...
@@ -19,8 +19,8 @@ namespace ChimeraTK {
class
ExceptionHandlingDecorator
:
public
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>
{
class
ExceptionHandlingDecorator
:
public
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>
{
public:
public:
ExceptionHandlingDecorator
(
ExceptionHandlingDecorator
(
boost
::
shared_ptr
<
ChimeraTK
::
NDRegisterAccessor
<
UserType
>>
accessor
,
DeviceModule
&
devMod
)
boost
::
shared_ptr
<
ChimeraTK
::
NDRegisterAccessor
<
UserType
>>
accessor
,
DeviceModule
&
devMod
,
EntityOwner
*
owner
)
:
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>
(
accessor
),
d
m
(
devMod
)
{}
:
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>
(
accessor
),
d
eviceModule
(
devMod
),
_owner
(
owner
)
{}
bool
doWriteTransfer
(
ChimeraTK
::
VersionNumber
versionNumber
=
{})
override
;
bool
doWriteTransfer
(
ChimeraTK
::
VersionNumber
versionNumber
=
{})
override
;
...
@@ -48,9 +48,11 @@ namespace ChimeraTK {
...
@@ -48,9 +48,11 @@ namespace ChimeraTK {
void
interrupt
()
override
;
void
interrupt
()
override
;
protected
:
protected
:
DeviceModule
&
d
m
;
DeviceModule
&
d
eviceModule
;
DataValidity
validity
{
DataValidity
::
ok
};
DataValidity
validity
{
DataValidity
::
ok
};
bool
genericTransfer
(
std
::
function
<
bool
(
void
)
>
callable
,
bool
invalidateOnFailure
=
true
);
bool
genericTransfer
(
std
::
function
<
bool
(
void
)
>
callable
,
bool
invalidateOnFailure
=
true
);
void
setOwnerValidity
(
DataValidity
newValidity
);
EntityOwner
*
_owner
;
};
};
DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES
(
ExceptionHandlingDecorator
);
DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES
(
ExceptionHandlingDecorator
);
...
...
This diff is collapsed.
Click to expand it.
src/Application.cc
+
2
−
2
View file @
6fa95cd7
...
@@ -358,7 +358,7 @@ boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> Application::createDe
...
@@ -358,7 +358,7 @@ boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> Application::createDe
assert
(
devmod
!=
nullptr
);
assert
(
devmod
!=
nullptr
);
// decorate the accessor with a ExceptionHandlingDecorator and return it
// decorate the accessor with a ExceptionHandlingDecorator and return it
return
boost
::
make_shared
<
ExceptionHandlingDecorator
<
UserType
>>
(
accessor
,
*
devmod
);
return
boost
::
make_shared
<
ExceptionHandlingDecorator
<
UserType
>>
(
accessor
,
*
devmod
,
nullptr
);
}
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
...
@@ -802,7 +802,7 @@ void Application::typedMakeConnection(VariableNetwork& network) {
...
@@ -802,7 +802,7 @@ void Application::typedMakeConnection(VariableNetwork& network) {
// In case we have one or more trigger receivers among our consumers, we
// In case we have one or more trigger receivers among our consumers, we
// produce one consuming application variable for each device. Later this will create a TriggerFanOut for
// produce one consuming application variable for each device. Later this will create a TriggerFanOut for
// each trigger cons
i
mer, i.e. one per device so one blocking device does not affect the others.
// each trigger cons
u
mer, i.e. one per device so one blocking device does not affect the others.
/** Map of deviceAliases to their corresponding TriggerFanOuts. */
/** Map of deviceAliases to their corresponding TriggerFanOuts. */
std
::
map
<
std
::
string
,
boost
::
shared_ptr
<
ChimeraTK
::
NDRegisterAccessor
<
UserType
>>>
triggerFanOuts
;
std
::
map
<
std
::
string
,
boost
::
shared_ptr
<
ChimeraTK
::
NDRegisterAccessor
<
UserType
>>>
triggerFanOuts
;
...
...
This diff is collapsed.
Click to expand it.
src/ExceptionHandlingDecorator.cc
+
29
−
13
View file @
6fa95cd7
...
@@ -7,33 +7,49 @@ constexpr useconds_t DeviceOpenTimeout = 500;
...
@@ -7,33 +7,49 @@ constexpr useconds_t DeviceOpenTimeout = 500;
namespace
ChimeraTK
{
namespace
ChimeraTK
{
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
setOwnerValidity
(
DataValidity
newValidity
)
{
if
(
newValidity
!=
validity
)
{
validity
=
newValidity
;
if
(
!
_owner
)
return
;
// hack to deal with null ptr until it filled correctly
if
(
newValidity
==
DataValidity
::
faulty
)
{
_owner
->
incrementDataFaultCounter
();
}
else
{
_owner
->
decrementDataFaultCounter
();
}
}
}
template
<
typename
UserType
>
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
genericTransfer
(
bool
ExceptionHandlingDecorator
<
UserType
>::
genericTransfer
(
std
::
function
<
bool
(
void
)
>
callable
,
bool
invalidateOnFailure
)
{
std
::
function
<
bool
(
void
)
>
callable
,
bool
updateOwnerValidityFlag
)
{
std
::
function
<
void
()
>
invalidateData
{};
if
(
invalidateOnFailure
)
{
std
::
function
<
void
(
DataValidity
)
>
setOwnerValidityFunction
{};
invalidateData
=
[
=
]()
{
setDataValidity
(
DataValidity
::
faulty
);
};
if
(
updateOwnerValidityFlag
)
{
}
setOwnerValidityFunction
=
std
::
bind
(
&
ExceptionHandlingDecorator
<
UserType
>::
setOwnerValidity
,
this
,
std
::
placeholders
::
_1
);
}
else
{
else
{
invalidateData
=
[](
)
{};
// do nothing if user does
setOwnerValidityFunction
=
[](
DataValidity
)
{};
// do nothing if user does
// not want to invalidate data.
// not want to invalidate data.
}
}
while
(
true
)
{
while
(
true
)
{
try
{
try
{
if
(
!
d
m
.
device
.
isOpened
())
{
if
(
!
d
eviceModule
.
device
.
isOpened
())
{
invalidateData
(
);
setOwnerValidityFunction
(
DataValidity
::
faulty
);
Application
::
getInstance
().
testableModeUnlock
(
"waitForDeviceOpen"
);
Application
::
getInstance
().
testableModeUnlock
(
"waitForDeviceOpen"
);
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
millisec
(
DeviceOpenTimeout
));
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
millisec
(
DeviceOpenTimeout
));
Application
::
getInstance
().
testableModeLock
(
"waitForDeviceOpen"
);
Application
::
getInstance
().
testableModeLock
(
"waitForDeviceOpen"
);
continue
;
continue
;
}
}
auto
retval
=
callable
();
auto
retval
=
callable
();
setDataValidity
(
DataValidity
::
ok
);
auto
delegatedValidity
=
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
dataValidity
();
setOwnerValidityFunction
(
delegatedValidity
);
return
retval
;
return
retval
;
}
}
catch
(
ChimeraTK
::
runtime_error
&
e
)
{
catch
(
ChimeraTK
::
runtime_error
&
e
)
{
invalidateData
(
);
setOwnerValidityFunction
(
DataValidity
::
faulty
);
d
m
.
reportException
(
e
.
what
());
d
eviceModule
.
reportException
(
e
.
what
());
}
}
}
}
}
}
...
@@ -127,7 +143,7 @@ namespace ChimeraTK {
...
@@ -127,7 +143,7 @@ namespace ChimeraTK {
template
<
typename
UserType
>
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
interrupt
()
{
void
ExceptionHandlingDecorator
<
UserType
>::
interrupt
()
{
// notify the condition variable waiting in reportException of the genericTransfer
// notify the condition variable waiting in reportException of the genericTransfer
d
m
.
notify
();
d
eviceModule
.
notify
();
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
interrupt
();
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
interrupt
();
}
}
...
...
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