SSession.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: SSession.cpp (S H A R E D) * 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 "SSession.hpp" 00051 00052 /***********************************************************************/ 00053 SSession::SSession(uint RtspSessionId, char *URL, char *clientAdr, char *SemiMovieId, 00054 uint OriginRtspSessionId, ulong prevDuration, 00055 uint bufferingDelayms, TimeMeasurement *timemsmnt) 00056 { 00057 00058 Globals::sdebug << "\nSSession::SSession(): SSession-Konstruktor1 "; 00059 00060 assert(URL != NULL && clientAdr != NULL && timemsmnt != NULL); 00061 00062 this->RtspSessionId = RtspSessionId; 00063 this->URL = new string(URL); 00064 this->clientAdr = new string(clientAdr); 00065 this->SemiMovieId = NULL; 00066 if (SemiMovieId != NULL) this->SemiMovieId = new string(SemiMovieId); 00067 this->OriginRtspSessionId = OriginRtspSessionId; 00068 this->prevDuration = prevDuration; 00069 this->estMsecsElapsed = 0; 00070 this->bufferingDelayms = bufferingDelayms; 00071 this->timemsmnt = timemsmnt; 00072 this->tsCount = 0; 00073 this->State = STATE_INIT; 00074 00075 //get current timestamp 00076 struct timeval currTime; 00077 gettimeofday(&currTime, NULL); 00078 this->tsCreation = currTime.tv_sec; 00079 Globals::sdebug << "\nsession-creation:tv_sec = " << currTime.tv_sec; 00080 Globals::sdebug << "\n=>" << semifunc::newStrCpy(semifunc::formatTimeSecs(tsCreation)); 00081 this->tsClosed = 0; 00082 00083 Globals::sdebug << "\nSSession::SSession(): created session:"; 00084 Globals::sdebug << "\n\t" << getRtspSessionId(); 00085 Globals::sdebug << "\n\turl: " << URL; 00086 Globals::sdebug << "\n\tclient: " << clientAdr; 00087 Globals::sdebug << "\n\tmovid: " << SemiMovieId; 00088 Globals::sdebug << "\n\torigSessId: " << this->OriginRtspSessionId; 00089 Globals::sdebug << "\n\tdur: " << this->prevDuration; 00090 Globals::sdebug << "\n\testMsecs: " << this->estMsecsElapsed; 00091 Globals::sdebug << "\n\tbufferdelay: " << this->bufferingDelayms; 00092 Globals::sdebug << "\n\tstate: " << this->State; 00093 Globals::sdebug << "\n\tcreation: " << this->tsCreation; 00094 Globals::sdebug << "\n\tclosed: " << this->tsClosed; 00095 } 00096 00097 /***********************************************************************/ 00098 SSession::SSession(uint RtspSessionId, char *URL, char *clientAdr, char *SemiMovieId, uint OriginRtspSessionId, 00099 ulong estMsecsElapsed, uint State, ulong duration, ulong prevDuration, uint tsCount, 00100 ulong tsCreation, ulong tsClosed) 00101 { 00102 Globals::sdebug << "\nSSession::SSession2(): SSession-Konstruktor2 "; 00103 00104 00105 this->RtspSessionId = RtspSessionId; 00106 this->URL = new string(URL); 00107 this->clientAdr = new string(clientAdr); 00108 this->SemiMovieId = new string(SemiMovieId); 00109 this->OriginRtspSessionId = OriginRtspSessionId; 00110 this->estMsecsElapsed = estMsecsElapsed; 00111 this->bufferingDelayms = 0; 00112 this->timemsmnt = NULL; 00113 this->duration = duration; 00114 this->prevDuration = prevDuration; 00115 this->tsCount = tsCount; 00116 this->State = State; 00117 this->tsCreation = tsCreation; 00118 this->tsClosed = tsClosed; 00119 00120 Globals::sdebug << "\nSSession::SSession(): created session:"; 00121 Globals::sdebug << "\n\t" << getRtspSessionId(); 00122 Globals::sdebug << "\n\t" << URL; 00123 Globals::sdebug << "\n\t" << clientAdr; 00124 Globals::sdebug << "\n\t" << SemiMovieId; 00125 Globals::sdebug << "\n\t" << this->OriginRtspSessionId; 00126 Globals::sdebug << "\n\t" << this->estMsecsElapsed; 00127 Globals::sdebug << "\n\t" << this->bufferingDelayms; 00128 Globals::sdebug << "\n\t" << this->duration; 00129 Globals::sdebug << "\n\t" << this->prevDuration; 00130 Globals::sdebug << "\n\t" << this->tsCount; 00131 Globals::sdebug << "\n\t" << this->State; 00132 Globals::sdebug << "\n\t" << this->tsCreation; 00133 Globals::sdebug << "\n\t" << this->tsClosed; 00134 } 00135 00136 /***********************************************************************/ 00137 SSession::~SSession() 00138 { 00139 Globals::sdebug << "\nSSession::~SSession(): session " << getRtspSessionId() << " deleted"; 00140 if (URL != NULL) delete URL; 00141 if (clientAdr != NULL) delete clientAdr; 00142 if (SemiMovieId != NULL) delete SemiMovieId; 00143 } 00144 00145 /***********************************************************************/ 00146 uint SSession::getRtspSessionId() 00147 { 00148 return this->RtspSessionId; 00149 } 00150 00151 /***********************************************************************/ 00152 void SSession::setRtspSessionId(uint SessionId) 00153 { 00154 this->RtspSessionId = SessionId; 00155 } 00156 00157 /***********************************************************************/ 00158 char* SSession::getUrl() 00159 { 00160 return (char *)URL->c_str(); 00161 } 00162 00163 /***********************************************************************/ 00164 char* SSession::getClientAdr() 00165 { 00166 return (char *)clientAdr->c_str(); 00167 } 00168 00169 /***********************************************************************/ 00170 char* SSession::getSemiMovieId() 00171 { 00172 return (SemiMovieId == NULL) ? (char*)(new string(""))->c_str() : (char *)SemiMovieId->c_str(); 00173 } 00174 00175 /***********************************************************************/ 00176 uint SSession::getOriginRtspSessionId() 00177 { 00178 return OriginRtspSessionId; 00179 } 00180 00181 /***********************************************************************/ 00182 uint SSession::getBufferingDelay() 00183 { 00184 return bufferingDelayms; 00185 } 00186 00187 /***********************************************************************/ 00188 void SSession::setActive() 00189 { 00190 State = STATE_RUNNING; 00191 } 00192 00193 /***********************************************************************/ 00194 void SSession::setInactive() 00195 { 00196 State = STATE_PAUSED; 00197 } 00198 00199 /***********************************************************************/ 00200 ulong SSession::getElapsedMsecs(uint sectionNr, ulong serverPlayout, ulong clientPlayout) 00201 { 00202 if (timemsmnt != NULL) 00203 { 00204 //called from semiproxy 00205 return timemsmnt->getElapsedTime(sectionNr, serverPlayout, clientPlayout); 00206 } 00207 else 00208 { 00209 //called from semiserver 00210 return estMsecsElapsed; 00211 } 00212 } 00213 00214 /***********************************************************************/ 00215 ulong SSession::getDuration() 00216 { 00217 if (timemsmnt != NULL) 00218 { 00219 //called from semiproxy 00220 return timemsmnt->getDuration(); 00221 } 00222 else 00223 { 00224 //called from semiserver 00225 return duration; 00226 } 00227 } 00228 00229 /***********************************************************************/ 00230 ulong SSession::getPreviousSessionDuration() 00231 { 00232 if (timemsmnt != NULL) 00233 { 00234 //called from semiproxy 00235 return timemsmnt->getPreviousSessionDuration(); 00236 } 00237 else 00238 { 00239 //called from semiserver 00240 return prevDuration; 00241 } 00242 } 00243 00244 /***********************************************************************/ 00245 uint SSession::getTimeSectionCount() 00246 { 00247 if (timemsmnt != NULL) 00248 { 00249 //called from semiproxy 00250 return timemsmnt->getTimeSectionCount(); 00251 } 00252 else 00253 { 00254 //called from semiserver 00255 return tsCount; 00256 } 00257 } 00258 00259 /***********************************************************************/ 00260 uint SSession::getState() 00261 { 00262 return State; 00263 } 00264 00265 /***********************************************************************/ 00266 void SSession::setClosed() 00267 { 00268 State = STATE_CLOSED; 00269 00270 //get current timestamp 00271 struct timeval currTime; 00272 gettimeofday(&currTime, NULL); 00273 //calculate to msecs 00274 this->tsClosed = currTime.tv_sec; 00275 } 00276 00277 /***********************************************************************/ 00278 bool SSession::isClosed() 00279 { 00280 return (State == STATE_CLOSED); 00281 } 00282 00283 /***********************************************************************/ 00284 bool SSession::isMaster() 00285 { 00286 return (OriginRtspSessionId == 0); 00287 } 00288 00289 /***********************************************************************/ 00290 ulong SSession::getTimestampCreated() 00291 { 00292 return tsCreation; 00293 } 00294 00295 /***********************************************************************/ 00296 ulong SSession::getTimestampClosed() 00297 { 00298 return tsClosed; 00299 }