From 6bcc036c715d48604bfa4cd39eaa39827fb473f6 Mon Sep 17 00:00:00 2001 From: mrkraimer Date: Fri, 12 Jan 2018 13:51:13 -0500 Subject: [PATCH] reimplement methods called by pvaPy The methods are: static PvaClientPtr create() EPICS_DEPRECATED; and static PvaClientMonitorPtr create( PvaClientPtr const &pvaClient, std::string const & channelName, std::string const & providerName, std::string const & request, PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester = PvaClientChannelStateChangeRequesterPtr(), PvaClientMonitorRequesterPtr const & monitorRequester = PvaClientMonitorRequesterPtr() ) EPICS_DEPRECATED; --- src/pv/pvaClient.h | 42 +++++++++++++++++++++++++++------ src/pvaClient.cpp | 1 + src/pvaClientMonitor.cpp | 50 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/pv/pvaClient.h b/src/pv/pvaClient.h index f89420d..3ef6148 100644 --- a/src/pv/pvaClient.h +++ b/src/pv/pvaClient.h @@ -120,6 +120,12 @@ public: /** @brief Get the requester name. * @return The name. */ + /** @brief Create an instance of PvaClient with providerName "pva ca". + * @return shared pointer to the single instance + * @deprecated This method will go away in future versions. Use get instead. + */ + static PvaClientPtr create() EPICS_DEPRECATED; + std::string getRequesterName(); /** @brief A new message. * @@ -972,8 +978,8 @@ class epicsShareClass PvaClientProcess : public: POINTER_DEFINITIONS(PvaClientProcess); /** @brief Create a PvaClientProcess. - * @param &pvaClient Interface to PvaClient - * @param channel Interface to Channel + * @param pvaClient Interface to PvaClient + * @param pvaClientChannel Interface to Channel * @param pvRequest The request structure. * @return The interface to the PvaClientProcess. */ @@ -1262,8 +1268,8 @@ class epicsShareClass PvaClientPut : public: POINTER_DEFINITIONS(PvaClientPut); /** @brief Create a PvaClientPut. - * @param &pvaClient Interface to PvaClient - * @param channel Interface to Channel + * @param pvaClient Interface to PvaClient + * @param pvaClientChannel Interface to Channel * @param pvRequest The request structure. * @return The interface to the PvaClientPut. */ @@ -1440,8 +1446,8 @@ class epicsShareClass PvaClientPutGet : public: POINTER_DEFINITIONS(PvaClientPutGet); /** @brief Create a PvaClientPutGet. - * @param &pvaClient Interface to PvaClient - * @param channel Interface to Channel + * @param pvaClient Interface to PvaClient + * @param pvaClientChannel Interface to Channel * @param pvRequest The request structure. * @return The interface to the PvaClientPutGet. */ @@ -1627,6 +1633,7 @@ typedef std::tr1::shared_ptr MonitorRequesterImplPtr; * Overview of PvaClientMonitor */ class epicsShareClass PvaClientMonitor : + public PvaClientChannelStateChangeRequester, // remove when deprecated create removed public PvaClientMonitorRequester, public std::tr1::enable_shared_from_this { @@ -1643,6 +1650,26 @@ public: PvaClientChannelPtr const & pvaClientChannel, epics::pvData::PVStructurePtr const &pvRequest ); + /** @brief Create a PvaClientMonitor. + * @param pvaClient Interface to PvaClient + * @param channelName channel name + * @param providerName provider name + * @param request The request. + * @param stateChangeRequester The state change requester. Can be null. + * @param monitorRequester The monitor requester. Can be null; + * @return The new instance. + * @deprecated client can create PvaClientMonitor on first channel connect. + */ + static PvaClientMonitorPtr create( + PvaClientPtr const &pvaClient, + std::string const & channelName, + std::string const & providerName, + std::string const & request, + PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester + = PvaClientChannelStateChangeRequesterPtr(), + PvaClientMonitorRequesterPtr const & monitorRequester + = PvaClientMonitorRequesterPtr() + ) EPICS_DEPRECATED; /** @brief Destructor */ ~PvaClientMonitor(); @@ -1740,8 +1767,9 @@ private: bool userPoll; bool userWait; MonitorRequesterImplPtr monitorRequester; - + PvaClientChannelStateChangeRequesterWPtr pvaClientChannelStateChangeRequester; //deprecate public: + void channelStateChange(PvaClientChannelPtr const & channel, bool isConnected); //deprecate void event(PvaClientMonitorPtr const & monitor); friend class MonitorRequesterImpl; }; diff --git a/src/pvaClient.cpp b/src/pvaClient.cpp index 8c17fb7..b95e7ab 100644 --- a/src/pvaClient.cpp +++ b/src/pvaClient.cpp @@ -111,6 +111,7 @@ PvaClientPtr PvaClient::get(std::string const & providerNames) return master; } +PvaClientPtr PvaClient::create() {return get();} PvaClient::PvaClient(std::string const & providerNames) : pvaClientChannelCache(new PvaClientChannelCache()), diff --git a/src/pvaClientMonitor.cpp b/src/pvaClientMonitor.cpp index 2663407..449209a 100644 --- a/src/pvaClientMonitor.cpp +++ b/src/pvaClientMonitor.cpp @@ -83,13 +83,42 @@ PvaClientMonitorPtr PvaClientMonitor::create( PvaClientChannelPtr const & pvaClientChannel, PVStructurePtr const &pvRequest) { - PvaClientMonitorPtr clientMonitor(new PvaClientMonitor(pvaClient,pvaClientChannel,pvRequest)); clientMonitor->monitorRequester = MonitorRequesterImplPtr( new MonitorRequesterImpl(clientMonitor,pvaClient)); return clientMonitor; } +PvaClientMonitorPtr PvaClientMonitor::create( + PvaClientPtr const &pvaClient, + std::string const & channelName, + std::string const & providerName, + std::string const & request, + PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, + PvaClientMonitorRequesterPtr const & monitorRequester) +{ + if(PvaClient::getDebug()) { + cout<< "PvaClientMonitor::create(pvaClient,channelName,providerName,request,stateChangeRequester,monitorRequester)\n" + << " channelName " << channelName + << " providerName " << providerName + << " request " << request + << endl; + } + CreateRequest::shared_pointer createRequest(CreateRequest::create()); + PVStructurePtr pvRequest(createRequest->createRequest(request)); + if(!pvRequest) throw std::runtime_error(createRequest->getMessage()); + PvaClientChannelPtr pvaClientChannel = pvaClient->createChannel(channelName,providerName); + PvaClientMonitorPtr clientMonitor(new PvaClientMonitor(pvaClient,pvaClientChannel,pvRequest)); + clientMonitor->monitorRequester = MonitorRequesterImplPtr( + new MonitorRequesterImpl(clientMonitor,pvaClient)); + if(stateChangeRequester) clientMonitor->pvaClientChannelStateChangeRequester = stateChangeRequester; + if(monitorRequester) clientMonitor->pvaClientMonitorRequester = monitorRequester; + pvaClientChannel->setStateChangeRequester(clientMonitor); + pvaClientChannel->issueConnect(); + return clientMonitor; +} + + PvaClientMonitor::PvaClientMonitor( PvaClientPtr const &pvaClient, PvaClientChannelPtr const & pvaClientChannel, @@ -121,6 +150,25 @@ PvaClientMonitor::~PvaClientMonitor() } } +void PvaClientMonitor::channelStateChange(PvaClientChannelPtr const & channel, bool isConnected) +{ + if(PvaClient::getDebug()) { + cout<< "PvaClientMonitor::channelStateChange" + << " channelName " << channel->getChannelName() + << " isConnected " << (isConnected ? "true" : "false") + << endl; + } + if(isConnected&&!monitor) + { + connectState = connectActive; + monitor = pvaClientChannel->getChannel()->createMonitor(monitorRequester,pvRequest); + } + PvaClientChannelStateChangeRequesterPtr req(pvaClientChannelStateChangeRequester.lock()); + if(req) { + req->channelStateChange(channel,isConnected); + } +} + void PvaClientMonitor::event(PvaClientMonitorPtr const & monitor) { if(PvaClient::getDebug()) {