openModeller  Version 1.4.0
TapirOccurrences.hh
Go to the documentation of this file.
00001 
00027 #ifndef _TAPIR_OCCURRENCESHH_
00028 #define _TAPIR_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 CapabilitiesInfo {
00042 
00043   CapabilitiesInfo(): _is_tapir(false), _has_guid(false), _has_name(false),_has_long(false),_has_lat(false),_accepts_any_model(false),_accepts_om_model(false),_accepts_om_template(false),_max_records("") { }
00044 
00045   XML_Parser _parser;
00046   bool _is_tapir; // indicates if it's a TAPIR response
00047   bool _has_guid; // indicates if provider mapped the DarwinCore global unique identifier concept
00048   bool _has_name; // indicates if provider mapped the DarwinCore scientific name concept
00049   bool _has_long; // indicates if provider mapped the DarwinCore longitude concept
00050   bool _has_lat;  // indicates if provider mapped the DarwinCore latitude concept
00051   bool _accepts_any_model; // indicates if provider accepts any output model
00052   bool _accepts_om_model;  // indicates if provider accepts the openModeller output model
00053   bool _accepts_om_template;  // indicates if provider accepts the openModeller query template
00054   std::string _max_records; // maximum number of records that can be returned by the provider
00055 };
00056 
00057 // Data structure to be used by the expat handlers during searches
00058 struct TapirRecordData {
00059 
00060   OccurrencesPtr _occurrences;
00061   int _next; // index of next record to be retrieved
00062 };
00063 
00069 class dllexp TapirOccurrences : public OccurrencesReader
00070 {
00071 public:
00072 
00076   static OccurrencesReader * CreateOccurrencesReaderCallback( const char * source, const char * coordSystem );
00077 
00083   TapirOccurrences( const char * url, const char * coordSystem );
00084 
00087   ~TapirOccurrences();
00088 
00092   bool load();
00093 
00099   OccurrencesPtr getPresences( const char *groupId );
00100 
00106   OccurrencesPtr getAbsences( const char *groupId ) { return new OccurrencesImpl( 0 ); }
00107 
00108 private:
00109 
00110   // Indicates if occurrences were already loaded.
00111   bool _loaded;
00112 
00113   // Default record limit to be retrieved from the provider
00114   int _default_limit;
00115 
00116   // Maximum number of records that can be returned by the provider
00117   int _provider_limit;
00118 
00119   // callback function that will be called by CURL when retrieving header content
00120   static size_t _curl_header_writer( void * ptr, size_t size, size_t nmemb, void * stream );
00121 
00122   // callback function that will be called by CURL when retrieving body content
00123   static size_t _curl_body_writer( void * ptr, size_t size, size_t nmemb, void * stream );
00124 
00125   // Parse capabilities response
00126   bool _parseCapabilities( const std::string * xml, CapabilitiesInfo * info );
00127 
00128   // Start element handler for capabilities parser
00129   static void _startCapabilitiesElement( void *data, const char *el, const char **attr );
00130 
00131   // Character data handler for maxElementRepetitions element
00132   static void _maxRecordsDataHandler( void *data, const char *value, int len );
00133 
00134   // End element handler for capabilities parser
00135   static void _endCapabilitiesElement( void *data, const char *el );
00136 
00137   // Retrieve records
00138   bool _retrieveRecords( TapirRecordData *data, int limit );
00139 
00140   // Start element handler for search parser
00141   static void _startSearchElement( void *data, const char *el, const char **attr );
00142 
00143 };
00144 
00145 #endif
00146