summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
authorzecke <zecke>2002-12-10 17:01:18 (UTC)
committer zecke <zecke>2002-12-10 17:01:18 (UTC)
commit4ecbf7407c19b59fc136c334f9386c53db453930 (patch) (unidiff)
tree1cba438e2533f7109af169b0b77988cec6664192 /libopie2/opiepim/backend
parent36375df6ff103e52455823f7afd64c4f4ae7fcb8 (diff)
downloadopie-4ecbf7407c19b59fc136c334f9386c53db453930.zip
opie-4ecbf7407c19b59fc136c334f9386c53db453930.tar.gz
opie-4ecbf7407c19b59fc136c334f9386c53db453930.tar.bz2
get in sync with HEAD again
-OPimBase was added to be used as a default struct inside OPimResolver and to work with DSOs -TodoListXML backend now uses mmap and madvise to load data -OContact added/changed rtti -OTodo added changed rtti OPimAccess* added stuff necessary for the Resolver and a 'state'/'hint' on how to load data OPimResolver which resolves uid + services to Records, rtti to QCOPChannels loads arbitary Service backends ( will work with DSOs soon ) -OPimMainWindow added some setDocument scripting possibility and internal marshalling and demarshalling of Records -OPimRecord added loadDataFromm and saveDataTo for marshalling purposes much more :)
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h16
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp43
2 files changed, 50 insertions, 9 deletions
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 4f00bc9..e268f4f 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -16,13 +16,15 @@
16 * of 16 * of
17 */ 17 */
18template <class T = OPimRecord> 18template <class T = OPimRecord>
19class OPimAccessBackend { 19class OPimAccessBackend {
20public: 20public:
21 typedef OTemplateBase<T> Frontend; 21 typedef OTemplateBase<T> Frontend;
22 OPimAccessBackend(); 22
23 /** The access hint from the frontend */
24 OPimAccessBackend(int access = 0);
23 virtual ~OPimAccessBackend(); 25 virtual ~OPimAccessBackend();
24 26
25 /** 27 /**
26 * load the resource 28 * load the resource
27 */ 29 */
28 virtual bool load() = 0; 30 virtual bool load() = 0;
@@ -85,29 +87,35 @@ public:
85 87
86 /** 88 /**
87 * set the read ahead count 89 * set the read ahead count
88 */ 90 */
89 void setReadAhead( uint count ); 91 void setReadAhead( uint count );
90protected: 92protected:
93 int access()const;
91 void cache( const T& t )const; 94 void cache( const T& t )const;
92 95
93 /** 96 /**
94 * use a prime number here! 97 * use a prime number here!
95 */ 98 */
96 void setSaneCacheSize( int ); 99 void setSaneCacheSize( int );
97 100
98 uint readAhead()const; 101 uint readAhead()const;
99 102
100private: 103private:
104 class Private;
105 Private* d;
101 Frontend* m_front; 106 Frontend* m_front;
102 uint m_read; 107 uint m_read;
108 int m_acc;
103 109
104}; 110};
105 111
106template <class T> 112template <class T>
107OPimAccessBackend<T>::OPimAccessBackend() { 113OPimAccessBackend<T>::OPimAccessBackend(int acc)
114 : m_acc( acc )
115{
108 m_front = 0l; 116 m_front = 0l;
109} 117}
110template <class T> 118template <class T>
111OPimAccessBackend<T>::~OPimAccessBackend() { 119OPimAccessBackend<T>::~OPimAccessBackend() {
112 120
113} 121}
@@ -135,7 +143,11 @@ void OPimAccessBackend<T>::setReadAhead( uint count ) {
135 m_read = count; 143 m_read = count;
136} 144}
137template <class T> 145template <class T>
138uint OPimAccessBackend<T>::readAhead()const { 146uint OPimAccessBackend<T>::readAhead()const {
139 return m_read; 147 return m_read;
140} 148}
149template <class T>
150int OPimAccessBackend<T>::access()const {
151 return m_acc;
152}
141#endif 153#endif
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index b2dfe80..21f93a0 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -1,6 +1,16 @@
1#include <errno.h>
2#include <fcntl.h>
3
4#include <sys/mman.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7
8#include <unistd.h>
9
10
1#include <qfile.h> 11#include <qfile.h>
2#include <qvector.h> 12#include <qvector.h>
3 13
4#include <qpe/global.h> 14#include <qpe/global.h>
5#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
6#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
@@ -49,26 +59,42 @@ bool OTodoAccessXML::load() {
49 dict.insert("Reminders", new int(OTodo::Reminders) ); 59 dict.insert("Reminders", new int(OTodo::Reminders) );
50 dict.insert("Notifiers", new int(OTodo::Notifiers) ); 60 dict.insert("Notifiers", new int(OTodo::Notifiers) );
51 dict.insert("Maintainer", new int(OTodo::Maintainer) ); 61 dict.insert("Maintainer", new int(OTodo::Maintainer) );
52 62
53 // here the custom XML parser from TT it's GPL 63 // here the custom XML parser from TT it's GPL
54 // but we want to push OpiePIM... to TT..... 64 // but we want to push OpiePIM... to TT.....
55 QFile f(m_file ); 65 // mmap part from zecke :)
56 if (!f.open(IO_ReadOnly) ) 66 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
67 struct stat attribut;
68 if ( fd < 0 ) return false;
69
70 if ( fstat(fd, &attribut ) == -1 ) {
71 ::close( fd );
57 return false; 72 return false;
73 }
74 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
75 if ( map_addr == ( (caddr_t)-1) ) {
76 ::close(fd );
77 return false;
78 }
79 /* advise the kernel who we want to read it */
80 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
81 /* we do not the file any more */
82 ::close( fd );
58 83
59 QByteArray ba = f.readAll(); 84 char* dt = (char*)map_addr;
60 f.close(); 85 int len = attribut.st_size;
61 char* dt = ba.data();
62 int len = ba.size();
63 int i = 0; 86 int i = 0;
64 char *point; 87 char *point;
65 const char* collectionString = "<Task "; 88 const char* collectionString = "<Task ";
89 int strLen = strlen(collectionString);
66 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 90 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
67 i = point -dt; 91 i = point -dt;
68 i+= strlen(collectionString); 92 i+= strLen;
93 qWarning("Found a start at %d %d", i, (point-dt) );
94
69 OTodo ev; 95 OTodo ev;
70 m_year = m_month = m_day = 0; 96 m_year = m_month = m_day = 0;
71 97
72 while ( TRUE ) { 98 while ( TRUE ) {
73 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 99 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
74 ++i; 100 ++i;
@@ -117,23 +143,26 @@ bool OTodoAccessXML::load() {
117 todo( &dict, ev, attr, str ); 143 todo( &dict, ev, attr, str );
118 144
119 } 145 }
120 /* 146 /*
121 * now add it 147 * now add it
122 */ 148 */
149 qWarning("End at %d", i );
123 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 150 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
124 ev.setUid( 1 ); 151 ev.setUid( 1 );
125 m_changed = true; 152 m_changed = true;
126 } 153 }
127 if ( ev.hasDueDate() ) { 154 if ( ev.hasDueDate() ) {
128 ev.setDueDate( QDate(m_year, m_month, m_day) ); 155 ev.setDueDate( QDate(m_year, m_month, m_day) );
129 } 156 }
130 m_events.insert(ev.uid(), ev ); 157 m_events.insert(ev.uid(), ev );
131 m_year = m_month = m_day = -1; 158 m_year = m_month = m_day = -1;
132 } 159 }
133 160
161 munmap(map_addr, attribut.st_size );
162
134 qWarning("counts %d records loaded!", m_events.count() ); 163 qWarning("counts %d records loaded!", m_events.count() );
135 return true; 164 return true;
136} 165}
137bool OTodoAccessXML::reload() { 166bool OTodoAccessXML::reload() {
138 return load(); 167 return load();
139} 168}