summaryrefslogtreecommitdiff
path: root/objects/objident_controller.cc
blob: deaf2fd15bf30164b042859a5e5f60406f26c30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
 * RTFL
 *
 * Copyright 2015 Sebastian Geerken <sgeerken@dillo.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version; with the following exception:
 *
 * The copyright holders of RTFL give you permission to link this file
 * statically or dynamically against all versions of the graphviz
 * library, which are published by AT&T Corp. under one of the following
 * licenses:
 *
 * - Common Public License version 1.0 as published by International
 *   Business Machines Corporation (IBM), or
 * - Eclipse Public License version 1.0 as published by the Eclipse
 *   Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include "objident_controller.hh"

using namespace lout::object;
using namespace lout::misc;
using namespace lout::container::untyped;
using namespace rtfl::tools;

#define TIMEOUT_SECS 1

namespace rtfl {

namespace objects {

ObjIdentController::PostController::PostController (ObjectsController
                                                    *successor)
{
   this->successor = successor;
   successor->setObjectsSource (this);
   setObjectsSink (successor);

   // The "canonocal" identity is stored both as key and as value. For
   // this reason, the second argument could be "false". Check whether
   // this is possible (order of delete etc.).
   identities = new EquivalenceRelation (true, true);
}

ObjIdentController::PostController::~PostController ()
{
   delete identities;
}

void ObjIdentController::PostController::objMsg (CommonLineInfo *info,
                                                 const char *id,
                                                 const char *aspect, int prio,
                                                 const char *message)
{
   successor->objMsg (info, mapId (id), aspect, prio, message);
}

void ObjIdentController::PostController::objMark (CommonLineInfo *info,
                                                  const char *id,
                                                  const char *aspect, int prio,
                                                  const char *message)
{
   successor->objMark (info, mapId (id), aspect, prio, message);
}

void ObjIdentController::PostController::objMsgStart (CommonLineInfo *info,
                                                      const char *id)
{
   successor->objMsgStart (info, mapId (id));
}

void ObjIdentController::PostController::objMsgEnd (CommonLineInfo *info,
                                                    const char *id)
{
   successor->objMsgEnd (info, mapId (id));
}

void ObjIdentController::PostController::objEnter (CommonLineInfo *info,
                                                   const char *id,
                                                   const char *aspect, int prio,
                                                   const char *funname,
                                                   const char *args)
{
   successor->objEnter (info, mapId (id), aspect, prio, funname, args);
}

void ObjIdentController::PostController::objLeave (CommonLineInfo *info,
                                                   const char *id,
                                                   const char *vals)
{
   successor->objLeave (info, mapId (id), vals);
}

void ObjIdentController::PostController::objCreate (CommonLineInfo *info,
                                                    const char *id,
                                                    const char *klass)
{
   successor->objCreate (info, mapId (id), klass);
}

void ObjIdentController::PostController::objIdent (CommonLineInfo *info,
                                                   const char *id1,
                                                   const char *id2)
{
   // "obj-ident" is not delegated.
}

void ObjIdentController::PostController::objNoIdent (CommonLineInfo *info)
{
   // "obj-noident" is not delegated.
}

void ObjIdentController::PostController::objAssoc (CommonLineInfo *info,
                                                   const char *parent,
                                                   const char *child)
{
   successor->objAssoc (info, mapId (parent), mapId (child));
}

void ObjIdentController::PostController::objSet (CommonLineInfo *info,
                                                 const char *id,
                                                 const char *var,
                                                 const char *val)
{
   successor->objSet (info, mapId (id), var, val);
}

void ObjIdentController::PostController::objClassColor (CommonLineInfo *info,
                                                        const char *klass,
                                                        const char *color)
{
   successor->objClassColor (info, klass, color);
}

void ObjIdentController::PostController::objObjectColor (CommonLineInfo *info,
                                                         const char *id,
                                                         const char *color)
{
   successor->objObjectColor (info, mapId (id), color);
}

void ObjIdentController::PostController::objDelete (CommonLineInfo *info,
                                                    const char *id)
{
   successor->objDelete (info, mapId (id));

   // TODO Remove from identities.
}

void ObjIdentController::PostController::addIdentity (const char *id1,
                                                      const char *id2)
{
   String key1 (id1), key2 (id2);
   
   if (!identities->contains (&key1))
      identities->put (new String (id1), new String (id1));
   
   if (!identities->contains (&key2))
      identities->put (new String (id2), new String (id2));

   identities->relate (&key1, &key2);
}

const char *ObjIdentController::PostController::mapId (const char *id)
{
   String key (id);
   if (!identities->contains (&key))
       identities->put (new String (id), new String (id));

   return ((String*)identities->get(&key))->chars ();
}

// ----------------------------------------------------------------------

ObjIdentController::ObjIdentController (ObjectsController *successor)
{
   noIdent = false;
   stackDepth = 0;
   createPending = false;

   postController = new PostController (successor);
   buffer = new ObjectsBuffer (postController);
   buffer->setObjectsSource (this);
   setObjectsSink (buffer);
}

ObjIdentController::~ObjIdentController ()
{
}

void ObjIdentController::objMsg (CommonLineInfo *info, const char *id,
                                 const char *aspect, int prio,
                                 const char *message)
{
   buffer->objMsg (info, id, aspect, prio, message);
}

void ObjIdentController::objMark (CommonLineInfo *info, const char *id,
                                  const char *aspect, int prio,
                                  const char *message)
{
   buffer->objMark (info, id, aspect, prio, message);
}

void ObjIdentController::objMsgStart (CommonLineInfo *info, const char *id)
{
   buffer->objMsgStart (info, id);
}

void ObjIdentController::objMsgEnd (CommonLineInfo *info, const char *id)
{
   buffer->objMsgEnd (info, id);
}

void ObjIdentController::objEnter (CommonLineInfo *info, const char *id,
                                   const char *aspect, int prio,
                                   const char *funname, const char *args)
{
   stackDepth++;

   buffer->objEnter (info, id, aspect, prio, funname, args);
}

void ObjIdentController::objLeave (CommonLineInfo *info, const char *id,
                                   const char *vals)
{
   stackDepth = max (stackDepth - 1, 0);

   if (createPending && stackDepth < minCreateStackDepth) {
      pass ();
      removeOwnTimeout (PASS);
   }

   buffer->objLeave (info, id, vals);
}

void ObjIdentController::objCreate (CommonLineInfo *info, const char *id,
                                    const char *klass)
{
   queue ();
   buffer->objCreate (info, id, klass);
}

void ObjIdentController::objIdent (CommonLineInfo *info, const char *id1,
                                   const char *id2)
{
   postController->addIdentity (id1, id2);

   // TODO: Possibly end queueing? Probably not.
   
   // "obj-ident" is not delegated.
}

void ObjIdentController::objNoIdent (CommonLineInfo *info)
{
   noIdent = true;
   pass ();

   // "obj-noident" is not delegated.
}

void ObjIdentController::objAssoc (CommonLineInfo *info, const char *parent,
                                   const char *child)
{
   buffer->objAssoc (info, parent, child);
}

void ObjIdentController::objSet (CommonLineInfo *info, const char *id,
                                 const char *var, const char *val)
{
   buffer->objSet (info, id, var, val);
}

void ObjIdentController::objClassColor (CommonLineInfo *info, const char *klass,
                                        const char *color)
{
   buffer->objClassColor (info, klass, color);
}

void ObjIdentController::objObjectColor (CommonLineInfo *info, const char *id,
                                         const char *color)
{
   buffer->objObjectColor (info, id, color);
}

void ObjIdentController::objDelete (CommonLineInfo *info, const char *id)
{
   buffer->objDelete (info, id);
}

void ObjIdentController::ownTimeout (int type)
{
   if (type == PASS)
      pass ();
}      

void ObjIdentController::ownFinish ()
{
   pass ();
}

void ObjIdentController::queue ()
{
   if (!noIdent) {
      if (createPending)
         minCreateStackDepth = min (minCreateStackDepth, stackDepth);
      else {
         buffer->queue ();
         createPending = true;
         minCreateStackDepth = stackDepth;
      }

      removeOwnTimeout (PASS);
      addOwnTimeout (TIMEOUT_SECS, PASS);
   }
}      

void ObjIdentController::pass ()
{
   buffer->pass ();
   createPending = false;
}      
  
} // namespace objects

} // namespace rtfl