OpenASIP  2.0
Socket.hh
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 Socket.hh
26  *
27  * Declaration of Socket class.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  * @note reviewed 22 Jun 2004 by ao, ml, vpj, ll
32  */
33 
34 #ifndef TTA_SOCKET_HH
35 #define TTA_SOCKET_HH
36 
37 #include <string>
38 #include <vector>
39 #include <set>
40 
41 #include "MachinePart.hh"
42 
43 namespace TTAMachine {
44 
45 class Segment;
46 class Connection;
47 class Port;
48 class Bus;
49 
50 /**
51  * Represents a socket in the TTA processor.
52  */
53 class Socket : public Component {
54 public:
55  /**
56  * Direction of data movements in socket.
57  */
58  enum Direction {
59  INPUT, ///< Data goes from bus to port.
60  OUTPUT, ///< Data goes from port to bus.
61  UNKNOWN ///< Unknown direction.
62  };
63 
64  Socket(const std::string& name);
65  Socket(const ObjectState* state);
66  virtual ~Socket();
67 
68  virtual void setName(const std::string& name);
70  Direction direction() const;
71  void attachBus(Segment& bus);
72  void detachBus(Segment& bus);
73  void detachBus(Bus& bus);
74  int portCount() const;
75  Port* port(int index) const;
76 
77  void detachAllPorts();
78  const Connection& connection(const Segment& bus) const;
79  bool isConnectedTo(const Bus& bus) const;
80  bool isConnectedTo(const Segment& bus) const;
81  std::set<Bus*> connectedBuses();
82  const std::set<Bus*> connectedBuses() const;
83 
84  int segmentCount() const;
85  Segment* segment(int index) const;
86 
87  bool hasDataPortWidth() const;
88 
89  const std::string& dataPortWidth() const;
90 
91  void setDataPortWidth(const std::string& width);
92 
93  virtual void setMachine(Machine& mach);
94  virtual void unsetMachine();
95 
96  virtual ObjectState* saveState() const;
97  virtual void loadState(const ObjectState* state);
98 
99  /// ObjectState name for socket.
100  static const std::string OSNAME_SOCKET;
101  /// ObjectState attribute key for socket direction.
102  static const std::string OSKEY_DIRECTION;
103  /// ObjectState attribute value for input direction.
104  static const std::string OSVALUE_INPUT;
105  /// ObjectState attribute value for output direction.
106  static const std::string OSVALUE_OUTPUT;
107  /// ObjectState attribute value for unknown direction.
108  static const std::string OSVALUE_UNKNOWN;
109 
110 private:
111  /// Table of Connection pointers.
112  typedef std::vector<const Connection*> ConnectionTable;
113  /// Table of port connections.
114  typedef std::vector<Port*> PortTable;
115 
116  /// Copying forbidden.
117  Socket(const Socket&);
118  /// Assingment forbidden.
119  Socket& operator=(const Socket&);
120 
122  void attachPort(Port& port);
123  void detachPort(const Port& port);
124  void detachAllBuses();
125 
126  /// Direction of the socket.
128  /// Dataport width
129  std::string dataPortWidth_;
130  /// Contains all connections to busses.
132  /// Contains all connections to ports.
134 
135  // port must be able to insert and remove ports from PortTable
136  friend class Port;
137 };
138 }
139 
140 #include "Socket.icc"
141 
142 #endif
TTAMachine::Socket::Socket
Socket(const std::string &name)
Definition: Socket.cc:69
TTAMachine::Socket::ports_
PortTable ports_
Contains all connections to ports.
Definition: Socket.hh:133
TTAMachine::Socket::connection
const Connection & connection(const Segment &bus) const
Definition: Socket.cc:302
TTAMachine::Socket::connectedBuses
std::set< Bus * > connectedBuses()
Definition: Socket.cc:368
TTAMachine::Socket::port
Port * port(int index) const
Definition: Socket.cc:266
TTAMachine::Socket::portCount
int portCount() const
TTAMachine::Socket::attachPort
void attachPort(Port &port)
Definition: Socket.cc:618
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::Socket::OSVALUE_OUTPUT
static const std::string OSVALUE_OUTPUT
ObjectState attribute value for output direction.
Definition: Socket.hh:106
TTAMachine::Socket::PortTable
std::vector< Port * > PortTable
Table of port connections.
Definition: Socket.hh:114
TTAMachine::Socket::OUTPUT
@ OUTPUT
Data goes from port to bus.
Definition: Socket.hh:60
TTAMachine::Segment
Definition: Segment.hh:54
TTAMachine::Socket::~Socket
virtual ~Socket()
Definition: Socket.cc:88
TTAMachine::Socket::direction_
Direction direction_
Direction of the socket.
Definition: Socket.hh:127
TTAMachine::Bus
Definition: Bus.hh:53
Socket.icc
TTAMachine::Socket::loadState
virtual void loadState(const ObjectState *state)
Definition: Socket.cc:502
ObjectState
Definition: ObjectState.hh:59
TTAMachine::Socket::segment
Segment * segment(int index) const
Definition: Socket.cc:401
TTAMachine::Socket::Direction
Direction
Definition: Socket.hh:58
TTAMachine::Socket::direction
Direction direction() const
TTAMachine::Socket::saveState
virtual ObjectState * saveState() const
Definition: Socket.cc:465
TTAMachine::Socket::detachAllPorts
void detachAllPorts()
Definition: Socket.cc:278
MachinePart.hh
TTAMachine::Socket::dataPortWidth_
std::string dataPortWidth_
Dataport width.
Definition: Socket.hh:129
TTAMachine::Socket::dataPortWidth
const std::string & dataPortWidth() const
Definition: Socket.cc:415
TTAMachine::Socket::detachPort
void detachPort(const Port &port)
Definition: Socket.cc:631
TTAMachine::Socket::attachBus
void attachBus(Segment &bus)
Definition: Socket.cc:166
TTAMachine::Socket::OSVALUE_UNKNOWN
static const std::string OSVALUE_UNKNOWN
ObjectState attribute value for unknown direction.
Definition: Socket.hh:108
TTAMachine::Port
Definition: Port.hh:54
TTAMachine::Socket::unsetMachine
virtual void unsetMachine()
Definition: Socket.cc:443
TTAMachine::Component
Definition: MachinePart.hh:90
TTAMachine::Socket::setMachine
virtual void setMachine(Machine &mach)
Definition: Socket.cc:432
TTAMachine::Socket
Definition: Socket.hh:53
TTAMachine::Socket::setName
virtual void setName(const std::string &name)
Definition: Socket.cc:103
TTAMachine::Socket::removeConnection
void removeConnection(const Connection *connection)
Definition: Socket.cc:605
TTAMachine::Socket::setDirection
void setDirection(Direction direction)
Definition: Socket.cc:130
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
TTAMachine::Socket::OSNAME_SOCKET
static const std::string OSNAME_SOCKET
ObjectState name for socket.
Definition: Socket.hh:100
TTAMachine::Socket::detachBus
void detachBus(Segment &bus)
Definition: Socket.cc:213
TTAMachine::Socket::OSKEY_DIRECTION
static const std::string OSKEY_DIRECTION
ObjectState attribute key for socket direction.
Definition: Socket.hh:102
TTAMachine::Connection
Definition: Connection.hh:48
TTAMachine::Socket::busses_
ConnectionTable busses_
Contains all connections to busses.
Definition: Socket.hh:131
TTAMachine::Socket::UNKNOWN
@ UNKNOWN
Unknown direction.
Definition: Socket.hh:61
TTAMachine::Socket::hasDataPortWidth
bool hasDataPortWidth() const
Definition: Socket.cc:410
TTAMachine::Socket::ConnectionTable
std::vector< const Connection * > ConnectionTable
Table of Connection pointers.
Definition: Socket.hh:112
TTAMachine::Socket::segmentCount
int segmentCount() const
TTAMachine::Socket::OSVALUE_INPUT
static const std::string OSVALUE_INPUT
ObjectState attribute value for input direction.
Definition: Socket.hh:104
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Socket::detachAllBuses
void detachAllBuses()
Definition: Socket.cc:640
TTAMachine::Socket::operator=
Socket & operator=(const Socket &)
Assingment forbidden.
TTAMachine::Socket::setDataPortWidth
void setDataPortWidth(const std::string &width)
Definition: Socket.cc:420
TTAMachine::Machine
Definition: Machine.hh:73
TTAMachine::Socket::INPUT
@ INPUT
Data goes from bus to port.
Definition: Socket.hh:59