OpenASIP  2.0
Public Member Functions | Private Member Functions | List of all members
ProDeSocketEditPolicy Class Reference

#include <ProDeSocketEditPolicy.hh>

Inheritance diagram for ProDeSocketEditPolicy:
Inheritance graph
Collaboration diagram for ProDeSocketEditPolicy:
Collaboration graph

Public Member Functions

 ProDeSocketEditPolicy ()
 
virtual ~ProDeSocketEditPolicy ()
 
virtual ComponentCommandgetCommand (Request *request)
 
virtual bool canHandle (Request *request) const
 
- Public Member Functions inherited from EditPolicy
 EditPolicy ()
 
virtual ~EditPolicy ()
 
EditParthost () const
 
void setHost (EditPart *host)
 

Private Member Functions

ComponentCommandcreateConnectCmd (Request *request)
 
ProDeSocketEditPolicyoperator= (ProDeSocketEditPolicy &old)
 Assignment not allowed. More...
 
 ProDeSocketEditPolicy (ProDeSocketEditPolicy &old)
 Copying not allowed. More...
 

Additional Inherited Members

- Protected Attributes inherited from EditPolicy
EditParthost_
 Host EditPart of this EditPolicy. More...
 

Detailed Description

Determines how a socket EditPart acts when a Request is performed on it.

Converts a given Request to a Command if the EditPolicy supports. the Request.

Definition at line 49 of file ProDeSocketEditPolicy.hh.

Constructor & Destructor Documentation

◆ ProDeSocketEditPolicy() [1/2]

ProDeSocketEditPolicy::ProDeSocketEditPolicy ( )

The Constructor.

Definition at line 61 of file ProDeSocketEditPolicy.cc.

61  : EditPolicy() {
62 }

◆ ~ProDeSocketEditPolicy()

ProDeSocketEditPolicy::~ProDeSocketEditPolicy ( )
virtual

The Destructor.

Definition at line 67 of file ProDeSocketEditPolicy.cc.

67  {
68 }

◆ ProDeSocketEditPolicy() [2/2]

ProDeSocketEditPolicy::ProDeSocketEditPolicy ( ProDeSocketEditPolicy old)
private

Copying not allowed.

Member Function Documentation

◆ canHandle()

bool ProDeSocketEditPolicy::canHandle ( Request request) const
virtual

Tells whether this EditPolicy is able to handle a certain type of Request.

Parameters
requestRequest to be asked if it can be handled.
Returns
True if the Request can be handled, false otherwise.

Implements EditPolicy.

Definition at line 115 of file ProDeSocketEditPolicy.cc.

115  {
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 }

References assert, MachineTester::canConnect(), Request::CONNECT_REQUEST, Request::COPY_REQUEST, Request::DELETE_REQUEST, EditPolicy::host_, TTAMachine::Port::isConnectedTo(), TTAMachine::Socket::isConnectedTo(), TTAMachine::Component::machine(), EditPart::model(), Request::MODIFY_REQUEST, TTAMachine::Segment::parentBus(), TTAMachine::Port::parentUnit(), ConnectRequest::part(), Request::STATUS_REQUEST, and Request::type().

Referenced by createConnectCmd().

Here is the call graph for this function:

◆ createConnectCmd()

ComponentCommand * ProDeSocketEditPolicy::createConnectCmd ( Request request)
private

Creates a command which connects the selected component to the requested component.

Parameters
requestConnectionRequest with the target component for the connection.
Returns
Command for connecting the selected and requested components.

Definition at line 173 of file ProDeSocketEditPolicy.cc.

173  {
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 }

References assert, canHandle(), EditPolicy::host_, EditPart::model(), and ConnectRequest::part().

Referenced by getCommand().

Here is the call graph for this function:

◆ getCommand()

ComponentCommand * ProDeSocketEditPolicy::getCommand ( Request request)
virtual

Returns the Command corresponding to the type of the Request.

Parameters
requestRequest to be handled.
Returns
NULL if the Request cannot be handled.

Implements EditPolicy.

Definition at line 77 of file ProDeSocketEditPolicy.cc.

77  {
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 }

References Request::CONNECT_REQUEST, Request::COPY_REQUEST, createConnectCmd(), Request::DELETE_REQUEST, EditPolicy::host_, ProDeTextGenerator::instance(), EditPart::model(), Request::MODIFY_REQUEST, TTAMachine::Component::name(), Request::STATUS_REQUEST, ProDeTextGenerator::STATUS_SOCKET, Texts::TextGenerator::text(), and Request::type().

Here is the call graph for this function:

◆ operator=()

ProDeSocketEditPolicy& ProDeSocketEditPolicy::operator= ( ProDeSocketEditPolicy old)
private

Assignment not allowed.


The documentation for this class was generated from the following files:
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
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
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
Request::CONNECT_REQUEST
@ CONNECT_REQUEST
Connect request.
Definition: Request.hh:50
SocketBusConnCmd
Definition: SocketBusConnCmd.hh:43
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
ConnectRequest
Definition: ConnectRequest.hh:43
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
TTAMachine::Segment::parentBus
Bus * parentBus() const
TTAMachine::Port
Definition: Port.hh:54
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
EditPolicy::EditPolicy
EditPolicy()
Definition: EditPolicy.cc:41
TTAMachine::Socket
Definition: Socket.hh:53
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPart
Definition: EditPart.hh:60
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
EditPart::model
TTAMachine::MachinePart * model() const
ComponentCommand
Definition: ComponentCommand.hh:46
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
MachineTester
Definition: MachineTester.hh:46
TTAMachine::Port::parentUnit
Unit * parentUnit() const