~ubuntu-branches/ubuntu/oneiric/djvulibre/oneiric

« back to all changes in this revision

Viewing changes to .pc/debian-changes-3.5.24-8/libdjvu/DjVuGlobal.cpp

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2011-06-22 11:48:22 UTC
  • mfrom: (12.2.20 sid)
  • Revision ID: package-import@ubuntu.com-20110622114822-fmb095f2y3ehozva
Tags: 3.5.24-8
ddjvu_anno_get_xmp consistent prototype vs implementation (closes: #613547)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//C-  -*- C++ -*-
 
2
//C- -------------------------------------------------------------------
 
3
//C- DjVuLibre-3.5
 
4
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
 
5
//C- Copyright (c) 2001  AT&T
 
6
//C-
 
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 .
 
12
//C-
 
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.
 
17
//C- 
 
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):
 
22
//C-
 
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.
 
28
//C- |
 
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 .
 
34
//C- |
 
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.
 
49
//C- |
 
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- +------------------------------------------------------------------
 
55
 
 
56
#ifdef HAVE_CONFIG_H
 
57
# include "config.h"
 
58
#endif
 
59
#if NEED_GNUG_PRAGMAS
 
60
# pragma implementation
 
61
#endif
 
62
 
 
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.
 
66
 */
 
67
  
 
68
 
 
69
#ifdef NEED_DJVU_PROGRESS
 
70
#include "DjVuGlobal.h"
 
71
 
 
72
 
 
73
// ----------------------------------------
 
74
 
 
75
#include "GOS.h"
 
76
#include "GThreads.h"
 
77
#include "GException.h"
 
78
#include "GContainer.h"
 
79
#include <stdlib.h>
 
80
#include <stdio.h>
 
81
#include <string.h>
 
82
 
 
83
#define INITIAL  500
 
84
#define INTERVAL 250
 
85
 
 
86
class DjVuProgressTask::Data : public GPEnabled
 
87
{
 
88
public:
 
89
  djvu_progress_callback *callback;
 
90
  DjVuProgressTask *head;
 
91
  const char *gtask;
 
92
  unsigned long lastsigdate;
 
93
  Data(djvu_progress_callback *_callback):
 
94
    callback(_callback), head(0), gtask(0), lastsigdate(0) {}
 
95
};
 
96
 
 
97
  
 
98
static GPMap<void *,DjVuProgressTask::Data> &
 
99
get_map(void)
 
100
{
 
101
  static GPMap<void *,DjVuProgressTask::Data> xmap;
 
102
  return xmap;
 
103
}
 
104
 
 
105
djvu_progress_callback *
 
106
DjVuProgressTask::set_callback(djvu_progress_callback *_callback)
 
107
 
108
  djvu_progress_callback *retval=0;
 
109
  if(_callback)
 
110
  {
 
111
    GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
 
112
    void *threadID=GThread::current();
 
113
    if(map.contains(threadID))
 
114
    {
 
115
      DjVuProgressTask::Data &data=*(map[threadID]);
 
116
      retval=data.callback;
 
117
      data.callback=_callback;
 
118
      data.head=0;
 
119
      data.gtask=0;
 
120
      data.lastsigdate=0;
 
121
    }else
 
122
    {
 
123
      map[threadID]=new Data(_callback);
 
124
    }
 
125
  }else
 
126
  {
 
127
    GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
 
128
    void *threadID=GThread::current();
 
129
    if(map.contains(threadID))
 
130
    {
 
131
      DjVuProgressTask::Data &data=*(map[threadID]);
 
132
      retval=data.callback;
 
133
      data.callback=0;
 
134
      data.head=0;
 
135
      data.gtask=0;
 
136
      data.lastsigdate=0;
 
137
      map.del(threadID);
 
138
    }
 
139
  }
 
140
  return retval;
 
141
}
 
142
 
 
143
DjVuProgressTask::DjVuProgressTask(const char *xtask,int nsteps)
 
144
  : task(xtask),parent(0), nsteps(nsteps), runtostep(0), gdata(0), data(0)
 
