// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ #define PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ #include "base/basictypes.h" #include "base/pickle.h" #include "base/tuple.h" #include "ipc/ipc_message.h" #include "ipc/ipc_message_utils.h" namespace ppapi { namespace internal { // TupleTypeMatch* check whether a tuple type contains elements of the specified // types. They are used to make sure the output parameters of UnpackMessage() // match the corresponding message type. template struct TupleTypeMatch1 { static const bool kValue = false; }; template struct TupleTypeMatch1, A> { static const bool kValue = true; }; template struct TupleTypeMatch2 { static const bool kValue = false; }; template struct TupleTypeMatch2, A, B> { static const bool kValue = true; }; template struct TupleTypeMatch3 { static const bool kValue = false; }; template struct TupleTypeMatch3, A, B, C> { static const bool kValue = true; }; template struct TupleTypeMatch4 { static const bool kValue = false; }; template struct TupleTypeMatch4, A, B, C, D> { static const bool kValue = true; }; template struct TupleTypeMatch5 { static const bool kValue = false; }; template struct TupleTypeMatch5, A, B, C, D, E> { static const bool kValue = true; }; } // namespace internal template bool UnpackMessage(const IPC::Message& msg, A* a) { static_assert( (internal::TupleTypeMatch1::kValue), "tuple types should match"); PickleIterator iter(msg); return IPC::ReadParam(&msg, &iter, a); } template bool UnpackMessage(const IPC::Message& msg, A* a, B* b) { static_assert( (internal::TupleTypeMatch2::kValue), "tuple types should match"); PickleIterator iter(msg); return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b); } template bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c) { static_assert( (internal::TupleTypeMatch3::kValue), "tuple types should match"); PickleIterator iter(msg); return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b) && IPC::ReadParam(&msg, &iter, c); } template bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d) { static_assert( (internal::TupleTypeMatch4::kValue), "tuple types should match"); PickleIterator iter(msg); return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b) && IPC::ReadParam(&msg, &iter, c) && IPC::ReadParam(&msg, &iter, d); } template bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e) { static_assert( (internal::TupleTypeMatch5< typename MsgClass::Param, A, B, C, D, E>::kValue), "tuple types should match"); PickleIterator iter(msg); return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b) && IPC::ReadParam(&msg, &iter, c) && IPC::ReadParam(&msg, &iter, d) && IPC::ReadParam(&msg, &iter, e); } } // namespace ppapi #endif // PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_