Add SCM API for disabling updates

This is to be used when the application is in the background. Rather than completely disable updates, it might perhaps be better simply to increase the delay used to throttle updates.
This commit is contained in:
Allan Odgaard
2013-02-03 10:48:39 +01:00
parent e599bb7379
commit 0fdd04b6d3
2 changed files with 30 additions and 1 deletions

View File

@@ -17,11 +17,14 @@ namespace scm
namespace scm { namespace ng
{
static bool Disabled = true;
static std::map<std::string, shared_info_weak_ptr> PendingUpdates;
// =================
// = shared_info_t =
// =================
struct shared_info_t
struct shared_info_t : std::enable_shared_from_this<shared_info_t>
{
shared_info_t (std::string const& rootPath, scm::driver_t const* driver);
~shared_info_t ();
@@ -35,6 +38,8 @@ namespace scm { namespace ng
void remove_client (info_t* client);
private:
friend void enable ();
void background_update ();
void fs_did_change (std::set<std::string> const& changedPaths);
@@ -177,6 +182,12 @@ namespace scm { namespace ng
void shared_info_t::background_update ()
{
if(Disabled)
{
PendingUpdates[_root_path] = shared_from_this();
return;
}
if(_pending_update)
return;
_pending_update = true;
@@ -262,6 +273,22 @@ namespace scm { namespace ng
return shared_info_ptr();
}
void disable ()
{
Disabled = true;
}
void enable ()
{
Disabled = false;
for(auto pair : PendingUpdates)
{
if(shared_info_ptr info = pair.second.lock())
info->background_update();
}
PendingUpdates.clear();
}
std::string root_for_path (std::string const& path)
{
if(path == NULL_STR || path == "" || path[0] != '/')

View File

@@ -36,6 +36,8 @@ namespace scm { namespace ng
shared_info_ptr _shared_info;
};
PUBLIC void disable ();
PUBLIC void enable ();
PUBLIC std::string root_for_path (std::string const& path);
PUBLIC info_ptr info (std::string path);