OpenASIP 2.2
Loading...
Searching...
No Matches
ProDeSocketEditPolicy.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 ProDeSocketEditPolicy.cc
26 *
27 * Definition of ProDeSocketEditPolicy class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: yellow
31 * @note reviewed Jul 20 2004 by vpj, jn, am
32 */
33
34#include <boost/format.hpp>
35
37#include "Request.hh"
38#include "ConnectRequest.hh"
39#include "ComponentCommand.hh"
40#include "ModifySocketCmd.hh"
41#include "DeleteSocketCmd.hh"
42#include "CopyComponent.hh"
43#include "SetStatusTextCmd.hh"
44#include "ProDeTextGenerator.hh"
45#include "EditPart.hh"
46#include "Socket.hh"
47#include "Port.hh"
48#include "Segment.hh"
49#include "Unit.hh"
50#include "Bus.hh"
51#include "MachineTester.hh"
52#include "SocketPortConnCmd.hh"
53#include "SocketBusConnCmd.hh"
54
55using boost::format;
56using namespace TTAMachine;
57
58/**
59 * The Constructor.
60 */
63
64/**
65 * The Destructor.
66 */
69
70/**
71 * Returns the Command corresponding to the type of the Request.
72 *
73 * @param request Request to be handled.
74 * @return NULL if the Request cannot be handled.
75 */
78
79 Request::RequestType type = request->type();
80
81 if (type == Request::MODIFY_REQUEST) {
82 ModifySocketCmd* modifyCmd = new ModifySocketCmd(host_);
83 return modifyCmd;
84
85 } else if (type == Request::DELETE_REQUEST) {
86 DeleteSocketCmd* deleteCmd = new DeleteSocketCmd(host_);
87 return deleteCmd;
88
89 } else if (type == Request::COPY_REQUEST) {
90 CopyComponent* copyCmd = new CopyComponent(host_);
91 return copyCmd;
92
93 } else if (type == Request::STATUS_REQUEST) {
94 Socket* socket = dynamic_cast<Socket*>(host_->model());
96 format fmt = generator->text(ProDeTextGenerator::STATUS_SOCKET);
97 fmt % socket->name();
98 SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
99 return statusCmd;
100 } if (type == Request::CONNECT_REQUEST) {
101 return createConnectCmd(request);
102 } else {
103 return NULL;
104 }
105}
106
107/**
108 * Tells whether this EditPolicy is able to handle a certain type
109 * of Request.
110 *
111 * @param request Request to be asked if it can be handled.
112 * @return True if the Request can be handled, false otherwise.
113 */
114bool
116 Request::RequestType type = request->type();
117 if (type == Request::MODIFY_REQUEST ||
118 type == Request::DELETE_REQUEST ||
119 type == Request::COPY_REQUEST ||
120 type == Request::STATUS_REQUEST) {
121 return true;
122 } else if (type == Request::CONNECT_REQUEST) {
123 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
124 assert(cr != NULL);
125 EditPart* part = cr->part();
126
127 if (part == NULL) {
128 // No selection.
129 // Socket can be selected for connecting, return true.
130 return true;
131 }
132
133 Port* port = dynamic_cast<Port*>(part->model());
134 Segment* segment = dynamic_cast<Segment*>(part->model());
135 if (port == NULL && segment == NULL) {
136 // Socket can be connected only to ports and segments.
137 return false;
138 }
139 MachineTester* tester = NULL;
140 if (port != NULL) {
141 tester = new MachineTester(*(port->parentUnit()->machine()));
142 } else {
143 tester = new MachineTester(*(segment->parentBus()->machine()));
144 }
145 Socket* socket = dynamic_cast<Socket*>(host_->model());
146 if ((port != NULL && (
147 port->isConnectedTo(*socket) ||
148 tester->canConnect(*socket, *port))) ||
149 (segment != NULL && (
150 socket->isConnectedTo(*segment) ||
151 tester->canConnect(*socket, *segment)))) {
152
153 delete tester;
154 return true;
155 }
156 delete tester;
157 return false;
158 } else {
159 return false;
160 }
161}
162
163
164/**
165 * Creates a command which connects the selected component to the
166 * requested component.
167 *
168 * @param request ConnectionRequest with the target component for the
169 * connection.
170 * @return Command for connecting the selected and requested components.
171 */
174
175 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
176 assert(cr != NULL);
177 EditPart* part = cr->part();
178
179 if (canHandle(request)) {
180 Port* port = dynamic_cast<Port*>(part->model());
181 Segment* segment = dynamic_cast<Segment*>(part->model());
182 Socket* socket = dynamic_cast<Socket*>(host_->model());
183 if (port == NULL && segment == NULL) {
184 return NULL;
185 }
186 ComponentCommand* cmd = NULL;
187 if (port != NULL) {
188 cmd = new SocketPortConnCmd(socket, port);
189 } else {
190 cmd = new SocketBusConnCmd(socket, segment);
191 }
192 return cmd;
193 } else {
194 return NULL;
195 }
196}
#define assert(condition)
EditPart * part()
TTAMachine::MachinePart * model() const
EditPart * host_
Host EditPart of this EditPolicy.
Definition EditPolicy.hh:74
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
virtual bool canHandle(Request *request) const
virtual ComponentCommand * getCommand(Request *request)
ComponentCommand * createConnectCmd(Request *request)
static ProDeTextGenerator * instance()
@ STATUS_SOCKET
Status line template for sockets.
RequestType
Data type for determining the type of a Request.
Definition Request.hh:46
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49
@ COPY_REQUEST
Copy request.
Definition Request.hh:51
@ CONNECT_REQUEST
Connect request.
Definition Request.hh:50
RequestType type() const
virtual Machine * machine() const
virtual TCEString name() const
virtual bool isConnectedTo(const Socket &socket) const
Definition Port.cc:393
Unit * parentUnit() const
Bus * parentBus() const
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
virtual boost::format text(int textId)