make it compile under mingw32 --with-curl

This commit is contained in:
Andrzej Rybczak
2009-03-25 23:13:34 +01:00
parent 65f52da949
commit f04472641b
7 changed files with 54 additions and 25 deletions

View File

@@ -75,15 +75,14 @@ dnl =================================
dnl = checking for curl and pthread = dnl = checking for curl and pthread =
dnl ================================= dnl =================================
if test "$curl" = "yes" ; then if test "$curl" = "yes" ; then
AC_CHECK_LIB(pthread, pthread_create, LDFLAGS="$LDFLAGS -lpthread", AC_MSG_ERROR([pthread library is required])) AC_CHECK_HEADERS([pthread.h], AC_CHECK_LIB(pthread, pthread_create, LDFLAGS="$LDFLAGS -lpthread", AC_MSG_ERROR([pthread library is required])), )
AC_CHECK_HEADERS([pthread.h], , AC_MSG_ERROR([missing pthread.h header]))
AC_PATH_PROG(CURL_CONFIG, curl-config) AC_PATH_PROG(CURL_CONFIG, curl-config)
if test "$CURL_CONFIG" != "" ; then if test "$CURL_CONFIG" != "" ; then
CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`" CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`"
AC_CHECK_LIB(curl, curl_easy_init, LDFLAGS="$LDFLAGS `$CURL_CONFIG --libs`", AC_MSG_ERROR([curl library is required])) AC_CHECK_LIB(curl, curl_easy_init, LDFLAGS="$LDFLAGS `$CURL_CONFIG --libs`", AC_MSG_ERROR([curl library is required]))
AC_CHECK_HEADERS([curl/curl.h], , AC_MSG_ERROR([missing curl.h header])) AC_CHECK_HEADERS([curl/curl.h], , AC_MSG_ERROR([missing curl.h header]))
else else
AC_MSG_ERROR([curl-config executable is missing]) AC_CHECK_LIB(curl, curl_easy_init, LDFLAGS="$LDFLAGS -lcurl", AC_MSG_ERROR([curl library is required]))
fi fi
fi fi

View File

@@ -38,9 +38,9 @@ namespace Global
extern size_t MainStartY; extern size_t MainStartY;
extern size_t MainHeight; extern size_t MainHeight;
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_PTHREAD_H
extern pthread_mutex_t CurlLock; extern pthread_mutex_t CurlLock;
# endif # endif // HAVE_PTHREAD_H
extern bool BlockItemListUpdate; extern bool BlockItemListUpdate;

View File

@@ -27,7 +27,9 @@
# else # else
# include <sys/stat.h> # include <sys/stat.h>
# endif // WIN32 # endif // WIN32
# ifdef HAVE_PTHREAD_H
# include <pthread.h> # include <pthread.h>
# endif
# include "curl/curl.h" # include "curl/curl.h"
# include "helpers.h" # include "helpers.h"
#endif #endif
@@ -49,8 +51,12 @@ using std::vector;
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
const std::string Info::Folder = home_folder + "/.ncmpcpp/artists"; const std::string Info::Folder = home_folder + "/.ncmpcpp/artists";
bool Info::ArtistReady = 0; bool Info::ArtistReady = 0;
#ifdef HAVE_PTHREAD_H
pthread_t Info::Downloader = 0; pthread_t Info::Downloader = 0;
#endif #endif // HAVE_PTHREAD_H
#endif // HAVE_CURL_CURL_H
Info *myInfo = new Info; Info *myInfo = new Info;
@@ -71,9 +77,9 @@ std::string Info::Title()
return itsTitle; return itsTitle;
} }
#ifdef HAVE_PTHREAD_H
void Info::Update() void Info::Update()
{ {
# ifdef HAVE_CURL_CURL_H
if (!ArtistReady) if (!ArtistReady)
return; return;
@@ -81,8 +87,8 @@ void Info::Update()
w->Flush(); w->Flush();
Downloader = 0; Downloader = 0;
ArtistReady = 0; ArtistReady = 0;
# endif // HAVE_CURL_CURL_H
} }
#endif // HAVE_PTHREAD_H
void Info::GetSong() void Info::GetSong()
{ {
@@ -121,6 +127,7 @@ void Info::GetArtist()
} }
else else
{ {
# ifdef HAVE_PTHREAD_H
if (Downloader && !ArtistReady) if (Downloader && !ArtistReady)
{ {
ShowMessage("Artist's info is being downloaded..."); ShowMessage("Artist's info is being downloaded...");
@@ -128,6 +135,7 @@ void Info::GetArtist()
} }
else if (ArtistReady) else if (ArtistReady)
Update(); Update();
# endif // HAVE_PTHREAD_H
string *artist = new string(); string *artist = new string();
@@ -148,10 +156,13 @@ void Info::GetArtist()
itsTitle = "Artist's info - " + *artist; itsTitle = "Artist's info - " + *artist;
w->Clear(); w->Clear();
static_cast<Window &>(*w) << "Fetching artist's info..."; static_cast<Window &>(*w) << "Fetching artist's info...";
# ifdef HAVE_PTHREAD_H
if (!Downloader) if (!Downloader)
{
pthread_create(&Downloader, NULL, PrepareArtist, artist); pthread_create(&Downloader, NULL, PrepareArtist, artist);
} # else
PrepareArtist(&artist);
w->Flush();
# endif // HAVE_PTHREAD_H
} }
else else
delete artist; delete artist;

View File

