OpenASIP  2.0
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 
37 #include "ProDePortEditPolicy.hh"
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 
51 using boost::format;
52 using std::string;
53 using namespace TTAMachine;
54 
55 /**
56  * The Constructor.
57  */
59 }
60 
61 /**
62  * The Destructor.
63  */
65 }
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  */
101 bool
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 }
ProDePortEditPolicy::ProDePortEditPolicy
ProDePortEditPolicy()
Definition: ProDePortEditPolicy.cc:58
DeletePortCmd.hh
MachineTester::canConnect
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
Definition: MachineTester.cc:86
Request::type
RequestType type() const
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
ProDePortEditPolicy.hh
ProDeTextGenerator::STATUS_PORT
@ STATUS_PORT
Status line template for ports.
Definition: ProDeTextGenerator.hh:293
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
DeletePortCmd
Definition: DeletePortCmd.hh:43
Socket.hh
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
Port.hh
Request.hh
ConnectRequest
Definition: ConnectRequest.hh:43
EditPart.hh
SocketPortConnCmd.hh
TTAMachine::Port
Definition: Port.hh:54
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
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
Machine.hh
SetStatusTextCmd.hh
ProDePortEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition: ProDePortEditPolicy.cc:75
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
ConnectRequest.hh
MachineTester.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
ConnectRequest::part
EditPart * part()
Definition: ConnectRequest.cc:58
ProDePortEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDePortEditPolicy.cc:102
TTAMachine::Component::machine
virtual Machine * machine() const
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
SocketPortConnCmd
Definition: SocketPortConnCmd.hh:46
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::Port::isConnectedTo
virtual bool isConnectedTo(const Socket &socket) const
Definition: Port.cc:393
TTAMachine
Definition: Assembler.hh:48
ProDePortEditPolicy::createConnectCmd
ComponentCommand * createConnectCmd(Request *request)
Definition: ProDePortEditPolicy.cc:145
MachineTester
Definition: MachineTester.hh:46
ProDePortEditPolicy::~ProDePortEditPolicy
virtual ~ProDePortEditPolicy()
Definition: ProDePortEditPolicy.cc:64
ComponentCommand.hh