This is Unofficial EPICS BASE Doxygen Site
channelLocal.cpp
Go to the documentation of this file.
1 /* channelLocal.cpp */
12 #include <sstream>
13 
14 #include <epicsGuard.h>
15 #include <epicsThread.h>
16 #include <pv/pvData.h>
17 #include <pv/pvAccess.h>
18 #include <pv/pvTimeStamp.h>
19 #include <pv/rpcService.h>
20 #include <pv/timeStamp.h>
21 #include <pv/createRequest.h>
22 #include <pv/pvaVersion.h>
23 #include <pv/pvaVersionNum.h>
24 #include <pv/serverContext.h>
25 #include <pv/pvSubArrayCopy.h>
26 
27 #define epicsExportSharedSymbols
28 #include "pv/pvStructureCopy.h"
29 #include "pv/pvDatabase.h"
31 
32 using namespace epics::pvData;
33 using namespace epics::pvAccess;
34 using namespace epics::pvCopy;
37 using std::cout;
38 using std::endl;
39 using std::string;
40 
41 namespace epics { namespace pvDatabase {
42 
43 static StructureConstPtr nullStructure;
44 
46 typedef std::tr1::shared_ptr<ChannelProcessLocal> ChannelProcessLocalPtr;
48 typedef std::tr1::shared_ptr<ChannelGetLocal> ChannelGetLocalPtr;
50 typedef std::tr1::shared_ptr<ChannelPutLocal> ChannelPutLocalPtr;
52 typedef std::tr1::shared_ptr<ChannelPutGetLocal> ChannelPutGetLocalPtr;
54 typedef std::tr1::shared_ptr<ChannelRPCLocal> ChannelRPCLocalPtr;
56 typedef std::tr1::shared_ptr<ChannelArrayLocal> ChannelArrayLocalPtr;
57 
58 static bool getProcess(PVStructurePtr pvRequest,bool processDefault)
59 {
60  PVFieldPtr pvField = pvRequest->getSubField("record._options.process");
61  if(!pvField || pvField->getField()->getType()!=scalar) {
62  return processDefault;
63  }
65  pvField->getField());
66  if(scalar->getScalarType()==pvString) {
68  return pvString->get().compare("true")==0 ? true : false;
69  } else if(scalar->getScalarType()==pvBoolean) {
71  return pvBoolean->get();
72  }
73  return processDefault;
74 }
75 
77  public ChannelProcess,
78  public std::tr1::enable_shared_from_this<ChannelProcessLocal>
79 {
80 public:
82  virtual ~ChannelProcessLocal();
83  virtual void destroy() {} // DEPRECATED
84  static ChannelProcessLocalPtr create(
85  ChannelLocalPtr const &channelLocal,
86  ChannelProcessRequester::shared_pointer const & channelProcessRequester,
87  PVStructurePtr const & pvRequest,
88  PVRecordPtr const &pvRecord);
89  virtual void process();
90  virtual std::tr1::shared_ptr<Channel> getChannel();
91  virtual void cancel(){}
92  virtual void lock();
93  virtual void unlock();
94  virtual void lastRequest() {}
95 private:
96  shared_pointer getPtrSelf()
97  {
98  return shared_from_this();
99  }
101  ChannelLocalPtr const &channelLocal,
102  ChannelProcessRequester::shared_pointer const & channelProcessRequester,
103  PVRecordPtr const &pvRecord,
104  int nProcess)
105  :
106  channelLocal(channelLocal),
107  channelProcessRequester(channelProcessRequester),
108  pvRecord(pvRecord),
109  nProcess(nProcess)
110  {
111  }
112  ChannelLocalWPtr channelLocal;
113  ChannelProcessRequester::weak_pointer channelProcessRequester;
114  PVRecordWPtr pvRecord;
115  int nProcess;
116  Mutex mutex;
117 };
118 
119 ChannelProcessLocalPtr ChannelProcessLocal::create(
120  ChannelLocalPtr const &channelLocal,
121  ChannelProcessRequester::shared_pointer const & channelProcessRequester,
122  PVStructurePtr const & pvRequest,
123  PVRecordPtr const &pvRecord)
124 {
125  PVFieldPtr pvField;
126  PVStructurePtr pvOptions;
127  int nProcess = 1;
128  if(pvRequest) pvField = pvRequest->getSubField("record._options");
129  if(pvField) {
130  pvOptions = static_pointer_cast<PVStructure>(pvField);
131  pvField = pvOptions->getSubField("nProcess");
132  if(pvField) {
133  PVStringPtr pvString = pvOptions->getSubField<PVString>("nProcess");
134  if(pvString) {
135  int size=0;
136  std::stringstream ss;
137  ss << pvString->get();
138  ss >> size;
139  nProcess = size;
140  }
141  }
142  }
143  ChannelProcessLocalPtr process(new ChannelProcessLocal(
144  channelLocal,
145  channelProcessRequester,
146  pvRecord,
147  nProcess));
148  if(pvRecord->getTraceLevel()>0)
149  {
150  cout << "ChannelProcessLocal::create";
151  cout << " recordName " << pvRecord->getRecordName() << endl;
152  }
153  channelProcessRequester->channelProcessConnect(Status::Ok, process);
154  return process;
155 }
156 
157 ChannelProcessLocal::~ChannelProcessLocal()
158 {
159 //cout << "~ChannelProcessLocal()\n";
160 }
161 
162 std::tr1::shared_ptr<Channel> ChannelProcessLocal::getChannel()
163 {
164  ChannelLocalPtr channel(channelLocal.lock());
165  return channel;
166 }
167 
169 {
170  PVRecordPtr pvr(pvRecord.lock());
171  if(!pvr) throw std::logic_error("pvRecord is deleted");
172  pvr->lock();
173 }
174 void ChannelProcessLocal::unlock()
175 {
176  PVRecordPtr pvr(pvRecord.lock());
177  if(!pvr) throw std::logic_error("pvRecord is deleted");
178  pvr->unlock();
179 }
180 
181 void ChannelProcessLocal::process()
182 {
183  ChannelProcessRequester::shared_pointer requester = channelProcessRequester.lock();
184  if(!requester) return;
185  PVRecordPtr pvr(pvRecord.lock());
186  if(!pvr) throw std::logic_error("pvRecord is deleted");
187  if(pvr->getTraceLevel()>1)
188  {
189  cout << "ChannelProcessLocal::process";
190  cout << " nProcess " << nProcess << endl;
191  }
192  try {
193  for(int i=0; i< nProcess; i++) {
194  epicsGuard <PVRecord> guard(*pvr);
195  pvr->beginGroupPut();
196  pvr->process();
197  pvr->endGroupPut();
198  }
199  requester->processDone(Status::Ok,getPtrSelf());
200  } catch(std::exception& ex) {
202  requester->processDone(status,getPtrSelf());
203  }
204 }
205 
207  public ChannelGet,
208  public std::tr1::enable_shared_from_this<ChannelGetLocal>
209 {
210 public:
212  virtual ~ChannelGetLocal();
213  virtual void destroy() {} // DEPRECATED
214  static ChannelGetLocalPtr create(
215  ChannelLocalPtr const &channelLocal,
216  ChannelGetRequester::shared_pointer const & channelGetRequester,
217  PVStructurePtr const & pvRequest,
218  PVRecordPtr const &pvRecord);
219  virtual void get();
220  virtual std::tr1::shared_ptr<Channel> getChannel();
221  virtual void cancel(){}
222  virtual void lock();
223  virtual void unlock();
224  virtual void lastRequest() {}
225 private:
226  shared_pointer getPtrSelf()
227  {
228  return shared_from_this();
229  }
231  bool callProcess,
232  ChannelLocalPtr const &channelLocal,
233  ChannelGetRequester::shared_pointer const & channelGetRequester,
234  PVCopyPtr const &pvCopy,
235  PVStructurePtr const&pvStructure,
236  BitSetPtr const & bitSet,
237  PVRecordPtr const &pvRecord)
238  :
239  firstTime(true),
240  callProcess(callProcess),
241  channelLocal(channelLocal),
242  channelGetRequester(channelGetRequester),
243  pvCopy(pvCopy),
244  pvStructure(pvStructure),
245  bitSet(bitSet),
246  pvRecord(pvRecord)
247  {
248  }
249  bool firstTime;
250  bool callProcess;
251  ChannelLocalWPtr channelLocal;
252  ChannelGetRequester::weak_pointer channelGetRequester;
253  PVCopyPtr pvCopy;
254  PVStructurePtr pvStructure;
255  BitSetPtr bitSet;
256  PVRecordWPtr pvRecord;
257  Mutex mutex;
258 };
259 
260 ChannelGetLocalPtr ChannelGetLocal::create(
261  ChannelLocalPtr const &channelLocal,
262  ChannelGetRequester::shared_pointer const & channelGetRequester,
263  PVStructurePtr const & pvRequest,
264  PVRecordPtr const &pvRecord)
265 {
266  PVCopyPtr pvCopy = PVCopy::create(
267  pvRecord->getPVRecordStructure()->getPVStructure(),
268  pvRequest,
269  "");
270  if(!pvCopy) {
271  Status status(
273  "invalid pvRequest");
274  ChannelGet::shared_pointer channelGet;
275  channelGetRequester->channelGetConnect(
276  status,
277  channelGet,
278  nullStructure);
279  ChannelGetLocalPtr localGet;
280  return localGet;
281  }
282  PVStructurePtr pvStructure = pvCopy->createPVStructure();
283  BitSetPtr bitSet(new BitSet(pvStructure->getNumberFields()));
284  ChannelGetLocalPtr get(new ChannelGetLocal(
285  getProcess(pvRequest,false),
286  channelLocal,
287  channelGetRequester,
288  pvCopy,
289  pvStructure,
290  bitSet,
291  pvRecord));
292  if(pvRecord->getTraceLevel()>0)
293  {
294  cout << "ChannelGetLocal::create";
295  cout << " recordName " << pvRecord->getRecordName() << endl;
296  }
297  channelGetRequester->channelGetConnect(
298  Status::Ok,get,pvStructure->getStructure());
299  return get;
300 }
301 
302 ChannelGetLocal::~ChannelGetLocal()
303 {
304 //cout << "~ChannelGetLocal()\n";
305 }
306 
307 std::tr1::shared_ptr<Channel> ChannelGetLocal::getChannel()
308 {
309  ChannelLocalPtr channel(channelLocal.lock());
310  return channel;
311 }
312 
314 {
315  PVRecordPtr pvr(pvRecord.lock());
316  if(!pvr) throw std::logic_error("pvRecord is deleted");
317  pvr->lock();
318 }
319 void ChannelGetLocal::unlock()
320 {
321  PVRecordPtr pvr(pvRecord.lock());
322  if(!pvr) throw std::logic_error("pvRecord is deleted");
323  pvr->unlock();
324 }
325 
326 
328 {
329  ChannelGetRequester::shared_pointer requester = channelGetRequester.lock();
330  if(!requester) return;
331  PVRecordPtr pvr(pvRecord.lock());
332  if(!pvr) throw std::logic_error("pvRecord is deleted");
333  try {
334  bool notifyClient = true;
335  bitSet->clear();
336  {
337  epicsGuard <PVRecord> guard(*pvr);
338  if(callProcess) {
339  pvr->beginGroupPut();
340  pvr->process();
341  pvr->endGroupPut();
342  }
343  notifyClient = pvCopy->updateCopySetBitSet(pvStructure, bitSet);
344  }
345  if(firstTime) {
346  bitSet->clear();
347  bitSet->set(0);
348  firstTime = false;
349  notifyClient = true;
350  }
351  if(notifyClient) {
352  requester->getDone(
353  Status::Ok,
354  getPtrSelf(),
355  pvStructure,
356  bitSet);
357  bitSet->clear();
358  } else {
359  BitSetPtr temp(new BitSet(bitSet->size()));
360  requester->getDone(
361  Status::Ok,
362  getPtrSelf(),
363  pvStructure,
364  temp);
365  }
366  if(pvr->getTraceLevel()>1)
367  {
368  cout << "ChannelGetLocal::get" << endl;
369  }
370  } catch(std::exception& ex) {
372  requester->getDone(status,getPtrSelf(),pvStructure,bitSet);
373  }
374 
375 }
376 
378  public ChannelPut,
379  public std::tr1::enable_shared_from_this<ChannelPutLocal>
380 {
381 public:
383  virtual ~ChannelPutLocal();
384  virtual void destroy() {} // DEPRECATED
385  static ChannelPutLocalPtr create(
386  ChannelLocalPtr const &channelLocal,
387  ChannelPutRequester::shared_pointer const & channelPutRequester,
388  PVStructurePtr const & pvRequest,
389  PVRecordPtr const &pvRecord);
390  virtual void put(PVStructurePtr const &pvStructure,BitSetPtr const &bitSet);
391  virtual void get();
392  virtual std::tr1::shared_ptr<Channel> getChannel();
393  virtual void cancel(){}
394  virtual void lock();
395  virtual void unlock();
396  virtual void lastRequest() {}
397 private:
398  shared_pointer getPtrSelf()
399  {
400  return shared_from_this();
401  }
403  bool callProcess,
404  ChannelLocalPtr const &channelLocal,
405  ChannelPutRequester::shared_pointer const & channelPutRequester,
406  PVCopyPtr const &pvCopy,
407  PVRecordPtr const &pvRecord)
408  :
409  callProcess(callProcess),
410  channelLocal(channelLocal),
411  channelPutRequester(channelPutRequester),
412  pvCopy(pvCopy),
413  pvRecord(pvRecord)
414  {
415  }
416  bool callProcess;
417  ChannelLocalWPtr channelLocal;
418  ChannelPutRequester::weak_pointer channelPutRequester;
419  PVCopyPtr pvCopy;
420  PVRecordWPtr pvRecord;
421  Mutex mutex;
422 };
423 
424 ChannelPutLocalPtr ChannelPutLocal::create(
425  ChannelLocalPtr const &channelLocal,
426  ChannelPutRequester::shared_pointer const & channelPutRequester,
427  PVStructurePtr const & pvRequest,
428  PVRecordPtr const &pvRecord)
429 {
430  PVCopyPtr pvCopy = PVCopy::create(
431  pvRecord->getPVRecordStructure()->getPVStructure(),
432  pvRequest,
433  "");
434  if(!pvCopy) {
435  Status status(
437  "invalid pvRequest");
438  ChannelPut::shared_pointer channelPut;
439  PVStructurePtr pvStructure;
440  BitSetPtr bitSet;
441  channelPutRequester->channelPutConnect(
442  status,
443  channelPut,
444  nullStructure);
445  ChannelPutLocalPtr localPut;
446  return localPut;
447  }
448  ChannelPutLocalPtr put(new ChannelPutLocal(
449  getProcess(pvRequest,true),
450  channelLocal,
451  channelPutRequester,
452  pvCopy,
453  pvRecord));
454  channelPutRequester->channelPutConnect(
455  Status::Ok, put, pvCopy->getStructure());
456  if(pvRecord->getTraceLevel()>0)
457  {
458  cout << "ChannelPutLocal::create";
459  cout << " recordName " << pvRecord->getRecordName() << endl;
460  }
461  return put;
462 }
463 
464 ChannelPutLocal::~ChannelPutLocal()
465 {
466 //cout << "~ChannelPutLocal()\n";
467 }
468 
469 std::tr1::shared_ptr<Channel> ChannelPutLocal::getChannel()
470 {
471  ChannelLocalPtr channel(channelLocal.lock());
472  return channel;
473 }
474 
476 {
477  PVRecordPtr pvr(pvRecord.lock());
478  if(!pvr) throw std::logic_error("pvRecord is deleted");
479  pvr->lock();
480 }
481 void ChannelPutLocal::unlock()
482 {
483  PVRecordPtr pvr(pvRecord.lock());
484  if(!pvr) throw std::logic_error("pvRecord is deleted");
485  pvr->unlock();
486 }
487 
488 
490 {
491  ChannelPutRequester::shared_pointer requester = channelPutRequester.lock();
492  if(!requester) return;
493  PVRecordPtr pvr(pvRecord.lock());
494  if(!pvr) throw std::logic_error("pvRecord is deleted");
495  try {
496  PVStructurePtr pvStructure = pvCopy->createPVStructure();
497  BitSetPtr bitSet(new BitSet(pvStructure->getNumberFields()));
498  bitSet->clear();
499  bitSet->set(0);
500  {
501  epicsGuard <PVRecord> guard(*pvr);
502  pvCopy->updateCopyFromBitSet(pvStructure, bitSet);
503  }
504  requester->getDone(
505  Status::Ok,getPtrSelf(),pvStructure,bitSet);
506  if(pvr->getTraceLevel()>1)
507  {
508  cout << "ChannelPutLocal::get" << endl;
509  }
510  } catch(std::exception& ex) {
512  PVStructurePtr pvStructure;
513  BitSetPtr bitSet;
514  requester->getDone(status,getPtrSelf(),pvStructure,bitSet);
515  }
516 }
517 
519  PVStructurePtr const &pvStructure,BitSetPtr const &bitSet)
520 {
521  ChannelPutRequester::shared_pointer requester = channelPutRequester.lock();
522  if(!requester) return;
523  PVRecordPtr pvr(pvRecord.lock());
524  if(!pvr) throw std::logic_error("pvRecord is deleted");
525  try {
526  {
527  epicsGuard <PVRecord> guard(*pvr);
528  pvr->beginGroupPut();
529  pvCopy->updateMaster(pvStructure, bitSet);
530  if(callProcess) {
531  pvr->process();
532  }
533  pvr->endGroupPut();
534  }
535  requester->putDone(Status::Ok,getPtrSelf());
536  if(pvr->getTraceLevel()>1)
537  {
538  cout << "ChannelPutLocal::put" << endl;
539  }
540  } catch(std::exception& ex) {
542  requester->putDone(status,getPtrSelf());
543  }
544 }
545 
546 
548  public ChannelPutGet,
549  public std::tr1::enable_shared_from_this<ChannelPutGetLocal>
550 {
551 public:
553  virtual ~ChannelPutGetLocal();
554  virtual void destroy() {} // DEPRECATED
555  static ChannelPutGetLocalPtr create(
556  ChannelLocalPtr const &channelLocal,
557  ChannelPutGetRequester::shared_pointer const & channelPutGetRequester,
558  PVStructurePtr const & pvRequest,
559  PVRecordPtr const &pvRecord);
560  virtual void putGet(
561  PVStructurePtr const &pvPutStructure,
562  BitSetPtr const &putBitSet);
563  virtual void getPut();
564  virtual void getGet();
565  virtual std::tr1::shared_ptr<Channel> getChannel();
566  virtual void cancel(){}
567  virtual void lock();
568  virtual void unlock();
569  virtual void lastRequest() {}
570 private:
571  shared_pointer getPtrSelf()
572  {
573  return shared_from_this();
574  }
576  bool callProcess,
577  ChannelLocalPtr const &channelLocal,
578  ChannelPutGetRequester::weak_pointer const & channelPutGetRequester,
579  PVCopyPtr const &pvPutCopy,
580  PVCopyPtr const &pvGetCopy,
581  PVStructurePtr const&pvGetStructure,
582  BitSetPtr const & getBitSet,
583  PVRecordPtr const &pvRecord)
584  :
585  callProcess(callProcess),
586  channelLocal(channelLocal),
587  channelPutGetRequester(channelPutGetRequester),
588  pvPutCopy(pvPutCopy),
589  pvGetCopy(pvGetCopy),
590  pvGetStructure(pvGetStructure),
591  getBitSet(getBitSet),
592  pvRecord(pvRecord)
593  {
594  }
595  bool callProcess;
596  ChannelLocalWPtr channelLocal;
597  ChannelPutGetRequester::weak_pointer channelPutGetRequester;
598  PVCopyPtr pvPutCopy;
599  PVCopyPtr pvGetCopy;
600  PVStructurePtr pvGetStructure;
601  BitSetPtr getBitSet;
602  PVRecordWPtr pvRecord;
603  Mutex mutex;
604 };
605 
606 ChannelPutGetLocalPtr ChannelPutGetLocal::create(
607  ChannelLocalPtr const &channelLocal,
608  ChannelPutGetRequester::shared_pointer const & channelPutGetRequester,
609  PVStructurePtr const & pvRequest,
610  PVRecordPtr const &pvRecord)
611 {
612  PVCopyPtr pvPutCopy = PVCopy::create(
613  pvRecord->getPVRecordStructure()->getPVStructure(),
614  pvRequest,
615  "putField");
616  PVCopyPtr pvGetCopy = PVCopy::create(
617  pvRecord->getPVRecordStructure()->getPVStructure(),
618  pvRequest,
619  "getField");
620  if(!pvPutCopy || !pvGetCopy) {
621  Status status(
623  "invalid pvRequest");
624  ChannelPutGet::shared_pointer channelPutGet;
625  channelPutGetRequester->channelPutGetConnect(
626  status,
627  channelPutGet,
628  nullStructure,
629  nullStructure);
630  ChannelPutGetLocalPtr localPutGet;
631  return localPutGet;
632  }
633  PVStructurePtr pvGetStructure = pvGetCopy->createPVStructure();
634  BitSetPtr getBitSet(new BitSet(pvGetStructure->getNumberFields()));
635  ChannelPutGetLocalPtr putGet(new ChannelPutGetLocal(
636  getProcess(pvRequest,true),
637  channelLocal,
638  channelPutGetRequester,
639  pvPutCopy,
640  pvGetCopy,
641  pvGetStructure,
642  getBitSet,
643  pvRecord));
644  if(pvRecord->getTraceLevel()>0)
645  {
646  cout << "ChannelPutGetLocal::create";
647  cout << " recordName " << pvRecord->getRecordName() << endl;
648  }
649  channelPutGetRequester->channelPutGetConnect(
650  Status::Ok, putGet, pvPutCopy->getStructure(),pvGetCopy->getStructure());
651  return putGet;
652 }
653 
654 ChannelPutGetLocal::~ChannelPutGetLocal()
655 {
656 //cout << "~ChannelPutGetLocal()\n";
657 }
658 
659 std::tr1::shared_ptr<Channel> ChannelPutGetLocal::getChannel()
660 {
661  ChannelLocalPtr channel(channelLocal.lock());
662  return channel;
663 }
664 
666 {
667  PVRecordPtr pvr(pvRecord.lock());
668  if(!pvr) throw std::logic_error("pvRecord is deleted");
669  pvr->lock();
670 }
671 void ChannelPutGetLocal::unlock()
672 {
673  PVRecordPtr pvr(pvRecord.lock());
674  if(!pvr) throw std::logic_error("pvRecord is deleted");
675  pvr->unlock();
676 }
677 
678 
679 void ChannelPutGetLocal::putGet(
680  PVStructurePtr const &pvPutStructure,BitSetPtr const &putBitSet)
681 {
682  ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
683  if(!requester) return;
684  PVRecordPtr pvr(pvRecord.lock());
685  if(!pvr) throw std::logic_error("pvRecord is deleted");
686  try {
687  {
688  epicsGuard <PVRecord> guard(*pvr);
689  pvr->beginGroupPut();
690  pvPutCopy->updateMaster(pvPutStructure, putBitSet);
691  if(callProcess) pvr->process();
692  getBitSet->clear();
693  pvGetCopy->updateCopySetBitSet(pvGetStructure, getBitSet);
694  pvr->endGroupPut();
695  }
696  requester->putGetDone(
697  Status::Ok,getPtrSelf(),pvGetStructure,getBitSet);
698  if(pvr->getTraceLevel()>1)
699  {
700  cout << "ChannelPutGetLocal::putGet" << endl;
701  }
702  } catch(std::exception& ex) {
704  requester->putGetDone(status,getPtrSelf(),pvGetStructure,getBitSet);
705  }
706 }
707 
708 void ChannelPutGetLocal::getPut()
709 {
710  ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
711  if(!requester) return;
712  PVRecordPtr pvr(pvRecord.lock());
713  if(!pvr) throw std::logic_error("pvRecord is deleted");
714  try {
715  PVStructurePtr pvPutStructure = pvPutCopy->createPVStructure();
716  BitSetPtr putBitSet(new BitSet(pvPutStructure->getNumberFields()));
717  {
718  epicsGuard <PVRecord> guard(*pvr);
719  pvPutCopy->initCopy(pvPutStructure, putBitSet);
720  }
721  requester->getPutDone(
722  Status::Ok,getPtrSelf(),pvPutStructure,putBitSet);
723  if(pvr->getTraceLevel()>1)
724  {
725  cout << "ChannelPutGetLocal::getPut" << endl;
726  }
727  } catch(std::exception& ex) {
729  PVStructurePtr pvPutStructure;
730  BitSetPtr putBitSet;
731  requester->getPutDone(status,getPtrSelf(),pvGetStructure,getBitSet);
732  }
733 }
734 
735 void ChannelPutGetLocal::getGet()
736 {
737  ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
738  if(!requester) return;
739  PVRecordPtr pvr(pvRecord.lock());
740  if(!pvr) throw std::logic_error("pvRecord is deleted");
741  try {
742  getBitSet->clear();
743  {
744  epicsGuard <PVRecord> guard(*pvr);
745  pvGetCopy->updateCopySetBitSet(pvGetStructure, getBitSet);
746  }
747  requester->getGetDone(
748  Status::Ok,getPtrSelf(),pvGetStructure,getBitSet);
749  if(pvr->getTraceLevel()>1)
750  {
751  cout << "ChannelPutGetLocal::getGet" << endl;
752  }
753  } catch(std::exception& ex) {
755  PVStructurePtr pvPutStructure;
756  BitSetPtr putBitSet;
757  requester->getGetDone(status,getPtrSelf(),pvGetStructure,getBitSet);
758  }
759 }
760 
761 
763  public ChannelRPC,
764  public RPCResponseCallback,
765  public std::tr1::enable_shared_from_this<ChannelRPCLocal>
766 {
767 public:
769  virtual void destroy() {} // DEPRECATED
770  static ChannelRPCLocalPtr create(
771  ChannelLocalPtr const & channelLocal,
772  ChannelRPCRequester::shared_pointer const & channelRPCRequester,
773  PVStructurePtr const & pvRequest,
774  PVRecordPtr const & pvRecord);
775 
777  ChannelLocalPtr const & channelLocal,
778  ChannelRPCRequester::shared_pointer const & channelRPCRequester,
779  RPCServiceAsync::shared_pointer const & service,
780  PVRecordPtr const & pvRecord) :
781  channelLocal(channelLocal),
782  channelRPCRequester(channelRPCRequester),
783  service(service),
784  pvRecord(pvRecord)
785  {
786  }
787 
788  virtual ~ChannelRPCLocal();
789  void processRequest(RPCService::shared_pointer const & service,
790  PVStructurePtr const & pvArgument);
791 
792  virtual void requestDone(Status const & status,
793  PVStructurePtr const & result)
794  {
795  ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
796  if(!requester) return;
797  requester->requestDone(status, getPtrSelf(), result);
798  }
799 
800  void processRequest(RPCServiceAsync::shared_pointer const & service,
801  PVStructurePtr const & pvArgument);
802 
803  virtual void request(PVStructurePtr const & pvArgument);
804  virtual Channel::shared_pointer getChannel();
805  virtual void cancel() {}
806  virtual void lock() {}
807  virtual void unlock() {}
808  virtual void lastRequest() {}
809 private:
810  shared_pointer getPtrSelf()
811  {
812  return shared_from_this();
813  }
814  ChannelLocalWPtr channelLocal;
815  ChannelRPCRequester::weak_pointer channelRPCRequester;
816  RPCServiceAsync::shared_pointer service;
817  PVRecordWPtr pvRecord;
818 };
819 
820 ChannelRPCLocalPtr ChannelRPCLocal::create(
821  ChannelLocalPtr const &channelLocal,
822  ChannelRPCRequester::shared_pointer const & channelRPCRequester,
823  PVStructurePtr const & pvRequest,
824  PVRecordPtr const &pvRecord)
825 {
826  RPCServiceAsync::shared_pointer service = pvRecord->getService(pvRequest);
827  if (!service)
828  {
830  "ChannelRPC not supported");
831  channelRPCRequester->channelRPCConnect(status,ChannelRPCLocalPtr());
832  return ChannelRPCLocalPtr();
833  }
834 
835  if (!channelRPCRequester)
836  throw std::invalid_argument("channelRPCRequester == null");
837 
838  // TODO use std::make_shared
839  ChannelRPCLocalPtr rpc(
840  new ChannelRPCLocal(channelLocal, channelRPCRequester, service, pvRecord)
841  );
842  channelRPCRequester->channelRPCConnect(Status::Ok, rpc);
843  if(pvRecord->getTraceLevel()>0)
844  {
845  cout << "ChannelRPCLocal::create";
846  cout << " recordName " << pvRecord->getRecordName() << endl;
847  }
848  return rpc;
849 }
850 
851 ChannelRPCLocal::~ChannelRPCLocal()
852 {
853 //cout << "~ChannelRPCLocal()\n";
854 }
855 
856 std::tr1::shared_ptr<Channel> ChannelRPCLocal::getChannel()
857 {
858  ChannelLocalPtr channel(channelLocal.lock());
859  return channel;
860 }
861 
862 
863 void ChannelRPCLocal::processRequest(
864  RPCService::shared_pointer const & service,
865  PVStructurePtr const & pvArgument)
866 {
869  bool ok = true;
870  try
871  {
872  result = service->request(pvArgument);
873  }
874  catch (RPCRequestException& rre)
875  {
876  status = Status(rre.getStatus(), rre.what());
877  ok = false;
878  }
879  catch (std::exception& ex)
880  {
881  status = Status(Status::STATUSTYPE_FATAL, ex.what());
882  ok = false;
883  }
884  catch (...)
885  {
886  // handle user unexpected errors
887  status = Status(Status::STATUSTYPE_FATAL, "Unexpected exception caught while calling RPCService.request(PVStructure).");
888  ok = false;
889  }
890 
891  // check null result
892  if (ok && !result)
893  {
894  status = Status(Status::STATUSTYPE_FATAL, "RPCService.request(PVStructure) returned null.");
895  }
896  ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
897  if(requester) requester->requestDone(status, getPtrSelf(), result);
898 }
899 
900 void ChannelRPCLocal::processRequest(
901  RPCServiceAsync::shared_pointer const & service,
902  PVStructurePtr const & pvArgument)
903 {
904  try
905  {
906  service->request(pvArgument, getPtrSelf());
907  }
908  catch (std::exception& ex)
909  {
910  // handle user unexpected errors
911  Status errorStatus(Status::STATUSTYPE_FATAL, ex.what());
912  ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
913  if(requester) requester->requestDone(errorStatus, getPtrSelf(), PVStructurePtr());
914  }
915  catch (...)
916  {
917  // handle user unexpected errors
918  Status errorStatus(Status::STATUSTYPE_FATAL,
919  "Unexpected exception caught while calling RPCServiceAsync.request(PVStructure, RPCResponseCallback).");
920  ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
921  if(requester) requester->requestDone(errorStatus, shared_from_this(), PVStructurePtr());
922  }
923 
924  // we wait for callback to be called
925 }
926 
927 
928 void ChannelRPCLocal::request(PVStructurePtr const & pvArgument)
929 {
930  PVRecordPtr pvr(pvRecord.lock());
931  if(pvr && pvr->getTraceLevel()>0) {
932  cout << "ChannelRPCLocal::request " << pvr->getRecordName() << endl;
933  }
934  RPCService::shared_pointer rpcService =
936  if (rpcService)
937  {
938  processRequest(rpcService, pvArgument);
939  return;
940  }
941 
942  RPCServiceAsync::shared_pointer rpcServiceAsync =
944  if (rpcServiceAsync)
945  {
946  processRequest(rpcServiceAsync, pvArgument);
947  return;
948  }
949 }
950 
951 
952 typedef std::tr1::shared_ptr<PVArray> PVArrayPtr;
953 
955  public ChannelArray,
956  public std::tr1::enable_shared_from_this<ChannelArrayLocal>
957 {
958 public:
960  virtual ~ChannelArrayLocal();
961  virtual void destroy() {} // DEPRECATED
962  static ChannelArrayLocalPtr create(
963  ChannelLocalPtr const &channelLocal,
964  ChannelArrayRequester::shared_pointer const & channelArrayRequester,
965  PVStructurePtr const & pvRequest,
966  PVRecordPtr const &pvRecord);
967  virtual void getArray(size_t offset, size_t count, size_t stride);
968  virtual void putArray(
969  PVArrayPtr const &putArray,
970  size_t offset, size_t count, size_t stride);
971  virtual void getLength();
972  virtual void setLength(size_t length);
973  virtual std::tr1::shared_ptr<Channel> getChannel();
974  virtual void cancel(){}
975  virtual void lock();
976  virtual void unlock();
977  virtual void lastRequest() {}
978 private:
979  shared_pointer getPtrSelf()
980  {
981  return shared_from_this();
982  }
984  ChannelLocalPtr const &channelLocal,
985  ChannelArrayRequester::shared_pointer const & channelArrayRequester,
986  PVArrayPtr const &pvArray,
987  PVArrayPtr const &pvCopy,
988  PVRecordPtr const &pvRecord)
989  :
990  channelLocal(channelLocal),
991  channelArrayRequester(channelArrayRequester),
992  pvArray(pvArray),
993  pvCopy(pvCopy),
994  pvRecord(pvRecord)
995  {
996  }
997 
998  ChannelLocalWPtr channelLocal;
999  ChannelArrayRequester::weak_pointer channelArrayRequester;
1000  PVArrayPtr pvArray;
1001  PVArrayPtr pvCopy;
1002  PVRecordWPtr pvRecord;
1003  Mutex mutex;
1004 };
1005 
1006 
1007 ChannelArrayLocalPtr ChannelArrayLocal::create(
1008  ChannelLocalPtr const &channelLocal,
1009  ChannelArrayRequester::shared_pointer const & channelArrayRequester,
1010  PVStructurePtr const & pvRequest,
1011  PVRecordPtr const &pvRecord)
1012 {
1013  PVFieldPtrArray const & pvFields = pvRequest->getPVFields();
1014  if(pvFields.size()!=1) {
1015  Status status(
1016  Status::STATUSTYPE_ERROR,"invalid pvRequest");
1017  ChannelArrayLocalPtr channelArray;
1018  ArrayConstPtr array;
1019  channelArrayRequester->channelArrayConnect(status,channelArray,array);
1020  return channelArray;
1021  }
1022  PVFieldPtr pvField = pvFields[0];
1023  string fieldName("");
1024  while(true) {
1025  string name = pvField->getFieldName();
1026  if(fieldName.size()>0) fieldName += '.';
1027  fieldName += name;
1029  PVFieldPtrArray const & pvfs = pvs->getPVFields();
1030  if(pvfs.size()!=1) break;
1031  pvField = pvfs[0];
1032  }
1033  size_t indfield = fieldName.find_first_of("field.");
1034  if(indfield==0) {
1035  fieldName = fieldName.substr(6);
1036  }
1037  pvField = pvRecord->getPVRecordStructure()->getPVStructure()->getSubField(fieldName);
1038  if(!pvField) {
1039  Status status(
1040  Status::STATUSTYPE_ERROR,fieldName +" not found");
1041  ChannelArrayLocalPtr channelArray;
1042  ArrayConstPtr array;
1043  channelArrayRequester->channelArrayConnect(
1044  status,channelArray,array);
1045  return channelArray;
1046  }
1047  if(pvField->getField()->getType()!=scalarArray
1048  && pvField->getField()->getType()!=structureArray
1049  && pvField->getField()->getType()!=unionArray)
1050  {
1051  Status status(
1052  Status::STATUSTYPE_ERROR,fieldName +" not array");
1053  ChannelArrayLocalPtr channelArray;
1054  ArrayConstPtr array;
1055  channelArrayRequester->channelArrayConnect(
1056  status,channelArray,array);
1057  return channelArray;
1058  }
1059  PVArrayPtr pvArray = static_pointer_cast<PVArray>(pvField);
1060  PVArrayPtr pvCopy;
1061  if(pvField->getField()->getType()==scalarArray) {
1063  pvCopy = getPVDataCreate()->createPVScalarArray(
1064  xxx->getScalarArray()->getElementType());
1065  } else if(pvField->getField()->getType()==structureArray) {
1067  pvCopy = getPVDataCreate()->createPVStructureArray(
1068  xxx->getStructureArray()->getStructure());
1069  } else {
1071  pvCopy = getPVDataCreate()->createPVUnionArray(
1072  xxx->getUnionArray()->getUnion());
1073  }
1074  ChannelArrayLocalPtr array(new ChannelArrayLocal(
1075  channelLocal,
1076  channelArrayRequester,
1077  pvArray,
1078  pvCopy,
1079  pvRecord));
1080  if(pvRecord->getTraceLevel()>0)
1081  {
1082  cout << "ChannelArrayLocal::create";
1083  cout << " recordName " << pvRecord->getRecordName() << endl;
1084  }
1085  channelArrayRequester->channelArrayConnect(
1086  Status::Ok, array, pvCopy->getArray());
1087  return array;
1088 }
1089 
1090 ChannelArrayLocal::~ChannelArrayLocal()
1091 {
1092 //cout << "~ChannelArrayLocal()\n";
1093 }
1094 
1095 std::tr1::shared_ptr<Channel> ChannelArrayLocal::getChannel()
1096 {
1097  ChannelLocalPtr channel(channelLocal.lock());
1098  return channel;
1099 }
1100 
1102 {
1103  PVRecordPtr pvr(pvRecord.lock());
1104  if(!pvr) throw std::logic_error("pvRecord is deleted");
1105  pvr->lock();
1106 }
1107 void ChannelArrayLocal::unlock()
1108 {
1109  PVRecordPtr pvr(pvRecord.lock());
1110  if(!pvr) throw std::logic_error("pvRecord is deleted");
1111  pvr->unlock();
1112 }
1113 
1114 void ChannelArrayLocal::getArray(size_t offset, size_t count, size_t stride)
1115 {
1116  ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
1117  if(!requester) return;
1118  PVRecordPtr pvr(pvRecord.lock());
1119  if(!pvr) throw std::logic_error("pvRecord is deleted");
1120  if(pvr->getTraceLevel()>1)
1121  {
1122  cout << "ChannelArrayLocal::getArray" << endl;
1123  }
1124  const char *exceptionMessage = NULL;
1125  try {
1126  bool ok = false;
1127  epicsGuard <PVRecord> guard(*pvr);
1128  while(true) {
1129  size_t length = pvArray->getLength();
1130  if(length<=0) break;
1131  if(count<=0) {
1132  count = (length -offset + stride -1)/stride;
1133  if(count>0) ok = true;
1134  break;
1135  }
1136  size_t maxcount = (length -offset + stride -1)/stride;
1137  if(count>maxcount) count = maxcount;
1138  ok = true;
1139  break;
1140  }
1141  if(ok) {
1142  pvCopy->setLength(count);
1143  copy(pvArray,offset,stride,pvCopy,0,1,count);
1144  }
1145  } catch(std::exception& e) {
1146  exceptionMessage = e.what();
1147  }
1149  if(exceptionMessage!=NULL) {
1150  status = Status(Status::STATUSTYPE_ERROR,exceptionMessage);
1151  }
1152  requester->getArrayDone(status,getPtrSelf(),pvCopy);
1153 }
1154 
1155 void ChannelArrayLocal::putArray(
1156  PVArrayPtr const & pvArray, size_t offset, size_t count, size_t stride)
1157 {
1158  ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
1159  if(!requester) return;
1160  PVRecordPtr pvr(pvRecord.lock());
1161  if(!pvr) throw std::logic_error("pvRecord is deleted");
1162  if(pvr->getTraceLevel()>1)
1163  {
1164  cout << "ChannelArrayLocal::putArray" << endl;
1165  }
1166  size_t newLength = offset + count*stride;
1167  if(newLength<pvArray->getLength()) pvArray->setLength(newLength);
1168  const char *exceptionMessage = NULL;
1169  try {
1170  epicsGuard <PVRecord> guard(*pvr);
1171  copy(pvArray,0,1,this->pvArray,offset,stride,count);
1172  } catch(std::exception& e) {
1173  exceptionMessage = e.what();
1174  }
1176  if(exceptionMessage!=NULL) {
1177  status = Status(Status::STATUSTYPE_ERROR,exceptionMessage);
1178  }
1179  requester->putArrayDone(status,getPtrSelf());
1180 }
1181 
1182 void ChannelArrayLocal::getLength()
1183 {
1184  ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
1185  if(!requester) return;
1186  PVRecordPtr pvr(pvRecord.lock());
1187  if(!pvr) throw std::logic_error("pvRecord is deleted");
1188  size_t length = 0;
1189  const char *exceptionMessage = NULL;
1190  try {
1191  epicsGuard <PVRecord> guard(*pvr);
1192  length = pvArray->getLength();
1193  } catch(std::exception& e) {
1194  exceptionMessage = e.what();
1195  }
1197  if(exceptionMessage!=NULL) {
1198  status = Status(Status::STATUSTYPE_ERROR,exceptionMessage);
1199  }
1200  requester->getLengthDone(status,getPtrSelf(),length);
1201 }
1202 
1203 void ChannelArrayLocal::setLength(size_t length)
1204 {
1205  ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
1206  if(!requester) return;
1207  PVRecordPtr pvr(pvRecord.lock());
1208  if(!pvr) throw std::logic_error("pvRecord is deleted");
1209  if(pvr->getTraceLevel()>1)
1210  {
1211  cout << "ChannelArrayLocal::setLength" << endl;
1212  }
1213  try {
1214  {
1215  epicsGuard <PVRecord> guard(*pvr);
1216  if(pvArray->getLength()!=length) pvArray->setLength(length);
1217  }
1218  requester->setLengthDone(Status::Ok,getPtrSelf());
1219  } catch(std::exception& e) {
1220  string exceptionMessage = e.what();
1221  Status status = Status(Status::STATUSTYPE_ERROR,exceptionMessage);
1222  requester->setLengthDone(status,getPtrSelf());
1223  }
1224 }
1225 
1226 
1227 ChannelLocal::ChannelLocal(
1228  ChannelProviderLocalPtr const & provider,
1229  ChannelRequester::shared_pointer const & requester,
1230  PVRecordPtr const & pvRecord)
1231 :
1232  requester(requester),
1233  provider(provider),
1234  pvRecord(pvRecord)
1235 {
1236  if(pvRecord->getTraceLevel()>0) {
1237  cout << "ChannelLocal::ChannelLocal()"
1238  << " recordName " << pvRecord->getRecordName()
1239  << " requester exists " << (requester ? "true" : "false")
1240  << endl;
1241  }
1242 }
1243 
1245 {
1246 // cout << "~ChannelLocal()" << endl;
1247 }
1248 
1249 ChannelProvider::shared_pointer ChannelLocal::getProvider()
1250 {
1251  return provider.lock();
1252 }
1253 
1254 void ChannelLocal::detach(PVRecordPtr const & pvRecord)
1255 {
1256  if(pvRecord->getTraceLevel()>0) {
1257  cout << "ChannelLocal::detach() "
1258  << " recordName " << pvRecord->getRecordName()
1259  << " requester exists " << (requester ? "true" : "false")
1260  << endl;
1261  }
1262  if(!requester) return;
1263  requester->channelStateChange(shared_from_this(),Channel::DESTROYED);
1264 }
1265 
1266 
1268 {
1269  PVRecordPtr pvr(pvRecord.lock());
1270  if(pvr && pvr->getTraceLevel()>0) {
1271  cout << "ChannelLocal::getRequesterName() "
1272  << " recordName " << pvr->getRecordName()
1273  << " requester exists " << (requester ? "true" : "false")
1274  << endl;
1275  }
1276 
1277  if(!requester) return string();
1278  return requester->getRequesterName();
1279 }
1280 
1282  string const &message,
1283  MessageType messageType)
1284 {
1285  PVRecordPtr pvr(pvRecord.lock());
1286  if(pvr && pvr->getTraceLevel()>1) {
1287  cout << "ChannelLocal::message() "
1288  << " recordName " << pvr->getRecordName()
1289  << " requester exists " << (requester ? "true" : "false")
1290  << endl;
1291  }
1292  if(requester) {
1293  requester->message(message,messageType);
1294  return;
1295  }
1296  string recordName("record deleted");
1297  if(pvr) recordName = pvr->getRecordName();
1298  cout << recordName
1299  << " message " << message
1300  << " messageType " << getMessageTypeName(messageType)
1301  << endl;
1302 }
1303 
1305 {
1306  return string("local");
1307 }
1308 
1310 {
1311  return Channel::CONNECTED;
1312 }
1313 
1315 {
1316  PVRecordPtr pvr(pvRecord.lock());
1317  string name("record deleted");
1318  if(pvr) name = pvr->getRecordName();
1319  return name;
1320 }
1321 
1322 ChannelRequester::shared_pointer ChannelLocal::getChannelRequester()
1323 {
1324  return requester;
1325 }
1326 
1328 {
1329  return true;
1330 }
1331 
1332 void ChannelLocal::getField(GetFieldRequester::shared_pointer const &requester,
1333  string const &subField)
1334 {
1335  PVRecordPtr pvr(pvRecord.lock());
1336  if(!pvr) throw std::logic_error("pvRecord is deleted");
1337  if(subField.size()<1) {
1339  pvr->getPVRecordStructure()->getPVStructure()->getStructure();
1340  requester->getDone(Status::Ok,structure);
1341  return;
1342  }
1343  PVFieldPtr pvField =
1344  pvr->getPVRecordStructure()->getPVStructure()->getSubField(subField);
1345  if(pvField) {
1346  requester->getDone(Status::Ok,pvField->getField());
1347  return;
1348  }
1349  Status status(Status::STATUSTYPE_ERROR,
1350  "client asked for illegal field");
1351  requester->getDone(status,FieldConstPtr());
1352 }
1353 
1355  PVField::shared_pointer const &pvField)
1356 {
1357  throw std::logic_error("Not Implemented");
1358 }
1359 
1360 ChannelProcess::shared_pointer ChannelLocal::createChannelProcess(
1361  ChannelProcessRequester::shared_pointer const & channelProcessRequester,
1362  PVStructure::shared_pointer const & pvRequest)
1363 {
1364  PVRecordPtr pvr(pvRecord.lock());
1365  if(!pvr) throw std::logic_error("pvRecord is deleted");
1366  if(pvr->getTraceLevel()>0) {
1367  cout << "ChannelLocal::createChannelProcess() "
1368  << " recordName " << pvr->getRecordName()
1369  << " requester exists " << (requester ? "true" : "false")
1370  << endl;
1371  }
1372  ChannelProcessLocalPtr channelProcess =
1374  getPtrSelf(),
1375  channelProcessRequester,
1376  pvRequest,
1377  pvr);
1378  return channelProcess;
1379 }
1380 
1381 ChannelGet::shared_pointer ChannelLocal::createChannelGet(
1382  ChannelGetRequester::shared_pointer const &channelGetRequester,
1383  PVStructure::shared_pointer const &pvRequest)
1384 {
1385  PVRecordPtr pvr(pvRecord.lock());
1386  if(!pvr) throw std::logic_error("pvRecord is deleted");
1387  if(pvr->getTraceLevel()>0) {
1388  cout << "ChannelLocal::createChannelGet() "
1389  << " recordName " << pvr->getRecordName()
1390  << " requester exists " << (requester ? "true" : "false")
1391  << endl;
1392  }
1393  ChannelGetLocalPtr channelGet =
1395  getPtrSelf(),
1396  channelGetRequester,
1397  pvRequest,
1398  pvr);
1399  return channelGet;
1400 }
1401 
1402 ChannelPut::shared_pointer ChannelLocal::createChannelPut(
1403  ChannelPutRequester::shared_pointer const &channelPutRequester,
1404  PVStructure::shared_pointer const &pvRequest)
1405 {
1406  PVRecordPtr pvr(pvRecord.lock());
1407  if(!pvr) throw std::logic_error("pvRecord is deleted");
1408  if(pvr->getTraceLevel()>0) {
1409  cout << "ChannelLocal::createChannelPut() "
1410  << " recordName " << pvr->getRecordName()
1411  << " requester exists " << (requester ? "true" : "false")
1412  << endl;
1413  }
1414 
1415  ChannelPutLocalPtr channelPut =
1417  getPtrSelf(),
1418  channelPutRequester,
1419  pvRequest,
1420  pvr);
1421  return channelPut;
1422 }
1423 
1424 ChannelPutGet::shared_pointer ChannelLocal::createChannelPutGet(
1425  ChannelPutGetRequester::shared_pointer const &channelPutGetRequester,
1426  PVStructure::shared_pointer const &pvRequest)
1427 {
1428  PVRecordPtr pvr(pvRecord.lock());
1429  if(!pvr) throw std::logic_error("pvRecord is deleted");
1430  if(pvr->getTraceLevel()>0) {
1431  cout << "ChannelLocal::createChannelPutGet() "
1432  << " recordName " << pvr->getRecordName()
1433  << " requester exists " << (requester ? "true" : "false")
1434  << endl;
1435  }
1436 
1437  ChannelPutGetLocalPtr channelPutGet =
1439  getPtrSelf(),
1440  channelPutGetRequester,
1441  pvRequest,
1442  pvr);
1443  return channelPutGet;
1444 }
1445 
1446 ChannelRPC::shared_pointer ChannelLocal::createChannelRPC(
1447  ChannelRPCRequester::shared_pointer const & channelRPCRequester,
1448  PVStructure::shared_pointer const & pvRequest)
1449 {
1450  PVRecordPtr pvr(pvRecord.lock());
1451  if(!pvr) throw std::logic_error("pvRecord is deleted");
1452  if(pvr->getTraceLevel()>0) {
1453  cout << "ChannelLocal::createChannelRPC() "
1454  << " recordName " << pvr->getRecordName()
1455  << " requester exists " << (requester ? "true" : "false")
1456  << endl;
1457  }
1458 
1459  ChannelRPCLocalPtr channelRPC =
1461  getPtrSelf(),
1462  channelRPCRequester,
1463  pvRequest,
1464  pvr);
1465  return channelRPC;
1466 }
1467 
1468 Monitor::shared_pointer ChannelLocal::createMonitor(
1469  MonitorRequester::shared_pointer const &monitorRequester,
1470  PVStructure::shared_pointer const &pvRequest)
1471 {
1472  PVRecordPtr pvr(pvRecord.lock());
1473  if(!pvr) throw std::logic_error("pvRecord is deleted");
1474  if(pvr->getTraceLevel()>0) {
1475  cout << "ChannelLocal::createMonitor() "
1476  << " recordName " << pvr->getRecordName()
1477  << " requester exists " << (requester ? "true" : "false")
1478  << endl;
1479  }
1480 
1481  MonitorPtr monitor = createMonitorLocal(
1482  pvr,
1483  monitorRequester,
1484  pvRequest);
1485  return monitor;
1486 }
1487 
1488 ChannelArray::shared_pointer ChannelLocal::createChannelArray(
1489  ChannelArrayRequester::shared_pointer const &channelArrayRequester,
1490  PVStructure::shared_pointer const &pvRequest)
1491 {
1492  PVRecordPtr pvr(pvRecord.lock());
1493  if(!pvr) throw std::logic_error("pvRecord is deleted");
1494  if(pvr->getTraceLevel()>0) {
1495  cout << "ChannelLocal::createChannelArray() "
1496  << " recordName " << pvr->getRecordName()
1497  << " requester exists " << (requester ? "true" : "false")
1498  << endl;
1499  }
1500  ChannelArrayLocalPtr channelArray =
1502  getPtrSelf(),
1503  channelArrayRequester,
1504  pvRequest,
1505  pvr);
1506  return channelArray;
1507 }
1508 
1510 {
1511  printInfo(std::cout);
1512 }
1513 
1514 void ChannelLocal::printInfo(std::ostream& out)
1515 {
1516  out << "ChannelLocal provides access to a record in the local PVDatabase";
1517 }
1518 
1519 }}
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
static ChannelArrayLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelArrayRequester::shared_pointer const &channelArrayRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
This class implements introspection object for Scalar.
Definition: pvIntrospect.h:397
pvac::PutEvent result
Definition: clientSync.cpp:117
std::string request
Data class for a unionArray.
Definition: pvData.h:1335
virtual void printInfo()
calls printInfo(std::cout);
std::tr1::shared_ptr< detail::SharedPut > put
epicsShareExtern std::string getMessageTypeName(MessageType messageType)
Definition: requester.cpp:25
virtual epics::pvAccess::ChannelPut::shared_pointer createChannelPut(epics::pvAccess::ChannelPutRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelPut.
epicsMutexId lock
Definition: osiClockTime.c:37
pvd::Status status
virtual void requestDone(Status const &status, PVStructurePtr const &result)
static Status Ok
Definition: status.h:47
int i
Definition: scan.c:967
std::tr1::shared_ptr< PVBoolean > PVBooleanPtr
Definition: pvData.h:504
std::tr1::shared_ptr< PVCopy > PVCopyPtr
Definition: pvPlugin.h:25
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
std::tr1::shared_ptr< const Array > ArrayConstPtr
Definition: pvIntrospect.h:154
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
#define NULL
Definition: catime.c:38
virtual std::string getRequesterName()
Get the requester name.
A vector of bits.
Definition: bitSet.h:56
static ChannelPutGetLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelPutGetRequester::shared_pointer const &channelPutGetRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
std::tr1::shared_ptr< ChannelRPCLocal > ChannelRPCLocalPtr
storage_t::arg_type get() const
Definition: pvData.h:396
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
std::tr1::shared_ptr< ChannelLocal > ChannelLocalPtr
static ChannelProcessLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelProcessRequester::shared_pointer const &channelProcessRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
std::tr1::shared_ptr< const Scalar > ScalarConstPtr
Definition: pvIntrospect.h:150
std::tr1::shared_ptr< PVArray > PVArrayPtr
virtual ~ChannelLocal()
Destructor.
std::tr1::weak_ptr< ChannelLocal > ChannelLocalWPtr
Holds all PVA related.
Definition: pvif.h:34
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
pvData
Definition: monitor.h:428
virtual void getField(epics::pvAccess::GetFieldRequester::shared_pointer const &requester, std::string const &subField)
Get the introspection interface for subField.
virtual epics::pvAccess::ChannelRPC::shared_pointer createChannelRPC(epics::pvAccess::ChannelRPCRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelRPC.
#define POINTER_DEFINITIONS(clazz)
Definition: sharedPtr.h:198
virtual epics::pvData::Monitor::shared_pointer createMonitor(epics::pvData::MonitorRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a monitor.
std::tr1::shared_ptr< PVStructureArray > PVStructureArrayPtr
Definition: pvData.h:100
epicsMutex mutex
Definition: pvAccess.cpp:71
virtual epics::pvAccess::ChannelArray::shared_pointer createChannelArray(epics::pvAccess::ChannelArrayRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelArray.
epicsShareFunc epics::pvData::MonitorPtr createMonitorLocal(PVRecordPtr const &pvRecord, epics::pvData::MonitorRequester::shared_pointer const &monitorRequester, epics::pvData::PVStructurePtr const &pvRequest)
std::tr1::shared_ptr< ChannelProviderLocal > ChannelProviderLocalPtr
const ChannelProcessRequester::weak_pointer requester
Definition: pvAccess.cpp:68
virtual epics::pvAccess::ChannelPutGet::shared_pointer createChannelPutGet(epics::pvAccess::ChannelPutGetRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelPutGet.
Base class for a scalarArray.
Definition: pvData.h:618
virtual epics::pvAccess::ChannelProvider::shared_pointer getProvider()
Get the channel provider.
std::tr1::shared_ptr< PVUnionArray > PVUnionArrayPtr
Definition: pvData.h:120
virtual epics::pvAccess::AccessRights getAccessRights(epics::pvData::PVField::shared_pointer const &pvField)
std::vector< PVFieldPtr > PVFieldPtrArray
Definition: pvData.h:70
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:137
std::tr1::shared_ptr< ChannelPutGetLocal > ChannelPutGetLocalPtr
std::tr1::shared_ptr< PVRecord > PVRecordPtr
Definition: pvDatabase.h:21
std::tr1::shared_ptr< ChannelArrayLocal > ChannelArrayLocalPtr
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
std::tr1::shared_ptr< PVString > PVStringPtr
Definition: pvData.h:540
Data class for a structureArray.
Definition: pvData.h:1236
std::tr1::shared_ptr< ChannelProcessLocal > ChannelProcessLocalPtr
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
std::tr1::shared_ptr< ChannelGetLocal > ChannelGetLocalPtr
virtual std::string getChannelName()
Get the channel name.
std::tr1::weak_ptr< PVRecord > PVRecordWPtr
Definition: pvDatabase.h:23
virtual epics::pvAccess::ChannelProcess::shared_pointer createChannelProcess(epics::pvAccess::ChannelProcessRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelProcess.
Definition: caget.c:48
static ChannelRPCLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelRPCRequester::shared_pointer const &channelRPCRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
ChannelRPCLocal(ChannelLocalPtr const &channelLocal, ChannelRPCRequester::shared_pointer const &channelRPCRequester, RPCServiceAsync::shared_pointer const &service, PVRecordPtr const &pvRecord)
std::tr1::shared_ptr< BitSet > BitSetPtr
Definition: bitSet.h:26
virtual epics::pvAccess::ChannelGet::shared_pointer createChannelGet(epics::pvAccess::ChannelGetRequester::shared_pointer const &requester, epics::pvData::PVStructurePtr const &pvRequest)
Create a channelGet.
epics::pvData::Status::StatusType getStatus() const
Definition: rpcService.h:43
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:808
std::tr1::shared_ptr< ChannelPutLocal > ChannelPutLocalPtr
virtual bool isConnected()
Is the channel connected?
static ChannelPutLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelPutRequester::shared_pointer const &channelPutRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
static ChannelGetLocalPtr create(ChannelLocalPtr const &channelLocal, ChannelGetRequester::shared_pointer const &channelGetRequester, PVStructurePtr const &pvRequest, PVRecordPtr const &pvRecord)
virtual void message(std::string const &message, epics::pvData::MessageType messageType)
Passes the message to the channel requester.
epicsMutex Mutex
Definition: lock.h:28
virtual std::string getRemoteAddress()
Get the remote address.
PVArray is the base class for all array types.
Definition: pvData.h:551
C++ and C descriptions for a thread.
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
Definition: pvData.h:82
virtual epics::pvAccess::ChannelRequester::shared_pointer getChannelRequester()
Get the channel requester.
virtual epics::pvAccess::Channel::ConnectionState getConnectionState()
virtual void detach(PVRecordPtr const &pvRecord)
Detach from the record.
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
std::tr1::shared_ptr< Monitor > MonitorPtr
Definition: monitor.h:44