pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
transportRegistry.h
1 
7 #ifndef TRANSPORTREGISTRY_H
8 #define TRANSPORTREGISTRY_H
9 
10 #include <map>
11 #include <vector>
12 #include <list>
13 #include <iostream>
14 
15 #ifdef epicsExportSharedSymbols
16 # define transportRegistryEpicsExportSharedSymbols
17 # undef epicsExportSharedSymbols
18 #endif
19 
20 #include <osiSock.h>
21 
22 #include <pv/lock.h>
23 #include <pv/pvType.h>
24 #include <pv/epicsException.h>
25 #include <pv/sharedPtr.h>
26 
27 #ifdef transportRegistryEpicsExportSharedSymbols
28 # define epicsExportSharedSymbols
29 # undef transportRegistryEpicsExportSharedSymbols
30 #endif
31 
32 #include <pv/remote.h>
33 #include <pv/inetAddressUtil.h>
34 
35 namespace epics {
36 namespace pvAccess {
37 
38 class TransportRegistry {
39 public:
40  class Reservation;
41 private:
42  struct Key {
43  osiSockAddr addr;
44  epics::pvData::int16 prio;
45  Key(const osiSockAddr& a, epics::pvData::int16 p) :addr(a), prio(p) {}
46  bool operator<(const Key& o) const;
47  };
48 
49  typedef std::map<Key, Transport::shared_pointer> transports_t;
51 
52 public:
53  POINTER_DEFINITIONS(TransportRegistry);
54 
55  typedef std::vector<Transport::shared_pointer> transportVector_t;
56 
57  class Reservation {
58  TransportRegistry* const owner;
59  const Key key;
60  std::tr1::shared_ptr<epics::pvData::Mutex> mutex;
61  public:
62 
63  // ctor blocks until no concurrent connect() in progress (success or failure)
64  Reservation(TransportRegistry *owner, const osiSockAddr& address, epics::pvData::int16 prio);
65  ~Reservation();
66  };
67 
68  TransportRegistry() {}
69  ~TransportRegistry();
70 
71  Transport::shared_pointer get(const osiSockAddr& address, epics::pvData::int16 prio);
72  void install(const Transport::shared_pointer& ptr);
73  Transport::shared_pointer remove(Transport::shared_pointer const & transport);
74  void clear();
75  size_t size();
76 
77  // optimized to avoid reallocation, adds to array
78  void toArray(transportVector_t & transportArray, const osiSockAddr *dest=0);
79 
80 private:
81  transports_t transports;
82  // per destination mutex to serialize concurrent connect() attempts
83  locks_t locks;
84 
85  epics::pvData::Mutex _mutex;
86 };
87 
88 }
89 }
90 
91 #endif /* INTROSPECTIONREGISTRY_H */
size_t size() const
bool operator<(const sub_match< _BiIter > &__lhs, const sub_match< _BiIter > &__rhs)