blob: 771b8cd8b51302485530975140c39c03ce266a1b [file] [log] [blame]
Ernesto Posse8a4f2962015-05-12 13:28:46 -04001// umlrtframeprotocol.cc
2
3/*******************************************************************************
4* Copyright (c) 2014-2015 Zeligsoft (2009) Limited and others.
5* All rights reserved. This program and the accompanying materials
6* are made available under the terms of the Eclipse Public License v1.0
7* which accompanies this distribution, and is available at
8* http://www.eclipse.org/legal/epl-v10.html
9*******************************************************************************/
10
11#include "umlrtcapsule.hh"
12#include "umlrtcapsuleid.hh"
13#include "umlrtcapsulepart.hh"
14#include "umlrtcommsport.hh"
15#include "umlrtcontroller.hh"
16#include "umlrtframeprotocol.hh"
17#include "umlrtframeservice.hh"
18#include "basefatal.hh"
19
20// Return true if a subClass is a sub-class of baseClass.
21bool UMLRTFrameProtocol::OutSignals::classIsKindOf( const UMLRTCommsPort * srcPort, const UMLRTCapsuleClass & subClass, const UMLRTCapsuleClass & baseClass )
22{
23 bool isKindOf = false;
24 const UMLRTCapsuleClass * parentClass = &subClass;
25
26 while ((parentClass != NULL) && !isKindOf)
27 {
28 if (parentClass == &baseClass)
29 {
30 isKindOf = true;
31 }
32 parentClass = parentClass->super;
33 }
34 return isKindOf;
35}
36
37// Return the name of a capsule class.
38const char * UMLRTFrameProtocol::OutSignals::className( const UMLRTCommsPort * srcPort, const UMLRTCapsuleClass & capsuleClass )
39{
40 return capsuleClass.name;
41}
42
43// Return the capsule class of a capsule instance.
44const UMLRTCapsuleClass & UMLRTFrameProtocol::OutSignals::classOf( const UMLRTCommsPort * srcPort, const UMLRTCapsuleId id )
45{
46 return *id.getCapsule()->getClass();
47}
48
49
50bool UMLRTFrameProtocol::OutSignals::deport( const UMLRTCommsPort * srcPort, const UMLRTCapsuleId id, const UMLRTCapsulePart * part )
51{
52 bool ok = false;
53
54 // Initialize error code to E_NONE, in case anybody looks at it after success.
55 srcPort->slot->controller->setError(UMLRTController::E_OK);
56
57 if (!id.isValid())
58 {
59 srcPort->slot->controller->setError(UMLRTController::E_DEPORT_INVLD);
60 }
61 else if (!part->role()->plugin)
62 {
63 srcPort->slot->controller->setError(UMLRTController::E_DEPORT_NONPLUG);
64 }
65 else
66 {
67 UMLRTCapsule * capsule = id.getCapsule();
68
69 // Only specified the the capsule id within the part - we must find the slot being deported.
70 for (size_t i = 0; (i < part->role()->multiplicityUpper) && !ok; ++i)
71 {
72 if (part->slots[i]->capsule == capsule)
73 {
74 ok = true;
75 UMLRTFrameService::requestControllerDeport(part->slots[i], false/*lockAcquired*/);
76 }
77 }
78 if (!ok)
79 {
80 srcPort->slot->controller->setError(UMLRTController::E_DEPORT_NOINST);
81 }
82 }
83 return ok;
84}
85
86bool UMLRTFrameProtocol::OutSignals::destroy( const UMLRTCommsPort * srcPort, const UMLRTCapsuleId id )
87{
88 bool ok = false;
89 UMLRTCapsule * capsule = id.getCapsule();
90
91 // Initialize error code to E_NONE, in case anybody looks at it after success.
92 srcPort->slot->controller->setError(UMLRTController::E_OK);
93
94 if (capsule == NULL)
95 {
96 srcPort->slot->controller->setError(UMLRTController::E_DESTR_INVALID);
97 }
98 else if (capsule->getSlot()->role() == NULL)
99 {
100 FATAL("Destroying capsule without a role. Destroying Top?");
101 }
102 else if (capsule->getSlot()->role()->optional)
103 {
104 srcPort->slot->controller->setError(UMLRTController::E_DESTR_NONOPT);
105 }
106 else
107 {
108 // Either we destroy the capsule in this context or we send a DESTROY Controller Command to execute the destroy.
109 UMLRTFrameService::requestControllerDestroy(capsule->getSlot(), true/*isTopSlot*/, false/*lockAcquired*/);
110 ok = true;
111 }
112 return ok;
113}
114
115bool UMLRTFrameProtocol::OutSignals::destroy( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part )
116{
117 bool ok = false;
118
119 // Initialize error code to E_NONE, in case anybody looks at it after success.
120 srcPort->slot->controller->setError(UMLRTController::E_OK);
121
122 if (part->role() == NULL)
123 {
124 FATAL("Destroying part without a role. Destroying Top?");
125 }
126 if (!part->role()->optional)
127 {
128 srcPort->slot->controller->setError(UMLRTController::E_DESTR_NONOPT);
129 }
130 else
131 {
132 ok = true; // Assume ok from this point.
133
134 for (size_t i = part->role()->multiplicityLower; i < part->numSlot; ++i)
135 {
136 if (part->slots[i]->capsule != NULL)
137 {
138 // Either we destroy the capsule in this context or we send a DESTROY Controller Command to execute the destroy.
139 // This is a destroy of multiple slots and each is the 'top slot' of its associated sub-structure.
140 UMLRTFrameService::requestControllerDestroy(part->slots[i], true/*isTopSlot*/, false/*lockAcquired*/);
141 ok = true;
142 }
143 }
144 }
145 return ok;
146}
147
148bool UMLRTFrameProtocol::OutSignals::import( const UMLRTCommsPort * srcPort, const UMLRTCapsuleId id, const UMLRTCapsulePart * destPart, int index )
149{
150 bool ok = false;
151
152 if (!id.isValid())
153 {
154 srcPort->slot->controller->setError(UMLRTController::E_IMPORT_NOINST);
155 }
156 else
157 {
158 ok = UMLRTFrameService::importCapsule(srcPort, id.getCapsule(), destPart, index);
159 }
160 return ok;
161}
162
163bool UMLRTFrameProtocol::OutSignals::import( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * srcPart, const UMLRTCapsulePart * dest, int index )
164{
165 bool ok = false;
166
167 if ((srcPart->numSlot > 1) && index == -1)
168 {
169 srcPort->slot->controller->setError(UMLRTController::E_IMPORT_PARTREPL);
170 }
171 else if (srcPart->slots[0]->capsule == NULL)
172 {
173 srcPort->slot->controller->setError(UMLRTController::E_IMPORT_NOINST);
174 }
175 else
176 {
177 ok = UMLRTFrameService::importCapsule(srcPort, srcPart->slots[0]->capsule, dest, index);
178 }
179 return ok;
180}
181
182const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const char * logThread, int index ) const
183{
184 return UMLRTFrameService::incarnateCapsule(
185 srcPort,
186 part, // part
187 NULL, // capsuleClass
188 NULL, // userData
189 NULL, // type
190 logThread,
191 NULL, // controller
192 index
193 );
194}
195
196const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, UMLRTController * controller, int index ) const
197{
198 return UMLRTFrameService::incarnateCapsule(
199 srcPort,
200 part,
201 NULL, // capsuleClass
202 NULL, // userData
203 NULL, // type
204 NULL, // logThread
205 controller,
206 index
207 );
208}
209
210const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, const char * logThread, int index ) const
211{
212 return UMLRTFrameService::incarnateCapsule(
213 srcPort,
214 part,
215 &capsuleClass,
216 NULL, // userData
217 NULL, // type
218 logThread,
219 NULL, // controller
220 index
221 );
222}
223
224const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, UMLRTController * controller, int index ) const
225{
226 return UMLRTFrameService::incarnateCapsule(
227 srcPort,
228 part,
229 &capsuleClass,
230 NULL, // userData
231 NULL, // type
232 NULL, // logThread
233 controller,
234 index
235 );
236}
237
238const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const void * userData, const UMLRTObject_class * type, const char * logThread, int index ) const
239{
240 return UMLRTFrameService::incarnateCapsule(
241 srcPort,
242 part,
243 NULL, // capsuleClass
244 userData,
245 type,
246 logThread,
247 NULL, // controller
248 index
249 );
250}
251
252const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const void * userData, const UMLRTObject_class * type, UMLRTController * controller, int index ) const
253{
254 return UMLRTFrameService::incarnateCapsule(
255 srcPort,
256 part,
257 NULL, // capsuleClass
258 userData,
259 type,
260 NULL, // logThread
261 controller,
262 index
263 );
264}
265
266const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, const void * userData, const UMLRTObject_class * type, const char * logThread, int index ) const
267{
268 return UMLRTFrameService::incarnateCapsule(
269 srcPort,
270 part,
271 &capsuleClass,
272 userData,
273 type,
274 logThread,
275 NULL, // controller
276 index
277 );
278}
279
280const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, const void * userData, const UMLRTObject_class * type, UMLRTController * controller, int index ) const
281{
282 return UMLRTFrameService::incarnateCapsule(
283 srcPort,
284 part,
285 &capsuleClass,
286 userData,
287 type,
288 NULL, // logThread
289 controller,
290 index
291 );
292}
293
294const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTTypedValue * value, const char * logThread, int index ) const
295{
296 return UMLRTFrameService::incarnateCapsule(
297 srcPort,
298 part,
299 NULL, // capsuleClass
300 value->data, // userData
301 value->type, // type
302 logThread,
303 NULL, // controller
304 index
305 );
306}
307
308const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTTypedValue * value, UMLRTController * controller, int index ) const
309{
310 return UMLRTFrameService::incarnateCapsule(
311 srcPort,
312 part,
313 NULL, // capsuleClass
314 value->data, // userData
315 value->type, // type
316 NULL, // logThread
317 controller,
318 index
319 );
320}
321
322const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, const UMLRTTypedValue * value, const char * logThread, int index ) const
323{
324 return UMLRTFrameService::incarnateCapsule(
325 srcPort,
326 part,
327 &capsuleClass,
328 value->data, // userData
329 value->type, // type
330 logThread,
331 NULL, // controller
332 index
333 );
334}
335
336const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnate( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, const UMLRTCapsuleClass & capsuleClass, const UMLRTTypedValue * value, UMLRTController * controller, int index ) const
337{
338 return UMLRTFrameService::incarnateCapsule(
339 srcPort,
340 part,
341 &capsuleClass,
342 value->data, // userData
343 value->type, // type
344 NULL, // logThread
345 controller,
346 index
347 );
348}
349
350const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::incarnateAt( const UMLRTCommsPort * srcPort, const UMLRTCapsulePart * part, int index )
351{
352 return UMLRTFrameService::incarnateCapsule(
353 srcPort,
354 part, // part
355 NULL, // capsuleClass
356 NULL, // userData
357 NULL, // type
358 NULL, // logThread
359 NULL, // controller
360 index
361 );
362}
363
364const UMLRTCapsuleId UMLRTFrameProtocol::OutSignals::me( const UMLRTCommsPort * srcPort )
365{
366 return UMLRTCapsuleId(srcPort->slot->capsule);
367}
368
369const UMLRTCapsuleClass & myClass( const UMLRTCommsPort * srcPort )
370{
371 return *srcPort->slot->capsule->getClass();
372}