Debian Codegraph @

protolib/src/sim/ns/tcp/TCPSocketFactory.cpp

raw
1 /*
2 * TCPSocketFactory.cpp
3 * FullerTCP
4 *
5 * Created by Ian Taylor on 07/03/2007.
6 *
7 */
8
9 #include "TCPSocketFactory.h"
10
11 Agent *TCPSocketFactory::instantiateAgent(const char *tclAgent) {
12 Tcl& tcl = Tcl::instance();
13
14 tcl.evalf("eval new %s", tclAgent);
15
16 const char *tcpVar = tcl.result();
17
18 if (tcpVar==NULL) return NULL;
19
20 return (Agent *)tcl.lookup(tcpVar);
21 }
22
23 Agent *TCPSocketFactory::instantiateAgent(const char *tclAgent, const char *par1) {
24 Tcl& tcl = Tcl::instance();
25
26 tcl.evalf("eval new %s %s", tclAgent, par1);
27
28 const char *tcpVar = tcl.result();
29
30 if (tcpVar==NULL) return NULL;
31
32 return (Agent *)tcl.lookup(tcpVar);
33 }
34
35 Agent *TCPSocketFactory::instantiateAgent(const char *tclAgent, const char *par1, const char *par2) {
36 Tcl& tcl = Tcl::instance();
37
38 tcl.evalf("eval new %s %s %s", tclAgent, par1, par2);
39
40 const char *tcpVar = tcl.result();
41
42 if (tcpVar==NULL) return NULL;
43
44 return (Agent *)tcl.lookup(tcpVar);
45 }
46
47 // CLIENTS
48
49 TCPSocketAgent *TCPSocketFactory::createSocketAgent(Agent *forMyAgent){
50 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/SocketAgent");
51 if (socket==NULL)
52 return NULL;
53 else {
54 TCPSocketAgent *socketAgent = (TCPSocketAgent *)socket;
55 socketAgent->setSimulationAgent(forMyAgent);
56 return socketAgent;
57 }
58 }
59
60 TCPSocketAgent *TCPSocketFactory::createSocketAgent(Agent *forMyAgent, nsaddr_t thePort) {
61 char portString[16];
62
63 sprintf(portString, "%i", thePort);
64
65 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/SocketAgent FULLTCP", portString);
66 if (socket==NULL)
67 return NULL;
68 else {
69 TCPSocketAgent *socketAgent = (TCPSocketAgent *)socket;
70 socketAgent->setSimulationAgent(forMyAgent);
71 return socketAgent;
72 }
73 }
74
75 TCPSocketAgent *TCPSocketFactory::createSocketAgent(Agent *forMyAgent, TCPSocketAgent::TcpProtocol theTCPProtocol, nsaddr_t thePort) {
76 const char *protocol;
77 char portString[16];
78
79 protocol = TCPSocketAgent::getTCPStringForProtocol(theTCPProtocol);
80 sprintf(portString, "%i", thePort);
81
82 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/SocketAgent", protocol, portString);
83 if (socket==NULL)
84 return NULL;
85 else {
86 TCPSocketAgent *socketAgent = (TCPSocketAgent *)socket;
87 socketAgent->setSimulationAgent(forMyAgent);
88 return socketAgent;
89 }
90 }
91
92
93 TCPSocketAgent *TCPSocketFactory::createSocketAgent(Agent *forMyAgent, TCPSocketAgent::TcpProtocol theTCPProtocol) {
94 const char *protocol;
95
96 protocol = TCPSocketAgent::getTCPStringForProtocol(theTCPProtocol);
97
98 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/SocketAgent", protocol);
99
100 if (socket==NULL)
101 return NULL;
102 else {
103 TCPSocketAgent *socketAgent = (TCPSocketAgent *)socket;
104 socketAgent->setSimulationAgent(forMyAgent);
105 return socketAgent;
106 }
107 }
108
109
110 // SERVERS
111
112 TCPServerSocketAgent *TCPSocketFactory::createServerSocketAgent(Agent *forMyAgent) {
113 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/ServerSocketAgent");
114 if (socket==NULL)
115 return NULL;
116 else {
117 TCPServerSocketAgent *socketAgent = (TCPServerSocketAgent *)socket;
118 socketAgent->setSimulationAgent(forMyAgent);
119 return socketAgent;
120 }
121 }
122
123 TCPServerSocketAgent *TCPSocketFactory::createServerSocketAgent(Agent *forMyAgent, nsaddr_t thePort) {
124 char portString[16];
125
126 sprintf(portString, "%i", thePort);
127
128 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/ServerSocketAgent FULLTCP", portString);
129 if (socket==NULL)
130 return NULL;
131 else {
132 TCPServerSocketAgent *socketAgent = (TCPServerSocketAgent *)socket;
133 socketAgent->setSimulationAgent(forMyAgent);
134 return socketAgent;
135 }
136 }
137
138 TCPServerSocketAgent *TCPSocketFactory::createServerSocketAgent(Agent *forMyAgent, TCPSocketAgent::TcpProtocol theTCPProtocol, nsaddr_t thePort) {
139 char portString[16];
140 const char *protocol;
141
142 protocol = TCPSocketAgent::getTCPStringForProtocol(theTCPProtocol);
143 sprintf(portString, "%i", thePort);
144
145 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/ServerSocketAgent", protocol, portString);
146 if (socket==NULL)
147 return NULL;
148 else {
149 TCPServerSocketAgent *socketAgent = (TCPServerSocketAgent *)socket;
150 socketAgent->setSimulationAgent(forMyAgent);
151 return socketAgent;
152 }
153 }
154
155 TCPServerSocketAgent *TCPSocketFactory::createServerSocketAgent(Agent *forMyAgent, TCPSocketAgent::TcpProtocol theTCPProtocol) {
156 const char *protocol;
157
158 protocol = TCPSocketAgent::getTCPStringForProtocol(theTCPProtocol);
159
160 Agent* socket = TCPSocketFactory::instantiateAgent("Agent/TCP/ServerSocketAgent", protocol);
161
162 if (socket==NULL)
163 return NULL;
164 else {
165 TCPServerSocketAgent *socketAgent = (TCPServerSocketAgent *)socket;
166 socketAgent->setSimulationAgent(forMyAgent);
167 return socketAgent;
168 }
169 }