OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
TTAMachine::Bridge Class Reference

#include <Bridge.hh>

Inheritance diagram for TTAMachine::Bridge:
Inheritance graph
Collaboration diagram for TTAMachine::Bridge:
Collaboration graph

Public Member Functions

 Bridge (const std::string &name, Bus &sourceBus, Bus &destinationBus)
 
 Bridge (const ObjectState *state, Machine &mach)
 
virtual ~Bridge ()
 
virtual void setName (const std::string &name)
 
BussourceBus () const
 
BusdestinationBus () const
 
BuspreviousBus () const
 
BusnextBus () const
 
virtual void setMachine (Machine &mach)
 
virtual void unsetMachine ()
 
virtual ObjectStatesaveState () const
 
virtual void loadState (const ObjectState *state)
 
- Public Member Functions inherited from TTAMachine::Component
virtual ~Component ()
 
virtual TCEString name () const
 
virtual Machinemachine () const
 
virtual void ensureRegistration (const Component &component) const
 
virtual bool isRegistered () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_BRIDGE = "bridge"
 ObjectState name for bridge.
 
static const std::string OSKEY_SOURCE_BUS = "source"
 ObjectState attribute key for source bus name.
 
static const std::string OSKEY_DESTINATION_BUS = "destination"
 ObjectState attribute key for destination bus name.
 
- Static Public Attributes inherited from TTAMachine::Component
static const std::string OSNAME_COMPONENT = "component"
 ObjectState name for component.
 
static const std::string OSKEY_NAME = "name"
 ObjectState attribute key for the name of the component.
 

Private Member Functions

void adjustChainDirection (const Bus &sourceBus, const Bus &destinationBus)
 
void setSourceAndDestination (Bus &sourceBus, Bus &destination)
 

Static Private Member Functions

static void setFirstOfChain (const Bus &bus)
 

Private Attributes

BussourceBus_
 Source bus.
 
BusdestinationBus_
 Destination bus.
 
bool sourcePrevious_
 Indicates which of the buses is previous and next.
 

Additional Inherited Members

- Protected Member Functions inherited from TTAMachine::Component
 Component (const std::string &name)
 
 Component (const ObjectState *state)
 
void internalSetMachine (Machine &machine)
 
void internalUnsetMachine ()
 
- Protected Member Functions inherited from TTAMachine::MachinePart
 MachinePart ()
 
virtual ~MachinePart ()
 

Detailed Description

Represents a bridge in the machine.

Definition at line 51 of file Bridge.hh.

Constructor & Destructor Documentation

◆ Bridge() [1/2]

TTAMachine::Bridge::Bridge ( const std::string &  name,
Bus sourceBus,
Bus destinationBus 
)

Constructor.

Parameters
nameName of the bridge.
sourceBusBus from which the bridge reads data.
destinationBusBus to which the bridge writes data.
Exceptions
IllegalRegistrationIf the given source and destination buses are not registered to the same machine.
ComponentAlreadyExistsIf there is another bridge by the same name in the machine which contains the source and destination buses.
IllegalConnectivityIf the bridge cannot be created because it would violate a connectivity constraint.
IllegalParametersIf the given buses are the same instance.
InvalidNameIf the given name is not a valid component name.

Definition at line 74 of file Bridge.cc.

