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
88a89a2f
Commit
88a89a2f
authored
6 years ago
by
Nadeem Shehzad
Browse files
Options
Downloads
Patches
Plain Diff
added: Variable group. Removed debug statements.
parent
bd751e90
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
include/DeviceModule.h
+14
-3
14 additions, 3 deletions
include/DeviceModule.h
src/DeviceModule.cc
+29
-22
29 additions, 22 deletions
src/DeviceModule.cc
with
43 additions
and
25 deletions
include/DeviceModule.h
+
14
−
3
View file @
88a89a2f
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include
"Module.h"
#include
"Module.h"
#include
"VirtualModule.h"
#include
"VirtualModule.h"
#include
"VariableGroup.h"
#include
"VariableGroup.h"
//#include "Application.h"
#include
"ScalarAccessor.h"
#include
"ScalarAccessor.h"
namespace
ChimeraTK
{
namespace
ChimeraTK
{
...
@@ -32,7 +31,11 @@ class DeviceModule : public Module {
...
@@ -32,7 +31,11 @@ class DeviceModule : public Module {
/** Default constructor: create dysfunctional device module */
/** Default constructor: create dysfunctional device module */
DeviceModule
()
{}
DeviceModule
()
{}
/** Destructor */
virtual
~
DeviceModule
();
/** Move operation with the move constructor */
/** Move operation with the move constructor */
DeviceModule
(
DeviceModule
&&
other
)
{
operator
=
(
std
::
move
(
other
));
}
DeviceModule
(
DeviceModule
&&
other
)
{
operator
=
(
std
::
move
(
other
));
}
...
@@ -42,6 +45,7 @@ class DeviceModule : public Module {
...
@@ -42,6 +45,7 @@ class DeviceModule : public Module {
deviceAliasOrURI
=
std
::
move
(
other
.
deviceAliasOrURI
);
deviceAliasOrURI
=
std
::
move
(
other
.
deviceAliasOrURI
);
registerNamePrefix
=
std
::
move
(
other
.
registerNamePrefix
);
registerNamePrefix
=
std
::
move
(
other
.
registerNamePrefix
);
subModules
=
std
::
move
(
other
.
subModules
);
subModules
=
std
::
move
(
other
.
subModules
);
deviceError
=
std
::
move
(
other
.
deviceError
);
return
*
this
;
return
*
this
;
}
}
...
@@ -71,7 +75,14 @@ class DeviceModule : public Module {
...
@@ -71,7 +75,14 @@ class DeviceModule : public Module {
void
terminate
()
override
;
void
terminate
()
override
;
VersionNumber
getCurrentVersionNumber
()
const
override
{
return
currentVersionNumber
;
}
void
setCurrentVersionNumber
(
VersionNumber
versionNumber
)
override
{
if
(
versionNumber
>
currentVersionNumber
)
currentVersionNumber
=
versionNumber
;
}
/** Version number of last push-type read operation - will be passed on to any write operations */
VersionNumber
currentVersionNumber
;
protected
:
protected
:
// populate virtualisedModuleFromCatalog based on the information in the device's catalogue
// populate virtualisedModuleFromCatalog based on the information in the device's catalogue
VirtualModule
&
virtualiseFromCatalog
()
const
;
VirtualModule
&
virtualiseFromCatalog
()
const
;
...
@@ -91,7 +102,7 @@ class DeviceModule : public Module {
...
@@ -91,7 +102,7 @@ class DeviceModule : public Module {
ScalarOutput
<
int
>
status
{
this
,
"status"
,
""
,
""
};
ScalarOutput
<
int
>
status
{
this
,
"status"
,
""
,
""
};
ScalarOutput
<
std
::
string
>
message
{
this
,
"errMsg"
,
""
,
""
};
ScalarOutput
<
std
::
string
>
message
{
this
,
"errMsg"
,
""
,
""
};
};
};
//DeviceError deviceError;
DeviceError
deviceError
{
this
,
"deviceError"
,
"Error"
};
DeviceError
deviceError
{
this
,
"deviceError"
,
"Error"
};
private
:
private
:
/** The thread executing reportException() */
/** The thread executing reportException() */
...
...
This diff is collapsed.
Click to expand it.
src/DeviceModule.cc
+
29
−
22
View file @
88a89a2f
...
@@ -35,10 +35,14 @@ namespace ChimeraTK {
...
@@ -35,10 +35,14 @@ namespace ChimeraTK {
deviceAliasOrURI
(
_deviceAliasOrURI
),
deviceAliasOrURI
(
_deviceAliasOrURI
),
registerNamePrefix
(
_registerNamePrefix
)
registerNamePrefix
(
_registerNamePrefix
)
{
{
std
::
cout
<<
"deviceModule"
<<
std
::
endl
;
application
->
registerDeviceModule
(
this
);
application
->
registerDeviceModule
(
this
);
}
}
/*********************************************************************************************************************/
DeviceModule
::~
DeviceModule
()
{
assert
(
!
moduleThread
.
joinable
());
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
...
@@ -51,8 +55,6 @@ namespace ChimeraTK {
...
@@ -51,8 +55,6 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
/*********************************************************************************************************************/
Module
&
DeviceModule
::
operator
[](
const
std
::
string
&
moduleName
)
const
{
Module
&
DeviceModule
::
operator
[](
const
std
::
string
&
moduleName
)
const
{
std
::
cout
<<
"DeviceModule:"
<<
moduleName
<<
std
::
endl
;
if
(
subModules
.
count
(
moduleName
)
==
0
)
{
if
(
subModules
.
count
(
moduleName
)
==
0
)
{
subModules
[
moduleName
]
=
{
deviceAliasOrURI
,
registerNamePrefix
/
moduleName
};
subModules
[
moduleName
]
=
{
deviceAliasOrURI
,
registerNamePrefix
/
moduleName
};
}
}
...
@@ -80,7 +82,6 @@ namespace ChimeraTK {
...
@@ -80,7 +82,6 @@ namespace ChimeraTK {
virtualisedModuleFromCatalog
=
VirtualModule
(
deviceAliasOrURI
,
"Device module"
,
ModuleType
::
Device
);
virtualisedModuleFromCatalog
=
VirtualModule
(
deviceAliasOrURI
,
"Device module"
,
ModuleType
::
Device
);
// obtain register catalogue
// obtain register catalogue
std
::
cout
<<
"DeviceModule::virtualiseFromCatalog"
<<
std
::
endl
;
Device
d
;
Device
d
;
d
.
open
(
deviceAliasOrURI
);
/// @todo: do not actually open the device (needs extension of DeviceAccess)!
d
.
open
(
deviceAliasOrURI
);
/// @todo: do not actually open the device (needs extension of DeviceAccess)!
auto
catalog
=
d
.
getRegisterCatalogue
();
auto
catalog
=
d
.
getRegisterCatalogue
();
...
@@ -172,44 +173,49 @@ namespace ChimeraTK {
...
@@ -172,44 +173,49 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void
DeviceModule
::
reportException
(
std
::
string
errMsg
){
void
DeviceModule
::
reportException
(
std
::
string
errMsg
){
status
=
1
;
deviceError
.
status
=
1
;
deviceError
.
status
=
1
;
deviceError
.
message
=
errMsg
;
deviceError
.
message
=
errMsg
;
deviceError
.
writeAll
();
deviceError
.
writeAll
();
std
::
unique_lock
<
std
::
mutex
>
lk
(
errorMutex
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
errorMutex
);
errorQueue
.
push
(
errMsg
);
errorQueue
.
push
(
errMsg
);
errorCondVar
.
wait
(
lk
);
errorCondVar
.
wait
(
lk
);
deviceError
.
status
=
0
;
deviceError
.
message
=
""
;
deviceError
.
writeAll
();
}
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void
DeviceModule
::
handleException
(){
void
DeviceModule
::
handleException
(){
Application
::
registerThread
(
"DM_"
+
getName
());
std
::
string
error
;
std
::
string
error
;
while
(
true
)
while
(
true
)
{
{
try
{
errorQueue
.
pop_wait
(
error
);
errorQueue
.
pop_wait
(
error
);
//if (error == "none")
//break;
Device
d
;
Device
d
;
while
(
true
)
while
(
true
)
{
{
d
.
open
(
deviceAliasOrURI
);
try
{
if
(
d
.
isOpened
())
d
.
open
(
deviceAliasOrURI
);
if
(
d
.
isOpened
())
{
break
;
}
usleep
(
5000
);
}
catch
(
std
::
exception
ex
)
{
{
break
;
//std::cout<<"caught exception:"<<ex.what()<<std::endl;
//deviceError.message = ex.what();
}
}
usleep
(
5000
);
}
deviceError
.
status
=
1
;
deviceError
.
message
=
""
;
//lk.unlock();
errorCondVar
.
notify_all
();
errorCondVar
.
notify_all
();
}
}
catch
(
std
::
exception
ex
)
{
std
::
cout
<<
"caught exception:"
<<
ex
.
what
()
<<
std
::
endl
;
//deviceError.message = ex.what();
}
}
}
}
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
...
@@ -217,7 +223,6 @@ namespace ChimeraTK {
...
@@ -217,7 +223,6 @@ namespace ChimeraTK {
void
DeviceModule
::
run
()
{
void
DeviceModule
::
run
()
{
// start the module thread
// start the module thread
std
::
cout
<<
"start the module thread"
<<
std
::
endl
;
assert
(
!
moduleThread
.
joinable
());
assert
(
!
moduleThread
.
joinable
());
moduleThread
=
boost
::
thread
(
&
DeviceModule
::
handleException
,
this
);
moduleThread
=
boost
::
thread
(
&
DeviceModule
::
handleException
,
this
);
}
}
...
@@ -225,17 +230,19 @@ namespace ChimeraTK {
...
@@ -225,17 +230,19 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void
DeviceModule
::
terminate
()
{
void
DeviceModule
::
terminate
()
{
//reportException("none");
if
(
moduleThread
.
joinable
())
{
if
(
moduleThread
.
joinable
())
{
moduleThread
.
interrupt
();
moduleThread
.
interrupt
();
// try joining the thread
// try joining the thread
while
(
!
moduleThread
.
try_join_for
(
boost
::
chrono
::
milliseconds
(
10
)))
{
while
(
!
moduleThread
.
try_join_for
(
boost
::
chrono
::
milliseconds
(
10
)))
{
// if thread is not yet joined, send interrupt() to all variables.
// if thread is not yet joined, send interrupt() to all variables.
for
(
auto
&
var
:
getAccessorListRecursive
())
{
for
(
auto
&
var
:
getAccessorListRecursive
())
{
if
(
var
.
getDirection
()
==
VariableDirection
{
VariableDirection
::
feeding
,
false
})
continue
;
if
(
var
.
getDirection
()
==
VariableDirection
{
VariableDirection
::
feeding
,
false
})
continue
;
var
.
getAppAccessorNoType
().
getHighLevelImplElement
()
->
interrupt
();
var
.
getAppAccessorNoType
().
getHighLevelImplElement
()
->
interrupt
();
}
}
// it may not suffice to send interrupt() once, as the exception might get overwritten in the queue, thus we
// repeat this until the thread was joined.
}
}
}
}
assert
(
!
moduleThread
.
joinable
());
assert
(
!
moduleThread
.
joinable
());
...
...
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