Branch data Line data Source code
1 : : // $Id: SerialInfo.h 6752 2009-06-14 04:24:52Z vern $
2 : : //
3 : : // Helper classes to pass data between serialization methods.
4 : :
5 : : #ifndef serialinfo_h
6 : : #define serialinfo_h
7 : :
8 : 3 : class SerialInfo {
9 : : public:
10 : 3 : SerialInfo(Serializer* arg_s)
11 : 3 : {
12 : 3 : chunk = 0;
13 : 3 : s = arg_s;
14 : 3 : may_suspend = clear_containers = false;
15 : 3 : cache = globals_as_names = true;
16 : 3 : type = SER_NONE;
17 : 3 : pid_32bit = false;
18 : 3 : include_locations = true;
19 : 3 : new_cache_strategy = false;
20 : 3 : }
21 : :
22 : 0 : SerialInfo(const SerialInfo& info)
23 : 0 : {
24 : 0 : s = info.s;
25 : 0 : may_suspend = info.may_suspend;
26 : 0 : cache = info.cache;
27 : 0 : type = info.type;
28 : 0 : clear_containers = info.clear_containers;
29 : 0 : globals_as_names = info.globals_as_names;
30 : 0 : pid_32bit = info.pid_32bit;
31 : 0 : include_locations = info.include_locations;
32 : 0 : new_cache_strategy = info.new_cache_strategy;
33 : 0 : }
34 : :
35 : : // Parameters that control serialization.
36 : : Serializer* s; // serializer to use
37 : : bool cache; // true if object caching is ok
38 : : bool may_suspend; // if true, suspending serialization is ok
39 : : bool clear_containers; // if true, store container values as empty
40 : : bool include_locations; // if true, include locations in serialization
41 : :
42 : : // If true, for NameExpr's serialize just the names of globals, just
43 : : // their value.
44 : : bool globals_as_names;
45 : :
46 : : bool pid_32bit; // if true, use old-style 32-bit permanent IDs
47 : :
48 : : // If true, we support keeping objs in cache permanently.
49 : : bool new_cache_strategy;
50 : :
51 : : ChunkedIO::Chunk* chunk; // chunk written right before the serialization
52 : :
53 : : // Attributes set during serialization.
54 : : SerialType type; // type of currently serialized object
55 : :
56 : : // State for suspending/resuming serialization
57 : : Continuation cont;
58 : : };
59 : :
60 : : class UnserialInfo {
61 : : public:
62 : 2 : UnserialInfo(Serializer* arg_s)
63 : : {
64 : 2 : s = arg_s;
65 : 2 : cache = true;
66 : 2 : type = SER_NONE;
67 : 2 : chunk = 0;
68 : 2 : install_globals = install_conns = true;
69 : 2 : install_uniques = false;
70 : 2 : ignore_callbacks = false;
71 : 2 : id_policy = Replace;
72 : 2 : print = 0;
73 : 2 : pid_32bit = false;
74 : 2 : new_cache_strategy = false;
75 : 2 : }
76 : :
77 : : UnserialInfo(const UnserialInfo& info)
78 : : {
79 : : s = info.s;
80 : : cache = info.cache;
81 : : type = info.type;
82 : : chunk = info.chunk;
83 : : install_globals = info.install_globals;
84 : : install_uniques = info.install_uniques;
85 : : install_conns = info.install_conns;
86 : : ignore_callbacks = info.ignore_callbacks;
87 : : id_policy = info.id_policy;
88 : : print = info.print;
89 : : pid_32bit = info.pid_32bit;
90 : : new_cache_strategy = info.new_cache_strategy;
91 : : }
92 : :
93 : : // Parameters that control unserialization.
94 : : Serializer* s; // serializer to use
95 : : bool cache; // if true, object caching is ok
96 : : FILE* print; // print read objects to given file (human-readable)
97 : :
98 : : ChunkedIO::Chunk* chunk; // chunk to parse (rather than reading one)
99 : :
100 : : bool install_globals; // if true, install unknown globals
101 : : // in global scope
102 : : bool install_conns; // if true, add connections to session table
103 : : bool install_uniques; // if true, install unknown globally
104 : : // unique IDs in global scope
105 : : bool ignore_callbacks; // if true, don't call Got*() callbacks
106 : : bool pid_32bit; // if true, use old-style 32-bit permanent IDs.
107 : :
108 : : // If true, we support keeping objs in cache permanently.
109 : : bool new_cache_strategy;
110 : :
111 : : // If a global ID already exits, of these policies is used.
112 : : enum {
113 : : Keep, // keep the old ID and ignore the new
114 : : Replace, // install the new ID (default)
115 : :
116 : : // Keep current ID instance but copy the new value into it
117 : : // (types have to match).
118 : : CopyNewToCurrent,
119 : :
120 : : // Install the new ID instance but replace its value
121 : : // with that of the old one (types have to match).
122 : : CopyCurrentToNew,
123 : :
124 : : // Instantiate a new ID, but do not insert it into the global
125 : : // space.
126 : : InstantiateNew,
127 : : } id_policy;
128 : :
129 : : // Attributes set during unserialization.
130 : : SerialType type; // type of currently unserialized object
131 : : };
132 : :
133 : : // Helper class to temporarily disable suspending for all next-level calls
134 : : // using the given SerialInfo. It saves the current value of info.may_suspend
135 : : // and then sets it to false. When it goes out of scope, the original value
136 : : // is restored.
137 : : //
138 : : // We need this because not all classes derived from SerialObj are
139 : : // suspension-aware yet, i.e., they don't work correctly if one of the
140 : : // next-level functions suspends. Eventually this may change, but actually
141 : : // it's not very important: most classes don't need to suspend anyway as
142 : : // their data volume is very small. We have to make sure though that those
143 : : // which do (e.g. TableVals) support suspension.
144 : : class DisableSuspend {
145 : : public:
146 : 121 : DisableSuspend(SerialInfo* arg_info)
147 : : {
148 : 121 : info = arg_info;
149 : 121 : old_may_suspend = info->may_suspend;
150 : 121 : info->may_suspend = false;
151 : 121 : }
152 : :
153 : 121 : ~DisableSuspend() { Restore(); }
154 : :
155 : 0 : void Release() { info = 0; }
156 : :
157 : : // Restores the suspension-state to its original value.
158 : 121 : void Restore()
159 : : {
160 [ + - ]: 121 : if ( info )
161 : 121 : info->may_suspend = old_may_suspend;
162 : 121 : }
163 : :
164 : : private:
165 : : SerialInfo* info;
166 : : bool old_may_suspend;
167 : : };
168 : :
169 : : #endif
|