Hello all Epics world, I am Giacomo Strangolino from the Elettra
Synchrotron Radiation Facility in Trieste, Italy.
I am new to Epics, and I am writing a C++ multi threaded library in
order to write GUIs in Qt and I have the following constraints:
- I want to monitor a pv in a separate thread;
- when a new value is available, I want a callback to be invoked (always
in the same background thread). There I extract data and forward it to
the main (GUI) thread.
- the background thread implements a wait condition so that it sleeps
until a new event arrives (for example, exit event or new variable to be
monitored is added)
I set things up like this in the init() method of a class I called
"CuMonitorActivity".
I used a pv structure as in camonitor C example:
void CuMonitorActivity::init()
{
int caTimeout = DEFAULT_TIMEOUT;
int reqElems = 1;
int nPvs = 1;
pv* pvs; /* Array of PV structures */
int result = ca_context_create(ca_enable_preemptive_callback);
if (result != ECA_NORMAL) {
...
}
else
{
/* Allocate PV structure array */
pvs = (pv *) calloc (nPvs, sizeof(pv));
if (!pvs)
{
...
}
else {
/* Connect channels */
memset(pvs[0].name, 0, 256);
strncpy(pvs[0].name, "giacomo:ai1", 255);
pvs[0].monitor_activity = this; /* store a reference to this
object to be used in the callback */
/* Create CA connections */
int returncode = create_pvs(pvs, nPvs, connection_handler_cb);
if ( returncode ) {
...
}
}
}
publishResult(tk);
}
NOTE: I enabled preemptive_callback so that I get
connection_handler_cb() called regularly when a new event arrives
From within connection_handler_cb I extract the current
CuMonitorActivity instance (stored in pv's monitor_activity field) and I
invoke the object's extraction method. Data is posted in the main thread.
NOTE: I notice that connection_handler_cb is invoked from ANOTHER
thread, not my main thread, not my secondary thread. This should be as
expected I guess for things to work and given the ca_
enable_preemptive_callback option.
* when I post an "exitEvent" on my secondary thread from the main one
(e.g. the GUI is closed), "ca_context_destroy();" is invoked in my
secondary thread (not the Epics thread that calls connection_handler_cb
during monitoring - is this OK? )
* Is there a way to ADD more PVs to monitor WHILE others are being
monitored (for example, is it legit to call create_pvs() again ) ?
* Are there any observations/corrections to my approach and to my
statements above?
Thanks for Your attention.
Giacomo Strangolino, Italy.
- Replies:
- Re: C++ multi threaded application. Andrew Johnson
- Navigate by Date:
- Prev:
Re: Another EPICS site, CSNS now producing neutrons Dave Gurd
- Next:
Re: FTP server on Linux(Ubuntu) keith.thorne
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
<2017>
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: Archiver: Problems with disconnected PVs Gabriel de Souza Fedel
- Next:
Re: C++ multi threaded application. Andrew Johnson
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
<2017>
2018
2019
2020
2021
2022
2023
2024
|