Logo Search packages:      
Sourcecode: djvulibre version File versions

GP< DataPool > DjVuDocument::request_data ( const DjVuPort source,
const GURL url 
) [virtual]

This request is issued when decoder needs additional data for decoding. Both {DjVuFile} and {DjVuDocument} are initialized with a URL, not the document data. As soon as they need the data, they call this function, whose responsibility is to locate the source of the data basing on the URL# passed and return it back in the form of the {DataPool}. If this particular receiver is unable to fullfil the request, it should return #0#.

Reimplemented from DjVuPort.

Reimplemented in DjVuDocEditor.

Definition at line 1419 of file DjVuDocument.cpp.

References GURL::base(), DataPool::create(), GURL::fname(), GURL::get_string(), and GURL::is_local_file_url().

Referenced by DjVuDocEditor::request_data().

{
   DEBUG_MSG("DjVuDocument::request_data(): seeing if we can do it\n");
   DEBUG_MAKE_INDENT(3);

   if (url==init_url)
     return init_data_pool;

   check(); // Don't put it before 'init_data_pool'

   {
       // See if there is a file in the "UnnamedFiles" list.
       // If it's there, then create an empty DataPool and store its
       // pointer in the list. The "init thread" will eventually
       // do smth with it.
      GCriticalSectionLock lock(&ufiles_lock);
      for(GPosition pos=ufiles_list;pos;++pos)
      {
       GP<UnnamedFile> f=ufiles_list[pos];
       if (f->url==url)
       {
          DEBUG_MSG("Found tmp unnamed DjVuFile. Return empty DataPool\n");
             // Remember the DataPool. We will connect it to the
             // actual data after the document structure becomes known
          f->data_pool=DataPool::create();
          return f->data_pool;
       }
      }
   }

      // Well, the url is not in the "UnnamedFiles" list, but it doesn't
      // mean, that it's not "artificial". Stay alert!
   GP<DataPool> data_pool;
   if (flags & DOC_TYPE_KNOWN)
      switch(doc_type)
      {
       case OLD_BUNDLED:
       {
          if (flags & DOC_DIR_KNOWN)
          {
             DEBUG_MSG("The document is in OLD_BUNDLED format\n");
             if (url.base()!=init_url)
                    G_THROW( ERR_MSG("DjVuDocument.URL_outside") "\t"+url.get_string());
       
             GP<DjVmDir0::FileRec> file=djvm_dir0->get_file(url.fname());
             if (!file)
               {
                 G_THROW( ERR_MSG("DjVuDocument.file_outside") "\t"+url.fname());
               }
             data_pool=DataPool::create(init_data_pool, file->offset, file->size);
          }
          break;
       }
       case BUNDLED:
       {
          if (flags & DOC_DIR_KNOWN)
          {
             DEBUG_MSG("The document is in new BUNDLED format\n");
             if (url.base()!=init_url)
               {
             G_THROW( ERR_MSG("DjVuDocument.URL_outside") "\t"
                   +url.get_string());
               }
       
             GP<DjVmDir::File> file=djvm_dir->id_to_file(url.fname());
             if (!file)
               {
                 G_THROW( ERR_MSG("DjVuDocument.file_outside") "\t"+url.fname());
               }
             data_pool=DataPool::create(init_data_pool, file->offset, file->size);
          }
          break;
       }
       case SINGLE_PAGE:
       case OLD_INDEXED:
       case INDIRECT:
       {
          DEBUG_MSG("The document is in SINGLE_PAGE or OLD_INDEXED or INDIRECT format\n");
          if (flags & DOC_DIR_KNOWN)
             if (doc_type==INDIRECT && !djvm_dir->id_to_file(url.fname()))
                    G_THROW( ERR_MSG("DjVuDocument.URL_outside2") "\t"+url.get_string());
       
          if (url.is_local_file_url())
          {
//           GUTF8String fname=GOS::url_to_filename(url);
//           if (GOS::basename(fname)=="-") fname="-";
             DEBUG_MSG("url=" << url << "\n");

             data_pool=DataPool::create(url);
          }
       }
      }
   return data_pool;
}


Generated by  Doxygen 1.6.0   Back to index