Back to index

nordugrid-arc-nox  1.1.0~rc6
PayloadFile.h
Go to the documentation of this file.
00001 #ifndef __ARC_PAYLOADFILE_H__
00002 #define __ARC_PAYLOADFILE_H__
00003 
00004 #include <vector>
00005 
00006 #include <arc/message/PayloadRaw.h>
00007 #include <arc/message/PayloadStream.h>
00008 
00009 namespace ARex {
00010 
00013 class PayloadFile: public Arc::PayloadRawInterface {
00014  protected:
00015   /* TODO: use system-independent file access */
00016   int handle_;
00017   char* addr_;
00018   size_t size_; 
00019   size_t start_; 
00020   size_t end_; 
00021   void SetRead(int h,Size_t start,Size_t end);
00022  public:
00025   PayloadFile(const char* filename,Size_t start,Size_t end);
00026   PayloadFile(int h,Size_t start,Size_t end);
00029   //PayloadFile(const char* filename,Size_t size);
00030   virtual ~PayloadFile(void);
00031   virtual char operator[](Size_t pos) const;
00032   virtual char* Content(Size_t pos = -1);
00033   virtual Size_t Size(void) const;
00034   virtual char* Insert(Size_t pos = 0,Size_t size = 0);
00035   virtual char* Insert(const char* s,Size_t pos = 0,Size_t size = -1);
00036   virtual char* Buffer(unsigned int num);
00037   virtual Size_t BufferSize(unsigned int num) const;
00038   virtual Size_t BufferPos(unsigned int num) const;
00039   virtual bool Truncate(Size_t size);
00040 
00041   operator bool(void) { return (handle_ != -1); };
00042   bool operator!(void) { return (handle_ == -1); };
00043 };
00044 
00045 class PayloadBigFile: public Arc::PayloadStream {
00046  private:
00047   static Size_t threshold_;
00048   size_t limit_; 
00049  public:
00051   PayloadBigFile(const char* filename,Size_t start,Size_t end);
00052   PayloadBigFile(int h,Size_t start,Size_t end);
00055   //PayloadBigFile(const char* filename,Size_t size);
00056   virtual ~PayloadBigFile(void);
00057   virtual Size_t Pos(void) const;
00058   virtual Size_t Size(void) const;
00059   virtual Size_t Limit(void) const;
00060   virtual bool Get(char* buf,int& size);
00061 
00062   operator bool(void) { return (handle_ != -1); };
00063   bool operator!(void) { return (handle_ == -1); };
00064   static Size_t Threshold(void) { return threshold_; };
00065   static void Threshold(Size_t t) { if(t > 0) threshold_=t; };
00066 };
00067 
00068 Arc::MessagePayload* newFileRead(const char* filename,Arc::PayloadRawInterface::Size_t start = 0,Arc::PayloadRawInterface::Size_t end = (Arc::PayloadRawInterface::Size_t)(-1));
00069 Arc::MessagePayload* newFileRead(int h,Arc::PayloadRawInterface::Size_t start = 0,Arc::PayloadRawInterface::Size_t end = (Arc::PayloadRawInterface::Size_t)(-1));
00070 
00071 } // namespace ARex
00072 
00073 #endif /* __ARC_PAYLOADFILE_H__ */