2 #include <epicsAtomic.h>
4 #include <epicsTimer.h>
5 #include <epicsMutex.h>
6 #include <epicsGuard.h>
7 #include <epicsEndian.h>
9 #include <pv/iocshelper.h>
11 #include <pv/pvAccess.h>
13 #define epicsExportSharedSymbols
18 namespace pva = epics::pvAccess;
19 namespace pvd = epics::pvData;
23 size_t GWChannel::num_instances;
25 GWChannel::GWChannel(
const ChannelCacheEntry::shared_pointer& e,
26 const epics::pvAccess::ChannelProvider::weak_pointer& srvprov,
27 const epics::pvAccess::ChannelRequester::weak_pointer &r,
28 const std::string& addr)
32 ,server_provder(srvprov)
34 epicsAtomicIncrSizeT(&num_instances);
37 GWChannel::~GWChannel()
39 epicsAtomicDecrSizeT(&num_instances);
43 GWChannel::getRequesterName()
52 std::tr1::shared_ptr<pva::ChannelProvider>
53 GWChannel::getProvider()
55 return pva::ChannelProvider::shared_pointer(server_provder);
59 GWChannel::getRemoteAddress()
62 return entry->channel->getRemoteAddress();
65 pva::Channel::ConnectionState
66 GWChannel::getConnectionState()
68 return entry->channel->getConnectionState();
72 GWChannel::getChannelName()
74 return entry->channelName;
77 std::tr1::shared_ptr<pva::ChannelRequester>
78 GWChannel::getChannelRequester()
80 return pva::ChannelRequester::shared_pointer(requester);
85 GWChannel::getField(pva::GetFieldRequester::shared_pointer
const & requester,
86 std::string
const & subField)
89 entry->channel->getField(requester, subField);
93 GWChannel::getAccessRights(pvd::PVField::shared_pointer
const & pvField)
95 return entry->channel->getAccessRights(pvField);
98 pva::ChannelProcess::shared_pointer
99 GWChannel::createChannelProcess(
100 pva::ChannelProcessRequester::shared_pointer
const & channelProcessRequester,
101 pvd::PVStructure::shared_pointer
const & pvRequest)
104 return entry->channel->createChannelProcess(channelProcessRequester, pvRequest);
106 return Channel::createChannelProcess(channelProcessRequester, pvRequest);
109 pva::ChannelGet::shared_pointer
110 GWChannel::createChannelGet(
111 pva::ChannelGetRequester::shared_pointer
const & channelGetRequester,
112 pvd::PVStructure::shared_pointer
const & pvRequest)
114 return entry->channel->createChannelGet(channelGetRequester, pvRequest);
117 pva::ChannelPut::shared_pointer
118 GWChannel::createChannelPut(
119 pva::ChannelPutRequester::shared_pointer
const & channelPutRequester,
120 pvd::PVStructure::shared_pointer
const & pvRequest)
124 return entry->channel->createChannelPut(channelPutRequester, pvRequest);
126 return Channel::createChannelPut(channelPutRequester, pvRequest);
129 pva::ChannelPutGet::shared_pointer
130 GWChannel::createChannelPutGet(
131 pva::ChannelPutGetRequester::shared_pointer
const & channelPutGetRequester,
132 pvd::PVStructure::shared_pointer
const & pvRequest)
135 return entry->channel->createChannelPutGet(channelPutGetRequester, pvRequest);
137 return Channel::createChannelPutGet(channelPutGetRequester, pvRequest);
140 pva::ChannelRPC::shared_pointer
141 GWChannel::createChannelRPC(
142 pva::ChannelRPCRequester::shared_pointer
const & channelRPCRequester,
143 pvd::PVStructure::shared_pointer
const & pvRequest)
146 return entry->channel->createChannelRPC(channelRPCRequester, pvRequest);
148 return Channel::createChannelRPC(channelRPCRequester, pvRequest);
157 pvd::Monitor::shared_pointer
158 GWChannel::createMonitor(
159 pvd::MonitorRequester::shared_pointer
const & monitorRequester,
160 pvd::PVStructure::shared_pointer
const & pvRequest)
162 ChannelCacheEntry::pvrequest_t ser;
164 pvd::serializeToVector(pvRequest.get(), EPICS_BYTE_ORDER, ser);
166 MonitorCacheEntry::shared_pointer ment;
167 MonitorUser::shared_pointer mon;
169 pvd::Status startresult;
170 pvd::StructureConstPtr typedesc;
174 Guard G(entry->mutex());
178 ment = entry->mon_entries.find(ser);
181 entry->mon_entries[ser] = ment;
182 ment->weakref = ment;
192 M = entry->channel->createMonitor(ment, pvRequest);
198 Guard G(ment->mutex());
201 ment->interested.insert(mon);
203 mon->srvchan = shared_pointer(weakref);
204 mon->req = monitorRequester;
206 typedesc = ment->typedesc;
207 startresult = ment->startresult;
209 }
catch(std::exception& e) {
211 std::cerr<<
"Exception in GWChannel::createMonitor()\n"
212 "is "<<e.what()<<
"\n";
213 startresult = pvd::Status(pvd::Status::STATUSTYPE_FATAL,
"Error during GWChannel setup");
218 if(typedesc || !startresult.isSuccess()) {
220 monitorRequester->monitorConnect(startresult, mon, typedesc);
226 pva::ChannelArray::shared_pointer
227 GWChannel::createChannelArray(
228 pva::ChannelArrayRequester::shared_pointer
const & channelArrayRequester,
229 pvd::PVStructure::shared_pointer
const & pvRequest)
231 return entry->channel->createChannelArray(channelArrayRequester, pvRequest);
236 GWChannel::printInfo(std::ostream& out)
238 out<<
"GWChannel for "<<entry->channelName<<
"\n";
242 void registerReadOnly()
244 epics::iocshVariable<int, &p2pReadOnly>(
"p2pReadOnly");