//
// $Id$
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <simgear/debug/logstream.hxx>
#include <stdlib.h>
_error_count( 0 ),
_stale_count( 0 ),
_dt( 0.0 ),
- _error_dt( 0.0 )
+ _error_dt( 0.0 ),
+ last_apt(0)
{
-#if defined(ENABLE_THREADS) && ENABLE_THREADS
+#if defined(ENABLE_THREADS)
thread = new MetarThread(this);
thread->start( 1 );
#endif // ENABLE_THREADS
FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
{
-#if defined(ENABLE_THREADS) && ENABLE_THREADS
+#if defined(ENABLE_THREADS)
thread->cancel();
thread->join();
#endif // ENABLE_THREADS
if ( result.m != NULL ) {
SG_LOG( SG_GENERAL, SG_INFO, "closest station w/ metar = "
<< a->getId());
- last_apt = *a;
+ last_apt = a;
_icao = a->getId();
search_elapsed = 0.0;
fetch_elapsed = 0.0;
latitude->getDoubleValue(),
true );
if ( a ) {
- if ( last_apt.getId() != a->getId()
+ if ( !last_apt || last_apt->getId() != a->getId()
|| fetch_elapsed > same_station_interval_sec )
{
SG_LOG( SG_GENERAL, SG_INFO, "closest station w/ metar = "
<< a->getId());
request_queue.push( a->getId() );
- last_apt = *a;
+ last_apt = a;
_icao = a->getId();
search_elapsed = 0.0;
fetch_elapsed = 0.0;
}
}
-#if defined(ENABLE_THREADS) && ENABLE_THREADS
+#if !defined(ENABLE_THREADS)
// No loader thread running so manually fetch the data
string id = "";
while ( !request_queue.empty() ) {
if (++_stale_count > 10) {
_error_count = 1000;
- throw sg_io_exception("More than 10 stale METAR messages in a row.");
+ throw sg_io_exception("More than 10 stale METAR messages in a row."
+ " Check your system time!");
}
} else
_stale_count = 0;
} catch (const sg_io_exception& e) {
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
<< e.getFormattedMessage().c_str() );
-#if defined(ENABLE_THREADS) && ENABLE_THREADS
+#if defined(ENABLE_THREADS)
if (_error_count++ >= 3) {
SG_LOG( SG_GENERAL, SG_WARN, "Stop fetching data permanently.");
thread->cancel();
}
-#if defined(ENABLE_THREADS) && ENABLE_THREADS
+#if defined(ENABLE_THREADS)
+/**
+ * Ensure mutex is unlocked.
+ */
+void
+metar_cleanup_handler( void* arg )
+{
+ FGMetarEnvironmentCtrl* fetcher = (FGMetarEnvironmentCtrl*) arg;
+ fetcher->mutex.unlock();
+}
+
/**
*
*/
}
pthread_cleanup_pop(1);
}
-
-/**
- * Ensure mutex is unlocked.
- */
-void
-metar_cleanup_handler( void* arg )
-{
- FGMetarEnvironmentCtrl* fetcher = (FGMetarEnvironmentCtrl*) arg;
- fetcher->mutex.unlock();
-}
#endif // ENABLE_THREADS