• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

DjVuGlobal.cpp

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: DjVuGlobal.cpp,v 1.7 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifdef HAVE_CONFIG_H
00058 # include "config.h"
00059 #endif
00060 #if NEED_GNUG_PRAGMAS
00061 # pragma implementation
00062 #endif
00063 
00070 #ifdef NEED_DJVU_PROGRESS
00071 #include "DjVuGlobal.h"
00072 
00073 
00074 // ----------------------------------------
00075 
00076 #include "GOS.h"
00077 #include "GThreads.h"
00078 #include "GException.h"
00079 #include "GContainer.h"
00080 #include <stdlib.h>
00081 #include <stdio.h>
00082 #include <string.h>
00083 
00084 #define INITIAL  500
00085 #define INTERVAL 250
00086 
00087 class DjVuProgressTask::Data : public GPEnabled
00088 {
00089 public:
00090   djvu_progress_callback *callback;
00091   DjVuProgressTask *head;
00092   const char *gtask;
00093   unsigned long lastsigdate;
00094   Data(djvu_progress_callback *_callback):
00095     callback(_callback), head(0), gtask(0), lastsigdate(0) {}
00096 };
00097 
00098   
00099 static GPMap<void *,DjVuProgressTask::Data> &
00100 get_map(void)
00101 {
00102   static GPMap<void *,DjVuProgressTask::Data> xmap;
00103   return xmap;
00104 }
00105 
00106 djvu_progress_callback *
00107 DjVuProgressTask::set_callback(djvu_progress_callback *_callback)
00108 { 
00109   djvu_progress_callback *retval=0;
00110   if(_callback)
00111   {
00112     GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
00113     void *threadID=GThread::current();
00114     if(map.contains(threadID))
00115     {
00116       DjVuProgressTask::Data &data=*(map[threadID]);
00117       retval=data.callback;
00118       data.callback=_callback;
00119       data.head=0;
00120       data.gtask=0;
00121       data.lastsigdate=0;
00122     }else
00123     {
00124       map[threadID]=new Data(_callback);
00125     }
00126   }else
00127   {
00128     GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
00129     void *threadID=GThread::current();
00130     if(map.contains(threadID))
00131     {
00132       DjVuProgressTask::Data &data=*(map[threadID]);
00133       retval=data.callback;
00134       data.callback=0;
00135       data.head=0;
00136       data.gtask=0;
00137       data.lastsigdate=0;
00138       map.del(threadID);
00139     }
00140   }
00141   return retval;
00142 }
00143 
00144 DjVuProgressTask::DjVuProgressTask(const char *xtask,int nsteps)
00145   : task(xtask),parent(0), nsteps(nsteps), runtostep(0), gdata(0), data(0)
00146 {
00147   //  gtask=task;
00148   {
00149     GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
00150     void *threadID=GThread::current();
00151     if(map.contains(threadID))
00152     {
00153       gdata=new GP<Data>;
00154       Data &d=*(data=((*(GP<Data> *)gdata)=map[threadID]));
00155       if(d.callback)
00156       {
00157         unsigned long curdate = GOS::ticks();
00158         startdate = curdate;
00159         if (!d.head)
00160           d.lastsigdate = curdate + INITIAL;
00161         parent = d.head;
00162         d.head = this;
00163       }
00164     }
00165   }
00166 }
00167 
00168 DjVuProgressTask::~DjVuProgressTask()
00169 {
00170   if (data && data->callback)
00171   {
00172     if (data->head != this)
00173       G_THROW( ERR_MSG("DjVuGlobal.not_compatible") );
00174     data->head = parent;
00175     if (!parent)
00176     {
00177       unsigned long curdate = GOS::ticks();
00178       if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, curdate-startdate))
00179       {
00180         G_THROW("INTERRUPT");
00181       }
00182     }
00183   }
00184   delete (GP<Data> *)gdata;
00185 }
00186 
00187 void
00188 DjVuProgressTask::run(int tostep)
00189 {
00190   if(data)
00191   {
00192     data->gtask=task;
00193     if ((data->callback)&&(tostep>runtostep))
00194     {
00195       unsigned long curdate = GOS::ticks();
00196       if (curdate > data->lastsigdate + INTERVAL)
00197         signal(curdate, curdate);
00198       runtostep = tostep;
00199     }
00200   }
00201 }
00202 
00203 void
00204 DjVuProgressTask::signal(unsigned long curdate, unsigned long estdate)
00205 {
00206   int inprogress = runtostep;
00207   if (inprogress > nsteps)
00208     inprogress = nsteps;
00209   if (inprogress > 0)
00210     {
00211       const unsigned long enddate = startdate+
00212         (unsigned long)(((float)(estdate-startdate) * (float)nsteps) / (float)inprogress);
00213       if (parent)
00214       {
00215         parent->signal(curdate, enddate);
00216       }
00217       else if (data && data->callback && curdate<enddate)
00218       {
00219         if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, enddate-startdate))
00220         {
00221           G_THROW("INTERRUPT");
00222         }
00223         data->lastsigdate = curdate;
00224       }
00225     }
00226 }
00227 
00228 // Progress callback
00229 //
00230 djvu_progress_callback *
00231 djvu_set_progress_callback( djvu_progress_callback *callback )
00232 {
00233    return DjVuProgressTask::set_callback(callback);
00234 }
00235 
00236 int djvu_supports_progress_callback(void) {return 1;}
00237 
00238 #else
00239 
00240 #ifndef HAS_DJVU_PROGRESS_TYPEDEF
00241 extern "C"
00242 {
00243   void *djvu_set_progress_callback(void *);
00244   int djvu_supports_progress_callback(void);
00245 }
00246 void *djvu_set_progress_callback(void *) { return 0; }
00247 int djvu_supports_progress_callback(void) {return 0;}
00248 #else
00249 int djvu_supports_progress_callback(void) {return 0;}
00250 djvu_progress_callback *
00251 djvu_set_progress_callback( djvu_progress_callback *) { return 0; }
00252 #endif
00253 
00254 #endif
00255 

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal