SemiProxy Class Reference

This class is the main-class of the semiproxy. More...

#include <SemiProxy.hpp>

List of all members.


Public Member Functions

 SemiProxy (uint proxyPort, uint responderPort)
 default constructor.
 ~SemiProxy ()
 default destructor
int createRtspServerSocket (const char *host, int port)
 Create a socket for communication with the media-server.
int openClientSocket (int proxyport)
 Open the socket for communication with the client (the player).
void addSession (SSession *asess)
 Add an active session to the list in Session-Management.
void removeSession (SSession *asess)
 Remove a session from the list in Session-Management.
SSessiongetSession (uint RtspSessionId)
UserListgetUserList ()
ProfileListgetProfileList ()
uint getProxyPort ()
void setAddDestination (bool shouldAddDestination)
 set addDestination flag
void setAddTermCaps (bool shouldAddTermCaps)
 set addTermcaps flag
void setRequestServerPosition (bool shouldRequestServerPosition)
 set requestServerPosition flag
void setRequestClientPosition (bool shouldRequestClientPosition)
 set requestClientPosition flag
bool shouldAddDestination ()
bool shouldAddTermCaps ()
bool shouldRequestServerPosition ()
bool shouldRequestClientPosition ()
void cleanup ()
 cleanup used memory spaced

Static Public Member Functions

bool isSemiProxyRunning ()
void setSemiProxyRunning (bool semiproxyRunning)
 set semiproxyRunning flag
SemiProxygetRefLastCreated ()

Detailed Description

This class is the main-class of the semiproxy.

On startup it reads all users and profiles into memory, creates a SessionManagement-object (which listens for requests from the semiserver) and creates another socket, on which incoming connections will be handled (by SemiProxySession.cpp).

Author:
Klaus Schoeffmann

Definition at line 84 of file SemiProxy.hpp.


Constructor & Destructor Documentation

SemiProxy::SemiProxy uint  proxyPort,
uint  responderPort
 

default constructor.

Starts Proxy (and Session-Management) and reads all users/profiles into memory.

Parameters:
proxyPort port to use for starting the proxy
responderPort port to use for starting the Session-Management
Definition at line 77 of file SemiProxy.cpp.

References ProfileList::readProfilesFromFile(), UserList::readUsersFromFile(), and VThread::start().

00078 { 00079 this->proxyPort = proxyPort; 00080 addDestination = true; 00081 semiproxyRunning = true; 00082 requestServerPosition = true; 00083 requestClientPosition = true; 00084 00085 //start Session-Management on specified port 00086 //(used for the socket-communication between semi-proxy and semi-server) 00087 sessMgmt = new SessionMgmt(responderPort); 00088 sessMgmt->start(); 00089 00090 //read all users from file 00091 ul = new UserList(); 00092 ul->readUsersFromFile(Globals::getConfigFilePath()); 00093 00094 00095 //read all profiles from file 00096 //(and also add each profile to corresponding user) 00097 prol = new ProfileList(); 00098 prol->readProfilesFromFile(Globals::getConfigFilePath(), ul); 00099 00100 refLastCreated = this; 00101 }


Member Function Documentation

int SemiProxy::createRtspServerSocket const char *  host,
int  port
 

Create a socket for communication with the media-server.

This function is called from SemiProxySession on demand (e.g. on Describe message). Definition at line 131 of file SemiProxy.cpp.

00132 { 00133 struct hostent *hp; 00134 struct sockaddr_in sin; 00135 int sock; 00136 00137 Globals::sdebug << "\n::createRtspServerSocket(): Trying to connect to " << host << " on port " << port << "..."; 00138 00139 if (!(hp = gethostbyname(host))) 00140 { 00141 cerr << "\n::createRtspServerSocket(): Cannot resolve host '" << host << "'" << endl; 00142 return 0; 00143 } 00144 00145 sin.sin_family = AF_INET; 00146 //bcopy (hp->h_addr, (char*) &sin.sin_addr, hp->h_length); 00147 memcpy((char*) &sin.sin_addr, hp->h_addr, hp->h_length); 00148 sin.sin_port = htons(port); 00149 00150 if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) 00151 { 00152 cerr << "\n::createRtspServerSocket(): Cannot create socket" << endl; 00153 return 0; 00154 } 00155 00156 if (::connect(sock, (struct sockaddr*) &sin, sizeof(sin)) < 0) 00157 { 00158 #ifdef WIN32 00159 closesocket(sock); 00160 #else 00161 close(sock); 00162 #endif 00163 cerr << "\n::createRtspServerSocket(): Cannot connect to host '" << host << "'" << endl; 00164 return 0; 00165 } 00166 00167 Globals::sdebug << "\n::createRtspServerSocket(): success!\r\n"; 00168 00169 return sock; 00170 }

ProfileList * SemiProxy::getProfileList  ) 
 

Returns:
a reference to the profilelist
Definition at line 267 of file SemiProxy.cpp.

Referenced by SemiProxySession::forwardToServer(), SemiProxySession::handlePlayResponse(), and SemiProxySession::play().

00268 { 00269 return prol; 00270 }

uint SemiProxy::getProxyPort  ) 
 