75 : Component(name), sourceBus_(NULL), destinationBus_(NULL) {
76 const string procName = "Bridge::Bridge";
77
78 if (&sourceBus == &destinationBus) {
79 throw IllegalParameters(__FILE__, __LINE__, procName);
80 }
81
84 if (!tester.canBridge(sourceBus, destinationBus)) {
85 string errorMsg = MachineTestReporter::bridgingError(
86 sourceBus, destinationBus, tester);
87 throw IllegalConnectivity(__FILE__, __LINE__, procName, errorMsg);
88 }
89
92}
static std::string bridgingError(const TTAMachine::Bus &sourceBus, const TTAMachine::Bus &destinationBus, const MachineTester &tester)
virtual bool canBridge(const TTAMachine::Bus &source, const TTAMachine::Bus &destination)
Bus * destinationBus() const
Bus * sourceBus() const
Bus * sourceBus_
Source bus.
Definition Bridge.hh:84
void setSourceAndDestination(Bus &sourceBus, Bus &destination)
Definition Bridge.cc:379
Bus * destinationBus_
Destination bus.
Definition Bridge.hh:86
virtual void setMachine(Machine &mach)
Definition Bridge.cc:196
virtual Machine * machine() const
Component(const std::string &name)
virtual void ensureRegistration(const Component &component) const
virtual TCEString name() const
MachineTester & machineTester() const
Definition Machine.cc:671

References MachineTestReporter::bridgingError(), MachineTester::canBridge(), destinationBus(), TTAMachine::Component::ensureRegistration(), TTAMachine::Component::machine(), TTAMachine::Machine::machineTester(), setMachine(), setSourceAndDestination(), and sourceBus().

Here is the call graph for this function:

◆ Bridge() [2/2]

TTAMachine::Bridge::Bridge ( const ObjectState state,
Machine mach 
)

Constructor.

Creates a skeleton objects with name only. This constructor should be used by Machine::loadState only. Do not use this constructor.

Parameters
stateThe ObjectState instance.
machThe machine to which the bridge belongs.
Exceptions
ObjectStateLoadingExceptionIf the machine already has a bridge by the same name as the coming name of this bridge or if the ObjectState instance is invalid.

Definition at line 107 of file Bridge.cc.

108 : Component(state), sourceBus_(NULL), destinationBus_(NULL) {
109 Machine::BridgeNavigator bridgeNav = mach.bridgeNavigator();
110
111 if (!bridgeNav.hasItem(name())) {
112 setMachine(mach);
113 } else {
114 MOMTextGenerator textGenerator;
115 format errorMsg = textGenerator.text(MOMTextGenerator::
116 TXT_BRIDGE_EXISTS_BY_SAME_NAME);
117 errorMsg % name();
118 string procName = "Bridge::Bridge";
119 throw ObjectStateLoadingException(__FILE__, __LINE__, procName,
120 errorMsg.str());
121 }
122}
Navigator< Bridge > BridgeNavigator
Navigator type for BridgeNavigator.
Definition Machine.hh:221
virtual boost::format text(int textId)

References TTAMachine::Machine::bridgeNavigator(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), TTAMachine::Component::name(), setMachine(), and Texts::TextGenerator::text().

Here is the call graph for this function:

◆ ~Bridge()

TTAMachine::Bridge::~Bridge ( )
virtual

Destructor.

Definition at line 127 of file Bridge.cc.

127 {
128 unsetMachine();
129}
virtual void unsetMachine()
Definition Bridge.cc:207

References unsetMachine().

Here is the call graph for this function:

Member Function Documentation

◆ adjustChainDirection()

void TTAMachine::Bridge::adjustChainDirection ( const Bus sourceBus,
const Bus destinationBus 
)
private

Adjusts the direction of the bus chain (next/previous).

When two bus chains are joined by a new bridge the direction of the destination side chain may have to be changed to verify that the direction of the new longer chain does not change in the middle of the chain. That is, if the source bus of the new bridge is the last of its chain and the destination bus of the new bridge is also the last, the direction of the destination side chain has to be changed such that the destination bus will become the first bus of its chain.

Parameters
sourceBusThe new source side bus.
destinationBusThe new destination side bus.

Definition at line 327 of file Bridge.cc.

