This is Unofficial EPICS BASE Doxygen Site
epics::pvAccess::RPCClient Class Reference

#include "rpcClient.h"

Classes

struct  RPCRequester
 

Public Member Functions

 POINTER_DEFINITIONS (RPCClient)
 
 RPCClient (const std::string &serviceName, epics::pvData::PVStructure::shared_pointer const &pvRequest, const ChannelProvider::shared_pointer &provider=ChannelProvider::shared_pointer(), const std::string &address=std::string())
 
 ~RPCClient ()
 
void destroy ()
 
bool connect (double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
 
void issueConnect ()
 
bool waitConnect (double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
 
epics::pvData::PVStructure::shared_pointer request (epics::pvData::PVStructure::shared_pointer const &pvArgument, double timeout=RPCCLIENT_DEFAULT_TIMEOUT, bool lastRequest=false)
 
void issueRequest (epics::pvData::PVStructure::shared_pointer const &pvArgument, bool lastRequest=false)
 
epics::pvData::PVStructure::shared_pointer waitResponse (double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
 

Static Public Member Functions

static shared_pointer create (const std::string &serviceName, epics::pvData::PVStructure::shared_pointer const &pvRequest=epics::pvData::PVStructure::shared_pointer())
 

Detailed Description

RPCClient is an interface class that is used by a service client.

Definition at line 39 of file rpcClient.h.

Constructor & Destructor Documentation

epics::pvAccess::RPCClient::RPCClient ( const std::string &  serviceName,
epics::pvData::PVStructure::shared_pointer const &  pvRequest,
const ChannelProvider::shared_pointer &  provider = ChannelProvider::shared_pointer(),
const std::string &  address = std::string() 
)
epics::pvAccess::RPCClient::~RPCClient ( )
inline

Definition at line 59 of file rpcClient.h.

Member Function Documentation

bool epics::pvAccess::RPCClient::connect ( double  timeout = RPCCLIENT_DEFAULT_TIMEOUT)

Connect to the server. The method blocks until the connection is made or a timeout occurs. It is the same as calling issueConnect and then waitConnect.

Parameters
timeoutTimeout in seconds to wait, 0 means forever.
Returns
(false,true) If (not connected, is connected). If false then connect must be reissued.

Definition at line 159 of file rpcClient.cpp.

160 {
161  issueConnect();
162  return waitConnect(timeout);
163 }
double timeout
Definition: pvutils.cpp:25
bool waitConnect(double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
Definition: rpcClient.cpp:169
RPCClient::shared_pointer epics::pvAccess::RPCClient::create ( const std::string &  serviceName,
epics::pvData::PVStructure::shared_pointer const &  pvRequest = epics::pvData::PVStructure::shared_pointer() 
)
static

Create a RPCClient.

Parameters
serviceNamethe service name
pvRequestthe pvRequest for the ChannelRPC
Returns
the RPCClient interface

Definition at line 266 of file rpcClient.cpp.

268 {
269  return RPCClient::shared_pointer(new RPCClient(serviceName, pvRequest));
270 }
RPCClient(const std::string &serviceName, epics::pvData::PVStructure::shared_pointer const &pvRequest, const ChannelProvider::shared_pointer &provider=ChannelProvider::shared_pointer(), const std::string &address=std::string())
void epics::pvAccess::RPCClient::destroy ( )

Destroy this instance (i.e. release resources).

Definition at line 145 of file rpcClient.cpp.

146 {
147  if (m_channel)
148  {
149  m_channel->destroy();
150  m_channel.reset();
151  }
152  if (m_rpc)
153  {
154  m_rpc->destroy();
155  m_rpc.reset();
156  }
157 }
void epics::pvAccess::RPCClient::issueConnect ( )

Issue a connect request and return immediately. waitConnect must be called to complete the request.

Definition at line 165 of file rpcClient.cpp.

166 {
167 }
void epics::pvAccess::RPCClient::issueRequest ( epics::pvData::PVStructure::shared_pointer const &  pvArgument,
bool  lastRequest = false 
)

Issue a channelRPC request and return immediately. waitRequest must be called to complete the request.

Parameters
pvAgumentThe argument to pass to the server.
lastRequestIf true an automatic destroy is made.
Exceptions
std::runtime_errorexcption thrown on any runtime error condition (e.g. no connection made).

Definition at line 201 of file rpcClient.cpp.

204 {
205  {
206  pvd::Lock L(m_rpc_requester->mutex);
207  TRACE("conn_status="<<m_rpc_requester->conn_status
208  <<" resp_status="<<m_rpc_requester->resp_status
209  <<" args:\n"<<pvArgument);
210  if(m_rpc_requester->inprogress)
211  throw std::logic_error("Request already in progress");
212  m_rpc_requester->inprogress = true;
213  m_rpc_requester->resp_status = pvd::Status::error("No Data");
214  if(!m_rpc_requester->conn_status.isSuccess()) {
215  TRACE("defer");
216  m_rpc_requester->last = lastRequest;
217  m_rpc_requester->next_args = pvArgument;
218  return;
219  }
220  TRACE("request args: "<<pvArgument);
221  }
222  if(lastRequest)
223  m_rpc->lastRequest();
224  m_rpc->request(pvArgument);
225 }
static Status error(const std::string &m)
Definition: status.h:50
A lock for multithreading.
Definition: lock.h:36
#define TRACE(msg)
Definition: rpcClient.cpp:26
epics::pvAccess::RPCClient::POINTER_DEFINITIONS ( RPCClient  )
pvd::PVStructure::shared_pointer epics::pvAccess::RPCClient::request ( epics::pvData::PVStructure::shared_pointer const &  pvArgument,
double  timeout = RPCCLIENT_DEFAULT_TIMEOUT,
bool  lastRequest = false 
)

Sends a request and wait for the response or until timeout occurs. This method will also wait for client to connect, if necessary.

Parameters
pvArgumentthe argument for the rpc
timeoutthe time in seconds to wait for the response, 0 means forever.
lastRequestIf true an automatic destroy is made.
Returns
request response.
Exceptions
RPCRequestExceptionexception thrown on error or timeout.

Definition at line 187 of file rpcClient.cpp.

191 {
192  if (connect(timeout))
193  {
194  issueRequest(pvArgument, lastRequest);
195  return waitResponse(timeout); // TODO reduce timeout for a time spent on connect
196  }
197  else
199 }
double timeout
Definition: pvutils.cpp:25
bool connect(double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
Definition: rpcClient.cpp:159
epics::pvData::PVStructure::shared_pointer waitResponse(double timeout=RPCCLIENT_DEFAULT_TIMEOUT)
Definition: rpcClient.cpp:227
void issueRequest(epics::pvData::PVStructure::shared_pointer const &pvArgument, bool lastRequest=false)
Definition: rpcClient.cpp:201
bool epics::pvAccess::RPCClient::waitConnect ( double  timeout = RPCCLIENT_DEFAULT_TIMEOUT)

Wait for the connect request to complete.

Parameters
timeouttimeout in seconds to wait, 0 means forever.
Returns
(false,true) If (not connected, is connected). If false then connect must be reissued.

Definition at line 169 of file rpcClient.cpp.

170 {
171  pvd::Lock L(m_rpc_requester->mutex);
172  TRACE("timeout="<<timeout);
173  while(!m_rpc_requester->conn_status.isSuccess()) {
174  L.unlock();
175  if(!m_rpc_requester->event.wait(timeout)) {
176  TRACE("TIMEOUT");
177  return false;
178  }
179  L.lock();
180  }
181  TRACE("Connected");
182  return true;
183 }
double timeout
Definition: pvutils.cpp:25
A lock for multithreading.
Definition: lock.h:36
#define TRACE(msg)
Definition: rpcClient.cpp:26
pvd::PVStructure::shared_pointer epics::pvAccess::RPCClient::waitResponse ( double  timeout = RPCCLIENT_DEFAULT_TIMEOUT)

Wait for the request to complete.

Parameters
timeoutthe time in seconds to wait for the reponse.
Returns
request response.
Exceptions
RPCRequestExceptionexception thrown on error or timeout.

Definition at line 227 of file rpcClient.cpp.

228 {
229  pvd::Lock L(m_rpc_requester->mutex);
230  TRACE("timeout="<<timeout);
231 
232  while(m_rpc_requester->inprogress)
233  {
234  L.unlock();
235  if(!m_rpc_requester->event.wait(timeout)) {
236  TRACE("TIMEOUT");
237  throw RPCRequestException(pvd::Status::STATUSTYPE_ERROR, "RPC timeout");
238  }
239  L.lock();
240  }
241  TRACE("Complete: conn_status="<<m_rpc_requester->conn_status
242  <<" resp_status="<<m_rpc_requester->resp_status
243  <<" data:\n"<<m_rpc_requester->last_data);
244 
245  if(!m_rpc_requester->conn_status.isSuccess())
246  throw RPCRequestException(pvd::Status::STATUSTYPE_ERROR, m_rpc_requester->conn_status.getMessage());
247 
248  if(!m_rpc_requester->resp_status.isSuccess())
249  throw RPCRequestException(pvd::Status::STATUSTYPE_ERROR, m_rpc_requester->resp_status.getMessage());
250 
251  // consume last_data so that we can't possibly return it twice
252  pvd::PVStructure::shared_pointer data;
253  data.swap(m_rpc_requester->last_data);
254 
255  if(!data)
256  throw std::logic_error("No request in progress");
257 
258  // copy it so that the caller need not worry about whether it will overwritten
259  // when the next request is issued
260  pvd::PVStructure::shared_pointer ret(pvd::getPVDataCreate()->createPVStructure(data->getStructure()));
261  ret->copyUnchecked(*data);
262 
263  return ret;
264 }
double timeout
Definition: pvutils.cpp:25
A lock for multithreading.
Definition: lock.h:36
#define TRACE(msg)
Definition: rpcClient.cpp:26
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648

The documentation for this class was generated from the following files: