pvAccessCPP  7.1.6
introspectionRegistry.h
1 /**
2  * Copyright - See the COPYRIGHT that is included with this distribution.
3  * pvAccessCPP is distributed subject to a Software License Agreement found
4  * in file LICENSE that is included with this distribution.
5  */
6 
7 #ifndef INTROSPECTIONREGISTRY_H
8 #define INTROSPECTIONREGISTRY_H
9 
10 #include <map>
11 #include <iostream>
12 
13 #ifdef epicsExportSharedSymbols
14 # define introspectionRegistryEpicsExportSharedSymbols
15 # undef epicsExportSharedSymbols
16 #endif
17 
18 #include <pv/lock.h>
19 #include <pv/pvIntrospect.h>
20 #include <pv/pvData.h>
21 #include <pv/byteBuffer.h>
22 #include <pv/serialize.h>
23 #include <pv/serializeHelper.h>
24 #include <pv/status.h>
25 #include <pv/standardField.h>
26 
27 #ifdef introspectionRegistryEpicsExportSharedSymbols
28 # define epicsExportSharedSymbols
29 # undef introspectionRegistryEpicsExportSharedSymbols
30 #endif
31 
32 // TODO check for memory leaks
33 
34 namespace epics {
35 namespace pvAccess {
36 
37 typedef std::map<const short,epics::pvData::FieldConstPtr> registryMap_t;
38 
39 
40 /**
41  * PVData Structure registry.
42  * Registry is used to cache introspection interfaces to minimize network traffic.
43  * @author gjansa
44  */
45 class IntrospectionRegistry {
46  EPICS_NOT_COPYABLE(IntrospectionRegistry)
47 public:
48  IntrospectionRegistry();
49  virtual ~IntrospectionRegistry();
50 
51  /**
52  * Resets registry, i.e. must be done when transport is changed (server restarted).
53  */
54  void reset();
55 
56 private:
57  /**
58  * Registers introspection interface and get it's ID. Always OUTGOING.
59  * If it is already registered only preassigned ID is returned.
60  *
61  * TODO !!!!!!this can get very slow in large maps. We need to change this !!!!!!
62  *
63  * @param field introspection interface to register
64  *
65  * @return id of given introspection interface
66  */
67  epics::pvData::int16 registerIntrospectionInterface(epics::pvData::FieldConstPtr const & field, bool& existing);
68 public:
69  /**
70  * Serializes introspection interface
71  *
72  * @param field
73  * @param buffer
74  * @param control
75  */
76  void serialize(epics::pvData::FieldConstPtr const & field, epics::pvData::ByteBuffer* buffer, epics::pvData::SerializableControl* control);
77 
78  /**
79  * Deserializes introspection interface
80  *
81  * TODO
82  *
83  * @param buffer
84  * @param control
85  *
86  * @return <code>Field</code> deserialized from the buffer.
87  */
88  epics::pvData::FieldConstPtr deserialize(epics::pvData::ByteBuffer* buffer, epics::pvData::DeserializableControl* control);
89 
90  /**
91  * Null type.
92  */
93  const static epics::pvData::int8 NULL_TYPE_CODE;
94 
95  /**
96  * Serialization contains only an ID (that was assigned by one of the previous <code>FULL_WITH_ID</code> descriptions).
97  */
98  const static epics::pvData::int8 ONLY_ID_TYPE_CODE;
99 
100  /**
101  * Serialization contains an ID (that can be used later, if cached) and full interface description.
102  */
103  const static epics::pvData::int8 FULL_WITH_ID_TYPE_CODE;
104 
105 private:
106  registryMap_t _registry;
107  epics::pvData::int16 _pointer;
108 
109  /**
110  * Field factory.
111  */
112  static epics::pvData::FieldCreatePtr _fieldCreate;
113 
114  bool registryContainsValue(epics::pvData::FieldConstPtr const & field, epics::pvData::int16& key);
115 };
116 
117 }
118 }
119 
120 #endif /* INTROSPECTIONREGISTRY_H */