Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
|
viettrungluu
2016/02/10 01:04:08
I got to this file (and haven't reviewed it yet).
vardhan
2016/02/11 22:47:53
hi!
| |
| 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_BINDINGS_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 11 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 | 14 |
| 15 template <typename I> | 15 template <typename I> |
| 16 class InterfacePtr; | |
| 17 | |
| 18 template <typename I> | |
| 19 class InterfaceHandle; | 16 class InterfaceHandle; |
| 20 | 17 |
| 21 namespace internal { | 18 namespace internal { |
| 22 | 19 |
| 23 // Please note that this is a different value than |mojo::kInvalidHandleValue|, | 20 // Please note that this is a different value than |mojo::kInvalidHandleValue|, |
| 24 // which is the "decoded" invalid handle. | 21 // which is the "decoded" invalid handle. |
| 25 const MojoHandle kEncodedInvalidHandleValue = static_cast<MojoHandle>(-1); | 22 const MojoHandle kEncodedInvalidHandleValue = static_cast<MojoHandle>(-1); |
| 26 | 23 |
| 27 size_t Align(size_t size); | 24 size_t Align(size_t size); |
| 28 char* AlignPointer(char* ptr); | 25 char* AlignPointer(char* ptr); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 67 |
| 71 // Note: This function doesn't validate the encoded pointer and handle values. | 68 // Note: This function doesn't validate the encoded pointer and handle values. |
| 72 template <typename T> | 69 template <typename T> |
| 73 inline void Decode(T* obj, std::vector<Handle>* handles) { | 70 inline void Decode(T* obj, std::vector<Handle>* handles) { |
| 74 DecodePointer(&obj->offset, &obj->ptr); | 71 DecodePointer(&obj->offset, &obj->ptr); |
| 75 if (obj->ptr) | 72 if (obj->ptr) |
| 76 obj->ptr->DecodePointersAndHandles(handles); | 73 obj->ptr->DecodePointersAndHandles(handles); |
| 77 } | 74 } |
| 78 | 75 |
| 79 template <typename T> | 76 template <typename T> |
| 80 inline void InterfacePointerToData(InterfacePtr<T> input, | 77 inline void InterfaceHandleToData(InterfaceHandle<T> input, |
| 81 Interface_Data* output) { | 78 Interface_Data* output) { |
| 82 InterfaceHandle<T> info = input.PassInterfaceHandle(); | 79 output->handle = input.PassHandle().release(); |
| 83 output->handle = info.PassHandle().release(); | 80 output->version = input.version(); |
| 84 output->version = info.version(); | |
| 85 } | 81 } |
| 86 | 82 |
| 87 template <typename T> | 83 template <typename T> |
| 88 inline void InterfaceDataToPointer(Interface_Data* input, | 84 inline void InterfaceDataToHandle(Interface_Data* input, |
| 89 InterfacePtr<T>* output) { | 85 InterfaceHandle<T>* output) { |
| 90 output->Bind(InterfaceHandle<T>( | 86 *output = InterfaceHandle<T>(MakeScopedHandle(FetchAndReset(&input->handle)), |
| 91 MakeScopedHandle(FetchAndReset(&input->handle)), input->version)); | 87 input->version); |
| 92 } | 88 } |
| 93 | 89 |
| 94 } // namespace internal | 90 } // namespace internal |
| 95 } // namespace mojo | 91 } // namespace mojo |
| 96 | 92 |
| 97 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_H_ | 93 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_SERIALIZATION_H_ |
| OLD | NEW |