OpenASIP 2.2
Loading...
Searching...
No Matches
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
50using boost::format;
51using namespace TTAMachine;
52
53/**
54 * The Constructor.
55 */
58
59/**
60 * The Destructor.
61 */
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 */
103bool
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}
#define assert(condition)
EditPart * part()
EditPart * parent() const
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_SEGMENT
Status line template for segments.
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
@ CONNECT_REQUEST
Connect request.
Definition Request.hh:50
RequestType type() const
virtual Machine * machine() const
std::string name() const
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
virtual boost::format text(int textId)