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/spy/spy.h" | 5 #include "mojo/spy/spy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 message_count_[1] = 0; | 42 message_count_[1] = 0; |
43 handle_count_[0] = 0; | 43 handle_count_[0] = 0; |
44 handle_count_[1] = 0; | 44 handle_count_[1] = 0; |
45 } | 45 } |
46 | 46 |
47 void Start(mojo::ScopedMessagePipeHandle client, | 47 void Start(mojo::ScopedMessagePipeHandle client, |
48 mojo::ScopedMessagePipeHandle interceptor) { | 48 mojo::ScopedMessagePipeHandle interceptor) { |
49 std::vector<mojo::MessagePipeHandle> pipes; | 49 std::vector<mojo::MessagePipeHandle> pipes; |
50 pipes.push_back(client.get()); | 50 pipes.push_back(client.get()); |
51 pipes.push_back(interceptor.get()); | 51 pipes.push_back(interceptor.get()); |
52 std::vector<MojoWaitFlags> wait_flags; | 52 std::vector<MojoHandleSignals> handle_signals; |
53 wait_flags.push_back(MOJO_WAIT_FLAG_READABLE); | 53 handle_signals.push_back(MOJO_WAIT_FLAG_READABLE); |
54 wait_flags.push_back(MOJO_WAIT_FLAG_READABLE); | 54 handle_signals.push_back(MOJO_WAIT_FLAG_READABLE); |
55 | 55 |
56 scoped_ptr<char[]> mbuf(new char[kMessageBufSize]); | 56 scoped_ptr<char[]> mbuf(new char[kMessageBufSize]); |
57 scoped_ptr<MojoHandle[]> hbuf(new MojoHandle[kHandleBufSize]); | 57 scoped_ptr<MojoHandle[]> hbuf(new MojoHandle[kHandleBufSize]); |
58 | 58 |
59 // Main processing loop: | 59 // Main processing loop: |
60 // 1- Wait for an endpoint to have a message. | 60 // 1- Wait for an endpoint to have a message. |
61 // 2- Read the message | 61 // 2- Read the message |
62 // 3- Log data | 62 // 3- Log data |
63 // 4- Wait until the opposite port is ready for writting | 63 // 4- Wait until the opposite port is ready for writting |
64 // 4- Write the message to opposite port. | 64 // 4- Write the message to opposite port. |
65 | 65 |
66 for (;;) { | 66 for (;;) { |
67 int r = WaitMany(pipes, wait_flags, MOJO_DEADLINE_INDEFINITE); | 67 int r = WaitMany(pipes, handle_signals, MOJO_DEADLINE_INDEFINITE); |
68 if ((r < 0) || (r > 1)) { | 68 if ((r < 0) || (r > 1)) { |
69 last_result_ = r; | 69 last_result_ = r; |
70 break; | 70 break; |
71 } | 71 } |
72 | 72 |
73 uint32_t bytes_read = kMessageBufSize; | 73 uint32_t bytes_read = kMessageBufSize; |
74 uint32_t handles_read = kHandleBufSize; | 74 uint32_t handles_read = kHandleBufSize; |
75 | 75 |
76 if (!CheckResult(ReadMessageRaw(pipes[r], | 76 if (!CheckResult(ReadMessageRaw(pipes[r], |
77 mbuf.get(), &bytes_read, | 77 mbuf.get(), &bytes_read, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Start intercepting mojo services. | 206 // Start intercepting mojo services. |
207 service_manager->SetInterceptor(new SpyInterceptor()); | 207 service_manager->SetInterceptor(new SpyInterceptor()); |
208 } | 208 } |
209 | 209 |
210 Spy::~Spy(){ | 210 Spy::~Spy(){ |
211 // TODO(cpu): Do not leak the interceptor. Lifetime between the | 211 // TODO(cpu): Do not leak the interceptor. Lifetime between the |
212 // service_manager and the spy is still unclear hence the leak. | 212 // service_manager and the spy is still unclear hence the leak. |
213 } | 213 } |
214 | 214 |
215 } // namespace mojo | 215 } // namespace mojo |
OLD | NEW |