You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/09/23 18:43:41 UTC

svn commit: r1000534 - in /subversion/branches/object-model/subversion: bindings/c++/Client.cpp bindings/c++/include/Client.h bindings/c++/include/Types.h tests/libsvn++/client-test.cpp

Author: hwright
Date: Thu Sep 23 16:43:40 2010
New Revision: 1000534

URL: http://svn.apache.org/viewvc?rev=1000534&view=rev
Log:
On the object-model branch:
Allow Client API consumers to subscribe to notifications.  This allows
multiple objects to be notified when an event occurs.

* subversion/bindings/c++/Client.cpp
  (Client): Set the notification function and baton in the context.
  (notify_func2, notify): New.

* subversion/bindings/c++/include/Client.h
  (notify_func2, notify, notifiers): New private members.
  (subscribeNotifier, unsubscribeNotifier): New public members.

* subversion/bindings/c++/include/Types.h
  (ClientNotifyInfo): New (but lacking getters right now).
 
* subversion/tests/libsvn++/client-test.cpp
  (Notifier, cleanup_baton): New.
  (cleanup_client): Destroy the notifier, as well as the client.
  (get_client): Add a default notifier.

Modified:
    subversion/branches/object-model/subversion/bindings/c++/Client.cpp
    subversion/branches/object-model/subversion/bindings/c++/include/Client.h
    subversion/branches/object-model/subversion/bindings/c++/include/Types.h
    subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp

Modified: subversion/branches/object-model/subversion/bindings/c++/Client.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Client.cpp?rev=1000534&r1=1000533&r2=1000534&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Client.cpp (original)
+++ subversion/branches/object-model/subversion/bindings/c++/Client.cpp Thu Sep 23 16:43:40 2010
@@ -34,6 +34,9 @@ Client::Client()
   : m_pool()
 {
   svn_error_clear(svn_client_create_context(&m_ctx, m_pool.pool()));
+
+  m_ctx->notify_func2 = notify_func2;
+  m_ctx->notify_baton2 = this;
 }
 
 Client::~Client()
@@ -99,4 +102,23 @@ Client::commit(const std::vector<std::st
                 m_ctx, pool.pool()));
 }
 
+void
+Client::notify_func2(void *baton,
+                     const svn_wc_notify_t *notify,
+                     apr_pool_t *pool)
+{
+  reinterpret_cast<Client *>(baton)->notify(ClientNotifyInfo(notify));
+}
+
+void
+Client::notify(const ClientNotifyInfo &info)
+{
+  for (std::set<Callback::ClientNotifier *>::const_iterator it
+                                                    = m_notifiers.begin();
+        it != m_notifiers.end(); ++it)
+    {
+      (*it)->notify(info);
+    }
+}
+
 }

Modified: subversion/branches/object-model/subversion/bindings/c++/include/Client.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Client.h?rev=1000534&r1=1000533&r2=1000534&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Client.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Client.h Thu Sep 23 16:43:40 2010
@@ -39,6 +39,7 @@
 #include <ostream>
 #include <string>
 #include <vector>
+#include <set>
 
 namespace SVN
 {
@@ -48,6 +49,13 @@ namespace SVN
     private:
       Pool m_pool;
       svn_client_ctx_t *m_ctx;
+      
+      std::set<Callback::ClientNotifier *> m_notifiers;
+
+      static void notify_func2(void *baton,
+                               const svn_wc_notify_t *notify,
+                               apr_pool_t *pool);
+      void notify(const ClientNotifyInfo &info);
 
     public:
       /** The constructor. */
@@ -59,6 +67,15 @@ namespace SVN
       /** The real work of the destructor.  Useful for "placement delete". */
       void dispose();
 
+      inline void subscribeNotifier(Callback::ClientNotifier *notifier)
+      {
+        m_notifiers.insert(notifier);
+      }
+      inline void unsubscribeNotifier(Callback::ClientNotifier *notifier)
+      {
+        m_notifiers.erase(m_notifiers.find(notifier));
+      }
+
       Version getVersion();
 
       inline void cat(std::ostream &stream, const std::string &path_or_url)

Modified: subversion/branches/object-model/subversion/bindings/c++/include/Types.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Types.h?rev=1000534&r1=1000533&r2=1000534&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Types.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Types.h Thu Sep 23 16:43:40 2010
@@ -30,6 +30,7 @@
 #include "Pool.h"
 #include "Revision.h"
 
+#include "svn_wc.h"
 #include "svn_types.h"
 
 #include <map>
@@ -102,6 +103,35 @@ class CommitInfo
     }
 };
 
+class ClientNotifyInfo
+{
+  private:
+    Pool m_pool;
+    svn_wc_notify_t *m_notify;
+
+  public:
+    inline
+    ClientNotifyInfo(const svn_wc_notify_t *info)
+      : m_pool()
+    {
+      m_notify = svn_wc_dup_notify(info, m_pool.pool());
+    }
+
+    inline
+    ClientNotifyInfo(const ClientNotifyInfo &that)
+      : m_pool()
+    {
+      m_notify = svn_wc_dup_notify(that.m_notify, m_pool.pool());
+    }
+
+    inline ClientNotifyInfo &
+    operator=(const ClientNotifyInfo &that)
+    {
+      m_pool.clear();
+      m_notify = svn_wc_dup_notify(that.m_notify, m_pool.pool());
+    }
+};
+
 }
 
 

Modified: subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/client-test.cpp?rev=1000534&r1=1000533&r2=1000534&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp (original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp Thu Sep 23 16:43:40 2010
@@ -37,15 +37,32 @@
 
 using namespace SVN;
 
+class Notifier : public Callback::ClientNotifier
+{
+  public:
+    void notify(const SVN::ClientNotifyInfo&)
+    {
+    }
+};
+
+struct cleanup_baton
+{
+  Client *client;
+  Notifier *notifier;
+};
+
 static apr_status_t
 cleanup_client(void *baton)
 {
-  Client *client = reinterpret_cast<Client *>(baton);
+  struct cleanup_baton *cb = reinterpret_cast<struct cleanup_baton *>(baton);
 
   // Explicitly call the destructor.  We can only do this since we used
   // the "placement new" syntax to create the object, and the pool will
   // reclaim the memory for us.
-  client->~Client();
+  cb->client->~Client();
+  cb->notifier->~Notifier();
+
+  delete cb;
 
   return APR_SUCCESS;
 }
@@ -58,7 +75,15 @@ get_client(Pool &pool)
   void *buf = pool.alloc(sizeof(Client));
   Client *client = new (buf) Client();
 
-  pool.registerCleanup(cleanup_client, client);
+  buf = pool.alloc(sizeof(Notifier));
+  Notifier *notifier = new (buf) Notifier();
+  client->subscribeNotifier(notifier);
+
+  struct cleanup_baton *cb = new cleanup_baton;
+  cb->client = client;
+  cb->notifier = notifier;
+
+  pool.registerCleanup(cleanup_client, cb);
 
   return client;
 }