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
9468db94
Commit
9468db94
authored
5 years ago
by
tkozak
Browse files
Options
Downloads
Patches
Plain Diff
Fix typo - make project compilable
parent
d0d98378
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ExceptionHandlingDecorator.cc
+117
-110
117 additions, 110 deletions
src/ExceptionHandlingDecorator.cc
with
117 additions
and
110 deletions
src/ExceptionHandlingDecorator.cc
+
117
−
110
View file @
9468db94
...
...
@@ -7,124 +7,131 @@ constexpr useconds_t DeviceOpenTimeout = 500;
namespace
ChimeraTK
{
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
genericTransfer
(
std
::
function
<
bool
(
void
)
>
callable
,
bool
invalidateOnFailure
)
{
std
::
function
<
void
()
>
invalidateData
{};
if
(
invalidateOnFailure
)
{
invalidateData
=
[
=
]()
{
setDataValidity
(
DataValidity
::
faulty
);
};
}
else
{
invalidateData
=
[]()
{};
// do nothing if user does
// not want to invalidate data.
}
while
(
true
)
{
try
{
if
(
!
dm
.
device
.
isOpened
())
{
invalidateData
();
Application
::
getInstance
().
testableModeUnlock
(
"waitForDeviceOpen"
);
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
millisec
(
DeviceOpenTimeout
));
Application
::
getInstance
().
testableModeLock
(
"waitForDeviceOpen"
);
continue
;
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
genericTransfer
(
std
::
function
<
bool
(
void
)
>
callable
,
bool
invalidateOnFailure
)
{
std
::
function
<
void
()
>
invalidateData
{};
if
(
invalidateOnFailure
)
{
invalidateData
=
[
=
](){
setDataValidity
(
DataValidity
::
faulty
);};
}
else
{
invalidateData
=
[]()
{
};
// do nothing if user does
// not want to invalidate data.
}
auto
retval
=
callable
();
setDataValidity
(
DataValidity
::
ok
);
return
retval
;
while
(
true
)
{
try
{
if
(
!
dm
.
device
.
isOpened
())
{
invalidateData
();
Application
::
getInstance
().
testableModeUnlock
(
"waitForDeviceOpen"
);
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
millisec
(
DeviceOpenTimeout
));
Application
::
getInstance
().
testableModeLock
(
"waitForDeviceOpen"
);
continue
;
}
auto
retval
=
callable
();
setDataValidity
(
DataValidity
::
ok
);
return
retval
;
}
catch
(
ChimeraTK
::
runtime_error
&
e
)
{
invalidateData
();
dm
.
reportException
(
e
.
what
());
}
}
}
catch
(
ChimeraTK
::
runtime_error
&
e
)
{
invalidateData
();
dm
.
reportException
(
e
.
what
());
}
}
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doWriteTransfer
(
ChimeraTK
::
VersionNumber
versionNumber
)
{
return
genericTransfer
([
this
,
versionNumber
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doWriteTransfer
(
versionNumber
);
},
false
);
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doWriteTransferDestructively
(
ChimeraTK
::
VersionNumber
versionNumber
)
{
return
genericTransfer
([
this
,
versionNumber
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doWriteTransferDestructively
(
versionNumber
);
},
false
);
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doReadTransfer
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransfer
(),
true
;
});
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferNonBlocking
()
{
return
genericTransfer
(
[
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferNonBlocking
();
});
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferLatest
()
{
return
genericTransfer
(
[
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferLatest
();
});
}
template
<
typename
UserType
>
TransferFuture
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferAsync
()
{
TransferFuture
future
;
genericTransfer
([
this
,
&
future
]()
{
future
=
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferAsync
();
return
true
;
});
return
future
;
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPreRead
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPreRead
(),
true
;
});
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPostRead
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPostRead
(),
true
;
});
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPreWrite
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPreWrite
(),
true
;
},
false
);
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPostWrite
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPostWrite
(),
true
;
},
false
);
}
template
<
typename
UserType
>
DataValidity
ExceptionHandlingDecorator
<
UserType
>::
dataValidity
()
const
{
// faulty Validity from the decorated class takes precedence over our own
auto
delegatedValidity
=
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
dataValidity
();
if
(
delegatedValidity
==
DataValidity
::
faulty
)
{
return
delegatedValidity
;
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doWriteTransfer
(
ChimeraTK
::
VersionNumber
versionNumber
)
{
return
genericTransfer
([
this
,
versionNumber
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doWriteTransfer
(
versionNumber
);
},
false
);
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doWriteTransferDestructively
(
ChimeraTK
::
VersionNumber
versionNumber
)
{
return
genericTransfer
([
this
,
versionNumber
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doWriteTransferDestructively
(
versionNumber
);
},
false
);
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doReadTransfer
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransfer
(),
true
;
});
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferNonBlocking
()
{
return
genericTransfer
(
[
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferNonBlocking
();
});
}
template
<
typename
UserType
>
bool
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferLatest
()
{
return
genericTransfer
(
[
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferLatest
();
});
}
template
<
typename
UserType
>
TransferFuture
ExceptionHandlingDecorator
<
UserType
>::
doReadTransferAsync
()
{
TransferFuture
future
;
genericTransfer
([
this
,
&
future
]()
{
future
=
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doReadTransferAsync
();
return
true
;
});
return
future
;
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPreRead
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPreRead
(),
true
;
});
}
return
validity
;
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPostRead
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPostRead
(),
true
;
});
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
setDataValidity
(
DataValidity
newValidity
)
{
// Remember ourselves, but also pass down the line
if
(
newValidity
!=
validity
)
{
validity
=
newValidity
;
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
setDataValidity
(
validity
);
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPreWrite
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPreWrite
(),
true
;
},
false
);
}
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
interrupt
()
{
// notify the condition variable waiting in reportException of the genericTransfer
dm
.
notify
();
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
interrupt
();
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
doPostWrite
()
{
genericTransfer
([
this
]()
{
return
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
doPostWrite
(),
true
;
},
false
);
}
template
<
typename
UserType
>
DataValidity
ExceptionHandlingDecorator
<
UserType
>::
dataValidity
()
const
{
// faulty Validity from the decorated class takes precedence over our own
auto
delegatedValidity
=
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
dataValidity
();
if
(
delegatedValidity
==
DataValidity
::
faulty
)
{
return
delegatedValidity
;
}
return
validity
;
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
setDataValidity
(
DataValidity
newValidity
)
{
// Remember ourselves, but also pass down the line
if
(
newValidity
!=
validity
)
{
validity
=
newValidity
;
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
setDataValidity
(
validity
);
}
}
template
<
typename
UserType
>
void
ExceptionHandlingDecorator
<
UserType
>::
interrupt
()
{
// notify the condition variable waiting in reportException of the genericTransfer
dm
.
notify
();
ChimeraTK
::
NDRegisterAccessorDecorator
<
UserType
>::
interrupt
();
}
INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES
(
ExceptionHandlingDecorator
);
INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES
(
ExceptionHandlingDecorator
);
}
/* namespace ChimeraTK */
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