#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_
#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_
#include <assert.h>
#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/system/core.h"
namespace mojo {
class NoInterface;
class NoInterfaceStub : public MessageReceiver {
public:
NoInterfaceStub(NoInterface* unused) {}
virtual bool Accept(Message* message) MOJO_OVERRIDE;
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
MOJO_OVERRIDE;
};
class NoInterface {
public:
typedef NoInterfaceStub _Stub;
typedef NoInterface _Peer;
};
typedef NoInterface AnyInterface;
template <typename S>
class InterfaceHandle : public MessagePipeHandle {
public:
InterfaceHandle() {}
explicit InterfaceHandle(MojoHandle value) : MessagePipeHandle(value) {}
};
template <typename S>
struct Interface {
typedef InterfaceHandle<S> Handle;
typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle;
};
template <>
struct Interface<mojo::NoInterface> {
typedef MessagePipeHandle Handle;
typedef ScopedMessagePipeHandle ScopedHandle;
};
template <typename S, typename P = typename S::_Peer>
class InterfacePipe {
public:
InterfacePipe() {
typename Interface<S>::Handle h0;
typename Interface<P>::Handle h1;
MojoResult result MOJO_ALLOW_UNUSED =
MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value());
assert(result == MOJO_RESULT_OK);
handle_to_self.reset(h0);
handle_to_peer.reset(h1);
}
typename Interface<S>::ScopedHandle handle_to_self;
typename Interface<P>::ScopedHandle handle_to_peer;
};
}
#endif