Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 24, 2004, 6:29:38 PM (21 years ago)
Author:
bensch
Message:

orxonox/branches/updater: threads are cool after all. trying again.

File:
1 edited

Legend:

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

    r3270 r3271  
    9090#ifdef HAVE_GTK2
    9191  updateDataWindowButton->connectSignal("button_press_event", updateDataWindow, Window::windowOpen);
    92   updateDataWindow->connectSignal("destroy", updateDataWindow, cancelDownload);
    93   updateDataWindow->connectSignal("delete_event", updateDataWindow, cancelDownload);
     92  updateDataWindow->connectSignal("destroy", updateDataWindow, Window::windowClose);
     93  updateDataWindow->connectSignal("delete_event", updateDataWindow, Window::windowClose);
    9494#endif /* HAVE_GTK2 */
    9595
     
    149149  FileInfo* info = new FileInfo;
    150150
    151   info->fileName = "03%20orxonox%203'.mp3";
     151  info->fileName = "02%20orxonox%203.mp3";
    152152  info->webRoot  = "http://www.orxonox.ethz.ch/files/";
    153153  info->localRoot = "./";
    154154  info->Bar = (ProgressBar*)bar;
    155155  PRINTF(3)("Preparing to download file %s.\n", info->fileName);
    156   download(info);
     156  download (info);
     157  /*
     158  if (downloadThreadID == NULL)
     159    {
     160      if ( (downloadThreadID =g_thread_create(&downloadThread, info, TRUE, NULL)) == 0 )
     161        PRINTF(1)("can't create the thread");
     162    }
     163  else
     164  PRINTF(1)("thread already in use\n");
     165  */
    157166}
    158167
     
    188197  Bar->setTotalSize(totalSize);
    189198  return 0;
     199
    190200}
    191201
    192202CURL* OrxonoxGuiUpdate::curlHandle = NULL;
     203GThread* OrxonoxGuiUpdate::downloadThreadID = NULL;
    193204
    194205void* OrxonoxGuiUpdate::download (void* fileInfo)
     
    209220  if(curlHandle)
    210221    {
     222     
    211223      outfile = fopen(fileOnDisk, "w");
    212      
     224
    213225      curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet);
    214226      curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, outfile);
     
    218230      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION, curlProgressFunc);
    219231      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar);
     232
     233      if (!downloadThreadID)
     234        {
     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);
     239        }
     240      else
     241        PRINTF(1)("thread already in use\n");
     242      //      res = curl_easy_perform(curlHandle);
    220243     
    221       res = curl_easy_perform(curlHandle);
    222      
    223       fclose(outfile);
    224       if (curlHandle)
    225         curl_easy_cleanup(curlHandle);
     244      //      fclose(outfile);
    226245    }
     246  //  downloadThreadID = NULL;
    227247  return NULL;
     248}
     249void* OrxonoxGuiUpdate::downloadThread(void* fileInfo)
     250{
     251  //  gdk_threads_enter();
     252  curl_easy_perform(curlHandle);
     253  if (curlHandle)
     254    curl_easy_cleanup(curlHandle);
     255  gdk_threads_leave();
     256  downloadThreadID = NULL;
     257  //  g_thread_exit (NULL);
     258}
     259
     260void* OrxonoxGuiUpdate::downloadThreadFinished(void* outfile)
     261{
     262  g_thread_join(downloadThreadID);
     263  PRINTF(3)("Closing the downloaded file.\n");
     264  fclose((FILE*)outfile);
    228265}
    229266
Note: See TracChangeset for help on using the changeset viewer.