OpenASIP 2.2
Loading...
Searching...
No Matches
ProDePortEditPolicy.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 ProDePortEditPolicy.cc
26 *
27 * Definition of ProDePortEditPolicy 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 <string>
35#include <boost/format.hpp>
36
38#include "ConnectRequest.hh"
39#include "Request.hh"
40#include "ComponentCommand.hh"
41#include "EditPart.hh"
42#include "Socket.hh"
43#include "Port.hh"
44#include "Machine.hh"
45#include "MachineTester.hh"
46#include "ProDeTextGenerator.hh"
47#include "SetStatusTextCmd.hh"
48#include "DeletePortCmd.hh"
49#include "SocketPortConnCmd.hh"
50
51using boost::format;
52using std::string;
53using namespace TTAMachine;
54
55/**
56 * The Constructor.
57 */
60
61/**
62 * The Destructor.
63 */
66
67/**
68 * Returns the Command corresponding to the type of the Request.
69 *
70 * @param request Request to be handled.
71 * @return NULL if the Request cannot be handled.
72 * @note ConnectCommand is not yet implemented, thus returns always NULL.
73 */
76 Request::RequestType type = request->type();
77 if (type == Request::CONNECT_REQUEST) {
78 return createConnectCmd(request);
79 } else if (type == Request::STATUS_REQUEST) {
80 Port* port = dynamic_cast<Port*>(host_->model());
82 format fmt = generator->text(ProDeTextGenerator::STATUS_PORT);
83 fmt % port->name();
84 SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
85 return statusCmd;
86 } else if (type == Request::DELETE_REQUEST) {
87 DeletePortCmd* deleteCmd = new DeletePortCmd(host_);
88 return deleteCmd;
89 } else {
90 return NULL;
91 }
92}
93
94/**
95 * Tells whether this EditPolicy is able to handle a certain type
96 * of Request.
97 *
98 * @param request Request to be asked if it can be handled.
99 * @return True if the Request can be handled, false otherwise.
100 */
101bool
103 Request::RequestType type = request->type();
104 if (type == Request::CONNECT_REQUEST) {
105 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
106 assert(cr != NULL);
107 EditPart* part = cr->part();
108
109 if (part == NULL) {
110 // No selection.
111 // Port can be selected for connecting, return true.
112 return true;
113 }
114
115 Socket* socket = dynamic_cast<Socket*>(part->model());
116 if (socket == NULL) {
117 // Port can be connected only to sockets, return false.
118 return false;
119 }
120 MachineTester tester(*(socket->machine()));
121 Port* port = dynamic_cast<Port*>(host_->model());
122 if (port->isConnectedTo(*socket) ||
123 tester.canConnect(*socket, *port)) {
124 return true;
125 }
126 return false;
127 } else if (type == Request::STATUS_REQUEST) {
128 return true;
129 } else if (type == Request::DELETE_REQUEST) {
130 return true;
131 } else {
132 return false;
133 }
134}
135
136/**
137 * Creates a command which connects the selected component to the
138 * requested component.
139 *
140 * @param request ConnectionRequest with the target component for the
141 * connection.
142 * @return Command for connecting the selected and requested components.
143 */
146
147 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
148 assert(cr != NULL);
149 EditPart* part = cr->part();
150
151 if (canHandle(request)) {
152 Port* port = dynamic_cast<Port*>(host_->model());
153 Socket* socket = dynamic_cast<Socket*>(part->model());
154 if (port == NULL) {
155 return NULL;
156 }
157 ComponentCommand* cmd = NULL;
158 cmd = new SocketPortConnCmd(socket, port);
159 return cmd;
160 } else {
161 return NULL;
162 }
163}
#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
ComponentCommand * createConnectCmd(Request *request)
virtual ComponentCommand * getCommand(Request *request)
static ProDeTextGenerator * instance()
@ STATUS_PORT
Status line template for ports.
RequestType
Data type for determining the type of a Request.
Definition Request.hh:46
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49
@ CONNECT_REQUEST
Connect request.
Definition Request.hh:50
RequestType type() const
virtual Machine * machine() const
virtual bool isConnectedTo(const Socket &socket) const
Definition Port.cc:393
virtual std::string name() const
Definition Port.cc:141
virtual boost::format text(int textId)