Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
ServerCommunication.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ServerCommunication.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 /*********************************************************************** 00045 * Video Session Migration System, 2004 * 00046 * Author: Klaus Schoeffmann * 00047 ************************************************************************/ 00048 00049 00050 #include "ServerCommunication.hpp" 00051 00052 00053 /***********************************************************************/ 00054 ServerCommunication::ServerCommunication(int clientsock, struct sockaddr_in* caller, SessionMgmt *sMgmt) 00055 { 00056 this->clientsock = clientsock; 00057 this->caller = caller; 00058 this->sMgmt = sMgmt; 00059 } 00060 00061 /***********************************************************************/ 00062 ServerCommunication::~ServerCommunication() 00063 { 00064 } 00065 00066 00067 /***********************************************************************/ 00068 void ServerCommunication::sendSessionsToServer() 00069 { 00070 int entries = 0; 00071 uint i = 0; 00072 vector<SSession*> *list = sMgmt->getVector(); 00073 00074 Globals::sdebug << "\nSC::sendSessionsToServer(): listSize=" << list->size(); 00075 00076 for (i = 0; i < list->size(); i++) 00077 { 00078 SSession *sess = (*list)[i]; 00079 00080 ulong tsCreated = sess->getTimestampCreated(); 00081 ulong tsClosed = sess->getTimestampClosed(); 00082 00083 if (tsClosed != 0) 00084 { 00085 uint remainTime = (tsClosed - tsCreated) / 3600000; 00086 00087 Globals::sdebug << " remainTime=" << remainTime << "\n"; 00088 00089 if (Globals::getHoursToPreserveClosedSessions() > remainTime && 00090 sess->getSemiMovieId() != NULL) 00091 { 00092 entries++; 00093 } 00094 else 00095 { 00096 sMgmt->removeSession(sess); 00097 } 00098 } 00099 else 00100 { 00101 entries++; 00102 } 00103 } 00104 00105 00106 00107 //first: send number of entries in the list 00108 #ifndef WIN32 00109 send(clientsock, &entries, sizeof(int), 0); 00110 #else 00111 send(clientsock, (const char *)&entries, sizeof(int), 0); 00112 #endif 00113 00114 Globals::sdebug << "\nSC::sendSessionsToServer(): entries=" << entries; 00115 00116 //then send whole vector 00117 list = sMgmt->getVector(); 00118 for (i=0; i < list->size(); i++) 00119 { 00120 SSession *asess = (*list)[i]; 00121 00122 uint RtspSessionId = asess->getRtspSessionId(); 00123 char *SemiMovieId = asess->getSemiMovieId(); 00124 uint movieIdlen = strlen(SemiMovieId); 00125 char *URL = asess->getUrl(); 00126 int URLlen = strlen(URL); 00127 char *clientAdr = asess->getClientAdr(); 00128 uint clientAdrlen = strlen(clientAdr); 00129 uint RtspSessionTOId = asess->getOriginRtspSessionId(); 00130 ulong secsElapsed = asess->getElapsedMsecs(); 00131 ulong duration = asess->getDuration(); 00132 ulong prevDuration = asess->getPreviousSessionDuration(); 00133 uint sectionCount = asess->getTimeSectionCount(); 00134 uint State = asess->getState(); 00135 ulong tsCreation = asess->getTimestampCreated(); 00136 ulong tsClosed = asess->getTimestampClosed(); 00137 00138 #ifndef WIN32 00139 send(clientsock, (uint *) &RtspSessionId, sizeof(uint), 0); 00140 send(clientsock, (uint *) &URLlen, sizeof(uint), 0); 00141 send(clientsock, (char *) URL, sizeof(char) * (URLlen+1), 0); 00142 send(clientsock, (uint *) &clientAdrlen, sizeof(uint), 0); 00143 send(clientsock, (char *) clientAdr, sizeof(char) * (clientAdrlen+1), 0); 00144 send(clientsock, (uint *) &movieIdlen, sizeof(uint), 0); 00145 send(clientsock, (char *) SemiMovieId, sizeof(char) * (movieIdlen+1), 0); 00146 send(clientsock, (uint *) &RtspSessionTOId, sizeof(uint), 0); 00147 send(clientsock, (ulong *) &secsElapsed, sizeof(ulong), 0); 00148 send(clientsock, (ulong *) &duration, sizeof(ulong), 0); 00149 send(clientsock, (ulong *) &prevDuration, sizeof(ulong), 0); 00150 send(clientsock, (uint *) §ionCount, sizeof(uint), 0); 00151 send(clientsock, (uint *) &State, sizeof(uint), 0); 00152 send(clientsock, (ulong *) &tsCreation, sizeof(ulong), 0); 00153 send(clientsock, (ulong *) &tsClosed, sizeof(ulong), 0); 00154 #else 00155 send(clientsock, (const char *)&RtspSessionId, sizeof(uint), 0); 00156 send(clientsock, (const char *)&URLlen, sizeof(uint), 0); 00157 send(clientsock, URL, sizeof(char) * (URLlen+1), 0); 00158 send(clientsock, (const char *)&clientAdrlen, sizeof(uint), 0); 00159 send(clientsock, clientAdr, sizeof(char) * (clientAdrlen+1), 0); 00160 send(clientsock, (const char *)&movieIdlen, sizeof(uint), 0); 00161 send(clientsock, SemiMovieId, sizeof(char) * (movieIdlen+1), 0); 00162 send(clientsock, (const char *)&RtspSessionTOId, sizeof(uint), 0); 00163 send(clientsock, (const char *)&secsElapsed, sizeof(ulong), 0); 00164 send(clientsock, (const char *)&duration, sizeof(ulong), 0); 00165 send(clientsock, (const char *)&prevDuration, sizeof(ulong), 0); 00166 send(clientsock, (const char *)§ionCount, sizeof(uint), 0); 00167 send(clientsock, (const char *)&State, sizeof(uint), 0); 00168 send(clientsock, (const char *)&tsCreation, sizeof(ulong), 0); 00169 send(clientsock, (const char *)&tsClosed, sizeof(ulong), 0); 00170 #endif 00171 00172 Globals::sdebug << "\nSC::sendSessionsToServer(): - SSession sent: " << RtspSessionId; cout.flush(); 00173 Globals::sdebug << "\n " << URL << "(" << URLlen << ")"; 00174 Globals::sdebug << "\n " << clientAdr << "(" << clientAdrlen << ")"; 00175 Globals::sdebug << "\n " << SemiMovieId << "(" << movieIdlen << ")"; 00176 Globals::sdebug << "\n " << RtspSessionTOId; 00177 Globals::sdebug << "\n " << secsElapsed; 00178 Globals::sdebug << "\n " << duration; 00179 Globals::sdebug << "\n " << prevDuration; 00180 Globals::sdebug << "\n " << sectionCount; 00181 Globals::sdebug << "\n " << State; 00182 Globals::sdebug << "\n " << tsCreation; 00183 Globals::sdebug << "\n " << tsClosed; 00184 00185 } 00186 } 00187