@@ -34,7 +34,9 @@ class Info : public Screen<Scrollpad>
virtual std::string Title(); virtual std::string Title();
# ifdef HAVE_PTHREAD_H
virtual void Update(); virtual void Update();
# endif // HAVE_PTHREAD_H
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed() { } virtual void SpacePressed() { }
@@ -57,7 +59,11 @@ class Info : public Screen<Scrollpad>
static const std::string Folder; static const std::string Folder;
static bool ArtistReady; static bool ArtistReady;
# ifdef HAVE_PTHREAD_H
static pthread_t Downloader; static pthread_t Downloader;
# endif // HAVE_PTHREAD_H
# endif // HAVE_CURL_CURL_H # endif // HAVE_CURL_CURL_H
std::string itsTitle; std::string itsTitle;

View File

@@ -49,15 +49,14 @@ using std::string;
const std::string Lyrics::Folder = home_folder + "/.lyrics"; const std::string Lyrics::Folder = home_folder + "/.lyrics";
bool Lyrics::Reload = 0; bool Lyrics::Reload = 0;
bool Lyrics::Ready = 0;
std::string Lyrics::Filename; std::string Lyrics::Filename;
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_PTHREAD_H
pthread_t Lyrics::Downloader = 0; pthread_t Lyrics::Downloader = 0;
pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER;
#endif // HAVE_PTHREAD_H
bool Lyrics::Ready = 0;
#endif
Lyrics *myLyrics = new Lyrics; Lyrics *myLyrics = new Lyrics;
@@ -75,10 +74,10 @@ void Lyrics::Resize()
void Lyrics::Update() void Lyrics::Update()
{ {
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_PTHREAD_H
if (myLyrics->Ready) if (myLyrics->Ready)
myLyrics->Take(); myLyrics->Take();
# endif // HAVE_CURL_CURL_H # endif // HAVE_PTHREAD_H
if (!Reload) if (!Reload)
return; return;
@@ -98,7 +97,7 @@ void Lyrics::SwitchTo()
} }
else else
{ {
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_PTHREAD_H
if (Downloader && !Ready) if (Downloader && !Ready)
{ {
ShowMessage("Lyrics are being downloaded..."); ShowMessage("Lyrics are being downloaded...");
@@ -109,7 +108,7 @@ void Lyrics::SwitchTo()
Take(); Take();
return; return;
} }
# endif # endif // HAVE_PTHREAD_H
const MPD::Song *s = Reload ? myPlaylist->NowPlayingSong() : myScreen->CurrentSong(); const MPD::Song *s = Reload ? myPlaylist->NowPlayingSong() : myScreen->CurrentSong();
@@ -132,14 +131,14 @@ void Lyrics::SwitchTo()
w->Clear(); w->Clear();
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
static_cast<Window &>(*w) << "Fetching lyrics..."; static_cast<Window &>(*w) << "Fetching lyrics...";
# endif // HAVE_CURL_CURL_H
# ifdef HAVE_PTHREAD_H
if (!Downloader) if (!Downloader)
{
pthread_create(&Downloader, NULL, Get, &itsSong); pthread_create(&Downloader, NULL, Get, &itsSong);
}
# else # else
Get(&itsSong); Get(&itsSong);
w->Flush(); w->Flush();
# endif # endif // HAVE_PTHREAD_H
} }
Reload = 0; Reload = 0;
} }
@@ -190,10 +189,8 @@ void *Lyrics::Get(void *song)
*myLyrics->Main() << line; *myLyrics->Main() << line;
first = 0; first = 0;
} }
# ifdef HAVE_CURL_CURL_H
Ready = 1; Ready = 1;
pthread_exit(NULL); pthread_exit(NULL);
# endif
} }
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
CURLcode code; CURLcode code;
@@ -295,6 +292,7 @@ void Lyrics::Edit()
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
#ifdef HAVE_PTHREAD_H
void Lyrics::Take() void Lyrics::Take()
{ {
if (!Ready) if (!Ready)
@@ -304,6 +302,7 @@ void Lyrics::Take()
Downloader = 0; Downloader = 0;
Ready = 0; Ready = 0;
} }
#endif // HAVE_PTHREAD_H
const char *Lyrics::GetPluginName(int offset) const char *Lyrics::GetPluginName(int offset)
{ {

View File

@@ -26,7 +26,9 @@
#include "screen.h" #include "screen.h"
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
# ifdef HAVE_PTHREAD_H
# include <pthread.h> # include <pthread.h>
# endif
# include "curl/curl.h" # include "curl/curl.h"
#endif #endif
@@ -74,14 +76,20 @@ class Lyrics : public Screen<Scrollpad>
static const std::string Folder; static const std::string Folder;
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
# ifdef HAVE_PTHREAD_H
void Take(); void Take();
# endif // HAVE_PTHREAD_H
static const Plugin *ChoosePlugin(int); static const Plugin *ChoosePlugin(int);
static bool LyricWiki_NotFound(const std::string &); static bool LyricWiki_NotFound(const std::string &);
static bool LyricsPlugin_NotFound(const std::string &); static bool LyricsPlugin_NotFound(const std::string &);
static bool Ready; static bool Ready;
# ifdef HAVE_PTHREAD_H
static pthread_t Downloader; static pthread_t Downloader;
# endif // HAVE_PTHREAD_H
static const char *PluginsList[]; static const char *PluginsList[];
static const Plugin LyricWiki; static const Plugin LyricWiki;

View File

@@ -27,6 +27,12 @@
#include "menu.h" #include "menu.h"
#include "scrollpad.h" #include "scrollpad.h"
#ifndef HAVE_PTHREAD_H
# define pthread_mutex_lock(x);
# define pthread_mutex_unlock(x);
# define pthread_exit(x) return 0;
#endif
using namespace NCurses; using namespace NCurses;
typedef std::pair<std::string, std::string> string_pair; typedef std::pair<std::string, std::string> string_pair;