gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9739: use a shared_ptr for all uses


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9739: use a shared_ptr for all uses of DiskStream
Date: Mon, 17 Nov 2008 10:05:30 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9739
committer: address@hidden
branch nick: rtmp
timestamp: Mon 2008-11-17 10:05:30 -0700
message:
  use a shared_ptr for all uses of DiskStream
modified:
  libnet/cache.cpp
  libnet/cache.h
  testsuite/libnet.all/test_cache.cpp
=== modified file 'libnet/cache.cpp'
--- a/libnet/cache.cpp  2008-11-15 03:17:57 +0000
+++ b/libnet/cache.cpp  2008-11-17 17:05:30 +0000
@@ -92,7 +92,7 @@
 };
 
 void
-Cache::addFile(const std::string &name, DiskStream *file)
+Cache::addFile(const std::string &name, boost::shared_ptr<DiskStream> &file)
 {
 //    GNASH_REPORT_FUNCTION;
     boost::mutex::scoped_lock lock(cache_mutex);
@@ -133,7 +133,7 @@
     return _responses[name];
 };
 
-DiskStream *
+boost::shared_ptr<DiskStream> 
 Cache::findFile(const std::string &name)
 {
 //    GNASH_REPORT_FUNCTION;
@@ -141,7 +141,7 @@
 #ifdef USE_STATS_CACHE
     clock_gettime (CLOCK_REALTIME, &_last_access);
     _file_lookups++;
-    map<string, DiskStream *>::const_iterator it;
+    map<string, boost::shared_ptr<DiskStream> >::const_iterator it;
     it = _files.find(name);
     if (it != _files.end()) {
         _file_hits++;
@@ -235,10 +235,10 @@
         os << "Response for \"" << name->first << "\" is: " << name->second << 
endl;
     }
 
-#if 0
-    map<std::string, DiskStream>::const_iterator data;
+#if 1
+    map<std::string, boost::shared_ptr<DiskStream> >::const_iterator data;
     for (data = _files.begin(); data != _files.end(); data++) {
-        DiskStream filedata = data->second;
+        boost::shared_ptr<DiskStream> filedata = data->second;
         os << "File info for \"" << data->first << "\" is: ";
 //        filedata.dump(os) << endl;
     }

=== modified file 'libnet/cache.h'
--- a/libnet/cache.h    2008-11-15 03:17:57 +0000
+++ b/libnet/cache.h    2008-11-17 17:05:30 +0000
@@ -55,8 +55,8 @@
     std::string &findResponse(const std::string &name);
     void removeResponse(const std::string &name);
     
-    void addFile(const std::string &name, DiskStream *file);
-    DiskStream *findFile(const std::string &name);
+    void addFile(const std::string &name, boost::shared_ptr<DiskStream > 
&file);
+    boost::shared_ptr<DiskStream> findFile(const std::string &name);
     void removeFile(const std::string &name);
     
     ///  \brief Dump the internal data of this class in a human readable form.
@@ -77,7 +77,7 @@
     std::map<std::string, std::string> _responses;
     /// \var Cache::_responses
     ///                The cache of Distream handles to often played files.
-    std::map<std::string, DiskStream *> _files;
+    std::map<std::string, boost::shared_ptr<DiskStream> > _files;
 
     /// \var Cache::_max_size
     ///                The maximum amount of memory the cache is allowed to 
use.

=== modified file 'testsuite/libnet.all/test_cache.cpp'
--- a/testsuite/libnet.all/test_cache.cpp       2008-11-15 03:34:53 +0000
+++ b/testsuite/libnet.all/test_cache.cpp       2008-11-17 17:05:30 +0000
@@ -149,39 +149,47 @@
         runtest.fail("addResponse()/findResponse()");
     }
 
-    DiskStream file1;
+    boost::shared_ptr<DiskStream> file1(new DiskStream);
     create_file("outbuf1.raw", 100);
-    file1.open("outbuf1.raw");
+    file1->open("outbuf1.raw");
 
-    DiskStream file2;
+    boost::shared_ptr<DiskStream> file2(new DiskStream);
     create_file("outbuf2.raw", 200);
-    file1.open("outbuf2.raw");
+    file1->open("outbuf2.raw");
 
-    DiskStream file3;
+    boost::shared_ptr<DiskStream> file3(new DiskStream);
     create_file("outbuf3.raw", 300);
-    file1.open("outbuf3.raw");
+    file1->open("outbuf3.raw");
 
-    DiskStream file4;
+    boost::shared_ptr<DiskStream> file4(new DiskStream);
     create_file("outbuf4.raw", 400);
