OpenASIP 2.2
Loading...
Searching...
No Matches
Connection.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 Connection.cc
26 *
27 * Implementation of Connection class.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 * @note reviewed 11 Jun 2004 by am, pj, jn, ll
31 * @note rating: red
32 */
33
34#include "Connection.hh"
35#include "Bus.hh"
36#include "Socket.hh"
37#include "Segment.hh"
38#include "Application.hh"
39#include "ObjectState.hh"
40
41using std::string;
42
43namespace TTAMachine {
44
45// initialization of static data members
46const string Connection::OSNAME_CONNECTION = "connection";
47const string Connection::OSKEY_SOCKET = "socket";
48const string Connection::OSKEY_BUS = "bus";
49const string Connection::OSKEY_SEGMENT = "segment";
50
51
52/**
53 * Constructor.
54 *
55 * @param socket Socket which is connected to the given segment.
56 * @param bus Segment of a bus which is connected to the socket.
57 */
59 socket_(&socket), bus_(&bus) {
60}
61
62/**
63 * Destructor.
64 *
65 * If Connection object still joins a socket and a segment, they are detached
66 * before destructing the Connection object.
67 */
69 if (socket_->isConnectedTo(*bus_)) {
70 assert(bus_->isConnectedTo(*socket_)); // sanity check
71 socket_->detachBus(*bus_); // or bus_->detachSocket(socket_)
72 } else {
73 // this is for when destructor is called by a detach methods
75 }
76}
77
78
79/**
80 * Saves its state to an ObjectState instance.
81 *
82 * @return The newly created ObjectState instance.
83 */
87 state->setAttribute(OSKEY_SOCKET, socket()->name());
88 state->setAttribute(OSKEY_BUS, bus()->parentBus()->name());
89 state->setAttribute(OSKEY_SEGMENT, bus()->name());
90 return state;
91}
92
93}
#define assert(condition)
void setAttribute(const std::string &name, const std::string &value)
Segment * bus_
Bus which is connected to the socket.
Definition Connection.hh:70
static const std::string OSKEY_SEGMENT
ObjectState attribute key for segment name.
Definition Connection.hh:64
Connection(Socket &socket, Segment &bus)
Definition Connection.cc:58
static const std::string OSKEY_BUS
ObjectState attribute key for bus name.
Definition Connection.hh:62
Socket * socket() const
static const std::string OSKEY_SOCKET
ObjectState attribute key for socket name.
Definition Connection.hh:60
ObjectState * saveState() const
Definition Connection.cc:85
static const std::string OSNAME_CONNECTION
ObjectState name for Connection.
Definition Connection.hh:58
Socket * socket_
Socket which is connected to the bus.
Definition Connection.hh:68
Segment * bus() const
bool isConnectedTo(const Socket &socket) const
Definition Segment.cc:274
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
void detachBus(Segment &bus)
Definition Socket.cc:213