summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-02-24 00:06:16 +0000
committerMike Buland <eichlan@xagasoft.com>2009-02-24 00:06:16 +0000
commitef2935347099967cc7092fa7f472d91d51571468 (patch)
treeabf0c041a31610fa7f8fb562c3c36a8277c438d2 /src
parent4309066dff46f52690998bbd1f60ec8b1631f142 (diff)
downloadlibbu++-ef2935347099967cc7092fa7f472d91d51571468.tar.gz
libbu++-ef2935347099967cc7092fa7f472d91d51571468.tar.bz2
libbu++-ef2935347099967cc7092fa7f472d91d51571468.tar.xz
libbu++-ef2935347099967cc7092fa7f472d91d51571468.zip
Whoa, lots of updates. Md5 is more general, nids, cache, cachestore, and
cachestorenids all support synchronizing now. Url is pretty much done.
Diffstat (limited to '')
-rw-r--r--src/cache.h38
-rw-r--r--src/cachestore.h3
-rw-r--r--src/cachestorenids.h21
-rw-r--r--src/cryptohash.h2
-rw-r--r--src/md5.cpp4
-rw-r--r--src/md5.h2
-rw-r--r--src/nids.cpp7
-rw-r--r--src/nids.h6
-rw-r--r--src/tests/md5.cpp6
-rw-r--r--src/url.cpp29
-rw-r--r--src/url.h20
11 files changed, 123 insertions, 15 deletions
diff --git a/src/cache.h b/src/cache.h
index ccc4966..036ceb4 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -100,6 +100,13 @@ namespace Bu
100 return kId; 100 return kId;
101 } 101 }
102 102
103 void unbind()
104 {
105 if( pCache && pData )
106 pCache->decRef( kId );
107 pData = NULL;
108 }
109
103 Ptr &operator=( const Ptr &rRhs ) 110 Ptr &operator=( const Ptr &rRhs )
104 { 111 {
105 if( pCache && pData ) 112 if( pCache && pData )
@@ -186,6 +193,11 @@ namespace Bu
186 return Ptr( this, pData, k ); 193 return Ptr( this, pData, k );
187 } 194 }
188 195
196 bool has( const keytype &cId )
197 {
198 return hEnt.has( cId ) || pStore->has( cId );
199 }
200
189 Ptr get( const keytype &cId ) 201 Ptr get( const keytype &cId )
190 { 202 {
191 TRACE( cId ); 203 TRACE( cId );
@@ -260,6 +272,32 @@ namespace Bu
260 return pStore->getKeys(); 272 return pStore->getKeys();
261 } 273 }
262 274
275 /**
276 * Make sure all currently loaded but not-in-use objects are synced to
277 * the store.
278 */
279 void sync()
280 {
281 TRACE();
282 int iSynced = 0;
283 for( typename CidHash::iterator i = hEnt.begin();
284 i != hEnt.end(); i++ )
285 {
286 if( i.getValue().iRefs == 0 )
287 {
288 pStore->sync(
289 i.getValue().pData,
290 i.getKey()
291 );
292 iSynced++;
293 }
294 }
295 if( iSynced > 0 )
296 {
297 pStore->sync();
298 }
299 }
300
263 private: 301 private:
264 void incRef( const keytype &cId ) 302 void incRef( const keytype &cId )
265 { 303 {
diff --git a/src/cachestore.h b/src/cachestore.h
index 97f02af..437b3d3 100644
--- a/src/cachestore.h
+++ b/src/cachestore.h
@@ -24,7 +24,10 @@ namespace Bu
24 virtual obtype *load( const keytype &key )=0; 24 virtual obtype *load( const keytype &key )=0;
25 virtual void unload( obtype *pObj, const keytype &key )=0; 25 virtual void unload( obtype *pObj, const keytype &key )=0;
26 virtual keytype create( obtype *pSrc )=0; 26 virtual keytype create( obtype *pSrc )=0;
27 virtual void sync()=0;
28 virtual void sync( obtype *pObj, const keytype &key )=0;
27 virtual void destroy( obtype *pObj, const keytype &key )=0; 29 virtual void destroy( obtype *pObj, const keytype &key )=0;
30 virtual bool has( const keytype &key )=0;
28 virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); } 31 virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); }
29 32
30 private: 33 private:
diff --git a/src/cachestorenids.h b/src/cachestorenids.h
index 40213cd..c6a00ce 100644
--- a/src/cachestorenids.h
+++ b/src/cachestorenids.h
@@ -97,6 +97,22 @@ namespace Bu
97 return key; 97 return key;
98 } 98 }
99 99
100 virtual void sync()
101 {
102 NidsStream ns = nStore.openStream( 0 );
103 Bu::Archive ar( ns, Bu::Archive::save );
104 ar << hId;
105
106 nStore.sync();
107 }
108
109 virtual void sync( obtype *pSrc, const keytype &key )
110 {
111 int iStream = hId.get( key );
112 NidsStream ns = nStore.openStream( iStream );
113 __cacheStoreNidsStore<obtype, keytype>( ns, *pSrc, key );
114 }
115
100 virtual void destroy( obtype *pObj, const keytype &key ) 116 virtual void destroy( obtype *pObj, const keytype &key )
101 { 117 {
102 int iStream = hId.get( key ); 118 int iStream = hId.get( key );
@@ -105,6 +121,11 @@ namespace Bu
105 delete pObj; 121 delete pObj;
106 } 122 }
107 123
124 virtual bool has( const keytype &key )
125 {
126 return hId.has( key );
127 }
128
108 virtual Bu::List<keytype> getKeys() 129 virtual Bu::List<keytype> getKeys()
109 { 130 {
110 return hId.getKeys(); 131 return hId.getKeys();
diff --git a/src/cryptohash.h b/src/cryptohash.h
index 01d4634..ed8d9ec 100644
--- a/src/cryptohash.h
+++ b/src/cryptohash.h
@@ -13,7 +13,7 @@ namespace Bu
13 13
14 virtual void reset() = 0; 14 virtual void reset() = 0;
15 virtual void setSalt( const Bu::FString &sSalt ) = 0; 15 virtual void setSalt( const Bu::FString &sSalt ) = 0;
16 virtual void addData( const char *sData, int iSize ) = 0; 16 virtual void addData( const void *sData, int iSize ) = 0;
17 virtual void addData( const Bu::FString &sData ); 17 virtual void addData( const Bu::FString &sData );
18 virtual FString getResult() = 0; 18 virtual FString getResult() = 0;
19 }; 19 };
diff --git a/src/md5.cpp b/src/md5.cpp
index aa965ed..44e8519 100644
--- a/src/md5.cpp
+++ b/src/md5.cpp
@@ -55,8 +55,10 @@ void Bu::Md5::setSalt( const Bu::FString & /*sSalt*/ )
55{ 55{
56} 56}
57 57
58void Bu::Md5::addData( const char *sData, int iSize ) 58void Bu::Md5::addData( const void *sVData, int iSize )
59{ 59{
60 const char *sData = (const char *)sVData;
61
60 int iInPos = 0; 62 int iInPos = 0;
61 for(;;) 63 for(;;)
62 { 64 {
diff --git a/src/md5.h b/src/md5.h
index c548041..f3f040c 100644
--- a/src/md5.h
+++ b/src/md5.h
@@ -20,7 +20,7 @@ namespace Bu
20 20
21 virtual void reset(); 21 virtual void reset();
22 virtual void setSalt( const Bu::FString &sSalt ); 22 virtual void setSalt( const Bu::FString &sSalt );
23 virtual void addData( const char *sData, int iSize ); 23 virtual void addData( const void *sData, int iSize );
24 using Bu::CryptoHash::addData; 24 using Bu::CryptoHash::addData;
25 virtual FString getResult(); 25 virtual FString getResult();
26 26
diff --git a/src/nids.cpp b/src/nids.cpp
index 26a7964..0bec952 100644
--- a/src/nids.cpp
+++ b/src/nids.cpp
@@ -31,6 +31,13 @@ Bu::Nids::~Nids()
31 updateHeader(); 31 updateHeader();
32} 32}
33 33
34void Bu::Nids::sync()
35{
36 updateHeader();
37
38 // Later, also flush all caches.
39}
40
34void Bu::Nids::initialize() 41void Bu::Nids::initialize()
35{ 42{
36 unsigned char buf[4]; 43 unsigned char buf[4];
diff --git a/src/nids.h b/src/nids.h
index 262d9c1..cab4448 100644
--- a/src/nids.h
+++ b/src/nids.h
@@ -70,6 +70,12 @@ namespace Bu
70 int getBlockStart(); 70 int getBlockStart();
71 int getBlockOverhead(); 71 int getBlockOverhead();
72 72
73 /**
74 * Syncronize the header data, etc. with the storage stream. It's not
75 * a bad idea to call this periodically.
76 */
77 void sync();
78
73 private: 79 private:
74 typedef struct Block 80 typedef struct Block
75 { 81 {
diff --git a/src/tests/md5.cpp b/src/tests/md5.cpp
index dea957b..2e9c318 100644
--- a/src/tests/md5.cpp
+++ b/src/tests/md5.cpp
@@ -12,12 +12,12 @@ int main( int argc, char *argv[] )
12 Bu::File fIn( *argv, Bu::File::Read ); 12 Bu::File fIn( *argv, Bu::File::Read );
13 Bu::Md5 m; 13 Bu::Md5 m;
14 14
15 char buf[1000]; 15 char buf[100000];
16 for(;;) 16 for(;;)
17 { 17 {
18 int iRead = fIn.read( buf, 1000 ); 18 int iRead = fIn.read( buf, 100000 );
19 m.addData( buf, iRead ); 19 m.addData( buf, iRead );
20 if( iRead < 1000 ) 20 if( iRead < 100000 )
21 break; 21 break;
22 } 22 }
23 23
diff --git a/src/url.cpp b/src/url.cpp
index 7cc4263..e4d2f55 100644
--- a/src/url.cpp
+++ b/src/url.cpp
@@ -235,3 +235,32 @@ void Bu::Url::clear()
235 iPort.clear(); 235 iPort.clear();
236} 236}
237 237
238Bu::FString Bu::Url::getFullPath() const
239{
240 Bu::FString sBuf = sPath;
241 if( !lParam.isEmpty() )
242 {
243 for( ParamList::const_iterator i = lParam.begin(); i; i++ )
244 {
245 if( i == lParam.begin() )
246 sBuf += "?";
247 else
248 sBuf += "&";
249
250 sBuf += encode( (*i).sName );
251 if( !(*i).sValue.isEmpty() )
252 {
253 sBuf += "=" + encode( (*i).sValue );
254 }
255 }
256 }
257
258 return sBuf;
259}
260
261Bu::FString Bu::Url::getUrl() const
262{
263 Bu::FString sBuf = sProtocol + "://" + sHost + getFullPath();
264 return sBuf;
265}
266
diff --git a/src/url.h b/src/url.h
index 861bb9f..8713ed4 100644
--- a/src/url.h
+++ b/src/url.h
@@ -29,15 +29,17 @@ namespace Bu
29 void parseParams( Bu::FString::const_iterator &i ); 29 void parseParams( Bu::FString::const_iterator &i );
30 void clear(); 30 void clear();
31 31
32 Bu::FString getUrl(); 32 Bu::FString getUrl() const;
33 Bu::FString getFullPath() const;
33 34
34 const Bu::FString &getProtocol() { return sProtocol; } 35 const Bu::FString &getProtocol() const { return sProtocol; }
35 const Bu::FString &getUser() { return sUser; } 36 const Bu::FString &getUser() const { return sUser; }
36 const Bu::FString &getPass() { return sPass; } 37 const Bu::FString &getPass() const { return sPass; }
37 const Bu::FString &getHost() { return sHost; } 38 const Bu::FString &getHost() const { return sHost; }
38 const Bu::FString &getPath() { return sPath; } 39 const Bu::FString &getPath() const { return sPath; }
39 int getPort() { return iPort; } 40 int getPort() const { return iPort; }
40 ParamList::const_iterator getParamBegin() { return lParam.begin(); } 41 ParamList::const_iterator getParamBegin() const
42 { return lParam.begin(); }
41 43
42 void setProtocol( const Bu::FString &sNewHost, bool bAutoSetPort=true ); 44 void setProtocol( const Bu::FString &sNewHost, bool bAutoSetPort=true );
43 void setUser( const Bu::FString &s ) { sUser = s; } 45 void setUser( const Bu::FString &s ) { sUser = s; }
@@ -47,7 +49,7 @@ namespace Bu
47 void setPort( int i ) { iPort = i; } 49 void setPort( int i ) { iPort = i; }
48 void addParam( const Bu::FString &n, const Bu::FString &v ); 50 void addParam( const Bu::FString &n, const Bu::FString &v );
49 51
50 bool hasPort() { return iPort.has(); } 52 bool hasPort() const { return iPort.has(); }
51 53
52 static Bu::FString decode( const Bu::FString &sStr ); 54 static Bu::FString decode( const Bu::FString &sStr );
53 static Bu::FString encode( const Bu::FString &sStr ); 55 static Bu::FString encode( const Bu::FString &sStr );