| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromeos/binder/command_stream.h" | 5 #include "chromeos/binder/command_stream.h" |
| 6 | 6 |
| 7 #include <linux/android/binder.h> | 7 #include <linux/android/binder.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "chromeos/binder/buffer_reader.h" | 12 #include "chromeos/binder/buffer_reader.h" |
| 11 #include "chromeos/binder/driver.h" | 13 #include "chromeos/binder/driver.h" |
| 12 #include "chromeos/binder/transaction_data.h" | 14 #include "chromeos/binder/transaction_data.h" |
| 13 #include "chromeos/binder/transaction_data_from_driver.h" | 15 #include "chromeos/binder/transaction_data_from_driver.h" |
| 14 #include "chromeos/binder/util.h" | 16 #include "chromeos/binder/util.h" |
| 15 | 17 |
| 16 namespace binder { | 18 namespace binder { |
| 17 | 19 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 } | 47 } |
| 46 | 48 |
| 47 bool CommandStream::CanProcessIncomingCommand() { | 49 bool CommandStream::CanProcessIncomingCommand() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 return incoming_data_reader_ && incoming_data_reader_->HasMoreData(); | 51 return incoming_data_reader_ && incoming_data_reader_->HasMoreData(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 bool CommandStream::ProcessIncomingCommand() { | 54 bool CommandStream::ProcessIncomingCommand() { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 DCHECK(CanProcessIncomingCommand()); | 56 DCHECK(CanProcessIncomingCommand()); |
| 55 uint32 command = 0; | 57 uint32_t command = 0; |
| 56 if (!incoming_data_reader_->Read(&command, sizeof(command)) || | 58 if (!incoming_data_reader_->Read(&command, sizeof(command)) || |
| 57 !OnIncomingCommand(command, incoming_data_reader_.get())) { | 59 !OnIncomingCommand(command, incoming_data_reader_.get())) { |
| 58 LOG(ERROR) << "Error while handling command: " << command; | 60 LOG(ERROR) << "Error while handling command: " << command; |
| 59 return false; | 61 return false; |
| 60 } | 62 } |
| 61 return true; | 63 return true; |
| 62 } | 64 } |
| 63 | 65 |
| 64 void CommandStream::AppendOutgoingCommand(uint32 command, | 66 void CommandStream::AppendOutgoingCommand(uint32_t command, |
| 65 const void* data, | 67 const void* data, |
| 66 size_t size) { | 68 size_t size) { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 69 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 VLOG(1) << "Appending " << CommandToString(command) << ", this = " << this; | 70 VLOG(1) << "Appending " << CommandToString(command) << ", this = " << this; |
| 69 | 71 |
| 70 DCHECK_EQ(0u, size % 4); // Must be 4-byte aligned. | 72 DCHECK_EQ(0u, size % 4); // Must be 4-byte aligned. |
| 71 outgoing_data_.insert( | 73 outgoing_data_.insert( |
| 72 outgoing_data_.end(), reinterpret_cast<const char*>(&command), | 74 outgoing_data_.end(), reinterpret_cast<const char*>(&command), |
| 73 reinterpret_cast<const char*>(&command) + sizeof(command)); | 75 reinterpret_cast<const char*>(&command) + sizeof(command)); |
| 74 outgoing_data_.insert(outgoing_data_.end(), | 76 outgoing_data_.insert(outgoing_data_.end(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 LOG(ERROR) << "WriteRead() failed: pos = " << pos | 88 LOG(ERROR) << "WriteRead() failed: pos = " << pos |
| 87 << ", size = " << outgoing_data_.size(); | 89 << ", size = " << outgoing_data_.size(); |
| 88 return false; | 90 return false; |
| 89 } | 91 } |
| 90 pos += written_bytes; | 92 pos += written_bytes; |
| 91 } | 93 } |
| 92 outgoing_data_.clear(); | 94 outgoing_data_.clear(); |
| 93 return true; | 95 return true; |
| 94 } | 96 } |
| 95 | 97 |
| 96 bool CommandStream::OnIncomingCommand(uint32 command, BufferReader* reader) { | 98 bool CommandStream::OnIncomingCommand(uint32_t command, BufferReader* reader) { |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 // TODO(hashimoto): Replace all NOTIMPLEMENTED with logic to handle incoming | 100 // TODO(hashimoto): Replace all NOTIMPLEMENTED with logic to handle incoming |
| 99 // commands. | 101 // commands. |
| 100 VLOG(1) << "Processing " << CommandToString(command) << ", this = " << this; | 102 VLOG(1) << "Processing " << CommandToString(command) << ", this = " << this; |
| 101 switch (command) { | 103 switch (command) { |
| 102 case BR_ERROR: { | 104 case BR_ERROR: { |
| 103 int32 error = 0; | 105 int32_t error = 0; |
| 104 if (!reader->Read(&error, sizeof(error))) { | 106 if (!reader->Read(&error, sizeof(error))) { |
| 105 LOG(ERROR) << "Failed to read error code."; | 107 LOG(ERROR) << "Failed to read error code."; |
| 106 return false; | 108 return false; |
| 107 } | 109 } |
| 108 break; | 110 break; |
| 109 } | 111 } |
| 110 case BR_OK: | 112 case BR_OK: |
| 111 break; | 113 break; |
| 112 case BR_TRANSACTION: | 114 case BR_TRANSACTION: |
| 113 NOTIMPLEMENTED(); | 115 NOTIMPLEMENTED(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 167 } |
| 166 return true; | 168 return true; |
| 167 } | 169 } |
| 168 | 170 |
| 169 void CommandStream::FreeTransactionBuffer(const void* ptr) { | 171 void CommandStream::FreeTransactionBuffer(const void* ptr) { |
| 170 DCHECK(thread_checker_.CalledOnValidThread()); | 172 DCHECK(thread_checker_.CalledOnValidThread()); |
| 171 AppendOutgoingCommand(BC_FREE_BUFFER, &ptr, sizeof(ptr)); | 173 AppendOutgoingCommand(BC_FREE_BUFFER, &ptr, sizeof(ptr)); |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace binder | 176 } // namespace binder |
| OLD | NEW |