2
//C- -------------------------------------------------------------------
4
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
5
//C- Copyright (c) 2001 AT&T
7
//C- This software is subject to, and may be distributed under, the
8
//C- GNU General Public License, either Version 2 of the license,
9
//C- or (at your option) any later version. The license should have
10
//C- accompanied the software or you may obtain a copy of the license
11
//C- from the Free Software Foundation at http://www.fsf.org .
13
//C- This program is distributed in the hope that it will be useful,
14
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
//C- GNU General Public License for more details.
18
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19
//C- Lizardtech Software. Lizardtech Software has authorized us to
20
//C- replace the original DjVu(r) Reference Library notice by the following
21
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
23
//C- ------------------------------------------------------------------
24
//C- | DjVu (r) Reference Library (v. 3.5)
25
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27
//C- | 6,058,214 and patents pending.
29
//C- | This software is subject to, and may be distributed under, the
30
//C- | GNU General Public License, either Version 2 of the license,
31
//C- | or (at your option) any later version. The license should have
32
//C- | accompanied the software or you may obtain a copy of the license
33
//C- | from the Free Software Foundation at http://www.fsf.org .
35
//C- | The computer code originally released by LizardTech under this
36
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37
//C- | ORIGINAL CODE." Subject to any third party intellectual property
38
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42
//C- | General Public License. This grant only confers the right to
43
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44
//C- | the extent such infringement is reasonably necessary to enable
45
//C- | recipient to make, have made, practice, sell, or otherwise dispose
46
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47
//C- | any greater extent that may be necessary to utilize further
48
//C- | modifications or combinations.
50
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54
//C- +------------------------------------------------------------------
60
# pragma implementation
63
/** This file impliments the DjVuProgressTask elements. The memory
64
functions are implimented in a separate file, because only the memory
65
functions should be compiled with out overloading of the memory functions.
69
#ifdef NEED_DJVU_PROGRESS
70
#include "DjVuGlobal.h"
73
// ----------------------------------------
77
#include "GException.h"
78
#include "GContainer.h"
86
class DjVuProgressTask::Data : public GPEnabled
89
djvu_progress_callback *callback;
90
DjVuProgressTask *head;
92
unsigned long lastsigdate;
93
Data(djvu_progress_callback *_callback):
94
callback(_callback), head(0), gtask(0), lastsigdate(0) {}
98
static GPMap<void *,DjVuProgressTask::Data> &
101
static GPMap<void *,DjVuProgressTask::Data> xmap;
105
djvu_progress_callback *
106
DjVuProgressTask::set_callback(djvu_progress_callback *_callback)
108
djvu_progress_callback *retval=0;
111
GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
112
void *threadID=GThread::current();
113
if(map.contains(threadID))
115
DjVuProgressTask::Data &data=*(map[threadID]);
116
retval=data.callback;
117
data.callback=_callback;
123
map[threadID]=new Data(_callback);
127
GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
128
void *threadID=GThread::current();
129
if(map.contains(threadID))
131
DjVuProgressTask::Data &data=*(map[threadID]);
132
retval=data.callback;
143
DjVuProgressTask::DjVuProgressTask(const char *xtask,int nsteps)
144
: task(xtask),parent(0), nsteps(nsteps), runtostep(0), gdata(0), data(0)
148
GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
149
void *threadID=GThread::current();
150
if(map.contains(threadID))
153
Data &d=*(data=((*(GP<Data> *)gdata)=map[threadID]));
156
unsigned long curdate = GOS::ticks();
159
d.lastsigdate = curdate + INITIAL;
167
DjVuProgressTask::~DjVuProgressTask()
169
if (data && data->callback)
171
if (data->head != this)
172
G_THROW( ERR_MSG("DjVuGlobal.not_compatible") );
176
unsigned long curdate = GOS::ticks();
177
if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, curdate-startdate))
179
G_THROW("INTERRUPT");
183
delete (GP<Data> *)gdata;
187
DjVuProgressTask::run(int tostep)
192
if ((data->callback)&&(tostep>runtostep))
194
unsigned long curdate = GOS::ticks();
195
if (curdate > data->lastsigdate + INTERVAL)
196
signal(curdate, curdate);
203
DjVuProgressTask::signal(unsigned long curdate, unsigned long estdate)
205
int inprogress = runtostep;
206
if (inprogress > nsteps)
210
const unsigned long enddate = startdate+
211
(unsigned long)(((float)(estdate-startdate) * (float)nsteps) / (float)inprogress);
214
parent->signal(curdate, enddate);
216
else if (data && data->callback && curdate<enddate)
218
if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, enddate-startdate))
220
G_THROW("INTERRUPT");
222
data->lastsigdate = curdate;
229
djvu_progress_callback *
230
djvu_set_progress_callback( djvu_progress_callback *callback )
232
return DjVuProgressTask::set_callback(callback);
235
int djvu_supports_progress_callback(void) {return 1;}
239
#ifndef HAS_DJVU_PROGRESS_TYPEDEF
242
void *djvu_set_progress_callback(void *);
243
int djvu_supports_progress_callback(void);
245
void *djvu_set_progress_callback(void *) { return 0; }
246
int djvu_supports_progress_callback(void) {return 0;}
248
int djvu_supports_progress_callback(void) {return 0;}
249
djvu_progress_callback *
250
djvu_set_progress_callback( djvu_progress_callback *) { return 0; }