1 | #ifndef SGCONNECTION_H |
---|
2 | #define SGCONNECTION_H |
---|
3 | |
---|
4 | #include "SgModule.h" |
---|
5 | |
---|
6 | namespace Sg |
---|
7 | { |
---|
8 | class SgConnection : public SgObject |
---|
9 | { |
---|
10 | public: |
---|
11 | enum SgProtocolType { TCP, UDP, MCAST}; |
---|
12 | enum SgNetworkType { LAN, PROCESS, PLATFORM }; |
---|
13 | |
---|
14 | static SgNameType ProtocolName(SgProtocolType protocol){ |
---|
15 | switch (protocol) |
---|
16 | { |
---|
17 | case TCP: return "tcp"; |
---|
18 | case UDP: return "udp"; |
---|
19 | case MCAST: return "mcast"; |
---|
20 | } |
---|
21 | return ""; |
---|
22 | } |
---|
23 | |
---|
24 | static SgNameType NetworkName(SgNetworkType network){ |
---|
25 | switch (network) |
---|
26 | { |
---|
27 | case LAN: return "Local Network"; |
---|
28 | case PROCESS: return "Process"; |
---|
29 | case PLATFORM: return "Platform"; |
---|
30 | } |
---|
31 | return ""; |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | public: |
---|
36 | SgConnection(const SgModule* module1, const SgPort* port1, |
---|
37 | const SgModule* module2, const SgPort* port2, |
---|
38 | SgProtocolType protocol, SgNetworkType network, const SgObject* parentObject=0); |
---|
39 | virtual ~SgConnection(); // destructor |
---|
40 | |
---|
41 | const SgModule* getFirstModule() const; // get first module name |
---|
42 | const SgPort* getFirstModulePort() const; // get name of port of first module |
---|
43 | const SgModule* getSecondModule() const; // get second module |
---|
44 | const SgPort* getSecondModulePort() const; // get name of port of second module |
---|
45 | SgProtocolType getProtocol() const; // get if connection is lossy |
---|
46 | SgNameType getProtocolName() const; // get if connection is lossy |
---|
47 | SgNetworkType getNetwork() const; // get network type |
---|
48 | SgNameType getNetworkName() const; // get network type |
---|
49 | bool getConnected() const; // get if connection is fine |
---|
50 | |
---|
51 | void setFirstModule(const SgModule * ); // set first module name |
---|
52 | void setFirstModulePort(const SgPort * ); // set name of port of first module |
---|
53 | void setSecondModule(const SgModule*); // set second module |
---|
54 | void setSecondModulePort(const SgPort* ); // set name of port of second module |
---|
55 | void setProtocol(SgProtocolType); // set if connection is lossy |
---|
56 | void setNetwork(SgNetworkType); // set network type |
---|
57 | void setConnected(const bool); // set if connection is fine |
---|
58 | |
---|
59 | bool refreshState(); |
---|
60 | |
---|
61 | static SgNameType FullConnectionName(std::string module1Name, std::string port1Name, |
---|
62 | std::string module2Name, std::string port2Name, |
---|
63 | SgProtocolType protocol, SgNetworkType network){ |
---|
64 | return module1Name+"."+port1Name+"_"+module2Name+"."+port2Name+ |
---|
65 | "_"+ ProtocolName(protocol)+"_"+NetworkName(network); |
---|
66 | } |
---|
67 | static SgNameType FullConnectionName(const SgConnection& org){ |
---|
68 | return org.getFirstModule()->getName()+"."+org.getFirstModulePort()->getName()+ |
---|
69 | "_"+org.getSecondModule()->getName()+"."+org.getSecondModulePort()->getName()+ |
---|
70 | "_"+ProtocolName(org.protocol)+"_"+NetworkName(org.network); |
---|
71 | } |
---|
72 | |
---|
73 | private: |
---|
74 | const SgModule* firstModule; // first module name |
---|
75 | const SgPort* firstModulePort; // name of port of first module |
---|
76 | const SgModule* secondModule; // second module |
---|
77 | const SgPort* secondModulePort; // name of port of second module |
---|
78 | SgProtocolType protocol; // if connection is lossy |
---|
79 | SgNetworkType network; // network type |
---|
80 | bool connected; // if connection is fine |
---|
81 | }; |
---|
82 | } // namespace Sg (END) |
---|
83 | |
---|
84 | #endif // SGCONNECTION_H |
---|