Changeset 3272 in orxonox.OLD for orxonox/branches/updater/src
- Timestamp:
- Dec 24, 2004, 8:41:18 PM (20 years ago)
- Location:
- orxonox/branches/updater/src/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/updater/src/gui/orxonox_gui_update.cc
r3271 r3272 201 201 202 202 CURL* OrxonoxGuiUpdate::curlHandle = NULL; 203 GThread* OrxonoxGuiUpdate::downloadThreadID = NULL; 203 pthread_t* OrxonoxGuiUpdate::downloadThreadID = new pthread_t; 204 bool OrxonoxGuiUpdate::isDownloading = false; 204 205 205 206 void* OrxonoxGuiUpdate::download (void* fileInfo) … … 209 210 FileInfo* info = (FileInfo*)fileInfo; 210 211 CURLcode res; 211 FILE* outfile;212 212 curlHandle = curl_easy_init(); 213 213 char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1]; … … 217 217 strcpy (fileOnDisk, info->localRoot); 218 218 strcat (fileOnDisk, info->fileName); 219 219 pthread_t test; 220 220 if(curlHandle) 221 221 { 222 222 223 outfile = fopen(fileOnDisk, "w");223 info->fileHandle = fopen(fileOnDisk, "w"); 224 224 225 225 curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet); 226 curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, outfile);226 curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, info->fileHandle); 227 227 curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteFunc); 228 228 curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, curlReadFunc); … … 231 231 curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar); 232 232 233 if (! downloadThreadID)233 if (!isDownloading) 234 234 { 235 235 //! \todo check if threads really were created. 236 downloadThreadID = g_thread_create(&downloadThread, info, TRUE, NULL); 237 238 g_thread_create(&downloadThreadFinished, outfile, TRUE, NULL); 236 pthread_create(downloadThreadID, NULL, downloadThread, info); 237 // else 238 // PRINTF(1)("thread already in use\n"); 239 // res = curl_easy_perform(curlHandle); 240 241 // fclose(outfile); 239 242 } 240 else241 PRINTF(1)("thread already in use\n");242 // res = curl_easy_perform(curlHandle);243 244 // fclose(outfile);245 243 } 246 // downloadThreadID = NULL;247 244 return NULL; 248 245 } 249 246 void* OrxonoxGuiUpdate::downloadThread(void* fileInfo) 250 247 { 251 // gdk_threads_enter(); 248 isDownloading = true; 249 250 FileInfo* info = (FileInfo*)fileInfo; 252 251 curl_easy_perform(curlHandle); 253 252 if (curlHandle) 254 253 curl_easy_cleanup(curlHandle); 255 gdk_threads_leave(); 256 downloadThreadID = NULL; 257 // g_thread_exit (NULL); 258 } 259 260 void* OrxonoxGuiUpdate::downloadThreadFinished(void* outfile) 261 { 262 g_thread_join(downloadThreadID); 254 255 pthread_join(*downloadThreadID, NULL); 263 256 PRINTF(3)("Closing the downloaded file.\n"); 264 fclose((FILE*)outfile); 265 } 257 fclose(info->fileHandle); 258 259 isDownloading = false; 260 } 261 266 262 267 263 #ifdef HAVE_GTK2 -
orxonox/branches/updater/src/gui/orxonox_gui_update.h
r3271 r3272 14 14 #include <curl/easy.h> 15 15 #endif /* HAVE_CURL */ 16 #include <pthread.h> 16 17 using namespace std; 17 18 … … 50 51 char* webRoot; //!< The Root of the File on The Web 51 52 char* localRoot; //!< The Root directory to put the files on the local disk. 53 FILE* fileHandle; //!< A fileHandler. 52 54 53 55 ProgressBar* Bar; //!< The ProgressBar, that sould be updated. … … 62 64 static gint cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar); 63 65 #endif /* HAVE_GTK2 */ 64 static GThread* downloadThreadID; 66 static pthread_t* downloadThreadID; 67 static bool isDownloading; 68 65 69 static void* download (void* fileInfo); 66 70 static void* downloadThread (void* fileInfo);
Note: See TracChangeset
for help on using the changeset viewer.