Returns:
port on which the semiproxy listens for new connections.
Definition at line 273 of file SemiProxy.cpp.
00274 { 00275 return proxyPort; 00276 }

SemiProxy * SemiProxy::getRefLastCreated  )  [static]
 

Returns:
reference to the last created object
Definition at line 339 of file SemiProxy.cpp.
00340 { 00341 return refLastCreated; 00342 }

SSession * SemiProxy::getSession uint  RtspSessionId  ) 
 

Returns:
a reference to the active session in Session-Management, having the Rtsp-SessionId specified by
Parameters:
RtspSessionId 
Definition at line 255 of file SemiProxy.cpp.

References SessionMgmt::getSession().

Referenced by SemiProxySession::handlePlayResponse(), and SemiProxySession::play().

00256 { 00257 return this->sessMgmt->getSession(RtspSessionId); 00258 }

UserList * SemiProxy::getUserList  ) 
 

Returns:
a reference to the userlist
Definition at line 261 of file SemiProxy.cpp.
00262 { 00263 return ul; 00264 }

bool SemiProxy::isSemiProxyRunning  )  [static]
 

Returns:
true if semiproxy is running, otherwise false
Definition at line 327 of file SemiProxy.cpp.

Referenced by openClientSocket().

00328 { 00329 return semiproxyRunning; 00330 }

int SemiProxy::openClientSocket int  proxyport  ) 
 

Open the socket for communication with the client (the player).

Every incoming connection on this socket is furhter handled from SemiProxySession Definition at line 173 of file SemiProxy.cpp.

References isSemiProxyRunning(), and VThread::start().

00174 { 00175 Globals::sdebug << "\n::openClientSocket(): Trying to open passive socket on port " << proxyport; 00176 00177 struct sockaddr_in sin, caller; 00178 int sock, newsocket; 00179 socklen_t len; 00180 00181 memset((char*) &sin, 0, sizeof(sin)); 00182 sin.sin_family = AF_INET; 00183 sin.sin_addr.s_addr = INADDR_ANY; 00184 sin.sin_port = htons(proxyport); 00185 00186 if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) 00187 { 00188 cerr << "\n::openClientSocket(): Cannot create Socket!" << endl; 00189 return 1; 00190 } 00191 00192 const int reuse = 1; 00193 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuse, sizeof(reuse)) < 0) 00194 { 00195 cerr << "\n::openClientSocket(): Cannot set sockOpt!" << endl; 00196 return 1; 00197 } 00198 00199 if (bind(sock, (struct sockaddr*) &sin, sizeof(sin)) < 0) 00200 { 00201 cerr << "\n::openClientSocket(): Cannot bind socket!" << endl; 00202 return 1; 00203 } 00204 00205 listen(sock, MAX_PENDING); 00206 00207 cout << "\nSemiProxy running on port " << proxyport << "..." << endl; 00208 00209 while (SemiProxy::isSemiProxyRunning()) 00210 { 00211 if ((newsocket = accept(sock, (struct sockaddr*) &caller, &len)) < 0) 00212 { 00213 cerr << "\n::openClientSocket(): Cannot accept socket!" << endl; 00214 return 1; 00215 } 00216 00217 Globals::sdebug << "\n::openClientSocket(): socket connected to " << inet_ntoa(caller.sin_addr) << " on port " << caller.sin_port << "\n"; 00218 00219 //start new proxy thread for this connection 00220 SemiProxySession *rtspthread = new SemiProxySession(newsocket, &caller, this); 00221 spsList.push_back(rtspthread); 00222 rtspthread->start(); 00223 00224 //wait 20 microseconds 00225 #ifndef WIN32 00226 usleep(20); 00227 #else 00228 Sleep(20); 00229 #endif 00230 00231 } 00232 00233 return 0; //success; 00234 }

bool SemiProxy::shouldAddDestination  ) 
 

Returns:
addDestination flag
Definition at line 303 of file SemiProxy.cpp.

Referenced by SemiProxySession::setup().

00304 { 00305 return addDestination; 00306 }

bool SemiProxy::shouldAddTermCaps  ) 
 

Returns:
addTermcaps flag
Definition at line 309 of file SemiProxy.cpp.

Referenced by SemiProxySession::forwardToServer().

00310 { 00311 return addTermCaps; 00312 }

bool SemiProxy::shouldRequestClientPosition  ) 
 

Returns:
requestClientPosition flag
Definition at line 321 of file SemiProxy.cpp.

Referenced by SemiProxySession::forwardToClient(), and SemiProxySession::play().

00322 { 00323 return requestClientPosition; 00324 }

bool SemiProxy::shouldRequestServerPosition  ) 
 

Returns:
requestServerPosition flag
Definition at line 315 of file SemiProxy.cpp.

Referenced by SemiProxySession::pause(), and SemiProxySession::play().

00316 { 00317 return requestServerPosition; 00318 }


The documentation for this class was generated from the following files: