[haiku-commits] haiku: hrev51830 - in src/apps/haikudepot: model server

  • From: waddlesplash@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 3 Mar 2018 15:01:22 -0500 (EST)

hrev51830 adds 1 changeset to branch 'master'
old head: 2cb3cabcb0e3362a8185c8fdb8ba7a386e5800f0
new head: d5b1013185427591f126d4af0b4e2968aae9b84b
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=d5b101318542+%5E2cb3cabcb0e3

----------------------------------------------------------------------------

d5b101318542: HaikuDepot : Coalesce Loading Change Notifications
  
  When the application is starting, it will load in bulk data.  As it
  does so, it may issue some change notifications to listeners.  For
  each small change in packages' data, there is a notification.  The
  system was built to accommodate coalesced changes.  This commit will
  coalesce those changes during the bulk load for cases where there
  are listeners present.
  
  Change-Id: I1cc6668f61917c0068d5559b2bf338ea75d453da

                                    [ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51830
Commit:      d5b1013185427591f126d4af0b4e2968aae9b84b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d5b101318542
Author:      Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Date:        Fri Feb 16 21:31:18 2018 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Mar  3 20:01:16 2018 UTC

----------------------------------------------------------------------------

3 files changed, 61 insertions(+), 4 deletions(-)
src/apps/haikudepot/model/PackageInfo.cpp        | 49 ++++++++++++++++++--
src/apps/haikudepot/model/PackageInfo.h          |  7 +++
.../haikudepot/server/PkgDataUpdateProcess.cpp   |  9 ++++

----------------------------------------------------------------------------

diff --git a/src/apps/haikudepot/model/PackageInfo.cpp 
b/src/apps/haikudepot/model/PackageInfo.cpp
index 904f3dbfec..c8d18ccb28 100644
--- a/src/apps/haikudepot/model/PackageInfo.cpp
+++ b/src/apps/haikudepot/model/PackageInfo.cpp
@@ -475,7 +475,10 @@ PackageInfo::PackageInfo()
        fArchitecture(),
        fLocalFilePath(),
        fFileName(),
-       fSize(0)
+       fSize(0),
+       fDepotName(""),
+       fIsCollatingChanges(false),
+       fCollatedChanges(0)
 {
 }
 
@@ -502,7 +505,11 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
        fArchitecture(info.ArchitectureName()),
        fLocalFilePath(),
        fFileName(info.FileName()),
-       fSize(0) // TODO: Retrieve local file size
+       fSize(0), // TODO: Retrieve local file size
+       fDepotName(""),
+       fIsCollatingChanges(false),
+       fCollatedChanges(0)
+
 {
        BString publisherURL;
        if (info.URLList().CountStrings() > 0)
@@ -545,7 +552,10 @@ PackageInfo::PackageInfo(const BString& name,
        fArchitecture(architecture),
        fLocalFilePath(),
        fFileName(),
-       fSize(0)
+       fSize(0),
+       fDepotName(""),
+       fIsCollatingChanges(false),
+       fCollatedChanges(0)
 {
 }
 
@@ -574,7 +584,10 @@ PackageInfo::PackageInfo(const PackageInfo& other)
        fArchitecture(other.fArchitecture),
        fLocalFilePath(other.fLocalFilePath),
        fFileName(other.fFileName),
-       fSize(other.fSize)
+       fSize(other.fSize),
+       fDepotName(other.fDepotName),
+       fIsCollatingChanges(false),
+       fCollatedChanges(0)
 {
 }
 
@@ -963,8 +976,36 @@ PackageInfo::CleanupDefaultIcon()
 }
 
 
+void
+PackageInfo::StartCollatingChanges()
+{
+       fIsCollatingChanges = true;
+       fCollatedChanges = 0;
+}
+
+
+void
+PackageInfo::EndCollatingChanges()
+{
+       if (fIsCollatingChanges && fCollatedChanges != 0)
+               _NotifyListenersImmediate(fCollatedChanges);
+       fIsCollatingChanges = false;
+       fCollatedChanges = 0;
+}
+
+
 void
 PackageInfo::_NotifyListeners(uint32 changes)
+{
+       if (fIsCollatingChanges)
+               fCollatedChanges |= changes;
+       else
+               _NotifyListenersImmediate(changes);
+}
+
+
+void
+PackageInfo::_NotifyListenersImmediate(uint32 changes)
 {
        int count = fListeners.CountItems();
        if (count == 0)
diff --git a/src/apps/haikudepot/model/PackageInfo.h 
b/src/apps/haikudepot/model/PackageInfo.h
index 99d508a2e7..0cf570c5f4 100644
--- a/src/apps/haikudepot/model/PackageInfo.h
+++ b/src/apps/haikudepot/model/PackageInfo.h
@@ -352,8 +352,12 @@ public:
 
        static  void                            CleanupDefaultIcon();
 
+                       void                            StartCollatingChanges();
+                       void                            EndCollatingChanges();
+
 private:
                        void                            _NotifyListeners(uint32 
changes);
+                       void                            
_NotifyListenersImmediate(uint32 changes);
 
 private:
                        BitmapRef                       fIcon;
@@ -383,6 +387,9 @@ private:
                        int64                           fSize;
                        BString                         fDepotName;
 
+                       bool                            fIsCollatingChanges;
+                       uint32                          fCollatedChanges;
+
        static  BitmapRef                       sDefaultIcon;
 };
 
diff --git a/src/apps/haikudepot/server/PkgDataUpdateProcess.cpp 
b/src/apps/haikudepot/server/PkgDataUpdateProcess.cpp
index c5d1b23b19..be4b1ec8e9 100644
--- a/src/apps/haikudepot/server/PkgDataUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/PkgDataUpdateProcess.cpp
@@ -103,6 +103,13 @@ PackageFillingPkgListener::ConsumePackage(const 
PackageInfoRef& package,
        DumpExportPkg* pkg = static_cast<DumpExportPkg*>(context);
        int32 i;
 
+               // Collects all of the changes here into one set of 
notifications to
+               // the package's listeners.  This way the quantity of BMessages
+               // communicated back to listeners is considerably reduced.  See 
stop
+               // invocation later in this method.
+
+       package->StartCollatingChanges();
+
        if (0 != pkg->CountPkgVersions()) {
 
                        // this makes the assumption that the only version will 
be the
@@ -169,6 +176,8 @@ PackageFillingPkgListener::ConsumePackage(const 
PackageInfoRef& package,
 
        fCount++;
 
+       package->EndCollatingChanges();
+
        return !fStoppable->WasStopped();
 }
 


Other related posts:

  • » [haiku-commits] haiku: hrev51830 - in src/apps/haikudepot: model server - waddlesplash