OpenASIP 2.2
Loading...
Searching...
No Matches
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
43namespace TTAMachine {
44
45class Segment;
46class Connection;
47class Port;
48class Bus;
49
50/**
51 * Represents a socket in the TTA processor.
52 */
53class Socket : public Component {
54public:
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);
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
110private:
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.
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
virtual TCEString name() const
std::string dataPortWidth_
Dataport width.
Definition Socket.hh:129
void setDirection(Direction direction)
Definition Socket.cc:130
static const std::string OSVALUE_INPUT
ObjectState attribute value for input direction.
Definition Socket.hh:104
virtual void unsetMachine()
Definition Socket.cc:443
@ OUTPUT
Data goes from port to bus.
Definition Socket.hh:60
@ INPUT
Data goes from bus to port.
Definition Socket.hh:59
@ UNKNOWN
Unknown direction.
Definition Socket.hh:61
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
void removeConnection(const Connection *connection)
Definition Socket.cc:605
static const std::string OSNAME_SOCKET
ObjectState name for socket.
Definition Socket.hh:100
static const std::string OSKEY_DIRECTION
ObjectState attribute key for socket direction.
Definition Socket.hh:102
void detachBus(Segment &bus)
Definition Socket.cc:213
Direction direction() const
ConnectionTable busses_
Contains all connections to busses.
Definition Socket.hh:131
void detachAllBuses()
Definition Socket.cc:640
static const std::string OSVALUE_OUTPUT
ObjectState attribute value for output direction.
Definition Socket.hh:106
bool hasDataPortWidth() const
Definition Socket.cc:410
const Connection & connection(const Segment &bus) const
Definition Socket.cc:302
void detachPort(const Port &port)
Definition Socket.cc:631
void setDataPortWidth(const std::string &width)
Definition Socket.cc:420
std::set< Bus * > connectedBuses()
Definition Socket.cc:368
Port * port(int index) const
Definition Socket.cc:266
virtual void loadState(const ObjectState *state)
Definition Socket.cc:502
void attachBus(Segment &bus)
Definition Socket.cc:166
virtual ObjectState * saveState() const
Definition Socket.cc:465
virtual ~Socket()
Definition Socket.cc:88
virtual void setName(const std::string &name)
Definition Socket.cc:103
PortTable ports_
Contains all connections to ports.
Definition Socket.hh:133
Segment * segment(int index) const
Definition Socket.cc:401
Socket & operator=(const Socket &)
Assingment forbidden.
virtual void setMachine(Machine &mach)
Definition Socket.cc:432
void detachAllPorts()
Definition Socket.cc:278
int segmentCount() const
std::vector< const Connection * > ConnectionTable
Table of Connection pointers.
Definition Socket.hh:112
int portCount() const
static const std::string OSVALUE_UNKNOWN
ObjectState attribute value for unknown direction.
Definition Socket.hh:108
Direction direction_
Direction of the socket.
Definition Socket.hh:127
Socket(const Socket &)
Copying forbidden.
const std::string & dataPortWidth() const
Definition Socket.cc:415
void attachPort(Port &port)
Definition Socket.cc:618
std::vector< Port * > PortTable
Table of port connections.
Definition Socket.hh:114