Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
ProfileList.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ProfileList.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 "ProfileList.hpp" 00051 00052 using namespace std; 00053 00054 /***********************************************************************/ 00055 ProfileList::ProfileList() 00056 {} 00057 00058 /***********************************************************************/ 00059 ProfileList::~ProfileList() 00060 { 00061 Globals::sdebug << "\nProfileList::~ProfileList cleanup..."; 00062 vector<Profile*>::iterator iter = list.begin(); 00063 while (iter != list.end()) 00064 { 00065 Profile *profl = *iter; 00066 delete profl; 00067 iter++; 00068 } 00069 list.clear(); 00070 Globals::sdebug << "\nProfileList::~ProfileList done!"; 00071 } 00072 00073 /***********************************************************************/ 00074 void ProfileList::addProfile(Profile* profile) 00075 { 00076 list.push_back(profile); 00077 } 00078 00079 /***********************************************************************/ 00080 void ProfileList::readProfilesFromFile(const char *filename, UserList *ul) 00081 { 00082 char line[READLINE_MAXLEN], *buffer, *tmp; 00083 char *profileName; 00084 uint *userIds, uidCount; 00085 uint profileId, width, height, bitsPerPixel, netkBps, bufferingDelay, refreshRate; 00086 bool color, colorRead; 00087 int profilesCount = 0; 00088 00089 //open file of profiles 00090 ifstream fp (filename, ios::in); 00091 if (! fp.is_open()) 00092 { 00093 cerr << "\nProfileList::readProfilesFromFile(): Error opening file '" << filename << "'"; 00094 exit (1); 00095 } 00096 00097 //reset variables used for reading 00098 profileName = NULL; 00099 profileId = width = height = bufferingDelay = 0; 00100 bitsPerPixel = refreshRate = 0; 00101 colorRead = false; 00102 00103 //go to start of profiles 00104 while (! fp.eof() ) 00105 { 00106 fp.getline(line,READLINE_MAXLEN); 00107 if (line != NULL && strncmp(line, "############PROFILES start############", strlen("############PROFILES end############")) == 0) break; 00108 } 00109 00110 //read line by line until end of file 00111 //Attention: maximum line characters is set in Globals.hpp 00112 while (! fp.eof() ) 00113 { 00114 fp.getline (line, READLINE_MAXLEN); 00115 if (line != NULL) 00116 { 00117 if (strncmp(line, "############PROFILES end############", strlen("############PROFILES end############")) == 0) break; 00118 00119 if (line[0] == '#') 00120 { 00121 //ignore comments 00122 } 00123 //look for profilename 00124 else if (line[0] == '[' && line[strlen(line) - 1] == ']') 00125 { 00126 profileName = new char[strlen(line) - 1]; 00127 strncpy(profileName, line + 1, strlen(line) - 2); 00128 profileName[strlen(line) - 2] = '\0'; 00129 } 00130 //look for profile-ID 00131 else if ((buffer = strstr(line, "profileId=")) != NULL) 00132 { 00133 profileId = atoi(buffer + 10); 00134 } 00135 //look for userids 00136 else if ((buffer = strstr(line, "uids=")) != NULL) 00137 { 00138 //exract user-IDs 00139 uidCount=0; 00140 userIds = (uint*) malloc(sizeof(uint)); 00141 userIds[uidCount++] = atoi(buffer + 5); 00142 00143 tmp = buffer + 5; 00144 while ((tmp = strstr(tmp, ",")) != NULL) 00145 { 00146 userIds = (uint*) realloc(userIds, sizeof(uint) * (uidCount + 1)); 00147 userIds[uidCount++] = atoi(tmp+1); 00148 tmp = tmp + 1; //this crashes, if behind a komma there is nothing! 00149 } 00150 00151 } 00152 //look for width 00153 else if ((buffer = strstr(line, "width=")) != NULL) 00154 { 00155 width = atoi(buffer + 6); 00156 } 00157 //look for height 00158 else if ((buffer = strstr(line, "height=")) != NULL) 00159 { 00160 height = atoi(buffer + 7); 00161 } 00162 //look for color 00163 else if ((buffer = strstr(line, "color=")) != NULL) 00164 { 00165 if (strncmp(buffer + 6, "yes", 3) == 0) 00166 { 00167 color = true; 00168 colorRead = true; 00169 } 00170 else if (strncmp(buffer + 6, "no", 5) == 0) 00171 { 00172 color = false; 00173 colorRead = true; 00174 } 00175 else 00176 { 00177 cerr << "\nProfileList::readProfilesFromFile(): Wrong parameter value for color: " << line << endl; 00178 exit(1); 00179 } 00180 } 00181 //look for bits-per-pixel 00182 else if ((buffer = strstr(line, "bpp=")) != NULL) 00183 { 00184 bitsPerPixel = atoi(buffer + 4); 00185 } 00186 //look for network bandwidth 00187 else if ((buffer =strstr(line, "netkBps=")) != NULL) 00188 { 00189 netkBps = atoi(buffer + 8); 00190 } 00191 //look for bufferingDelay 00192 else if ((buffer = strstr(line, "bufferingDelay=")) != NULL) 00193 { 00194 bufferingDelay = atoi(buffer + 15); 00195 } 00196 //look for refreshRate 00197 else if ((buffer = strstr(line, "refreshRate=")) != NULL) 00198 { 00199 refreshRate = atoi(buffer + 12); 00200 } 00201 else 00202 { 00203 //Unrecognized parameter ignored 00204 } 00205 } 00206 00207 //if all necessary information was read, add user to list 00208 //and reset variables used for reading 00209 if (profileName != NULL && width != 0 && height != 0 00210 && bitsPerPixel != 0 && netkBps != 0 00211 && bufferingDelay != 0 && colorRead == true && refreshRate != 0) 00212 { 00213 00214 Profile *profile = new Profile(profileId, uidCount, userIds, profileName, width, height, bitsPerPixel, 00215 netkBps, bufferingDelay, color, refreshRate); 00216 addProfile(profile); 00217 profilesCount++; 00218 00219 //add reference for this profile to corresponding users 00220 for (uint i = 0; i < uidCount; i++) 00221 { 00222 ul->getUserById(userIds[i])->addProfile(profile); 00223 } 00224 00225 profileName = NULL; 00226 profileId = width = height = bufferingDelay = 0; 00227 bitsPerPixel = netkBps = refreshRate = 0; 00228 colorRead = false; 00229 } 00230 00231 } 00232 00233 fp.close(); 00234 00235 Globals::sdebug << "\nProfileList::readProfilesFromFile(): read profiles successfully finished with " << profilesCount << "entries!"; 00236 } 00237 00238 /***********************************************************************/ 00239 Profile* ProfileList::getProfileById(const uint profileId) 00240 { 00241 Globals::sdebug << "\nProfileList::getProfileById(): searching for profile " << profileId; 00242 uint i; 00243 for (i=0; i < list.size(); i++) 00244 { 00245 Profile *profile = list[i]; 00246 if (profile->getProfileId() == profileId) return profile; 00247 } 00248 00249 Globals::sdebug << "\nProfileList::getProfileById(): NOT FOUND!!!"; 00250 return NULL; 00251 }