Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3274 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Dec 24, 2004, 11:46:56 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/updater: better check if pthread is not enabled

Location:
orxonox/branches/updater
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/configure

    r3273 r3274  
    69706970
    69716971##checking for pthread
     6972if test x$have_gthread = xyes ; then
    69726973
    69736974for ac_header in pthread.h
     
    71227123done
    71237124
    7124 echo "$as_me:$LINENO: checking for main in -lpthread" >&5
     7125  echo "$as_me:$LINENO: checking for main in -lpthread" >&5
    71257126echo $ECHO_N "checking for main in -lpthread... $ECHO_C" >&6
    71267127if test "${ac_cv_lib_pthread_main+set}" = set; then
     
    71847185fi
    71857186
    7186  if test "$FOUND_pthread" = "yes" ; then
    7187     LIBS="$LIBS -lpthread"
    7188  fi
    7189 
     7187   if test "$FOUND_pthread" = "yes" ; then
     7188      LIBS="$LIBS -lpthread"
     7189   fi
     7190fi
    71907191
    71917192# FIXME: Replace `main' with a function in `-lm':
  • orxonox/branches/updater/configure.ac

    r3273 r3274  
    404404
    405405##checking for pthread
    406 AC_CHECK_HEADERS([pthread.h], pthreadHeader="yes", pthreadHeader="no")
    407 AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
    408  if test "$FOUND_pthread" = "yes" ; then
    409     LIBS="$LIBS -lpthread"
    410  fi
    411 
     406if test x$have_gthread = xyes ; then
     407  AC_CHECK_HEADERS([pthread.h], pthreadHeader="yes", pthreadHeader="no")
     408  AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
     409   if test "$FOUND_pthread" = "yes" ; then
     410      LIBS="$LIBS -lpthread"
     411   fi
     412fi
    412413
    413414# FIXME: Replace `main' with a function in `-lm':
  • orxonox/branches/updater/src/Makefile.in

    r3273 r3274  
    282282          esac; \
    283283        done; \
    284         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/Makefile'; \
     284        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  src/Makefile'; \
    285285        cd $(top_srcdir) && \
    286           $(AUTOMAKE) --gnu  src/Makefile
     286          $(AUTOMAKE) --foreign  src/Makefile
    287287.PRECIOUS: Makefile
    288288Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • orxonox/branches/updater/src/console/Makefile.in

    r3273 r3274  
    201201          esac; \
    202202        done; \
    203         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/console/Makefile'; \
     203        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  src/console/Makefile'; \
    204204        cd $(top_srcdir) && \
    205           $(AUTOMAKE) --gnu  src/console/Makefile
     205          $(AUTOMAKE) --foreign  src/console/Makefile
    206206.PRECIOUS: Makefile
    207207Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • orxonox/branches/updater/src/gui/Makefile.in

    r3273 r3274  
    232232          esac; \
    233233        done; \
    234         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/gui/Makefile'; \
     234        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  src/gui/Makefile'; \
    235235        cd $(top_srcdir) && \
    236           $(AUTOMAKE) --gnu  src/gui/Makefile
     236          $(AUTOMAKE) --foreign  src/gui/Makefile
    237237.PRECIOUS: Makefile
    238238Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • orxonox/branches/updater/src/gui/orxonox_gui_update.cc

    r3273 r3274  
    8181  updateDataBox->fill(updateDataBar);
    8282
    83   updateDataBegin = new Button ("begin Download");
    84   updateDataBegin->connectSignal ("button_press_event", updateDataBar, updateDataFunc);
     83  FileInfo* dataInfo = new FileInfo;
     84  dataInfo->bar = updateDataBar;
     85
     86  updateDataBegin = new Button ("begin.");
     87  dataInfo->stateButton = updateDataBegin;
     88  dataInfo->buttonSignal = updateDataBegin->connectSignal ("button_press_event", dataInfo, updateDataFunc);
    8589  updateDataBox->fill(updateDataBegin);
    8690
     
    145149   \param button The Button, that triggered this event.
    146150*/
    147 gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* bar)
    148 {
    149   FileInfo* info = new FileInfo;
    150 
    151   info->fileName = "02%20orxonox%203.mp3";
    152   info->webRoot  = "http://www.orxonox.ethz.ch/files/";
    153   info->localRoot = "./";
    154   info->Bar = (ProgressBar*)bar;
    155   PRINTF(3)("Preparing to download file %s.\n", info->fileName);
    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   */
     151gint OrxonoxGuiUpdate::updateDataFunc(GtkWidget* w, GdkEventKey* event, void* info)
     152{
     153  FileInfo* dataInfo = (FileInfo*)info;
     154
     155  dataInfo->fileName = "02%20orxonox%203.mp3";
     156  dataInfo->webRoot  = "http://www.orxonox.ethz.ch/files/";
     157  dataInfo->localRoot = "./";
     158  PRINTF(3)("Preparing to download file %s.\n", dataInfo->fileName);
     159  download (dataInfo);
    166160}
    167161
     
    196190  Bar->setProgress(progress);
    197191  Bar->setTotalSize(totalSize);
     192#ifdef HAVE_GTK2
     193#ifndef HAVE_PTHREAD_H
     194  while(gtk_events_pending()) gtk_main_iteration();
     195#endif
     196#endif
    198197  return 0;
    199 
    200 }
    201 
    202 #ifdef HAVE_CURL
     198}
     199
    203200CURL* OrxonoxGuiUpdate::curlHandle = NULL;
    204 #endif /* HAVE_CURL */
    205201
    206202#ifdef HAVE_PTHREAD_H
     
    209205bool OrxonoxGuiUpdate::isDownloading = false;
    210206
    211 void* OrxonoxGuiUpdate::download (void* fileInfo)
    212 {
    213  
     207bool OrxonoxGuiUpdate::download (void* fileInfo)
     208{
     209  if (isDownloading)
     210    {
     211      PRINTF(2)("unable to Download. already getting some file\n");
     212      return false;
     213    }
    214214  PRINTF(3)("Downloading.\n");
    215215  FileInfo* info = (FileInfo*)fileInfo;
     
    227227     
    228228      info->fileHandle = fopen(fileOnDisk, "w");
    229 
     229     
    230230      curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet);
    231231      curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, info->fileHandle);
     
    234234      curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, FALSE);
    235235      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION, curlProgressFunc);
    236       curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar);
     236      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->bar);
    237237
    238238      if (!isDownloading)
     
    241241#ifdef HAVE_PTHREAD_H
    242242          pthread_create(downloadThreadID, NULL, downloadThread, info);
     243
     244          pthread_t finish;
     245          pthread_create(&finish, NULL, downloadThreadFinished, info); 
    243246#else
    244247          downloadThread(info);
     248          downloadThreadFinished(info);
    245249#endif /* HAVE_PTHREAD_H */
    246250         
    247           //      else
    248           //    PRINTF(1)("thread already in use\n");
    249251          //      res = curl_easy_perform(curlHandle);
    250252         
    251253          //      fclose(outfile);
    252254        }
     255      else
     256        PRINTF(1)("thread already in use\n");
     257
    253258    }
    254   return NULL;
     259  return true;
    255260}
    256261void* OrxonoxGuiUpdate::downloadThread(void* fileInfo)
    257262{
     263  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
     264  gdk_threads_enter();
    258265  isDownloading = true;
    259 
    260266  FileInfo* info = (FileInfo*)fileInfo;
     267  info->stateButton->disconnectSignal(info->buttonSignal);
     268  info->buttonSignal = info->stateButton->connectSignal("button_press_event", info, cancelDownload);
     269  info->stateButton->setTitle("cancel");
     270  gdk_threads_leave();
     271  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
     272
    261273  curl_easy_perform(curlHandle);
     274 
     275}
     276
     277void* OrxonoxGuiUpdate::downloadThreadFinished(void* fileInfo)
     278{
     279  FileInfo* info = (FileInfo*)fileInfo;
     280#ifdef HAVE_PTHREAD_H
     281  pthread_join (*downloadThreadID, NULL);
     282#endif /* HAVE_PTHREAD_H */
     283  gdk_threads_enter();
    262284  if (curlHandle)
    263285    curl_easy_cleanup(curlHandle);
    264 #ifdef HAVE_PTHREAD_H
    265   pthread_join(*downloadThreadID, NULL);
    266 #endif /* HAVE_PTHREAD_H */
     286 
    267287  PRINTF(3)("Closing the downloaded file.\n");
    268288  fclose(info->fileHandle);
    269289
     290  if (isDownloading)
     291    info->stateButton->setTitle("go on");
     292  //  else
     293  //    info->stateButton->setTitle("done");
     294  info->stateButton->disconnectSignal(info->buttonSignal);
     295  info->buttonSignal = info->stateButton->connectSignal("button_press_event", info, updateDataFunc);
    270296  isDownloading = false;
    271 }
    272 
     297  gdk_threads_leave();
     298
     299}
    273300
    274301#ifdef HAVE_GTK2
    275302gint OrxonoxGuiUpdate::cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar)
    276303{
    277   //  curl_easy_cleanup(curlHandle);
    278   //  curlHandle = NULL;
     304#ifdef HAVE_PTHREAD_H
     305  pthread_cancel(*downloadThreadID);
     306#else
     307  PRINTF(2)("Cannot cancle the Downloading process until after this File, because no threading was enabled");
     308#endif /* HAVE_PTHREAD_H*/
    279309}
    280310#endif /* HAVE_GTK2 */
  • orxonox/branches/updater/src/gui/orxonox_gui_update.h

    r3273 r3274  
    4242 
    4343#ifdef HAVE_GTK2
    44   static gint updateDataFunc (GtkWidget* w, GdkEventKey* event, void* bar);
    45   static gint updateSourceFunc (GtkWidget* w, GdkEventKey* event, void* bar);
     44  static gint updateDataFunc (GtkWidget* w, GdkEventKey* event, void* info);
     45  static gint updateSourceFunc (GtkWidget* w, GdkEventKey* event, void* info);
    4646#endif /* HAVE_GTK2 */
    4747
     
    5555    FILE* fileHandle;     //!< A fileHandler.
    5656
    57     ProgressBar* Bar;     //!< The ProgressBar, that sould be updated.
     57    Button* stateButton;  //!< A button that shows either start or cancel;
     58    long int buttonSignal;//!< The Signal of the stateButton.
     59    ProgressBar* bar;     //!< The ProgressBar, that sould be updated.
    5860  };
    5961
     
    7173  static bool isDownloading;
    7274
    73   static void* download (void* fileInfo);
     75  static bool download (void* fileInfo);
    7476  static void* downloadThread (void* fileInfo);
    75   static void* downloadThreadFinished(void* outfile);
     77  static void* downloadThreadFinished(void* fileInfo);
    7678
    7779 
  • orxonox/branches/updater/src/importer/Makefile.in

    r3273 r3274  
    208208          esac; \
    209209        done; \
    210         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/importer/Makefile'; \
     210        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  src/importer/Makefile'; \
    211211        cd $(top_srcdir) && \
    212           $(AUTOMAKE) --gnu  src/importer/Makefile
     212          $(AUTOMAKE) --foreign  src/importer/Makefile
    213213.PRECIOUS: Makefile
    214214Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
Note: See TracChangeset for help on using the changeset viewer.