-    file1.open("outbuf4.raw");
-
-    cache.addFile("foo", &file1);
-    cache.addFile("bar", &file2);
-    cache.addFile("barfoo", &file3);
-    cache.addFile("foobar", &file4);
-    if ((cache.findFile("foo")->getFileSize() == file1.getFileSize())
-         && (cache.findFile("bar")->getFileSize() == file2.getFileSize())) {
-        runtest.pass("addFile()/findFile()");
+    file1->open("outbuf4.raw");
+
+    cache.addFile("foo", file1);
+    cache.addFile("bar", file2);
+    cache.addFile("barfoo", file3);
+    cache.addFile("foobar", file4);
+
+    boost::shared_ptr<DiskStream> ds1 = cache.findFile("foo");
+    boost::shared_ptr<DiskStream> ds2 = cache.findFile("bar");
+    if (ds1 && ds2) {
+        if ((ds1->getFileSize() == file1->getFileSize())
+            && (ds2->getFileSize() == file2->getFileSize())) {
+            runtest.pass("addFile()/findFile()");
+        } else {
+            runtest.fail("addFile()/findFile()");
+        }
     } else {
-        runtest.fail("addFile()/findFile()");
+        runtest.unresolved("addFile()/findFile()");        
     }
-    
 //     if (dbglogfile.getVerbosity() > 0) {
 //         cache.dump();
 //     }
 
-    file1.close();
-    
+    file1->close();
+    file2->close();
+    file3->close();
+    file4->close();
 }
 
 static void
@@ -226,35 +234,42 @@
         runtest.fail("Cache::removeResponse()");
     }
 
-    DiskStream file1;
+    boost::shared_ptr<DiskStream> file1(new DiskStream);
     create_file("outbuf1.raw", 100);
-    file1.open("outbuf1.raw");
+    file1->open("outbuf1.raw");
 
-    DiskStream file2;
+    boost::shared_ptr<DiskStream> file2(new DiskStream);
     create_file("outbuf2.raw", 200);
-    file1.open("outbuf2.raw");
+    file2->open("outbuf2.raw");
 
-    DiskStream file3;
+    boost::shared_ptr<DiskStream> file3(new DiskStream);
     create_file("outbuf3.raw", 300);
-    file1.open("outbuf3.raw");
+    file3->open("outbuf3.raw");
 
-    DiskStream file4;
+    boost::shared_ptr<DiskStream> file4(new DiskStream);
     create_file("outbuf4.raw", 400);
-    file1.open("outbuf4.raw");
+    file4->open("outbuf4.raw");
 
-    cache.addFile("foo", &file1);
-    cache.addFile("bar", &file2);
-    cache.addFile("barfoo", &file3);
-    cache.addFile("foobar", &file4);
+    cache.addFile("foo", file1);
+    cache.addFile("bar", file2);
+    cache.addFile("barfoo", file3);
+    cache.addFile("foobar", file4);
     cache.removeFile("barfoo");
-    if ((cache.findFile("foo")->getFileSize() == file1.getFileSize())
-        && (cache.findFile("barfoo") == 0)
-        && (cache.findFile("bar")->getFileSize() == file2.getFileSize())) {
-        runtest.pass("Cache::removeFile()");
+
+    boost::shared_ptr<DiskStream> ds1 = cache.findFile("foo");
+    boost::shared_ptr<DiskStream> ds2 = cache.findFile("bar");
+    if (ds1 && ds2) {
+        if ((cache.findFile("foo")->getFileSize() == file1->getFileSize())
+            && (cache.findFile("barfoo") == 0)
+            && (cache.findFile("bar")->getFileSize() == file2->getFileSize())) 
{
+            runtest.pass("Cache::removeFile()");
+        } else {
+            runtest.fail("Cache::removeFile()");
+        }
     } else {
-        runtest.fail("Cache::removeFile()");
-    }    
-
+        runtest.unresolved("Cache::removeFile()");
+    }
+    
     if (dbglogfile.getVerbosity() > 0) {
          cache.dump();
      }
@@ -287,18 +302,18 @@
         runtest.fail("Cache::findResponse()");
     }
 
-    DiskStream file1;
+    boost::shared_ptr<DiskStream> file1(new DiskStream);
 //    create_file("outbuf1.raw", 100);   it's created aleady in test().
-    file1.open("outbuf1.raw");
+    file1->open("outbuf1.raw");
 
-    cache.addFile("foo", &file1);
-    if ((cache.findFile("foo")->getFileSize() == file1.getFileSize())
+    cache.addFile("foo", file1);
+    if ((cache.findFile("foo")->getFileSize() == file1->getFileSize())
          && (cache.findFile("bar") == 0)) {
         runtest.pass("Cache::addFile()/findFile()");
     } else {
         runtest.fail("Cache::addFile()/findFile()");
     }
-
+    
     // see what happens if we try an uninitialized Cache.
     Cache c1;
     


reply via email to

[Prev in Thread] Current Thread [Next in Thread]