OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
ProDePortEditPolicy Class Reference

#include <ProDePortEditPolicy.hh>

Inheritance diagram for ProDePortEditPolicy:
Inheritance graph
Collaboration diagram for ProDePortEditPolicy:
Collaboration graph

Public Member Functions

 ProDePortEditPolicy ()
 
virtual ~ProDePortEditPolicy ()
 
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)
 
ProDePortEditPolicyoperator= (ProDePortEditPolicy &old)
 Assignment not allowed.
 
 ProDePortEditPolicy (ProDePortEditPolicy &old)
 Copying not allowed.
 

Additional Inherited Members

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

Detailed Description

Determines how a port 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 ProDePortEditPolicy.hh.

Constructor & Destructor Documentation

◆ ProDePortEditPolicy() [1/2]

ProDePortEditPolicy::ProDePortEditPolicy ( )

The Constructor.

Definition at line 58 of file ProDePortEditPolicy.cc.

58 : EditPolicy() {
59}

◆ ~ProDePortEditPolicy()

ProDePortEditPolicy::~ProDePortEditPolicy ( )
virtual

The Destructor.

Definition at line 64 of file ProDePortEditPolicy.cc.

64 {
65}

◆ ProDePortEditPolicy() [2/2]

ProDePortEditPolicy::ProDePortEditPolicy ( ProDePortEditPolicy old)
private

Copying not allowed.

Member Function Documentation

◆ canHandle()

bool ProDePortEditPolicy::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 102 of file ProDePortEditPolicy.cc.

102 {
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}
#define assert(condition)
EditPart * part()
TTAMachine::MachinePart * model() const
EditPart * host_
Host EditPart of this EditPolicy.
Definition EditPolicy.hh:74
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

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

Referenced by createConnectCmd().

Here is the call graph for this function:

◆ createConnectCmd()

ComponentCommand * ProDePortEditPolicy::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 145 of file ProDePortEditPolicy.cc.

145 {
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}
virtual bool canHandle(Request *request) const

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

Referenced by getCommand().

Here is the call graph for this function:

◆ getCommand()

ComponentCommand * ProDePortEditPolicy::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.
Note
ConnectCommand is not yet implemented, thus returns always NULL.

Implements EditPolicy.

Definition at line 75 of file ProDePortEditPolicy.cc.

75 {
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}
ComponentCommand * createConnectCmd(Request *request)
static ProDeTextGenerator * instance()
@ STATUS_PORT
Status line template for ports.
virtual std::string name() const
Definition Port.cc:141
virtual boost::format text(int textId)

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

Here is the call graph for this function:

◆ operator=()

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

Assignment not allowed.


The documentation for this class was generated from the following files: