You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/11/15 22:28:05 UTC

mesos git commit: Enabled rvalue reference parameters in protobuf handlers.

Repository: mesos
Updated Branches:
  refs/heads/master 8fc5658b5 -> 8cd1bd2fc


Enabled rvalue reference parameters in protobuf handlers.

Using rvalue reference parameter in protobuf handler opts-out of arena
usage, and allows the handler to move the message.

Review: https://reviews.apache.org/r/63639/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8cd1bd2f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8cd1bd2f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8cd1bd2f

Branch: refs/heads/master
Commit: 8cd1bd2fcb8a4d2330a781a86b62e55ada6d4984
Parents: 8fc5658
Author: Dmitry Zhuk <dz...@twopensource.com>
Authored: Wed Nov 15 14:19:39 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Wed Nov 15 14:19:39 2017 -0800

----------------------------------------------------------------------
 .../libprocess/include/process/protobuf.hpp     | 60 ++++++++++++++++++++
 1 file changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8cd1bd2f/3rdparty/libprocess/include/process/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/protobuf.hpp b/3rdparty/libprocess/include/process/protobuf.hpp
index 5b9794f..08605db 100644
--- a/3rdparty/libprocess/include/process/protobuf.hpp
+++ b/3rdparty/libprocess/include/process/protobuf.hpp
@@ -134,6 +134,18 @@ protected:
     delete m;
   }
 
+  template <typename M>
+  void install(void (T::*method)(const process::UPID&, M&&))
+  {
+    google::protobuf::Message* m = new M();
+    T* t = static_cast<T*>(this);
+    protobufHandlers[m->GetTypeName()] =
+      lambda::bind(&handlerMutM<M>,
+                   t, method,
+                   lambda::_1, lambda::_2);
+    delete m;
+  }
+
   template <typename M, typename P>
   using MessageProperty = P(M::*)() const;
 
@@ -183,6 +195,18 @@ protected:
   }
 
   template <typename M>
+  void install(void (T::*method)(M&&))
+  {
+    google::protobuf::Message* m = new M();
+    T* t = static_cast<T*>(this);
+    protobufHandlers[m->GetTypeName()] =
+      lambda::bind(&_handlerMutM<M>,
+                   t, method,
+                   lambda::_1, lambda::_2);
+    delete m;
+  }
+
+  template <typename M>
   void install(void (T::*method)())
   {
     google::protobuf::Message* m = new M();
@@ -237,6 +261,24 @@ private:
     }
   }
 
+  template <typename M>
+  static void handlerMutM(
+      T* t,
+      void (T::*method)(const process::UPID&, M&&),
+      const process::UPID& sender,
+      const std::string& data)
+  {
+    M m;
+    m.ParseFromString(data);
+
+    if (m.IsInitialized()) {
+      (t->*method)(sender, std::move(m));
+    } else {
+      LOG(WARNING) << "Initialization errors: "
+                   << m.InitializationErrorString();
+    }
+  }
+
   static void handler0(
       T* t,
       void (T::*method)(const process::UPID&),
@@ -287,6 +329,24 @@ private:
     }
   }
 
+  template <typename M>
+  static void _handlerMutM(
+      T* t,
+      void (T::*method)(M&&),
+      const process::UPID&,
+      const std::string& data)
+  {
+    M m;
+    m.ParseFromString(data);
+
+    if (m.IsInitialized()) {
+      (t->*method)(std::move(m));
+    } else {
+      LOG(WARNING) << "Initialization errors: "
+                   << m.InitializationErrorString();
+    }
+  }
+
   static void _handler0(
       T* t,
       void (T::*method)(),