OpenASIP  2.0
ProDeSegmentEditPolicy.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 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 ProDeSegmentEditPolicy.cc
26  *
27  * Definition of ProDeSegmentEditPolicy class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2010
31  * @note rating: yellow
32  * @note reviewed Jul 20 2004 by vpj, jn, am
33  */
34 
35 #include <boost/format.hpp>
37 #include "Request.hh"
38 #include "ComponentCommand.hh"
39 #include "ConnectRequest.hh"
40 #include "Segment.hh"
41 #include "Socket.hh"
42 #include "MachineTester.hh"
43 #include "SocketBusConnCmd.hh"
44 #include "ModifyBusCmd.hh"
45 #include "Bus.hh"
46 #include "ProDeTextGenerator.hh"
47 #include "DeleteSegmentCmd.hh"
48 #include "SetStatusTextCmd.hh"
49 
50 using boost::format;
51 using namespace TTAMachine;
52 
53 /**
54  * The Constructor.
55  */
57 }
58 
59 /**
60  * The Destructor.
61  */
63 }
64 
65 /**
66  * Returns the Command corresponding to the type of the Request.
67  *
68  * @param request Request to be handled.
69  * @return NULL if the Request cannot be handled.
70  * @note ConnectCommand is not yet implemented, thus returns always NULL.
71  */
74 
75 
76  Request::RequestType type = request->type();
77  if (type == Request::CONNECT_REQUEST) {
78  return createConnectCmd(request);
79  } else if (type == Request::MODIFY_REQUEST) {
80  return new ModifyBusCmd(host_->parent());
81  } else if (type == Request::DELETE_REQUEST) {
82  return new DeleteSegmentCmd(host_);
83  } else if (type == Request::STATUS_REQUEST) {
84  // Editing segments is unsupported feature => return empty command
85  return NULL;
86  Segment* segment = dynamic_cast<Segment*>(host_->model());
88  format fmt = generator->text(ProDeTextGenerator::STATUS_SEGMENT);
89  fmt % segment->name();
90  SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
91  return statusCmd;
92  }
93  return NULL;
94 }
95 
96 /**
97  * Tells whether this EditPolicy is able to handle a certain type
98  * of Request.
99  *
100  * @param request Request to be asked if it can be handled.
101  * @return True if the Request can be handled, false otherwise.
102  */
103 bool
105  Request::RequestType type = request->type();
106  if (type == Request::CONNECT_REQUEST) {
107  ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
108  assert(cr != NULL);
109  EditPart* part = cr->part();
110 
111  if (part == NULL) {
112  // No selection.
113  // Segment can be selected for connecting, return true.
114  return true;
115  }
116  Socket* socket = dynamic_cast<Socket*>(part->model());
117  if (socket == NULL) {
118  // Segment can be connected only to sockets, return false.
119  return false;
120  }
121  MachineTester tester(*(socket->machine()));
122  Segment* segment = dynamic_cast<Segment*>(host_->model());
123  if (socket->isConnectedTo(*segment) ||
124  tester.canConnect(*socket, *segment)) {
125  return true;
126  }
127  return false;
128  } else if (type == Request::STATUS_REQUEST) {
129  return true;
130  } else if (type == Request::DELETE_REQUEST) {
131  return true;
132  } else if (type == Request::MODIFY_REQUEST) {
133  return true;
134  } else {
135  return false;
136  }
137 }
138 
139 /**
140  * Creates a command which connects the selected component to the
141  * requested component.
142  *
143  * @param request ConnectionRequest with the target component for the
144  * connection.
145  * @return Command for connecting the selected and requested components.
146  */
149 
150  ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
151  assert(cr != NULL);
152  EditPart* part = cr->part();
153 
154  if (canHandle(request)) {
155  Segment* segment = dynamic_cast<Segment*>(host_->model());
156  Socket* socket = dynamic_cast<Socket*>(part->model());
157  if (socket == NULL) {
158  return NULL;
159  }
160  ComponentCommand* cmd = NULL;
161  cmd = new SocketBusConnCmd(socket, segment);
162  return cmd;
163  } else {
164  return NULL;
165  }
166 }
MachineTester::canConnect
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
Definition: MachineTester.cc:86
Request::type
RequestType type() const
TTAMachine::Segment
Definition: Segment.hh:54
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
SocketBusConnCmd.hh
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Request::CONNECT_REQUEST
@ CONNECT_REQUEST
Connect request.
Definition: Request.hh:50
SocketBusConnCmd
Definition: SocketBusConnCmd.hh:43
Socket.hh
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
Segment.hh
Request.hh
DeleteSegmentCmd
Definition: DeleteSegmentCmd.hh:43
ConnectRequest
Definition: ConnectRequest.hh:43
ProDeSegmentEditPolicy::~ProDeSegmentEditPolicy
virtual ~ProDeSegmentEditPolicy()
Definition: ProDeSegmentEditPolicy.cc:62
ModifyBusCmd.hh
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
ProDeTextGenerator::STATUS_SEGMENT
@ STATUS_SEGMENT
Status line template for segments.
Definition: ProDeTextGenerator.hh:290
TTAMachine::Socket
Definition: Socket.hh:53
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
Bus.hh
SetStatusTextCmd.hh
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
ConnectRequest.hh
MachineTester.hh
EditPart::parent
EditPart * parent() const
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
ModifyBusCmd
Definition: ModifyBusCmd.hh:43
ConnectRequest::part
EditPart * part()
Definition: ConnectRequest.cc:58
TTAMachine::Component::machine
virtual Machine * machine() const
ProDeSegmentEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDeSegmentEditPolicy.cc:104
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::Segment::name
std::string name() const
TTAMachine
Definition: Assembler.hh:48
DeleteSegmentCmd.hh
MachineTester
Definition: MachineTester.hh:46
ProDeSegmentEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition: ProDeSegmentEditPolicy.cc:73
ProDeSegmentEditPolicy::ProDeSegmentEditPolicy
ProDeSegmentEditPolicy()
Definition: ProDeSegmentEditPolicy.cc:56
ProDeSegmentEditPolicy::createConnectCmd
ComponentCommand * createConnectCmd(Request *request)
Definition: ProDeSegmentEditPolicy.cc:148
ProDeSegmentEditPolicy.hh
ComponentCommand.hh