OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "mojo/android/system/core_impl.h" | 5 #include "mojo/android/system/core_impl.h" |
6 | 6 |
7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_registrar.h" | 9 #include "base/android/jni_registrar.h" |
10 #include "base/android/library_loader/library_loader_hooks.h" | 10 #include "base/android/library_loader/library_loader_hooks.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 return MojoGetTimeTicksNow(); | 57 return MojoGetTimeTicksNow(); |
58 } | 58 } |
59 | 59 |
60 static jint WaitMany(JNIEnv* env, | 60 static jint WaitMany(JNIEnv* env, |
61 jobject jcaller, | 61 jobject jcaller, |
62 jobject buffer, | 62 jobject buffer, |
63 jlong deadline) { | 63 jlong deadline) { |
64 // Buffer contains first the list of handles, then the list of signals. | 64 // Buffer contains first the list of handles, then the list of signals. |
65 const void* buffer_start = env->GetDirectBufferAddress(buffer); | 65 const void* buffer_start = env->GetDirectBufferAddress(buffer); |
66 DCHECK(buffer_start); | 66 DCHECK(buffer_start); |
67 DCHECK_EQ(0, reinterpret_cast<const uintptr_t>(buffer_start) % 8); | |
viettrungluu
2014/07/21 17:12:29
Nit (here and everywhere else): No need for |const
qsr
2014/07/22 08:15:11
Done.
| |
67 const size_t record_size = 8; | 68 const size_t record_size = 8; |
68 const size_t buffer_size = env->GetDirectBufferCapacity(buffer); | 69 const size_t buffer_size = env->GetDirectBufferCapacity(buffer); |
69 DCHECK_EQ(buffer_size % record_size, 0u); | 70 DCHECK_EQ(buffer_size % record_size, 0u); |
70 | 71 |
71 const size_t nb_handles = buffer_size / record_size; | 72 const size_t nb_handles = buffer_size / record_size; |
72 const MojoHandle* handle_start = static_cast<const MojoHandle*>(buffer_start); | 73 const MojoHandle* handle_start = static_cast<const MojoHandle*>(buffer_start); |
73 const MojoHandleSignals* signals_start = | 74 const MojoHandleSignals* signals_start = |
74 static_cast<const MojoHandleSignals*>(handle_start + nb_handles); | 75 static_cast<const MojoHandleSignals*>(handle_start + nb_handles); |
75 return MojoWaitMany(handle_start, signals_start, nb_handles, deadline); | 76 return MojoWaitMany(handle_start, signals_start, nb_handles, deadline); |
76 } | 77 } |
77 | 78 |
78 static jobject CreateMessagePipe(JNIEnv* env, | 79 static jobject CreateMessagePipe(JNIEnv* env, |
79 jobject jcaller, | 80 jobject jcaller, |
80 jobject options_buffer) { | 81 jobject options_buffer) { |
81 const MojoCreateMessagePipeOptions* options = NULL; | 82 const MojoCreateMessagePipeOptions* options = NULL; |
82 if (options_buffer) { | 83 if (options_buffer) { |
83 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 84 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
84 DCHECK(buffer_start); | 85 DCHECK(buffer_start); |
86 DCHECK_EQ(0, reinterpret_cast<const uintptr_t>(buffer_start) % 8); | |
85 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); | 87 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); |
86 DCHECK_EQ(buffer_size, sizeof(MojoCreateMessagePipeOptions)); | 88 DCHECK_EQ(buffer_size, sizeof(MojoCreateMessagePipeOptions)); |
87 options = static_cast<const MojoCreateMessagePipeOptions*>(buffer_start); | 89 options = static_cast<const MojoCreateMessagePipeOptions*>(buffer_start); |
88 DCHECK_EQ(options->struct_size, buffer_size); | 90 DCHECK_EQ(options->struct_size, buffer_size); |
89 } | 91 } |
90 MojoHandle handle1; | 92 MojoHandle handle1; |
91 MojoHandle handle2; | 93 MojoHandle handle2; |
92 MojoResult result = MojoCreateMessagePipe(options, &handle1, &handle2); | 94 MojoResult result = MojoCreateMessagePipe(options, &handle1, &handle2); |
93 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) | 95 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) |
94 .Release(); | 96 .Release(); |
95 } | 97 } |
96 | 98 |
97 static jobject CreateDataPipe(JNIEnv* env, | 99 static jobject CreateDataPipe(JNIEnv* env, |
98 jobject jcaller, | 100 jobject jcaller, |
99 jobject options_buffer) { | 101 jobject options_buffer) { |
100 const MojoCreateDataPipeOptions* options = NULL; | 102 const MojoCreateDataPipeOptions* options = NULL; |
101 if (options_buffer) { | 103 if (options_buffer) { |
102 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 104 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
103 DCHECK(buffer_start); | 105 DCHECK(buffer_start); |
106 DCHECK_EQ(0, reinterpret_cast<const uintptr_t>(buffer_start) % 8); | |
104 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); | 107 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); |
105 DCHECK_EQ(buffer_size, sizeof(MojoCreateDataPipeOptions)); | 108 DCHECK_EQ(buffer_size, sizeof(MojoCreateDataPipeOptions)); |
106 options = static_cast<const MojoCreateDataPipeOptions*>(buffer_start); | 109 options = static_cast<const MojoCreateDataPipeOptions*>(buffer_start); |
107 DCHECK_EQ(options->struct_size, buffer_size); | 110 DCHECK_EQ(options->struct_size, buffer_size); |
108 } | 111 } |
109 MojoHandle handle1; | 112 MojoHandle handle1; |
110 MojoHandle handle2; | 113 MojoHandle handle2; |
111 MojoResult result = MojoCreateDataPipe(options, &handle1, &handle2); | 114 MojoResult result = MojoCreateDataPipe(options, &handle1, &handle2); |
112 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) | 115 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) |
113 .Release(); | 116 .Release(); |
114 } | 117 } |
115 | 118 |
116 static jobject CreateSharedBuffer(JNIEnv* env, | 119 static jobject CreateSharedBuffer(JNIEnv* env, |
117 jobject jcaller, | 120 jobject jcaller, |
118 jobject options_buffer, | 121 jobject options_buffer, |
119 jlong num_bytes) { | 122 jlong num_bytes) { |
120 const MojoCreateSharedBufferOptions* options = 0; | 123 const MojoCreateSharedBufferOptions* options = 0; |
121 if (options_buffer) { | 124 if (options_buffer) { |
122 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 125 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
123 DCHECK(buffer_start); | 126 DCHECK(buffer_start); |
127 DCHECK_EQ(0, reinterpret_cast<const uintptr_t>(buffer_start) % 8); | |
124 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); | 128 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); |
125 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions)); | 129 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions)); |
126 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start); | 130 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start); |
127 DCHECK_EQ(options->struct_size, buffer_size); | 131 DCHECK_EQ(options->struct_size, buffer_size); |
128 } | 132 } |
129 MojoHandle handle; | 133 MojoHandle handle; |
130 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle); | 134 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle); |
131 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) | 135 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) |
132 .Release(); | 136 .Release(); |
133 } | 137 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); | 373 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); |
370 mojo::Environment::GetDefaultAsyncWaiter()->CancelWait(id); | 374 mojo::Environment::GetDefaultAsyncWaiter()->CancelWait(id); |
371 } | 375 } |
372 | 376 |
373 bool RegisterCoreImpl(JNIEnv* env) { | 377 bool RegisterCoreImpl(JNIEnv* env) { |
374 return RegisterNativesImpl(env); | 378 return RegisterNativesImpl(env); |
375 } | 379 } |
376 | 380 |
377 } // namespace android | 381 } // namespace android |
378 } // namespace mojo | 382 } // namespace mojo |
OLD | NEW |