329 {
330
331 Machine* mach = sourceBus.machine();
332 Machine::BridgeNavigator bridgeNav = mach->bridgeNavigator();
333
334 // if another bridge joining the buses is found, see the direction
335 // from that bridge
336 for (int i = 0; i < bridgeNav.count(); i++) {
337 Bridge* bridge = bridgeNav.item(i);
338 if (bridge->sourceBus() == &destinationBus &&
339 bridge->destinationBus() == &sourceBus) {
340 if (bridge->previousBus() == &sourceBus) {
341 sourcePrevious_ = true;
342 } else {
343 sourcePrevious_ = false;
344 }
345 return;
346 }
347 }
348
349 // change the direction of the bus chain containing destinationBus if
350 // needed
351 if (!sourceBus.hasNextBus()) {
352 sourcePrevious_ = true;
354 } else {
355 sourcePrevious_ = false;
356 // find the bus that should be the first bus of destination side
357 // chain
358 const Bus* otherEnd = &destinationBus;
359 while (otherEnd->hasNextBus()) {
360 otherEnd = otherEnd->nextBus();
361 }
362 if (otherEnd != &destinationBus) {
363 setFirstOfChain(*otherEnd);
364 }
365 }
366}
Bridge(const std::string &name, Bus &sourceBus, Bus &destinationBus)
Definition Bridge.cc:74
static void setFirstOfChain(const Bus &bus)
Definition Bridge.cc:400
bool sourcePrevious_
Indicates which of the buses is previous and next.
Definition Bridge.hh:88
virtual bool hasNextBus() const
Definition Bus.cc:488
virtual Bus * nextBus() const
Definition Bus.cc:501
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404

References TTAMachine::Machine::bridgeNavigator(), TTAMachine::Machine::Navigator< ComponentType >::count(), destinationBus(), TTAMachine::Bus::hasNextBus(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), TTAMachine::Bus::nextBus(), previousBus(), setFirstOfChain(), sourceBus(), and sourcePrevious_.

Referenced by setSourceAndDestination().

Here is the call graph for this function:

◆ destinationBus()

Bus * TTAMachine::Bridge::destinationBus ( ) const

◆ loadState()

void TTAMachine::Bridge::loadState ( const ObjectState state)
virtual

Loads its state from the given ObjectState instance.

If the bridge is already joining two buses, the function will not work and ObjectStateLoadingException is thrown. This method works only if the bridge was created by the constructor with ObjectState argument.

Parameters
stateThe ObjectState instance.
Exceptions
ObjectStateLoadingExceptionIf the machine already a bridge by the same name as the coming name of this bridge or if creating references fails or if the given ObjectState instance is invalid.

Reimplemented from TTAMachine::Component.

Definition at line 264 of file Bridge.cc.

