17 #define epicsExportSharedSymbols 26 namespace epics {
namespace pvaClient {
34 if(PvaClient::getDebug()) cout <<
"PvaClientChannelCache::~PvaClientChannelCache\n";
37 string const & channelName,
38 string const & providerName);
43 map<string,PvaClientChannelPtr> pvaClientChannelMap;
47 string const & channelName,
48 string const & providerName)
50 string name = channelName + providerName;
51 map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(name);
52 if(iter!=pvaClientChannelMap.end())
return iter->second;
58 Channel::shared_pointer channel = pvaClientChannel->getChannel();
59 string name = channel->getChannelName()
60 + channel->getProvider()->getProviderName();
61 map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(name);
62 if(iter!=pvaClientChannelMap.end()) {
63 throw std::runtime_error(
"pvaClientChannelCache::addChannel channel already cached");
65 pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
66 name,pvaClientChannel));
69 void PvaClientChannelCache::showCache()
71 map<string,PvaClientChannelPtr>::iterator iter;
72 for(iter = pvaClientChannelMap.begin(); iter != pvaClientChannelMap.end(); ++iter)
75 Channel::shared_pointer channel = pvaChannel->getChannel();
76 string channelName = channel->getChannelName();
77 string providerName = channel->getProvider()->getProviderName();
78 cout <<
"channel " << channelName <<
" provider " << providerName << endl;
79 pvaChannel->showCache();
83 size_t PvaClientChannelCache::cacheSize()
85 return pvaClientChannelMap.size();
90 static bool debug = 0;
92 void PvaClient::setDebug(
bool value)
97 bool PvaClient::getDebug()
115 PvaClient::PvaClient(std::string
const & providerNames)
121 stringstream ss(providerNames);
124 cout<<
"PvaClient::PvaClient()\n";
126 while (getline(ss, providerName,
' '))
128 if(providerName==
"pva") {
130 cout<<
"calling ClientFactory::start()\n";
132 ClientFactory::start();
134 }
else if(providerName==
"ca") {
136 cout<<
"calling CAClientFactory::start()\n";
138 CAClientFactory::start();
141 if(!channelRegistry->getProvider(providerName)) {
142 cerr <<
"PvaClient::get provider " << providerName <<
" not known" << endl;
148 PvaClient::~PvaClient() {
150 cout<<
"PvaClient::~PvaClient()\n" 151 <<
"pvaChannel cache:\n";
155 if(getDebug()) cout<<
"calling ClientFactory::stop()\n";
156 ClientFactory::stop();
157 if(getDebug()) cout<<
"after calling ClientFactory::stop()\n";
160 if(getDebug()) cout<<
"calling CAClientFactory::stop()\n";
161 CAClientFactory::stop();
162 if(getDebug()) cout<<
"after calling CAClientFactory::stop()\n";
164 channelRegistry.reset();
167 string PvaClient:: getRequesterName()
169 static string name(
"pvaClient");
172 return req->getRequesterName();
177 void PvaClient::message(
178 string const & message,
183 req->message(message,messageType);
190 std::string
const & channelName,
191 std::string
const & providerName,
195 pvaClientChannelCache->getChannel(channelName,providerName);
196 if(pvaClientChannel)
return pvaClientChannel;
197 pvaClientChannel = createChannel(channelName,providerName);
198 pvaClientChannel->connect(timeOut);
199 pvaClientChannelCache->addChannel(pvaClientChannel);
200 return pvaClientChannel;
205 return PvaClientChannel::create(shared_from_this(),channelName,providerName);
213 void PvaClient::clearRequester()
218 void PvaClient::showCache()
220 if(pvaClientChannelCache->cacheSize()>=1) {
221 pvaClientChannelCache->showCache();
223 cout <<
"pvaClientChannelCache is empty\n";
228 size_t PvaClient::cacheSize()
230 return pvaClientChannelCache->cacheSize();
std::tr1::shared_ptr< PvaClient > PvaClientPtr
epicsShareExtern std::string getMessageTypeName(MessageType messageType)
std::tr1::shared_ptr< PvaClientChannel > PvaClientChannelPtr
std::tr1::shared_ptr< Requester > RequesterPtr
TODO only here because of the Lockable.
A lock for multithreading.
ChannelProviderRegistry::shared_pointer clients
const ChannelProcessRequester::weak_pointer requester
pvaClient is a synchronous wrapper for the pvAccess API, which is a callback based API...