26namespace epics {
namespace pvaClient {
29class epicsShareClass PvaClientChannelCache
32 PvaClientChannelCache(){}
33 ~PvaClientChannelCache(){
34 if(PvaClient::getDebug()) cout <<
"PvaClientChannelCache::~PvaClientChannelCache\n";
36 PvaClientChannelPtr getChannel(
37 string const & channelName,
38 string const & providerName);
39 void addChannel(PvaClientChannelPtr
const & pvaClientChannel);
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));
69void 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();
83size_t PvaClientChannelCache::cacheSize()
85 return pvaClientChannelMap.size();
115PvaClient::PvaClient(std::string
const & providerNames)
116: pvaClientChannelCache(new PvaClientChannelCache()),
119 channelRegistry(ChannelProviderRegistry::clients())
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;
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";
164channelRegistry.reset();
169 static string name(
"pvaClient");
170 RequesterPtr req = requester.lock();
172 return req->getRequesterName();
178 string const & message,
179 MessageType messageType)
181 RequesterPtr req = requester.lock();
183 req->message(
message,messageType);
186 cout << getMessageTypeName(messageType) <<
" " <<
message << endl;
190 std::string
const & channelName,
191 std::string
const & providerName,
195 pvaClientChannelCache->getChannel(channelName,providerName);
196 if(pvaClientChannel)
return pvaClientChannel;
198 pvaClientChannel->connect(timeOut);
199 pvaClientChannelCache->addChannel(pvaClientChannel);
200 return pvaClientChannel;
205 return PvaClientChannel::create(shared_from_this(),channelName,providerName);
210 this->requester = requester;
220 if(pvaClientChannelCache->cacheSize()>=1) {
221 pvaClientChannelCache->showCache();
223 cout <<
"pvaClientChannelCache is empty\n";
230 return pvaClientChannelCache->cacheSize();