264 {
265 const string procName = "Bridge::loadState";
266
267 if (state->name() != OSNAME_BRIDGE) {
268 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
269 }
270 if (sourceBus() != NULL || destinationBus() != NULL) {
271 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
272 }
273
275
276 try {
277 string sourceBusName = state->stringAttribute(OSKEY_SOURCE_BUS);
278 string destinationBusName =
280
283 Bus* source;
284 Bus* destination;
285 try {
286 source = busNav.item(sourceBusName);
287 destination = busNav.item(destinationBusName);
288 } catch (InstanceNotFound& e) {
289 MOMTextGenerator textGenerator;
290 format errorMsg = textGenerator.text(
292 errorMsg % name();
293 throw ObjectStateLoadingException(__FILE__, __LINE__, procName,
294 errorMsg.str());
295 }
296 MachineTester& tester = machine()->machineTester();
297 if (tester.canBridge(*source, *destination)) {
298 setSourceAndDestination(*source, *destination);
299 } else {
300 string errorMsg = MachineTestReporter::bridgingError(
301 *source, *destination, tester);
302 throw ObjectStateLoadingException(__FILE__, __LINE__, procName,
303 errorMsg);
304 }
305
306 } catch(Exception& e) {
307 throw ObjectStateLoadingException(__FILE__, __LINE__, procName,
308 e.errorMessage());
309 }
310}
#define assert(condition)
std::string errorMessage() const
Definition Exception.cc:123
std::string stringAttribute(const std::string &name) const
std::string name() const
static const std::string OSNAME_BRIDGE
ObjectState name for bridge.
Definition Bridge.hh:70
static const std::string OSKEY_DESTINATION_BUS
ObjectState attribute key for destination bus name.
Definition Bridge.hh:74
static const std::string OSKEY_SOURCE_BUS
ObjectState attribute key for source bus name.
Definition Bridge.hh:72
virtual void loadState(const ObjectState *state)
virtual bool isRegistered() const
ComponentType * item(int index) const
Navigator< Bus > BusNavigator
Navigator type for BusNavigator.
Definition Machine.hh:213
virtual BusNavigator busNavigator() const
Definition Machine.cc:356

References assert, MachineTestReporter::bridgingError(), TTAMachine::Machine::busNavigator(), MachineTester::canBridge(), destinationBus(), Exception::errorMessage(), TTAMachine::Component::isRegistered(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::loadState(), TTAMachine::Component::machine(), TTAMachine::Machine::machineTester(), TTAMachine::Component::name(), ObjectState::name(), OSKEY_DESTINATION_BUS, OSKEY_SOURCE_BUS, OSNAME_BRIDGE, setSourceAndDestination(), sourceBus(), ObjectState::stringAttribute(), Texts::TextGenerator::text(), and MOMTextGenerator::TXT_BRIDGE_UNKNOWN_SRC_OR_DST.

Referenced by TTAMachine::Machine::loadState().

Here is the call graph for this function:

◆ nextBus()

Bus * TTAMachine::Bridge::nextBus ( ) const

Returns the next bus from location point of view.

Returns
The next bus.

Definition at line 179 of file Bridge.cc.

179 {
180 if (sourcePrevious_) {
181 return destinationBus_;
182 } else {
183 return sourceBus_;
184 }
185}

References destinationBus_, sourceBus_, and sourcePrevious_.

Referenced by TTAMachine::Bus::nextBus(), TTAMachine::Bus::previousBridge(), and setFirstOfChain().

◆ previousBus()

Bus * TTAMachine::Bridge::previousBus ( ) const

Returns the previous bus from location point of view.

Returns
The previous bus.

Definition at line 164 of file Bridge.cc.

164 {
165 if (sourcePrevious_) {
166 return sourceBus_;
167 } else {
168 return destinationBus_;
169 }
170}

References destinationBus_, sourceBus_, and sourcePrevious_.

Referenced by adjustChainDirection(), TTAMachine::Bus::nextBridge(), and TTAMachine::Bus::previousBus().

◆ saveState()

ObjectState * TTAMachine::Bridge::saveState ( ) const
virtual

Saves the contents to an ObjectState object.

Returns
The newly created ObjectState object.

Reimplemented from TTAMachine::Component.

Definition at line 238 of file Bridge.cc.

238 {
240 bridge->setName(OSNAME_BRIDGE);
241 string sourceBusName = sourceBus_->name();
242 string destinationBusName = destinationBus_->name();
243 bridge->setAttribute(OSKEY_SOURCE_BUS, sourceBusName);
244 bridge->setAttribute(OSKEY_DESTINATION_BUS, destinationBusName);
245 return bridge;
246}
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
virtual ObjectState * saveState() const

References destinationBus_, TTAMachine::Component::name(), OSKEY_DESTINATION_BUS, OSKEY_SOURCE_BUS, OSNAME_BRIDGE, TTAMachine::Component::saveState(), ObjectState::setAttribute(), ObjectState::setName(), and sourceBus_.

Here is the call graph for this function:

◆ setFirstOfChain()

void TTAMachine::Bridge::setFirstOfChain ( const Bus bus)
staticprivate

Sets the given bus to the first bus of the bus chain.

That is, changes the direction of the chain if the given bus is currently the last bus of the chain. The given bus must be at the end of chain.

Parameters
busThe bus to be set to the first bus of the chain.

Definition at line 400 of file Bridge.cc.

400 {
401
402 assert(!(bus.hasPreviousBus() && bus.hasNextBus()));
403
404 if (bus.hasNextBus()) {
405 // if the bus is already the first
406 return;
407 } else {
408 const Bus* observable = &bus;
409
410 // collect the buses of the chain to set
411 set<const Bus*> busesInChain;
412 busesInChain.insert(observable);
413 while (observable->hasPreviousBus()) {
414 observable = observable->previousBus();
415 busesInChain.insert(observable);
416 }
417
418 Machine::BridgeNavigator bridgeNav =
419 bus.machine()->bridgeNavigator();
420 // change (next/previous) direction of each bridge that is joining
421 // a bus in the set
422 for (int i = 0; i < bridgeNav.count(); i++) {
423 Bridge* bridge = bridgeNav.item(i);
424 // Source bus or destination bus is NULL only if the bridge
425 // was created from ObjectState. Then calling nextBus() is
426 // illegal because sourcePrevious_ member is not initialized.
427 if (bridge->sourceBus() != NULL &&
428 bridge->destinationBus() != NULL &&
429 AssocTools::containsKey(busesInChain, bridge->nextBus())) {
430 bridge->sourcePrevious_ = !bridge->sourcePrevious_;
431 }
432 }
433 }
434}
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)

References assert, TTAMachine::Machine::bridgeNavigator(), AssocTools::containsKey(), TTAMachine::Machine::Navigator< ComponentType >::count(), destinationBus(), TTAMachine::Bus::hasNextBus(), TTAMachine::Bus::hasPreviousBus(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), nextBus(), TTAMachine::Bus::previousBus(), sourceBus(), and sourcePrevious_.

Referenced by adjustChainDirection().

Here is the call graph for this function:

◆ setMachine()

void TTAMachine::Bridge::setMachine ( Machine mach)
virtual

Registers the bridge to a machine.

Parameters
machMachine to which the bridge is going to be registered.
Exceptions
ComponentAlreadyExistsIf the given machine already has another bridge by the same name.

Implements TTAMachine::Component.

Definition at line 196 of file Bridge.cc.

196 {
197 mach.addBridge(*this);
198 internalSetMachine(mach);
199}
void internalSetMachine(Machine &machine)

References TTAMachine::Machine::addBridge(), and TTAMachine::Component::internalSetMachine().

Referenced by Bridge(), and Bridge().

Here is the call graph for this function:

◆ setName()

void TTAMachine::Bridge::setName ( const std::string &  name)
virtual

Sets the name of the bridge.

Parameters
nameName of the bridge.
Exceptions
ComponentAlreadyExistsIf a bridge with the given name is already in the same machine.
InvalidNameIf the given name is not a valid component name.

Reimplemented from TTAMachine::Component.

Definition at line 141 of file Bridge.cc.

141 {
142 if (name == this->name()) {
143 return;
144 }
145
146 if (machine() != NULL) {
147 if (machine()->bridgeNavigator().hasItem(name)) {
148 string procName = "Bridge::setName";
149 throw ComponentAlreadyExists(__FILE__, __LINE__, procName);
150 } else {
152 }
153 } else {
155 }
156}
virtual void setName(const std::string &name)

References TTAMachine::Component::machine(), TTAMachine::Component::name(), and TTAMachine::Component::setName().

Here is the call graph for this function:

◆ setSourceAndDestination()

void TTAMachine::Bridge::setSourceAndDestination ( Bus sourceBus,
Bus destinationBus 
)
private

Sets the source and destination buses of the bridge.

The bridge must not have source and destination buses before calling this method.

Parameters
sourceBusThe source bus.
destinationBusThe destination bus.

Definition at line 379 of file Bridge.cc.

379 {
380 assert(sourceBus_ == NULL && destinationBus_ == NULL);
388}
void adjustChainDirection(const Bus &sourceBus, const Bus &destinationBus)
Definition Bridge.cc:327
virtual bool canWrite(const Bus &bus) const
Definition Bus.cc:558
virtual void setDestinationBridge(Bridge &bridge)
Definition Bus.cc:613
virtual void setSourceBridge(Bridge &bridge)
Definition Bus.cc:594
virtual bool canRead(const Bus &bus) const
Definition Bus.cc:537

References adjustChainDirection(), assert, TTAMachine::Bus::canRead(), TTAMachine::Bus::canWrite(), destinationBus(), destinationBus_, TTAMachine::Bus::setDestinationBridge(), TTAMachine::Bus::setSourceBridge(), sourceBus(), and sourceBus_.

Referenced by Bridge(), and loadState().

Here is the call graph for this function:

◆ sourceBus()

Bus * TTAMachine::Bridge::sourceBus ( ) const

◆ unsetMachine()

void TTAMachine::Bridge::unsetMachine ( )
virtual

Removes registration of the bridge from its current machine.

The bridge is deleted because it cannot be unregistered from the machine.

Implements TTAMachine::Component.

Definition at line 207 of file Bridge.cc.

207 {
208
209 assert(machine() != NULL);
210
211 Bus* oldSource = sourceBus_;
212 Bus* oldDestination = destinationBus_;
213 sourceBus_ = NULL;
214 destinationBus_ = NULL;
215
216 if (oldSource != NULL) {
217 // may be NULL if loading the state from ObjectState has failed
218 oldSource->clearDestinationBridge(*this);
219 }
220
221 if (oldDestination != NULL) {
222 // may be NULL if loading the state from ObjectState has failed
223 oldDestination->clearSourceBridge(*this);
224 }
225
226 Machine* mach = machine();
228 mach->deleteBridge(*this);
229}
virtual void clearDestinationBridge(Bridge &bridge)
Definition Bus.cc:652

References assert, TTAMachine::Bus::clearDestinationBridge(), TTAMachine::Bus::clearSourceBridge(), TTAMachine::Machine::deleteBridge(), destinationBus_, TTAMachine::Component::internalUnsetMachine(), TTAMachine::Component::machine(), and sourceBus_.

Referenced by ~Bridge().

Here is the call graph for this function:

Member Data Documentation

◆ destinationBus_

Bus* TTAMachine::Bridge::destinationBus_
private

Destination bus.

Definition at line 86 of file Bridge.hh.

Referenced by nextBus(), previousBus(), saveState(), setSourceAndDestination(), and unsetMachine().

◆ OSKEY_DESTINATION_BUS

const string TTAMachine::Bridge::OSKEY_DESTINATION_BUS = "destination"
static

ObjectState attribute key for destination bus name.

Definition at line 74 of file Bridge.hh.

Referenced by ADFSerializer::bridgeToMachine(), ADFSerializer::bridgeToMDF(), loadState(), and saveState().

◆ OSKEY_SOURCE_BUS

const string TTAMachine::Bridge::OSKEY_SOURCE_BUS = "source"
static

ObjectState attribute key for source bus name.

Definition at line 72 of file Bridge.hh.

Referenced by ADFSerializer::bridgeToMachine(), ADFSerializer::bridgeToMDF(), loadState(), and saveState().

◆ OSNAME_BRIDGE

const string TTAMachine::Bridge::OSNAME_BRIDGE = "bridge"
static

◆ sourceBus_

Bus* TTAMachine::Bridge::sourceBus_
private

Source bus.

Definition at line 84 of file Bridge.hh.

Referenced by nextBus(), previousBus(), saveState(), setSourceAndDestination(), and unsetMachine().

◆ sourcePrevious_

bool TTAMachine::Bridge::sourcePrevious_
private

Indicates which of the buses is previous and next.

Definition at line 88 of file Bridge.hh.

Referenced by adjustChainDirection(), nextBus(), previousBus(), and setFirstOfChain().


The documentation for this class was generated from the following files: