OpenASIP
2.0
src
procgen
ProDe
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
36
#include "
ProDeSocketEditPolicy.hh
"
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
55
using
boost::format;
56
using namespace
TTAMachine
;
57
58
/**
59
* The Constructor.
60
*/
61
ProDeSocketEditPolicy::ProDeSocketEditPolicy
():
EditPolicy
() {
62
}
63
64
/**
65
* The Destructor.
66
*/
67
ProDeSocketEditPolicy::~ProDeSocketEditPolicy
() {
68
}
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
*/
76
ComponentCommand
*
77
ProDeSocketEditPolicy::getCommand
(
Request
* request) {
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
());
95
ProDeTextGenerator
* generator =
ProDeTextGenerator::instance
();
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
*/
114
bool
115
ProDeSocketEditPolicy::canHandle
(
Request
* request)
const
{
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
*/
172
ComponentCommand
*
173
ProDeSocketEditPolicy::createConnectCmd
(
Request
* request) {
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
}
CopyComponent
Definition:
CopyComponent.hh:42
ModifySocketCmd
Definition:
ModifySocketCmd.hh:43
MachineTester::canConnect
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
Definition:
MachineTester.cc:86
Request::type
RequestType type() const
TTAMachine::Component::name
virtual TCEString name() const
Definition:
MachinePart.cc:125
TTAMachine::Segment
Definition:
Segment.hh:54
ProDeTextGenerator::STATUS_SOCKET
@ STATUS_SOCKET
Status line template for sockets.
Definition:
ProDeTextGenerator.hh:291
ProDeSocketEditPolicy::~ProDeSocketEditPolicy
virtual ~ProDeSocketEditPolicy()
Definition:
ProDeSocketEditPolicy.cc:67
DeleteSocketCmd.hh
SetStatusTextCmd
Definition:
SetStatusTextCmd.hh:43
SocketBusConnCmd.hh
ProDeSocketEditPolicy::createConnectCmd
ComponentCommand * createConnectCmd(Request *request)
Definition:
ProDeSocketEditPolicy.cc:173
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition:
Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
ModifySocketCmd.hh
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
Unit.hh
assert
#define assert(condition)
Definition:
Application.hh:86
Port.hh
Segment.hh
Request.hh
ConnectRequest
Definition:
ConnectRequest.hh:43
ProDeSocketEditPolicy::ProDeSocketEditPolicy
ProDeSocketEditPolicy()
Definition:
ProDeSocketEditPolicy.cc:61
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition:
Request.hh:51
EditPart.hh
CopyComponent.hh
TTAMachine::Segment::parentBus
Bus * parentBus() const
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
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
ProDeSocketEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition:
ProDeSocketEditPolicy.cc:77
ComponentCommand
Definition:
ComponentCommand.hh:46
ConnectRequest.hh
MachineTester.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition:
ProDeTextGenerator.cc:382
ProDeSocketEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition:
ProDeSocketEditPolicy.cc:115
ConnectRequest::part
EditPart * part()
Definition:
ConnectRequest.cc:58
TTAMachine::Component::machine
virtual Machine * machine() const
SocketPortConnCmd
Definition:
SocketPortConnCmd.hh:46
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition:
Request.hh:48
DeleteSocketCmd
Definition:
DeleteSocketCmd.hh:42
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
ProDeSocketEditPolicy.hh
MachineTester
Definition:
MachineTester.hh:46
ComponentCommand.hh
TTAMachine::Port::parentUnit
Unit * parentUnit() const
Generated by
1.8.17