Blame libdjvu/DjVuPort.h

Packit df99a1
//C-  -*- C++ -*-
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
Packit df99a1
#ifndef _DJVUPORT_H
Packit df99a1
#define _DJVUPORT_H
Packit df99a1
#ifdef HAVE_CONFIG_H
Packit df99a1
#include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma interface
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
#include "GThreads.h"
Packit df99a1
#include "GURL.h"
Packit df99a1
#include "stddef.h"
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
namespace DJVU {
Packit df99a1
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
class DataPool;
Packit df99a1
Packit df99a1
/** @name DjVuPort.h
Packit df99a1
    Files #"DjVuPort.h"# and #"DjVuPort.cpp"# implement a communication
Packit df99a1
    mechanism between different parties involved in decoding DjVu files.
Packit df99a1
    It should be pretty clear that the creator of \Ref{DjVuDocument} and
Packit df99a1
    \Ref{DjVuFile} would like to receive some information about the progress
Packit df99a1
    of decoding, errors occurred, etc. It may also want to provide source data
Packit df99a1
    for decoders (like it's done in the plugin where the real data is downloaded
Packit df99a1
    from the net and is fed into DjVu decoders).
Packit df99a1
Packit df99a1
    Normally this functionality is implemented by means of callbacks which are
Packit df99a1
    run when a given condition comes true. Unfortunately it's not quite easy
Packit df99a1
    to implement this strategy in our case. The reason is that there may be
Packit df99a1
    more than one "client" working with the same document, and the document
Packit df99a1
    should send the information to each of the clients. This could be done by
Packit df99a1
    means of callback {\em lists}, of course, but we want to achieve more
Packit df99a1
    bulletproof results: we want to be sure that the client that we're about
Packit df99a1
    to contact is still alive, and is not being destroyed by another thread.
Packit df99a1
    Besides, we are going to call these "callbacks" from many places, from
Packit df99a1
    many different classes.  Maintaining multi-thread safe callback lists is
Packit df99a1
    very difficult.
Packit df99a1
Packit df99a1
    Finally, we want to provide some default implementation of these
Packit df99a1
    "callbacks" in the library, which should attempt to process the requests
Packit df99a1
    themselves if they can, and contact the client only if they're unable to
Packit df99a1
    do it (like in the case of \Ref{DjVuPort::request_data}() with local URL
Packit df99a1
    where \Ref{DjVuDocument} can get the data from the hard drive itself not
Packit df99a1
    disturbing the document's creator.
Packit df99a1
Packit df99a1
    Two classes implement a general communication mechanism: \Ref{DjVuPort} and
Packit df99a1
    \Ref{DjVuPortcaster}. Any sender and recipient of requests should be a
Packit df99a1
    subclass of \Ref{DjVuPort}.  \Ref{DjVuPortcaster} maintains a map of
Packit df99a1
    routes between \Ref{DjVuPort}s, which should be configured by somebody
Packit df99a1
    else. Whenever a port wants to send a request, it calls the corresponding
Packit df99a1
    function of \Ref{DjVuPortcaster}, and the portcaster relays the request to
Packit df99a1
    all the destinations that it sees in the internal map.
Packit df99a1
Packit df99a1
    The \Ref{DjVuPortcaster} is responsible for keeping the map up to date by
Packit df99a1
    getting rid of destinations that have been destroyed.  Map updates are
Packit df99a1
    performed from a single place and are serialized by a global monitor.
Packit df99a1
    
Packit df99a1
    @memo DjVu decoder communication mechanism.
Packit df99a1
    @author Andrei Erofeev <eaf@geocities.com>\\
Packit df99a1
            L\'eon Bottou <leonb@research.att.com>
Packit df99a1
*/
Packit df99a1
//@{
Packit df99a1
Packit df99a1
class DjVuPort;
Packit df99a1
class DjVuPortcaster;
Packit df99a1
class DjVuFile;
Packit df99a1
Packit df99a1
/** Base class for notification targets.
Packit df99a1
    #DjVuPort# provides base functionality for classes willing to take part in
Packit df99a1
    sending and receiving messages generated during decoding process.  You
Packit df99a1
    need to derive your class from #DjVuPort# if you want it to be able to
Packit df99a1
    send or receive requests. In addition, for receiving requests you should
Packit df99a1
    override one or more virtual function.
Packit df99a1
Packit df99a1
    {\bf Important remark} --- All ports should be allocated on the heap using
Packit df99a1
    #operator new# and immediately secured using a \Ref{GP} smart pointer.
Packit df99a1
    Ports which are not secured by a smart-pointer are not considered
Packit df99a1
    ``alive'' and never receive notifications! */
Packit df99a1
Packit df99a1
class DJVUAPI DjVuPort : public GPEnabled
Packit df99a1
{
Packit df99a1
public:
Packit df99a1
   DjVuPort();
Packit df99a1
   virtual ~DjVuPort();
Packit df99a1
   static void *operator new (size_t sz);
Packit df99a1
   static void operator delete(void *addr);
Packit df99a1
Packit df99a1
      /**  Use this function to get a copy of the global \Ref{DjVuPortcaster}. */
Packit df99a1
   static DjVuPortcaster *get_portcaster(void);
Packit df99a1
Packit df99a1
      /** Copy constructor. When #DjVuPort#s are copied, the portcaster
Packit df99a1
          copies all incoming and outgoing routes of the original. */
Packit df99a1
   DjVuPort(const DjVuPort & port);
Packit df99a1
Packit df99a1
      /** Copy operator. Similarly to the copy constructor, the portcaster
Packit df99a1
          copies all incoming and outgoing coming routes of the original. */
Packit df99a1
   DjVuPort & operator=(const DjVuPort & port);
Packit df99a1
Packit df99a1
      /** Should return 1 if the called class inherits class #class_name#.
Packit df99a1
	  When a destination receives a request, it can retrieve the pointer
Packit df99a1
	  to the source #DjVuPort#. This virtual function should be able
Packit df99a1
	  to help to identify the source of the request. For example,
Packit df99a1
	  \Ref{DjVuFile} is also derived from #DjVuPort#. In order for
Packit df99a1
	  the receiver to recognize the sender, the \Ref{DjVuFile} should
Packit df99a1
	  override this function to return #TRUE# when the #class_name#
Packit df99a1
	  is either #DjVuPort# or #DjVuFile# */
Packit df99a1
   virtual bool		inherits(const GUTF8String &class_name) const;
Packit df99a1
Packit df99a1
      /** @name Notifications. 
Packit df99a1
          These virtual functions may be overridden by the subclasses
Packit df99a1
          of #DjVuPort#.  They are called by the \Ref{DjVuPortcaster}
Packit df99a1
          when the port is alive and when there is a route between the 
Packit df99a1
          source of the notification and this port. */
Packit df99a1
      //@{
Packit df99a1
Packit df99a1
      /** This request is issued to request translation of the ID, used
Packit df99a1
	  in an DjVu INCL chunk to a URL, which may be used to request
Packit df99a1
	  data associated with included file. \Ref{DjVuDocument} usually
Packit df99a1
	  intercepts all such requests, and the user doesn't have to
Packit df99a1
	  worry about the translation */
Packit df99a1
   virtual GURL		id_to_url(const DjVuPort * source, const GUTF8String &id;;
Packit df99a1
Packit df99a1
      /** This request is used to get a file corresponding to the
Packit df99a1
	  given ID. \Ref{DjVuDocument} is supposed to intercept it
Packit df99a1
	  and either create a new instance of \Ref{DjVuFile} or reuse
Packit df99a1
	  an existing one from the cache. */
Packit df99a1
   virtual GP<DjVuFile>	id_to_file(const DjVuPort * source, const GUTF8String &id;;
Packit df99a1
Packit df99a1
      /** This request is issued when decoder needs additional data
Packit df99a1
	  for decoding.  Both \Ref{DjVuFile} and \Ref{DjVuDocument} are
Packit df99a1
	  initialized with a URL, not the document data.  As soon as
Packit df99a1
	  they need the data, they call this function, whose responsibility
Packit df99a1
	  is to locate the source of the data basing on the #URL# passed
Packit df99a1
	  and return it back in the form of the \Ref{DataPool}. If this
Packit df99a1
	  particular receiver is unable to fullfil the request, it should
Packit df99a1
	  return #0#. */
Packit df99a1
   virtual GP<DataPool>	request_data(const DjVuPort * source, const GURL & url);
Packit df99a1
Packit df99a1
      /** This notification is sent when an error occurs and the error message
Packit df99a1
	  should be shown to the user.  The receiver should return #0# if it is 
Packit df99a1
          unable to process the request. Otherwise the receiver should return 1. */
Packit df99a1
   virtual bool		notify_error(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
Packit df99a1
      /** This notification is sent to update the decoding status.  The
Packit df99a1
          receiver should return #0# if it is unable to process the
Packit df99a1
          request. Otherwise the receiver should return 1. */
Packit df99a1
   virtual bool		notify_status(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
Packit df99a1
      /** This notification is sent by \Ref{DjVuImage} when it should be
Packit df99a1
	  redrawn. It may be used to implement progressive redisplay.
Packit df99a1
Packit df99a1
	  @param source The sender of the request */
Packit df99a1
   virtual void		notify_redisplay(const class DjVuImage * source);
Packit df99a1
Packit df99a1
      /** This notification is sent by \ref{DjVuImage} when its geometry
Packit df99a1
	  has been changed as a result of decoding. It may be used to
Packit df99a1
	  implement progressive redisplay. */
Packit df99a1
   virtual void		notify_relayout(const class DjVuImage * source);
Packit df99a1
Packit df99a1
      /** This notification is sent when a new chunk has been decoded. */
Packit df99a1
   virtual void		notify_chunk_done(const DjVuPort * source, const GUTF8String &name);
Packit df99a1
Packit df99a1
      /** This notification is sent after the \Ref{DjVuFile} flags have
Packit df99a1
	  been changed. This happens, for example, when:
Packit df99a1
	  \begin{itemize}
Packit df99a1
	    \item Decoding succeeded, failed or just stopped
Packit df99a1
	    \item All data has been received
Packit df99a1
	    \item All included files have been created
Packit df99a1
	  \end{itemize}
Packit df99a1
	  
Packit df99a1
	  @param source \Ref{DjVuFile}, which flags have been changed
Packit df99a1
	  @param set_mask bits, which have been set
Packit df99a1
	  @param clr_mask bits, which have been cleared */
Packit df99a1
   virtual void		notify_file_flags_changed(const class DjVuFile * source,
Packit df99a1
						  long set_mask, long clr_mask);
Packit df99a1
Packit df99a1
      /** This notification is sent after the \Ref{DjVuDocument} flags have
Packit df99a1
	  been changed. This happens, for example, after it receives enough
Packit df99a1
	  data and can determine its structure (#BUNDLED#, #OLD_INDEXED#, etc.).
Packit df99a1
Packit df99a1
	  @param source \Ref{DjVuDocument}, which flags have been changed
Packit df99a1
	  @param set_mask bits, which have been set
Packit df99a1
	  @param clr_mask bits, which have been cleared */
Packit df99a1
   virtual void		notify_doc_flags_changed(const class DjVuDocument * source,
Packit df99a1
						 long set_mask, long clr_mask);
Packit df99a1
   
Packit df99a1
      /** This notification is sent from time to time while decoding is in
Packit df99a1
	  progress. The purpose is obvious: to provide a way to know how much
Packit df99a1
	  is done and how long the decoding will continue.  Argument #done# is
Packit df99a1
	  a number from 0 to 1 reflecting the progress. */
Packit df99a1
   virtual void		notify_decode_progress(const DjVuPort * source, float done);
Packit df99a1
Packit df99a1
      /** This is the standard types for defining what to do in case of errors.
Packit df99a1
          This is only used by some of the subclasses, but it needs to be 
Packit df99a1
          defined here to guarantee all subclasses use the same enum types.
Packit df99a1
          In general, many errors are non recoverable.  Using a setting
Packit df99a1
          other than ABORT may just result in even more errors. */
Packit df99a1
   enum ErrorRecoveryAction {ABORT=0,SKIP_PAGES=1,SKIP_CHUNKS=2,KEEP_ALL=3 }; 
Packit df99a1
      //@}
Packit df99a1
public:
Packit df99a1
   class DjVuPortCorpse;
Packit df99a1
private:
Packit df99a1
   static GCriticalSection	* corpse_lock;
Packit df99a1
   static DjVuPortCorpse	* corpse_head;
Packit df99a1
   static DjVuPortCorpse        * corpse_tail;
Packit df99a1
   static int			corpse_num;
Packit df99a1
};
Packit df99a1
Packit df99a1
/** Simple port.  
Packit df99a1
    An instance of #DjVuSimplePort# is automatically created when you create a
Packit df99a1
    \Ref{DjVuFile} or a \Ref{DjVuDocument} without specifying a port.  This
Packit df99a1
    simple port can retrieve data for local urls (i.e. urls referring to local
Packit df99a1
    files) and display error messages on #stderr#.  All other notifications
Packit df99a1
    are ignored. */
Packit df99a1
Packit df99a1
class DJVUAPI DjVuSimplePort : public DjVuPort
Packit df99a1
{
Packit df99a1
public:
Packit df99a1
      /// Returns 1 if #class_name# is #"DjVuPort"# or #"DjVuSimplePort"#.
Packit df99a1
   virtual bool		inherits(const GUTF8String &class_name) const;
Packit df99a1
Packit df99a1
      /** If #url# is local, it created a \Ref{DataPool}, connects it to the
Packit df99a1
	  file with the given name and returns.  Otherwise returns #0#. */
Packit df99a1
   virtual GP<DataPool>	request_data(const DjVuPort * source, const GURL & url);
Packit df99a1
Packit df99a1
      /// Displays error on #stderr#. Always returns 1.
Packit df99a1
   virtual bool		notify_error(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
   
Packit df99a1
      /// Displays status on #stderr#. Always returns 1.
Packit df99a1
   virtual bool		notify_status(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
/** Memory based port.
Packit df99a1
    This \Ref{DjVuPort} maintains a map associating pseudo urls with data
Packit df99a1
    segments.  It processes the #request_data# notifications according to this
Packit df99a1
    map.  After initializing the port, you should add as many pairs #
Packit df99a1
    pool># as needed need and add a route from a \Ref{DjVuDocument} or
Packit df99a1
    \Ref{DjVuFile} to this port. */
Packit df99a1
Packit df99a1
class DJVUAPI DjVuMemoryPort : public DjVuPort
Packit df99a1
{
Packit df99a1
public:
Packit df99a1
      /// Returns 1 if #class_name# is #"DjVuPort"# or #"DjVuMemoryPort"#
Packit df99a1
   virtual bool		inherits(const GUTF8String &class_name) const;
Packit df99a1
Packit df99a1
      /** If #url# is one of those, that have been added before by means
Packit df99a1
	  of \Ref{add_data}() function, it will return the associated
Packit df99a1
	  \Ref{DataPool}. #ZERO# otherwize. */
Packit df99a1
   virtual GP<DataPool>	request_data(const DjVuPort * source, const GURL & url);
Packit df99a1
Packit df99a1
      /** Adds #<url, pool># pair to the internal map. From now on, if
Packit df99a1
	  somebody asks for data corresponding to the #url#, it will
Packit df99a1
	  be returning the #pool# */
Packit df99a1
   void		add_data(const GURL & url, const GP<DataPool> & pool);
Packit df99a1
private:
Packit df99a1
   GCriticalSection	lock;
Packit df99a1
   GPMap<GURL, DataPool>map;
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/** Maintains associations between ports.
Packit df99a1
    It monitors the status of all ports (have they been destructed yet?),
Packit df99a1
    accepts requests and notifications from them and forwards them to
Packit df99a1
    destinations according to internally maintained map of routes.
Packit df99a1
Packit df99a1
    The caller can modify the route map any way he likes (see
Packit df99a1
    \Ref{add_route}(), \Ref{del_route}(), \Ref{copy_routes}(),
Packit df99a1
    etc. functions). Any port can be either a sender of a message, an
Packit df99a1
    intermediary receiver or a final destination.  
Packit df99a1
Packit df99a1
    When a request is sent, the #DjVuPortcaster# computes the list of
Packit df99a1
    destinations by consulting with the route map.  Notifications are only
Packit df99a1
    sent to ``alive'' ports.  A port is alive if it is referenced by a valid
Packit df99a1
    \Ref{GP} smartpointer.  As a consequence, a port usually becomes alive
Packit df99a1
    after running the constructor (since the returned pointer is then assigned
Packit df99a1
    to a smartpointer) and is no longer alive when the port is destroyed
Packit df99a1
    (because it would not be destroyed if a smartpointer was referencing it).
Packit df99a1
Packit df99a1
    Destination ports are sorted according to their distance from the source.
Packit df99a1
    For example, if port {\bf A} is connected to ports {\bf B} and {\bf C}
Packit df99a1
    directly, and port {\bf B} is connected to {\bf D}, then {\bf B} and {\bf
Packit df99a1
    C} are assumed to be one hop away from {\bf A}, while {\bf D} is two hops
Packit df99a1
    away from {\bf A}.
Packit df99a1
Packit df99a1
    In some cases the requests and notifications are sent to every possible
Packit df99a1
    destination, and the order is not significant (like it is for
Packit df99a1
    \Ref{notify_file_flags_changed}() request). Others should be sent to the closest
Packit df99a1
    destinations first, and only then to the farthest, in case if they have
Packit df99a1
    not been processed by the closest. The examples are \Ref{request_data}(),
Packit df99a1
    \Ref{notify_error}() and \Ref{notify_status}().
Packit df99a1
Packit df99a1
    The user is not expected to create the #DjVuPortcaster# itself. He should
Packit df99a1
    use \Ref{get_portcaster}() global function instead.  */
Packit df99a1
class DJVUAPI DjVuPortcaster
Packit df99a1
{
Packit df99a1
public:
Packit df99a1
      /**  Use this function to get a copy of the global \Ref{DjVuPortcaster}. */
Packit df99a1
   static DjVuPortcaster *get_portcaster(void)
Packit df99a1
    { return DjVuPort::get_portcaster(); } ;
Packit df99a1
Packit df99a1
      /** The default constructor. */
Packit df99a1
   DjVuPortcaster(void);
Packit df99a1
Packit df99a1
   virtual ~DjVuPortcaster(void);
Packit df99a1
Packit df99a1
      /** Removes the specified port from all routes. It will no longer
Packit df99a1
	  be able to receive or generate messages and will be considered
Packit df99a1
    {\bf "dead"} by \Ref{is_port_alive}() function. */
Packit df99a1
   void		del_port(const DjVuPort * port);
Packit df99a1
   
Packit df99a1
      /** Adds route from #src# to #dst#. Whenever a request is
Packit df99a1
	  sent or received by #src#, it will be forwarded to #dst# as well.
Packit df99a1
	  @param src The source
Packit df99a1
	  @param dst The destination */
Packit df99a1
   void		add_route(const DjVuPort *src, DjVuPort *dst);
Packit df99a1
Packit df99a1
      /** The opposite of \Ref{add_route}(). Removes the association
Packit df99a1
	  between #src# and #dst# */
Packit df99a1
   void		del_route(const DjVuPort *src, DjVuPort *dst);
Packit df99a1
Packit df99a1
      /** Copies all incoming and outgoing routes from #src# to
Packit df99a1
	  #dst#. This function should be called when a \Ref{DjVuPort} is
Packit df99a1
	  copied, if you want to preserve the connectivity. */
Packit df99a1
   void		copy_routes(DjVuPort *dst, const DjVuPort *src);
Packit df99a1
Packit df99a1
      /** Returns a smart pointer to the port if #port# is a valid pointer
Packit df99a1
          to an existing #DjVuPort#.  Returns a null pointer otherwise. */
Packit df99a1
   GP<DjVuPort> is_port_alive(DjVuPort *port);
Packit df99a1
Packit df99a1
      /** Assigns one more {\em alias} for the specified \Ref{DjVuPort}.
Packit df99a1
	  {\em Aliases} are names, which can be used later to retrieve this
Packit df99a1
	  \Ref{DjVuPort}, if it still exists. Any \Ref{DjVuPort} may have
Packit df99a1
	  more than one {\em alias}. But every {\em alias} must correspond
Packit df99a1
	  to only one \Ref{DjVuPort}. Thus, if the specified alias is
Packit df99a1
	  already associated with another port, this association will be
Packit df99a1
	  removed. */
Packit df99a1
   void		add_alias(const DjVuPort * port, const GUTF8String &alias);
Packit df99a1
Packit df99a1
      /** Removes all the aliases */
Packit df99a1
   static void		clear_all_aliases(void);
Packit df99a1
Packit df99a1
      /** Removes all aliases associated with the given \Ref{DjVuPort}. */
Packit df99a1
   void		clear_aliases(const DjVuPort * port);
Packit df99a1
Packit df99a1
      /** Returns \Ref{DjVuPort} associated with the given #alias#. If nothing
Packit df99a1
	  is known about name #alias#, or the port associated with it has
Packit df99a1
	  already been destroyed #ZERO# pointer will be returned. */
Packit df99a1
   GP<DjVuPort>	alias_to_port(const GUTF8String &name);
Packit df99a1
Packit df99a1
      /** Returns a list of \Ref{DjVuPort}s with aliases starting with
Packit df99a1
	  #prefix#. If no \Ref{DjVuPort}s have been found, empty
Packit df99a1
	  list is returned. */
Packit df99a1
   GPList<DjVuPort>	prefix_to_ports(const GUTF8String &prefix);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest until one of them returns non-empty \Ref{GURL}. */
Packit df99a1
   virtual GURL		id_to_url(const DjVuPort * source, const GUTF8String &id;;
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest until one of them returns non-zero pointer to
Packit df99a1
	  \Ref{DjVuFile}. */
Packit df99a1
   virtual GP<DjVuFile>	id_to_file(const DjVuPort * source, const GUTF8String &id;;
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest until one of them returns non-zero \Ref{DataPool}. */
Packit df99a1
   virtual GP<DataPool>	request_data(const DjVuPort * source, const GURL & url);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding.
Packit df99a1
	  function in each of the ports from the destination starting from
Packit df99a1
	  the closest until one of them returns 1. */
Packit df99a1
   virtual bool		notify_error(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest until one of them returns 1. */
Packit df99a1
   virtual bool		notify_status(const DjVuPort * source, const GUTF8String &msg;;
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_redisplay(const class DjVuImage * source);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_relayout(const class DjVuImage * source);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_chunk_done(const DjVuPort * source, const GUTF8String &name);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_file_flags_changed(const class DjVuFile * source,
Packit df99a1
						  long set_mask, long clr_mask);
Packit df99a1
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_doc_flags_changed(const class DjVuDocument * source,
Packit df99a1
						 long set_mask, long clr_mask);
Packit df99a1
   
Packit df99a1
      /** Computes destination list for #source# and calls the corresponding
Packit df99a1
	  function in each of the ports from the destination list starting from
Packit df99a1
	  the closest. */
Packit df99a1
   virtual void		notify_decode_progress(const DjVuPort * source, float done);
Packit df99a1
Packit df99a1
private:
Packit df99a1
      // We use these 'void *' to minimize template instantiations.
Packit df99a1
   friend class DjVuPort;
Packit df99a1
   GCriticalSection		map_lock;
Packit df99a1
   GMap<const void *, void *>	route_map;	// GMap<DjVuPort *, GList<DjVuPort *> *>
Packit df99a1
   GMap<const void *, void *>	cont_map;	// GMap<DjVuPort *, DjVuPort *>
Packit df99a1
   GMap<GUTF8String, const void *>	a2p_map;	// GMap<GUTF8String, DjVuPort *>
Packit df99a1
   void add_to_closure(GMap<const void*, void*> & set,
Packit df99a1
                       const DjVuPort *dst, int distance);
Packit df99a1
   void compute_closure(const DjVuPort *src, GPList<DjVuPort> &list,
Packit df99a1
                        bool sorted=false);
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
inline bool
Packit df99a1
DjVuPort::inherits(const GUTF8String &class_name) const
Packit df99a1
{
Packit df99a1
   return (class_name == "DjVuPort");
Packit df99a1
}
Packit df99a1
Packit df99a1
inline bool
Packit df99a1
DjVuSimplePort::inherits(const GUTF8String &class_name) const
Packit df99a1
{
Packit df99a1
   return
Packit df99a1
      (class_name == "DjVuSimplePort") || DjVuPort::inherits(class_name);
Packit df99a1
}
Packit df99a1
Packit df99a1
inline bool
Packit df99a1
DjVuMemoryPort::inherits(const GUTF8String &class_name) const
Packit df99a1
{
Packit df99a1
   return
Packit df99a1
      (class_name == "DjVuMemoryPort") || DjVuPort::inherits(class_name);
Packit df99a1
}
Packit df99a1
Packit df99a1
//@}
Packit df99a1
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
}
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
using namespace DJVU;
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#endif