openModeller
Version 1.4.0
|
00001 00027 #ifndef _GBIF_OCCURRENCESHH_ 00028 #define _GBIF_OCCURRENCESHH_ 00029 00030 #include <openmodeller/occ_io/OccurrencesReader.hh> 00031 00032 #include <openmodeller/om_defs.hh> 00033 #include <openmodeller/Occurrences.hh> 00034 00035 #include <string> 00036 using std::string; 00037 00038 #include <expat.h> 00039 00040 // Data structure to store relevant information about a TAPIR capabilities response 00041 struct ServiceInfo { 00042 00043 ServiceInfo(): _is_gbif(false), _max_records("") { } 00044 00045 XML_Parser _parser; 00046 bool _is_gbif; // indicates if it's a GBIF WS REST response 00047 std::string _max_records; // maximum number of records that can be returned by the provider 00048 }; 00049 00050 // Data structure to be used by the expat handlers during searches 00051 struct GbifRecordData { 00052 00053 XML_Parser _parser; 00054 OccurrencesPtr _occurrences; 00055 std::string _last_guid; // last guid 00056 Coord _last_lg; // last longitude 00057 Coord _last_lt; // last latitude 00058 int _next; // index of next record to be retrieved 00059 }; 00060 00065 class dllexp GbifOccurrences : public OccurrencesReader 00066 { 00067 public: 00068 00072 static OccurrencesReader * CreateOccurrencesReaderCallback( const char * source, const char * coordSystem ); 00073 00079 GbifOccurrences( const char * url, const char * coordSystem ); 00080 00083 ~GbifOccurrences(); 00084 00088 bool load(); 00089 00095 OccurrencesPtr getPresences( const char *groupId ); 00096 00102 OccurrencesPtr getAbsences( const char *groupId ) { return new OccurrencesImpl( 0 ); } 00103 00104 private: 00105 00106 // Indicates if occurrences were already loaded. 00107 bool _loaded; 00108 00109 // Default record limit to be retrieved from the provider 00110 int _default_limit; 00111 00112 // Maximum number of records that can be returned by the provider 00113 int _provider_limit; 00114 00115 // callback function that will be called by CURL when retrieving header content 00116 static size_t _curl_header_writer( void * ptr, size_t size, size_t nmemb, void * stream ); 00117 00118 // callback function that will be called by CURL when retrieving body content 00119 static size_t _curl_body_writer( void * ptr, size_t size, size_t nmemb, void * stream ); 00120 00121 // Parse service info response 00122 bool _parseServiceInfo( const std::string * xml, ServiceInfo * info ); 00123 00124 // Start element handler for service info parser 00125 static void _startServiceInfoElement( void *data, const char *el, const char **attr ); 00126 00127 // Retrieve records 00128 bool _retrieveRecords( GbifRecordData *data, int limit ); 00129 00130 // Start element handler for search parser 00131 static void _startSearchElement( void *data, const char *el, const char **attr ); 00132 00133 // End element handler for search parser 00134 static void _endSearchElement( void *data, const char *el ); 00135 00136 // Latitude character data handler for TaxonOccurrence element 00137 static void _ltDataHandler( void *data, const char *value, int len ); 00138 00139 // Longitude character data handler for TaxonOccurrence element 00140 static void _lgDataHandler( void *data, const char *value, int len ); 00141 00142 }; 00143 00144 #endif 00145