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 2014/12/02 22:57:03 UTC
mesos git commit: Extended install() to support more arguments.
Repository: mesos
Updated Branches:
refs/heads/master bf977ec84 -> 0750549cb
Extended install() to support more arguments.
Review: https://reviews.apache.org/r/28363
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0750549c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0750549c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0750549c
Branch: refs/heads/master
Commit: 0750549cb6017a1b897606832d80c413fa5bb158
Parents: bf977ec
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Tue Dec 2 13:51:47 2014 -0800
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Dec 2 13:52:43 2014 -0800
----------------------------------------------------------------------
.../libprocess/include/process/protobuf.hpp | 123 +++++++++++++++++++
1 file changed, 123 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0750549c/3rdparty/libprocess/include/process/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/protobuf.hpp b/3rdparty/libprocess/include/process/protobuf.hpp
index f3fc539..91493de 100644
--- a/3rdparty/libprocess/include/process/protobuf.hpp
+++ b/3rdparty/libprocess/include/process/protobuf.hpp
@@ -114,6 +114,7 @@ protected:
send(from, message);
}
+ // TODO(vinod): Use ENUM_PARAMS for the overloads.
// Installs that take the sender as the first argument.
template <typename M>
void install(void (T::*method)(const process::UPID&, const M&))
@@ -234,6 +235,32 @@ protected:
delete m;
}
+ template <typename M,
+ typename P1, typename P1C,
+ typename P2, typename P2C,
+ typename P3, typename P3C,
+ typename P4, typename P4C,
+ typename P5, typename P5C,
+ typename P6, typename P6C>
+ void install(
+ void (T::*method)(const process::UPID&, P1C, P2C, P3C, P4C, P5C, P6C),
+ P1 (M::*p1)() const,
+ P2 (M::*p2)() const,
+ P3 (M::*p3)() const,
+ P4 (M::*p4)() const,
+ P5 (M::*p5)() const,
+ P6 (M::*p6)() const)
+ {
+ google::protobuf::Message* m = new M();
+ T* t = static_cast<T*>(this);
+ protobufHandlers[m->GetTypeName()] =
+ lambda::bind(&handler6<M, P1, P1C, P2, P2C, P3, P3C,
+ P4, P4C, P5, P5C, P6, P6C>,
+ t, method, p1, p2, p3, p4, p5, p6,
+ lambda::_1, lambda::_2);
+ delete m;
+ }
+
// Installs that do not take the sender.
template <typename M>
void install(void (T::*method)(const M&))
@@ -354,6 +381,32 @@ protected:
delete m;
}
+ template <typename M,
+ typename P1, typename P1C,
+ typename P2, typename P2C,
+ typename P3, typename P3C,
+ typename P4, typename P4C,
+ typename P5, typename P5C,
+ typename P6, typename P6C>
+ void install(
+ void (T::*method)(P1C, P2C, P3C, P4C, P5C, P6C),
+ P1 (M::*p1)() const,
+ P2 (M::*p2)() const,
+ P3 (M::*p3)() const,
+ P4 (M::*p4)() const,
+ P5 (M::*p5)() const,
+ P6 (M::*p6)() const)
+ {
+ google::protobuf::Message* m = new M();
+ T* t = static_cast<T*>(this);
+ protobufHandlers[m->GetTypeName()] =
+ lambda::bind(&_handler6<M, P1, P1C, P2, P2C, P3, P3C,
+ P4, P4C, P5, P5C, P6, P6C>,
+ t, method, p1, p2, p3, p4, p5, p6,
+ lambda::_1, lambda::_2);
+ delete m;
+ }
+
using process::Process<T>::install;
private:
@@ -513,6 +566,42 @@ private:
}
}
+ template <typename M,
+ typename P1, typename P1C,
+ typename P2, typename P2C,
+ typename P3, typename P3C,
+ typename P4, typename P4C,
+ typename P5, typename P5C,
+ typename P6, typename P6C>
+ static void handler6(
+ T* t,
+ void (T::*method)(const process::UPID&, P1C, P2C, P3C, P4C, P5C, P6C),
+ P1 (M::*p1)() const,
+ P2 (M::*p2)() const,
+ P3 (M::*p3)() const,
+ P4 (M::*p4)() const,
+ P5 (M::*p5)() const,
+ P6 (M::*p6)() const,
+ const process::UPID& sender,
+ const std::string& data)
+ {
+ M m;
+ m.ParseFromString(data);
+ if (m.IsInitialized()) {
+ (t->*method)(sender,
+ google::protobuf::convert((&m->*p1)()),
+ google::protobuf::convert((&m->*p2)()),
+ google::protobuf::convert((&m->*p3)()),
+ google::protobuf::convert((&m->*p4)()),
+ google::protobuf::convert((&m->*p5)()),
+ google::protobuf::convert((&m->*p6)()));
+ } else {
+ LOG(WARNING) << "Initialization errors: "
+ << m.InitializationErrorString();
+ }
+ }
+
+
// Handlers that ignore the sender.
template <typename M>
static void _handlerM(
@@ -665,6 +754,40 @@ private:
}
}
+ template <typename M,
+ typename P1, typename P1C,
+ typename P2, typename P2C,
+ typename P3, typename P3C,
+ typename P4, typename P4C,
+ typename P5, typename P5C,
+ typename P6, typename P6C>
+ static void _handler6(
+ T* t,
+ void (T::*method)(P1C, P2C, P3C, P4C, P5C, P6C),
+ P1 (M::*p1)() const,
+ P2 (M::*p2)() const,
+ P3 (M::*p3)() const,
+ P4 (M::*p4)() const,
+ P5 (M::*p5)() const,
+ P6 (M::*p6)() const,
+ const process::UPID&,
+ const std::string& data)
+ {
+ M m;
+ m.ParseFromString(data);
+ if (m.IsInitialized()) {
+ (t->*method)(google::protobuf::convert((&m->*p1)()),
+ google::protobuf::convert((&m->*p2)()),
+ google::protobuf::convert((&m->*p3)()),
+ google::protobuf::convert((&m->*p4)()),
+ google::protobuf::convert((&m->*p5)()),
+ google::protobuf::convert((&m->*p6)()));
+ } else {
+ LOG(WARNING) << "Initialization errors: "
+ << m.InitializationErrorString();
+ }
+ }
+
typedef lambda::function<
void(const process::UPID&, const std::string&)> handler;
hashmap<std::string, handler> protobufHandlers;