Back to index

nordugrid-arc-nox  1.1.0~rc6
DataPoint.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_DATAPOINT_H__
00004 #define __ARC_DATAPOINT_H__
00005 
00006 #include <list>
00007 #include <string>
00008 
00009 #include <arc/DateTime.h>
00010 #include <arc/URL.h>
00011 #include <arc/data/DataStatus.h>
00012 #include <arc/data/FileInfo.h>
00013 #include <arc/loader/Loader.h>
00014 #include <arc/loader/Plugin.h>
00015 
00016 namespace Arc {
00017 
00018   class Logger;
00019   class DataBuffer;
00020   class DataCallback;
00021   class UserConfig;
00022   class XMLNode;
00023 
00025 
00031   class DataPoint
00032     : public Plugin {
00033   public:
00035 
00038     DataPoint(const URL& url, const UserConfig& usercfg);
00039 
00041     virtual ~DataPoint();
00042 
00044     virtual const URL& GetURL() const;
00045 
00047     virtual const UserConfig& GetUserConfig() const;
00048 
00050     virtual std::string str() const;
00051 
00053     virtual operator bool() const;
00054 
00056     virtual bool operator!() const;
00057 
00059 
00064     virtual DataStatus StartReading(DataBuffer& buffer) = 0;
00065 
00067 
00075     virtual DataStatus StartWriting(DataBuffer& buffer,
00076                                     DataCallback *space_cb = NULL) = 0;
00077 
00079 
00083     virtual DataStatus StopReading() = 0;
00084 
00086 
00090     virtual DataStatus StopWriting() = 0;
00091 
00093 
00095     virtual DataStatus Check() = 0;
00096 
00098     virtual DataStatus Remove() = 0;
00099 
00101 
00108     virtual DataStatus ListFiles(std::list<FileInfo>& files,
00109                                  bool long_list = false,
00110                                  bool resolve = false,
00111                                  bool metadata = false) = 0;
00112 
00115 
00116     virtual void ReadOutOfOrder(bool v) = 0;
00117 
00120     virtual bool WriteOutOfOrder() = 0;
00121 
00123 
00126     virtual void SetAdditionalChecks(bool v) = 0;
00127 
00129     virtual bool GetAdditionalChecks() const = 0;
00130 
00132 
00133     virtual void SetSecure(bool v) = 0;
00134 
00136     virtual bool GetSecure() const = 0;
00137 
00140     virtual void Passive(bool v) = 0;
00141 
00144     virtual DataStatus GetFailureReason(void) const;
00145 
00147 
00148     virtual void Range(unsigned long long int start = 0,
00149                        unsigned long long int end = 0) = 0;
00150 
00152 
00155     virtual DataStatus Resolve(bool source) = 0;
00156 
00158 
00159     virtual bool Registered() const = 0;
00160 
00162 
00171     virtual DataStatus PreRegister(bool replication, bool force = false) = 0;
00172 
00174 
00179     virtual DataStatus PostRegister(bool replication) = 0;
00180 
00182 
00187     virtual DataStatus PreUnregister(bool replication) = 0;
00188 
00190 
00194     virtual DataStatus Unregister(bool all) = 0;
00195 
00197     virtual bool CheckSize() const;
00198 
00200     virtual void SetSize(const unsigned long long int val);
00201 
00203     virtual unsigned long long int GetSize() const;
00204 
00206     virtual bool CheckCheckSum() const;
00207 
00209     virtual void SetCheckSum(const std::string& val);
00210 
00212     virtual const std::string& GetCheckSum() const;
00213 
00215     virtual const std::string DefaultCheckSum() const;
00216 
00218     virtual bool CheckCreated() const;
00219 
00221     virtual void SetCreated(const Time& val);
00222 
00224     virtual const Time& GetCreated() const;
00225 
00227     virtual bool CheckValid() const;
00228 
00230     virtual void SetValid(const Time& val);
00231 
00233     virtual const Time& GetValid() const;
00234 
00236     virtual long long int BufSize() const = 0;
00237 
00239     virtual int BufNum() const = 0;
00240 
00242     virtual bool Cache() const;
00243 
00245     virtual bool Local() const = 0;
00246 
00247     // Returns true if file is readonly.
00248     virtual bool ReadOnly() const = 0;
00249 
00251     virtual int GetTries() const;
00252 
00254     virtual void SetTries(const int n);
00255 
00257     virtual void NextTry(void);
00258 
00260     virtual bool IsIndex() const = 0;
00261 
00263     virtual bool AcceptsMeta() = 0;
00264 
00267     virtual bool ProvidesMeta() = 0;
00268 
00270 
00272     virtual void SetMeta(const DataPoint& p);
00273 
00275 
00277     virtual bool CompareMeta(const DataPoint& p) const;
00278 
00280     virtual const URL& CurrentLocation() const = 0;
00281 
00283 
00284     virtual const std::string& CurrentLocationMetadata() const = 0;
00285 
00287 
00289     virtual DataStatus CompareLocationMetadata() const = 0;
00290     
00292 
00294     virtual bool NextLocation() = 0;
00295 
00297     virtual bool LocationValid() const = 0;
00298 
00300     virtual bool HaveLocations() const = 0;
00301 
00303 
00305     virtual DataStatus AddLocation(const URL& url,
00306                                    const std::string& meta) = 0;
00307 
00309     virtual DataStatus RemoveLocation() = 0;
00310 
00312     virtual DataStatus RemoveLocations(const DataPoint& p) = 0;
00313 
00314   protected:
00315     const URL& url;
00316     const UserConfig& usercfg;
00317 
00318     // attributes
00319     unsigned long long int size;
00320     std::string checksum;
00321     Time created;
00322     Time valid;
00323     int triesleft;
00324     DataStatus failure_code; /* filled by callback methods */
00325     bool cache;
00327     std::list<std::string> valid_url_options;
00328 
00329     static Logger logger;
00330   };
00331 
00332   class DataPointLoader
00333     : public Loader {
00334   private:
00335     DataPointLoader();
00336     ~DataPointLoader();
00337     DataPoint* load(const URL& url, const UserConfig& usercfg);
00338     friend class DataHandle;
00339   };
00340 
00341   class DataPointPluginArgument
00342     : public PluginArgument {
00343   public:
00344     DataPointPluginArgument(const URL& url, const UserConfig& usercfg)
00345       : url(url),
00346        usercfg(usercfg) {}
00347     ~DataPointPluginArgument() {}
00348     operator const URL&() {
00349       return url;
00350     }
00351     operator const UserConfig&() {
00352       return usercfg;
00353     }
00354   private:
00355     const URL& url;
00356     const UserConfig& usercfg;
00357   };
00358 
00359 } // namespace Arc
00360 
00361 #endif // __ARC_DATAPOINT_H__