Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 24, 2004, 8:41:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/updater: using pthread as Threader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/src/gui/orxonox_gui_update.cc

    r3271 r3272  
    201201
    202202CURL* OrxonoxGuiUpdate::curlHandle = NULL;
    203 GThread* OrxonoxGuiUpdate::downloadThreadID = NULL;
     203pthread_t* OrxonoxGuiUpdate::downloadThreadID = new pthread_t;
     204bool OrxonoxGuiUpdate::isDownloading = false;
    204205
    205206void* OrxonoxGuiUpdate::download (void* fileInfo)
     
    209210  FileInfo* info = (FileInfo*)fileInfo;
    210211  CURLcode res;
    211   FILE* outfile;
    212212  curlHandle = curl_easy_init();
    213213  char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1];
     
    217217  strcpy (fileOnDisk, info->localRoot);
    218218  strcat (fileOnDisk, info->fileName);
    219 
     219  pthread_t test;
    220220  if(curlHandle)
    221221    {
    222222     
    223       outfile = fopen(fileOnDisk, "w");
     223      info->fileHandle = fopen(fileOnDisk, "w");
    224224
    225225      curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet);
    226       curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, outfile);
     226      curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, info->fileHandle);
    227227      curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteFunc);
    228228      curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, curlReadFunc);
     
    231231      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar);
    232232
    233       if (!downloadThreadID)
     233      if (!isDownloading)
    234234        {
    235235          //! \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);
    239242        }
    240       else
    241         PRINTF(1)("thread already in use\n");
    242       //      res = curl_easy_perform(curlHandle);
    243      
    244       //      fclose(outfile);
    245243    }
    246   //  downloadThreadID = NULL;
    247244  return NULL;
    248245}
    249246void* OrxonoxGuiUpdate::downloadThread(void* fileInfo)
    250247{
    251   //  gdk_threads_enter();
     248  isDownloading = true;
     249
     250  FileInfo* info = (FileInfo*)fileInfo;
    252251  curl_easy_perform(curlHandle);
    253252  if (curlHandle)
    254253    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);
    263256  PRINTF(3)("Closing the downloaded file.\n");
    264   fclose((FILE*)outfile);
    265 }
     257  fclose(info->fileHandle);
     258
     259  isDownloading = false;
     260}
     261
    266262
    267263#ifdef HAVE_GTK2
Note: See TracChangeset for help on using the changeset viewer.