| 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> |
| 9 |
| 8 #include "mojo/public/cpp/bindings/associated_group_controller.h" | 10 #include "mojo/public/cpp/bindings/associated_group_controller.h" |
| 9 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 10 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/interface_data_view.h" |
| 11 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 16 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 14 #include "mojo/public/cpp/bindings/lib/serialization_context.h" | 17 #include "mojo/public/cpp/bindings/lib/serialization_context.h" |
| 15 #include "mojo/public/cpp/bindings/lib/serialization_forward.h" | 18 #include "mojo/public/cpp/bindings/lib/serialization_forward.h" |
| 16 #include "mojo/public/cpp/system/handle.h" | 19 #include "mojo/public/cpp/system/handle.h" |
| 17 | 20 |
| 18 namespace mojo { | 21 namespace mojo { |
| 19 namespace internal { | 22 namespace internal { |
| 20 | 23 |
| 21 template <typename T> | 24 template <typename Base, typename T> |
| 22 struct Serializer<AssociatedInterfacePtrInfo<T>, | 25 struct Serializer<AssociatedInterfacePtrInfoDataView<Base>, |
| 23 AssociatedInterfacePtrInfo<T>> { | 26 AssociatedInterfacePtrInfo<T>> { |
| 27 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 28 |
| 24 static void Serialize(AssociatedInterfacePtrInfo<T>& input, | 29 static void Serialize(AssociatedInterfacePtrInfo<T>& input, |
| 25 AssociatedInterface_Data* output, | 30 AssociatedInterface_Data* output, |
| 26 SerializationContext* context) { | 31 SerializationContext* context) { |
| 27 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); | 32 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); |
| 28 DCHECK_EQ(input.handle().group_controller(), | 33 DCHECK_EQ(input.handle().group_controller(), |
| 29 context->group_controller.get()); | 34 context->group_controller.get()); |
| 30 output->version = input.version(); | 35 output->version = input.version(); |
| 31 output->interface_id = input.PassHandle().release(); | 36 output->interface_id = input.PassHandle().release(); |
| 32 } | 37 } |
| 33 | 38 |
| 34 static bool Deserialize(AssociatedInterface_Data* input, | 39 static bool Deserialize(AssociatedInterface_Data* input, |
| 35 AssociatedInterfacePtrInfo<T>* output, | 40 AssociatedInterfacePtrInfo<T>* output, |
| 36 SerializationContext* context) { | 41 SerializationContext* context) { |
| 37 output->set_handle(context->group_controller->CreateLocalEndpointHandle( | 42 output->set_handle(context->group_controller->CreateLocalEndpointHandle( |
| 38 FetchAndReset(&input->interface_id))); | 43 FetchAndReset(&input->interface_id))); |
| 39 output->set_version(input->version); | 44 output->set_version(input->version); |
| 40 return true; | 45 return true; |
| 41 } | 46 } |
| 42 }; | 47 }; |
| 43 | 48 |
| 44 template <typename T> | 49 template <typename Base, typename T> |
| 45 struct Serializer<AssociatedInterfaceRequest<T>, | 50 struct Serializer<AssociatedInterfaceRequestDataView<Base>, |
| 46 AssociatedInterfaceRequest<T>> { | 51 AssociatedInterfaceRequest<T>> { |
| 52 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 53 |
| 47 static void Serialize(AssociatedInterfaceRequest<T>& input, | 54 static void Serialize(AssociatedInterfaceRequest<T>& input, |
| 48 AssociatedInterfaceRequest_Data* output, | 55 AssociatedInterfaceRequest_Data* output, |
| 49 SerializationContext* context) { | 56 SerializationContext* context) { |
| 50 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); | 57 DCHECK(!input.handle().is_valid() || !input.handle().is_local()); |
| 51 DCHECK_EQ(input.handle().group_controller(), | 58 DCHECK_EQ(input.handle().group_controller(), |
| 52 context->group_controller.get()); | 59 context->group_controller.get()); |
| 53 output->interface_id = input.PassHandle().release(); | 60 output->interface_id = input.PassHandle().release(); |
| 54 } | 61 } |
| 55 | 62 |
| 56 static bool Deserialize(AssociatedInterfaceRequest_Data* input, | 63 static bool Deserialize(AssociatedInterfaceRequest_Data* input, |
| 57 AssociatedInterfaceRequest<T>* output, | 64 AssociatedInterfaceRequest<T>* output, |
| 58 SerializationContext* context) { | 65 SerializationContext* context) { |
| 59 output->Bind(context->group_controller->CreateLocalEndpointHandle( | 66 output->Bind(context->group_controller->CreateLocalEndpointHandle( |
| 60 FetchAndReset(&input->interface_id))); | 67 FetchAndReset(&input->interface_id))); |
| 61 return true; | 68 return true; |
| 62 } | 69 } |
| 63 }; | 70 }; |
| 64 | 71 |
| 65 template <typename T> | 72 template <typename Base, typename T> |
| 66 struct Serializer<InterfacePtr<T>, InterfacePtr<T>> { | 73 struct Serializer<InterfacePtrDataView<Base>, InterfacePtr<T>> { |
| 74 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 75 |
| 67 static void Serialize(InterfacePtr<T>& input, | 76 static void Serialize(InterfacePtr<T>& input, |
| 68 Interface_Data* output, | 77 Interface_Data* output, |
| 69 SerializationContext* context) { | 78 SerializationContext* context) { |
| 70 InterfacePtrInfo<T> info = input.PassInterface(); | 79 InterfacePtrInfo<T> info = input.PassInterface(); |
| 71 output->handle = context->handles.AddHandle(info.PassHandle().release()); | 80 output->handle = context->handles.AddHandle(info.PassHandle().release()); |
| 72 output->version = info.version(); | 81 output->version = info.version(); |
| 73 } | 82 } |
| 74 | 83 |
| 75 static bool Deserialize(Interface_Data* input, | 84 static bool Deserialize(Interface_Data* input, |
| 76 InterfacePtr<T>* output, | 85 InterfacePtr<T>* output, |
| 77 SerializationContext* context) { | 86 SerializationContext* context) { |
| 78 output->Bind(InterfacePtrInfo<T>( | 87 output->Bind(InterfacePtrInfo<T>( |
| 79 context->handles.TakeHandleAs<mojo::MessagePipeHandle>(input->handle), | 88 context->handles.TakeHandleAs<mojo::MessagePipeHandle>(input->handle), |
| 80 input->version)); | 89 input->version)); |
| 81 return true; | 90 return true; |
| 82 } | 91 } |
| 83 }; | 92 }; |
| 84 | 93 |
| 85 template <typename T> | 94 template <typename Base, typename T> |
| 86 struct Serializer<InterfaceRequest<T>, InterfaceRequest<T>> { | 95 struct Serializer<InterfaceRequestDataView<Base>, InterfaceRequest<T>> { |
| 96 static_assert(std::is_base_of<Base, T>::value, "Interface type mismatch."); |
| 97 |
| 87 static void Serialize(InterfaceRequest<T>& input, | 98 static void Serialize(InterfaceRequest<T>& input, |
| 88 Handle_Data* output, | 99 Handle_Data* output, |
| 89 SerializationContext* context) { | 100 SerializationContext* context) { |
| 90 *output = context->handles.AddHandle(input.PassMessagePipe().release()); | 101 *output = context->handles.AddHandle(input.PassMessagePipe().release()); |
| 91 } | 102 } |
| 92 | 103 |
| 93 static bool Deserialize(Handle_Data* input, | 104 static bool Deserialize(Handle_Data* input, |
| 94 InterfaceRequest<T>* output, | 105 InterfaceRequest<T>* output, |
| 95 SerializationContext* context) { | 106 SerializationContext* context) { |
| 96 output->Bind(context->handles.TakeHandleAs<MessagePipeHandle>(*input)); | 107 output->Bind(context->handles.TakeHandleAs<MessagePipeHandle>(*input)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 111 SerializationContext* context) { | 122 SerializationContext* context) { |
| 112 *output = context->handles.TakeHandleAs<T>(*input); | 123 *output = context->handles.TakeHandleAs<T>(*input); |
| 113 return true; | 124 return true; |
| 114 } | 125 } |
| 115 }; | 126 }; |
| 116 | 127 |
| 117 } // namespace internal | 128 } // namespace internal |
| 118 } // namespace mojo | 129 } // namespace mojo |
| 119 | 130 |
| 120 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ | 131 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_INTERFACE_SERIALIZATION_H_ |
| OLD | NEW |