openModeller  Version 1.5.0
GbifOccurrences.hh
Go to the documentation of this file.
1 
27 #ifndef _GBIF_OCCURRENCESHH_
28 #define _GBIF_OCCURRENCESHH_
29 
31 
32 #include <openmodeller/om_defs.hh>
34 
35 #include <string>
36 using std::string;
37 
38 #include <expat.h>
39 
40 // Data structure to store relevant information about a TAPIR capabilities response
41 struct ServiceInfo {
42 
43  ServiceInfo(): _is_gbif(false), _max_records("") { }
44 
45  XML_Parser _parser;
46  bool _is_gbif; // indicates if it's a GBIF WS REST response
47  std::string _max_records; // maximum number of records that can be returned by the provider
48 };
49 
50 // Data structure to be used by the expat handlers during searches
52 
53  XML_Parser _parser;
55  std::string _last_guid; // last guid
56  Coord _last_lg; // last longitude
57  Coord _last_lt; // last latitude
58  int _next; // index of next record to be retrieved
59 };
60 
65 class dllexp GbifOccurrences : public OccurrencesReader
66 {
67 public:
68 
72  static OccurrencesReader * CreateOccurrencesReaderCallback( const char * source, const char * coordSystem );
73 
79  GbifOccurrences( const char * url, const char * coordSystem );
80 
83  ~GbifOccurrences();
84 
88  bool load();
89 
95  OccurrencesPtr getPresences( const char *groupId );
96 
102  OccurrencesPtr getAbsences( const char *groupId ) { return new OccurrencesImpl( 0 ); }
103 
104 private:
105 
106  // Indicates if occurrences were already loaded.
107  bool _loaded;
108 
109  // Default record limit to be retrieved from the provider
111 
112  // Maximum number of records that can be returned by the provider
114 
115  // callback function that will be called by CURL when retrieving header content
116  static size_t _curl_header_writer( void * ptr, size_t size, size_t nmemb, void * stream );
117 
118  // callback function that will be called by CURL when retrieving body content
119  static size_t _curl_body_writer( void * ptr, size_t size, size_t nmemb, void * stream );
120 
121  // Parse service info response
122  bool _parseServiceInfo( const std::string * xml, ServiceInfo * info );
123 
124  // Start element handler for service info parser
125  static void _startServiceInfoElement( void *data, const char *el, const char **attr );
126 
127  // Retrieve records
128  bool _retrieveRecords( GbifRecordData *data, int limit );
129 
130  // Start element handler for search parser
131  static void _startSearchElement( void *data, const char *el, const char **attr );
132 
133  // End element handler for search parser
134  static void _endSearchElement( void *data, const char *el );
135 
136  // Latitude character data handler for TaxonOccurrence element
137  static void _ltDataHandler( void *data, const char *value, int len );
138 
139  // Longitude character data handler for TaxonOccurrence element
140  static void _lgDataHandler( void *data, const char *value, int len );
141 
142 };
143 
144 #endif
145 
std::string _max_records
std::string _last_guid
virtual OccurrencesPtr getPresences(const char *groupId)
virtual bool load()=0
OccurrencesPtr getAbsences(const char *groupId)
double Coord
Type of map coordinates.
Definition: om_defs.hh:38
XML_Parser _parser
XML_Parser _parser
OccurrencesPtr _occurrences