Logo Search packages:      
Sourcecode: djvulibre version File versions

void DataPool::connect ( const GURL url,
int  start = 0,
int  length = -1 
)

Connects the DataPool# to the specified offsets range of the named url#.

Parameters:
url Name of the file to connect to.
start Beginning of the offsets range which the DataPool# is mapped into
length Length of the offsets range. If negative, the range is assumed to extend up to the end of the file.

Definition at line 903 of file DataPool.cpp.

References add_data(), FCPools::add_pool(), ByteStream::create(), GURL::is_local_file_url(), GURL::name(), ByteStream::read(), and set_eof().

{
   DEBUG_MSG("DataPool::connect(): connecting to a file\n");
   DEBUG_MAKE_INDENT(3);
   
   if (pool)
     G_THROW( ERR_MSG("DataPool.connected1") );
   if (furl.is_local_file_url())
     G_THROW( ERR_MSG("DataPool.connected2") );
   if (start_in<0)
     G_THROW( ERR_MSG("DataPool.neg_start") );


   if (furl_in.name() == "-")
   {
      DEBUG_MSG("This is stdin => just read the data...\n");
      DEBUG_MAKE_INDENT(3);
      char buffer[1024];
      int length;
      GP<ByteStream> gstr=ByteStream::create(furl_in, "rb");
      ByteStream &str=*gstr;
      while((length=str.read(buffer, 1024)))
       add_data(buffer, length);
      set_eof();
   } else if(furl_in.is_local_file_url())
   {
       // Open the stream (just in this function) too see if
       // the file is accessible. In future we will be using 'OpenFiles'
       // to request and release streams
      GP<ByteStream> str=ByteStream::create(furl_in,"rb");
      str->seek(0, SEEK_END);
      int file_size=str->tell();

      furl=furl_in;
      start=start_in;
      length=length_in;
      if (start>=file_size)
        length=0;
      else if (length<0 || start+length>=file_size)
        length=file_size-start;

      eof_flag=true;

      if(str->is_static())
      {
        data=str;
        added_data(0,length);
      }else 
      {
        data=0;
      }

      FCPools::get()->add_pool(furl, this);

      wake_up_all_readers();
   
       // Call every trigger callback
      GCriticalSectionLock lock(&triggers_lock);
      for(GPosition pos=triggers_list;pos;++pos)
      {
       GP<Trigger> t=triggers_list[pos];
       call_callback(t->callback, t->cl_data);
      }
      triggers_list.empty();
   }
}


Generated by  Doxygen 1.6.0   Back to index