| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ |
| 7 | 7 |
| 8 #include <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/associated_group_controller.h" | 10 #include "mojo/public/cpp/bindings/associated_group_controller.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 template <typename Base, typename T> | 24 template <typename Base, typename T> |
| 25 struct Serializer<AssociatedInterfacePtrInfoDataView<Base>, | 25 struct Serializer<AssociatedInterfacePtrInfoDataView<Base>, |
| 26 AssociatedInterfacePtrInfo<T>> { | 26 AssociatedInterfacePtrInfo<T>> { |
| 27 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); | 27 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 28 | 28 |
| 29 static void Serialize(AssociatedInterfacePtrInfo<T>& input, | 29 static void Serialize(AssociatedInterfacePtrInfo<T>& input, |
| 30 AssociatedInterface_Data* output, | 30 AssociatedInterface_Data* output, |
| 31 SerializationContext* context) { | 31 SerializationContext* context) { |
| 32 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); | 32 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); |
| 33 DCHECK_EQ(input.handle().group_controller(), | 33 if (input.handle().is_valid()) { |
| 34 context->group_controller.get()); | 34 DCHECK_EQ(input.handle().group_controller(), |
| 35 context->group_controller.get()); |
| 36 } |
| 35 output->version = input.version(); | 37 output->version = input.version(); |
| 36 output->interface_id = input.PassHandle().release(); | 38 output->interface_id = input.PassHandle().release(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 static bool Deserialize(AssociatedInterface_Data* input, | 41 static bool Deserialize(AssociatedInterface_Data* input, |
| 40 AssociatedInterfacePtrInfo<T>* output, | 42 AssociatedInterfacePtrInfo<T>* output, |
| 41 SerializationContext* context) { | 43 SerializationContext* context) { |
| 42 output->set_handle(context->group_controller->CreateLocalEndpointHandle( | 44 output->set_handle(context->group_controller->CreateLocalEndpointHandle( |
| 43 FetchAndReset(&input->interface_id))); | 45 FetchAndReset(&input->interface_id))); |
| 44 output->set_version(input->version); | 46 output->set_version(input->version); |
| 45 return true; | 47 return true; |
| 46 } | 48 } |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 template <typename Base, typename T> | 51 template <typename Base, typename T> |
| 50 struct Serializer<AssociatedInterfaceRequestDataView<Base>, | 52 struct Serializer<AssociatedInterfaceRequestDataView<Base>, |
| 51 AssociatedInterfaceRequest<T>> { | 53 AssociatedInterfaceRequest<T>> { |
| 52 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); | 54 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 53 | 55 |
| 54 static void Serialize(AssociatedInterfaceRequest<T>& input, | 56 static void Serialize(AssociatedInterfaceRequest<T>& input, |
| 55 AssociatedInterfaceRequest_Data* output, | 57 AssociatedInterfaceRequest_Data* output, |
| 56 SerializationContext* context) { | 58 SerializationContext* context) { |
| 57 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); | 59 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); |
| 58 DCHECK_EQ(input.handle().group_controller(), | 60 if (input.handle().is_valid()) { |
| 59 context->group_controller.get()); | 61 DCHECK_EQ(input.handle().group_controller(), |
| 62 context->group_controller.get()); |
| 63 } |
| 60 output->interface_id = input.PassHandle().release(); | 64 output->interface_id = input.PassHandle().release(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 static bool Deserialize(AssociatedInterfaceRequest_Data* input, | 67 static bool Deserialize(AssociatedInterfaceRequest_Data* input, |
| 64 AssociatedInterfaceRequest<T>* output, | 68 AssociatedInterfaceRequest<T>* output, |
| 65 SerializationContext* context) { | 69 SerializationContext* context) { |
| 66 output->Bind(context->group_controller->CreateLocalEndpointHandle( | 70 output->Bind(context->group_controller->CreateLocalEndpointHandle( |
| 67 FetchAndReset(&input->interface_id))); | 71 FetchAndReset(&input->interface_id))); |
| 68 return true; | 72 return true; |
| 69 } | 73 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SerializationContext* context) { | 126 SerializationContext* context) { |
| 123 *output = context->handles.TakeHandleAs<T>(*input); | 127 *output = context->handles.TakeHandleAs<T>(*input); |
| 124 return true; | 128 return true; |
| 125 } | 129 } |
| 126 }; | 130 }; |
| 127 | 131 |
| 128 } // namespace internal | 132 } // namespace internal |
| 129 } // namespace mojo | 133 } // namespace mojo |
| 130 | 134 |
| 131 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ | 135 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ |
| OLD | NEW |