qmca  0.0.20
epicsinteger.cpp
Go to the documentation of this file.
1 #include "epicsinteger.h"
2 #include <QMutexLocker>
3 
4 #include <stdio.h>
5 
6 EpicsInteger::EpicsInteger(QString pvName, QObject *parent, int debug)
7  : EpicsObject(pvName, parent, debug),
8  m_Value(0)
9 {
10 }
11 
13 {
14 }
15 
16 void EpicsInteger::event_handler(struct event_handler_args args)
17 {
18  union db_access_val *pb = (union db_access_val *) args.dbr;
19 
20  int res=0;
21 
22  switch (args.type) {
23  case DBR_SHORT:
24  res = pb->shrtval;
25  break;
26  case DBR_LONG:
27  res = pb->longval;
28  break;
29  case DBR_FLOAT:
30  res = pb->fltval;
31  break;
32  case DBR_ENUM:
33  res = pb->enmval;
34  break;
35  case DBR_CHAR:
36  res = pb->charval;
37  break;
38  case DBR_DOUBLE:
39  res = pb->doubleval;
40  break;
41  default:
42  printf("data type %ld not supported\n", args.type);
43  }
44 
45  EpicsInteger* i = ((EpicsInteger*) args.usr);
46 
47  if (i && i->debug()) {
48  printf("%s Epics Integer Event Handler called %ld = %d\n", ca_name(args.chid), args.type, res);
49  }
50 
51  ((EpicsInteger*) args.usr) -> changeValue(res);
52 }
53 
54 caEventCallBackFunc *EpicsInteger::get_event_handler()
55 {
57 }
58 
59 void EpicsInteger::changeValue(int newval)
60 {
61 // printf("ca_put(%d,%p,%g)\n", DBR_INT, channelID(), newval);
62 
63 // ca_put(DBR_INT, channelID(), &newval);
64 
65  QMutexLocker lock(&m_Mutex);
66 
67  if (m_Value != newval) {
68 
69  m_Value = newval;
70  emit valueChanged(m_Value);
71  }
72 }
73 
74 void EpicsInteger::caput(int val)
75 {
76  ca_put(DBR_INT, channelID(), &val);
77  ca_pend_io(0.5);
78 }
79 
81 {
82  QMutexLocker lock(&m_Mutex);
83 
84  return m_Value;
85 }
EpicsInteger(QString pvName, QObject *parent=0, int debug=0)
Definition: epicsinteger.cpp:6
virtual caEventCallBackFunc * get_event_handler()
void changeValue(int val)
void caput(int val)
static void event_handler(struct event_handler_args arg)
void valueChanged()
virtual ~EpicsInteger()
static QMutex m_Mutex
Definition: epicsobject.h:42
chid channelID()
Definition: epicsobject.cpp:63
void ca_pend_io(double t)