OpenASIP  2.0
ResourceMapper.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ResourceMapper.cc
26  *
27  * Implementation of ResourceMapper class.
28  *
29  * @author Ari Mets�halme 2006 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "Application.hh"
34 #include "ResourceMapper.hh"
35 #include "ResourceBroker.hh"
36 #include "ContainerTools.hh"
37 #include "MachinePart.hh"
38 
39 using std::string;
40 
41 /**
42  * Constructor.
43  */
45 }
46 
47 /**
48  * Destructor.
49  */
51 }
52 
53 /**
54  * Register broker as one of the elements that contribute to mapping a
55  * subset of machine parts to resources.
56  *
57  * @param broker Broker to register.
58  */
59 void
62  string msg = "Broker already exists in resource map!";
63  throw ObjectAlreadyExists(__FILE__, __LINE__, __func__, msg);
64  } else {
65  brokers_.push_back(&broker);
66  }
67 }
68 
69 /**
70  * Return the number of resources that correspond to the given machine part.
71  *
72  * @param mp Machine part.
73  * @return The number of resources that correspond to the given machine part.
74  */
75 int
77  int count = 0;
78  for (unsigned int i = 0; i < brokers_.size(); i++) {
79  if (brokers_[i]->hasResourceOf(mp)) {
80  count++;
81  }
82  }
83  return count;
84 }
85 
86 /**
87  * Find the resource object that corresponds to given machine part with
88  * index (default 0).
89  *
90  * @param mp Machine part to find Scheduling Resource for
91  * @param index Index of machine part, in case there are several
92  * @return The resource object that corresponds to given machine part and
93  * index.
94  */
97  const unsigned int brokerSize = brokers_.size();
98  for (unsigned int i = 0; i < brokerSize; i++) {
99  SchedulingResource* res = brokers_[i]->resourceOf(mp);
100  if (res != NULL) {
101  if (index == 0) {
102  return *res;
103  } else {
104  index--;
105  continue;
106  }
107  }
108  }
109  std::string errMsg = "None of the brokers has resource for part ";
110  const TTAMachine::Component * comp =
111  dynamic_cast<const TTAMachine::Component*>(&mp);
112  const TTAMachine::SubComponent * subcomp =
113  dynamic_cast<const TTAMachine::SubComponent*>(&mp);
114 
115  if (comp != NULL) {
116  errMsg += ": " + comp->name();
117  }
118  if (subcomp != NULL) {
119  errMsg += ", some subcomponent";
120  }
121 
122  throw KeyNotFound(__FILE__, __LINE__, __func__, errMsg);
123 }
TTAMachine::SubComponent
Definition: MachinePart.hh:168
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ResourceMapper.hh
ResourceBroker
Definition: ResourceBroker.hh:61
ResourceMapper::resourceOf
SchedulingResource & resourceOf(const TTAMachine::MachinePart &mp, int index=0) const
Definition: ResourceMapper.cc:96
MachinePart.hh
SchedulingResource
Definition: SchedulingResource.hh:52
Application.hh
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::Component
Definition: MachinePart.hh:90
TTAMachine::MachinePart
Definition: MachinePart.hh:57
ResourceBroker.hh
ResourceMapper::resourceCount
int resourceCount(const TTAMachine::MachinePart &mp) const
Definition: ResourceMapper.cc:76
ObjectAlreadyExists
Definition: Exception.hh:1002
ResourceMapper::~ResourceMapper
virtual ~ResourceMapper()
Definition: ResourceMapper.cc:50
ResourceMapper::ResourceMapper
ResourceMapper()
Definition: ResourceMapper.cc:44
ContainerTools::containsValue
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
KeyNotFound
Definition: Exception.hh:285
ResourceMapper::addResourceMap
void addResourceMap(const ResourceBroker &broker)
Definition: ResourceMapper.cc:60
ResourceMapper::brokers_
std::vector< const ResourceBroker * > brokers_
Resource brokers.
Definition: ResourceMapper.hh:63
ContainerTools.hh