kviewshell
DataPool.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _DATAPOOL_H
00058 #define _DATAPOOL_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00066
00067 #include "GThreads.h"
00068 #include "GString.h"
00069 #include "GURL.h"
00070
00071 #ifdef HAVE_NAMESPACES
00072 namespace DJVU {
00073 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00074 }
00075 #endif
00076 #endif
00077
00078 class ByteStream;
00079
00103
00225 class DataPool : public GPEnabled
00226 {
00227 public:
00228
00229 class Incrementor;
00230 class Reader;
00231 class Trigger;
00232 class OpenFiles;
00233 class OpenFiles_File;
00234 class BlockList;
00235 class Counter;
00236 protected:
00237 DataPool(void);
00238
00239 public:
00246 static GP<DataPool> create(void);
00247
00253 static GP<DataPool> create(const GP<ByteStream> & str);
00254
00266 static GP<DataPool> create(const GP<DataPool> & master_pool, int start=0, int length=-1);
00267
00278 static GP<DataPool> create(const GURL &url, int start=0, int length=-1);
00279
00280 virtual ~DataPool();
00281
00290 void connect(const GP<DataPool> & master_pool, int start=0, int length=-1);
00299 void connect(const GURL &url, int start=0, int length=-1);
00301
00312 void stop(bool only_blocked=false);
00313
00341 void add_data(const void * buffer, int size);
00342
00358 void add_data(const void * buffer, int offset, int size);
00359
00370 void set_eof(void);
00372
00423 int get_data(void * buffer, int offset, int size);
00424
00429 GP<ByteStream> get_stream(void);
00431
00436 bool is_connected(void) const;
00437
00445 bool has_data(int start, int length);
00446
00447
00448
00449
00450
00451 bool is_eof(void) const {return eof_flag;}
00452
00469 int get_length(void) const;
00476 int get_size(void) const {return get_size(0, -1);}
00478
00510 void add_trigger(int start, int length,
00511
00512 void (* callback)(void *), void * cl_data);
00513
00521
00522 void add_trigger(int thresh, void (* callback)(void *), void * cl_data);
00523
00527 void del_trigger(void (* callback)(void *), void * cl_data);
00528
00530
00540 void load_file(void);
00546 static void load_file(const GURL &url);
00547
00549 static void close_all(void);
00550
00551
00552 void clear_stream(const bool release = true);
00553
00556 bool simple_compare(DataPool &pool) const;
00557 private:
00558 bool eof_flag;
00559 bool stop_flag;
00560 bool stop_blocked_flag;
00561
00562 Counter *active_readers;
00563
00564
00565 GP<DataPool> pool;
00566 GURL furl;
00567 GP<OpenFiles_File> fstream;
00568 GCriticalSection class_stream_lock;
00569 GP<ByteStream> data;
00570 GCriticalSection data_lock;
00571 BlockList *block_list;
00572 int add_at;
00573 int start, length;
00574
00575
00576 GPList<Reader> readers_list;
00577 GCriticalSection readers_lock;
00578
00579
00580 GPList<Trigger> triggers_list;
00581 GCriticalSection triggers_lock;
00582 GCriticalSection trigger_lock;
00583
00584 void init(void);
00585 void wait_for_data(const GP<Reader> & reader);
00586 void wake_up_all_readers(void);
00587 void check_triggers(void);
00588 int get_data(void * buffer, int offset, int size, int level);
00589 int get_size(int start, int length) const;
00590 void restart_readers(void);
00591
00592
00593 static void static_trigger_cb(void *);
00594 void trigger_cb(void);
00595 void analyze_iff(void);
00596 void added_data(const int offset, const int size);
00597 public:
00598 static const char *Stop;
00599 friend class FCPools;
00600 };
00601
00602 inline bool
00603 DataPool::simple_compare(DataPool &pool) const
00604 {
00605
00606
00607 return (this == &pool)
00608 ||(furl.is_valid()&&!furl.is_empty()&&pool.furl.is_valid()&&(furl == pool.furl))
00609 ||(data && (data == pool.data));
00610 }
00611
00612 inline bool
00613 DataPool::is_connected(void) const
00614 {
00615 return furl.is_local_file_url() || pool!=0;
00616 }
00617
00619
00620
00621 #ifdef HAVE_NAMESPACES
00622 }
00623 # ifndef NOT_USING_DJVU_NAMESPACE
00624 using namespace DJVU;
00625 # endif
00626 #endif
00627 #endif