OpenASIP  2.0
ProDeGCUEditPolicy.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 ProDeGCUEditPolicy.cc
26  *
27  * Definition of ProDeGCUEditPolicy 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 "ProDeGCUEditPolicy.hh"
38 #include "Request.hh"
39 #include "ComponentCommand.hh"
40 #include "ModifyGCUCmd.hh"
41 #include "DeleteGCUCmd.hh"
42 #include "CopyComponent.hh"
43 #include "EditPart.hh"
44 #include "ControlUnit.hh"
45 #include "ProDeTextGenerator.hh"
46 #include "SetStatusTextCmd.hh"
47 
48 using std::string;
49 using boost::format;
50 using namespace TTAMachine;
51 
52 /**
53  * The Constructor.
54  */
56 }
57 
58 /**
59  * The Destructor.
60  */
62 }
63 
64 /**
65  * Returns the Command corresponding to the type of the Request.
66  *
67  * @param request Request to be handled.
68  * @return NULL if the Request cannot be handled.
69  */
72 
73  Request::RequestType type = request->type();
74 
75  if (type == Request::MODIFY_REQUEST) {
76  ModifyGCUCmd* modifyCmd = new ModifyGCUCmd(host_);
77  return modifyCmd;
78 
79  } else if (type == Request::DELETE_REQUEST) {
80  DeleteGCUCmd* deleteCmd = new DeleteGCUCmd(host_);
81  return deleteCmd;
82 
83  } else if (type == Request::COPY_REQUEST) {
84  CopyComponent* copyCmd = new CopyComponent(host_);
85  return copyCmd;
86 
87  } else if (type == Request::STATUS_REQUEST) {
88  ControlUnit* gcu = dynamic_cast<ControlUnit*>(host_->model());
90  format fmt = generator->text(ProDeTextGenerator::STATUS_GCU);
91  fmt % gcu->name();
92  SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
93  return statusCmd;
94 
95  } else {
96  return NULL;
97  }
98 }
99 
100 /**
101  * Tells whether this EditPolicy is able to handle a certain type
102  * of Request.
103  *
104  * @param request Request to be asked if it can be handled.
105  * @return True if the Request can be handled, false otherwise.
106  */
107 bool
109  Request::RequestType type = request->type();
110  if (type == Request::MODIFY_REQUEST ||
111  type == Request::DELETE_REQUEST ||
112  type == Request::COPY_REQUEST) {
113  return true;
114  } else {
115  return false;
116  }
117 }
CopyComponent
Definition: CopyComponent.hh:42
ModifyGCUCmd.hh
ProDeGCUEditPolicy::~ProDeGCUEditPolicy
virtual ~ProDeGCUEditPolicy()
Definition: ProDeGCUEditPolicy.cc:61
DeleteGCUCmd
Definition: DeleteGCUCmd.hh:42
Request::type
RequestType type() const
ProDeGCUEditPolicy.hh
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ProDeGCUEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDeGCUEditPolicy.cc:108
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
ModifyGCUCmd
Definition: ModifyGCUCmd.hh:43
Request.hh
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
EditPart.hh
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
CopyComponent.hh
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPolicy
Definition: EditPolicy.hh:47
DeleteGCUCmd.hh
SetStatusTextCmd.hh
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
ProDeGCUEditPolicy::getCommand
virtual ComponentCommand * getCommand(Request *request)
Definition: ProDeGCUEditPolicy.cc:71
ProDeTextGenerator::STATUS_GCU
@ STATUS_GCU
Status line template for GCUs.
Definition: ProDeTextGenerator.hh:288
ControlUnit.hh
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine
Definition: Assembler.hh:48
ProDeGCUEditPolicy::ProDeGCUEditPolicy
ProDeGCUEditPolicy()
Definition: ProDeGCUEditPolicy.cc:55
ComponentCommand.hh