145
{
 
146
  //  gtask=task;
 
147
  {
 
148
    GMap<void *,GP<DjVuProgressTask::Data> > &map=get_map();
 
149
    void *threadID=GThread::current();
 
150
    if(map.contains(threadID))
 
151
    {
 
152
      gdata=new GP<Data>;
 
153
      Data &d=*(data=((*(GP<Data> *)gdata)=map[threadID]));
 
154
      if(d.callback)
 
155
      {
 
156
        unsigned long curdate = GOS::ticks();
 
157
        startdate = curdate;
 
158
        if (!d.head)
 
159
          d.lastsigdate = curdate + INITIAL;
 
160
        parent = d.head;
 
161
        d.head = this;
 
162
      }
 
163
    }
 
164
  }
 
165
}
 
166
 
 
167
DjVuProgressTask::~DjVuProgressTask()
 
168
{
 
169
  if (data && data->callback)
 
170
  {
 
171
    if (data->head != this)
 
172
      G_THROW( ERR_MSG("DjVuGlobal.not_compatible") );
 
173
    data->head = parent;
 
174
    if (!parent)
 
175
    {
 
176
      unsigned long curdate = GOS::ticks();
 
177
      if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, curdate-startdate))
 
178
      {
 
179
        G_THROW("INTERRUPT");
 
180
      }
 
181
    }
 
182
  }
 
183
  delete (GP<Data> *)gdata;
 
184
}
 
185
 
 
186
void
 
187
DjVuProgressTask::run(int tostep)
 
188
{
 
189
  if(data)
 
190
  {
 
191
    data->gtask=task;
 
192
    if ((data->callback)&&(tostep>runtostep))
 
193
    {
 
194
      unsigned long curdate = GOS::ticks();
 
195
      if (curdate > data->lastsigdate + INTERVAL)
 
196
        signal(curdate, curdate);
 
197
      runtostep = tostep;
 
198
    }
 
199
  }
 
200
}
 
201
 
 
202
void
 
203
DjVuProgressTask::signal(unsigned long curdate, unsigned long estdate)
 
204
{
 
205
  int inprogress = runtostep;
 
206
  if (inprogress > nsteps)
 
207
    inprogress = nsteps;
 
208
  if (inprogress > 0)
 
209
    {
 
210
      const unsigned long enddate = startdate+
 
211
        (unsigned long)(((float)(estdate-startdate) * (float)nsteps) / (float)inprogress);
 
212
      if (parent)
 
213
      {
 
214
        parent->signal(curdate, enddate);
 
215
      }
 
216
      else if (data && data->callback && curdate<enddate)
 
217
      {
 
218
        if((*(data->callback))(data->gtask?data->gtask:"",curdate-startdate, enddate-startdate))
 
219
        {
 
220
          G_THROW("INTERRUPT");
 
221
        }
 
222
        data->lastsigdate = curdate;
 
223
      }
 
224
    }
 
225
}
 
226
 
 
227
// Progress callback
 
228
//
 
229
djvu_progress_callback *
 
230
djvu_set_progress_callback( djvu_progress_callback *callback )
 
231
{
 
232
   return DjVuProgressTask::set_callback(callback);
 
233
}
 
234
 
 
235
int djvu_supports_progress_callback(void) {return 1;}
 
236
 
 
237
#else
 
238
 
 
239
#ifndef HAS_DJVU_PROGRESS_TYPEDEF
 
240
extern "C"
 
241
{
 
242
  void *djvu_set_progress_callback(void *);
 
243
  int djvu_supports_progress_callback(void);
 
244
}
 
245
void *djvu_set_progress_callback(void *) { return 0; }
 
246
int djvu_supports_progress_callback(void) {return 0;}
 
247
#else
 
248
int djvu_supports_progress_callback(void) {return 0;}
 
249
djvu_progress_callback *
 
250
djvu_set_progress_callback( djvu_progress_callback *) { return 0; }
 
251
#endif
 
252
 
 
253
#endif
 
254