hal/bluetooth_gatt_interface.cpp \
hal/bluetooth_interface.cpp \
ipc/ipc_handler.cpp \
- ipc/ipc_handler_unix.cpp \
ipc/ipc_manager.cpp \
- ipc/unix_ipc_host.cpp \
logging_helpers.cpp \
low_energy_client.cpp \
settings.cpp \
util/atomic_string.cpp \
uuid.cpp
+btserviceLinuxSrc := \
+ ipc/ipc_handler_linux.cpp \
+ ipc/linux_ipc_host.cpp
+
btserviceBinderSrc := \
ipc/binder/bluetooth_binder_server.cpp \
ipc/binder/bluetooth_gatt_server_binder_server.cpp \
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(btserviceBinderSrc) \
+ $(btserviceLinuxSrc) \
$(btserviceCommonSrc) \
main.cpp
LOCAL_C_INCLUDES += $(btserviceCommonIncludes)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(btserviceCommonSrc) \
+ $(btserviceLinuxSrc) \
hal/fake_bluetooth_gatt_interface.cpp \
hal/fake_bluetooth_interface.cpp \
test/adapter_unittest.cpp \
test/advertise_data_unittest.cpp \
test/fake_hal_util.cpp \
- test/ipc_unix_unittest.cpp \
+ test/ipc_linux_unittest.cpp \
test/low_energy_client_unittest.cpp \
test/settings_unittest.cpp \
test/stub_ipc_handler_binder.cpp \
"daemon.cpp",
"gatt_server.cpp",
"ipc/ipc_handler.cpp",
- "ipc/ipc_handler_unix.cpp",
+ "ipc/ipc_handler_linux.cpp",
"ipc/ipc_manager.cpp",
- "ipc/unix_ipc_host.cpp",
+ "ipc/linux_ipc_host.cpp",
"logging_helpers.cpp",
"settings.cpp",
"uuid.cpp"
testonly = true
sources = [
"test/fake_hal_util.cpp",
- "test/ipc_unix_unittest.cpp",
+ "test/ipc_linux_unittest.cpp",
"test/settings_unittest.cpp",
"test/uuid_unittest.cpp",
]
// If an IPC socket path was given, initialize IPC with it. Otherwise
// initialize Binder IPC.
if (settings_->UseSocketIPC()) {
- if (!ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) {
+ if (!ipc_manager_->Start(ipc::IPCManager::TYPE_LINUX, nullptr)) {
LOG(ERROR) << "Failed to set up UNIX domain-socket IPCManager";
return false;
}
// limitations under the License.
//
-#include "service/ipc/ipc_handler_unix.h"
+#include "service/ipc/ipc_handler_linux.h"
#include <sys/socket.h>
#include <sys/un.h>
#include "osi/include/socket_utils/sockets.h"
#include "service/daemon.h"
-#include "service/ipc/unix_ipc_host.h"
+#include "service/ipc/linux_ipc_host.h"
#include "service/settings.h"
namespace ipc {
-IPCHandlerUnix::IPCHandlerUnix(bluetooth::Adapter* adapter,
+IPCHandlerLinux::IPCHandlerLinux(bluetooth::Adapter* adapter,
IPCManager::Delegate* delegate)
: IPCHandler(adapter, delegate),
running_(false),
- thread_("IPCHandlerUnix"),
+ thread_("IPCHandlerLinux"),
keep_running_(true) {
}
-IPCHandlerUnix::~IPCHandlerUnix() {
+IPCHandlerLinux::~IPCHandlerLinux() {
// This will only be set if the Settings::create_ipc_socket_path() was
// originally provided.
if (!socket_path_.empty())
unlink(socket_path_.value().c_str());
}
-bool IPCHandlerUnix::Run() {
+bool IPCHandlerLinux::Run() {
CHECK(!running_);
const std::string& android_suffix =
// Start an IO thread and post the listening task.
base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
if (!thread_.StartWithOptions(options)) {
- LOG(ERROR) << "Failed to start IPCHandlerUnix thread";
+ LOG(ERROR) << "Failed to start IPCHandlerLinux thread";
running_ = false;
return false;
}
thread_.task_runner()->PostTask(
FROM_HERE,
- base::Bind(&IPCHandlerUnix::StartListeningOnThread, this));
+ base::Bind(&IPCHandlerLinux::StartListeningOnThread, this));
return true;
}
-void IPCHandlerUnix::Stop() {
+void IPCHandlerLinux::Stop() {
keep_running_ = false;
// At this moment the listening thread might be blocking on the accept
NotifyStoppedOnOriginThread();
}
-void IPCHandlerUnix::StartListeningOnThread() {
+void IPCHandlerLinux::StartListeningOnThread() {
CHECK(socket_.is_valid());
CHECK(adapter());
CHECK(running_);
LOG(ERROR) << "Failed to listen on domain socket: " << strerror(errno);
origin_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&IPCHandlerUnix::ShutDownOnOriginThread, this));
+ base::Bind(&IPCHandlerLinux::ShutDownOnOriginThread, this));
return;
}
LOG(INFO) << "Established client connection: fd=" << client_socket;
- UnixIPCHost ipc_host(client_socket, adapter());
+ LinuxIPCHost ipc_host(client_socket, adapter());
// TODO(armansito): Use |thread_|'s MessageLoopForIO instead of using a
// custom event loop to poll from the socket.
}
}
-void IPCHandlerUnix::ShutDownOnOriginThread() {
- LOG(INFO) << "Shutting down IPCHandlerUnix thread";
+void IPCHandlerLinux::ShutDownOnOriginThread() {
+ LOG(INFO) << "Shutting down IPCHandlerLinux thread";
thread_.Stop();
running_ = false;
NotifyStoppedOnCurrentThread();
}
-void IPCHandlerUnix::NotifyStartedOnOriginThread() {
+void IPCHandlerLinux::NotifyStartedOnOriginThread() {
if (!delegate())
return;
origin_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&IPCHandlerUnix::NotifyStartedOnCurrentThread, this));
+ base::Bind(&IPCHandlerLinux::NotifyStartedOnCurrentThread, this));
}
-void IPCHandlerUnix::NotifyStartedOnCurrentThread() {
+void IPCHandlerLinux::NotifyStartedOnCurrentThread() {
if (delegate())
- delegate()->OnIPCHandlerStarted(IPCManager::TYPE_UNIX);
+ delegate()->OnIPCHandlerStarted(IPCManager::TYPE_LINUX);
}
-void IPCHandlerUnix::NotifyStoppedOnOriginThread() {
+void IPCHandlerLinux::NotifyStoppedOnOriginThread() {
if (!delegate())
return;
origin_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&IPCHandlerUnix::NotifyStoppedOnCurrentThread, this));
+ base::Bind(&IPCHandlerLinux::NotifyStoppedOnCurrentThread, this));
}
-void IPCHandlerUnix::NotifyStoppedOnCurrentThread() {
+void IPCHandlerLinux::NotifyStoppedOnCurrentThread() {
if (delegate())
- delegate()->OnIPCHandlerStopped(IPCManager::TYPE_UNIX);
+ delegate()->OnIPCHandlerStopped(IPCManager::TYPE_LINUX);
}
} // namespace ipc
namespace ipc {
-// Implements a UNIX domain-socket based IPCHandler
-class IPCHandlerUnix : public IPCHandler {
+// Implements a Linux sequential packet domain-socket based IPCHandler
+class IPCHandlerLinux : public IPCHandler {
public:
- IPCHandlerUnix(bluetooth::Adapter* adapter,
+ IPCHandlerLinux(bluetooth::Adapter* adapter,
IPCManager::Delegate* delegate);
- ~IPCHandlerUnix() override;
+ ~IPCHandlerLinux() override;
// IPCHandler overrides:
bool Run() override;
void Stop() override;
private:
- IPCHandlerUnix() = default;
+ IPCHandlerLinux() = default;
// Starts listening for incoming connections. Posted on |thread_| by Run().
void StartListeningOnThread();
// The origin thread's task runner.
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
- DISALLOW_COPY_AND_ASSIGN(IPCHandlerUnix);
+ DISALLOW_COPY_AND_ASSIGN(IPCHandlerLinux);
};
} // namespace ipc
#include "service/ipc/ipc_manager.h"
#include "service/ipc/binder/ipc_handler_binder.h"
-#include "service/ipc/ipc_handler_unix.h"
+#include "service/ipc/ipc_handler_linux.h"
namespace ipc {
// holding a reference to them. Instead, explicitly stop them here.
if (BinderStarted())
binder_handler_->Stop();
- if (UnixStarted())
- unix_handler_->Stop();
+ if (LinuxStarted())
+ linux_handler_->Stop();
}
bool IPCManager::Start(Type type, Delegate* delegate) {
switch (type) {
- case TYPE_UNIX:
- if (UnixStarted()) {
- LOG(ERROR) << "IPCManagerUnix already started.";
+ case TYPE_LINUX:
+ if (LinuxStarted()) {
+ LOG(ERROR) << "IPCManagerLinux already started.";
return false;
}
- unix_handler_ = new IPCHandlerUnix(adapter_, delegate);
- if (!unix_handler_->Run()) {
- unix_handler_ = nullptr;
+ linux_handler_ = new IPCHandlerLinux(adapter_, delegate);
+ if (!linux_handler_->Run()) {
+ linux_handler_ = nullptr;
return false;
}
return true;
return binder_handler_.get();
}
-bool IPCManager::UnixStarted() const {
- return unix_handler_.get();
+bool IPCManager::LinuxStarted() const {
+ return linux_handler_.get();
}
} // namespace ipc
// IPCManager is a class for initializing and running supported IPC mechanisms.
// It manages the life-time of different IPC flavors that are available on the
-// system. There are two flavors: a plain UNIX domain socket based system and
-// one based on the Binder-based android.bluetooth framework.
+// system. There are two flavors: a Linux sequential packet domain socket based
+// system and one based on the Binder-based android.bluetooth framework.
class IPCManager {
public:
// Possible IPC types.
enum Type {
- TYPE_UNIX, // IPC based on a UNIX domain socket
+ TYPE_LINUX, // IPC based on a Linux sequential packet domain socket
TYPE_BINDER // IPC based on the Binder
};
// yet been initialized and returns true on success. Returns false if that
// type has already been initialized or an error occurs.
//
- // If TYPE_UNIX is given, the file path to use for the domain socket will be
+ // If TYPE_LINUX is given, the file path to use for the domain socket will be
// obtained from the global Settings object. Hence, the Settings object must
// have been initialized before calling this method.
//
// Returns true if an IPC type has been initialized.
bool BinderStarted() const;
- bool UnixStarted() const;
+ bool LinuxStarted() const;
private:
IPCManager() = default;
// Pointers to the different IPC handler classes. These are initialized and
// owned by us.
scoped_refptr<IPCHandler> binder_handler_;
- scoped_refptr<IPCHandler> unix_handler_;
+ scoped_refptr<IPCHandler> linux_handler_;
// The Bluetooth adapter instance. This is owned by Daemon so we keep a raw
// pointer to it.
#define LOG_TAG "bt_bluetooth_host"
-#include "service/ipc/unix_ipc_host.h"
+#include "service/ipc/linux_ipc_host.h"
#include <errno.h>
#include <stdio.h>
const char kStopServiceCommand[] = "stop-service";
const char kWriteCharacteristicCommand[] = "write-characteristic";
-// Useful values for indexing UnixIPCHost::pfds_
+// Useful values for indexing LinuxIPCHost::pfds_
// Not super general considering that we should be able to support
-// many GATT FDs owned by one UnixIPCHost.
+// many GATT FDs owned by one LinuxIPCHost.
enum {
kFdIpc = 0,
kFdGatt = 1,
namespace ipc {
-UnixIPCHost::UnixIPCHost(int sockfd, Adapter* adapter)
+LinuxIPCHost::LinuxIPCHost(int sockfd, Adapter* adapter)
: adapter_(adapter), pfds_(1, {sockfd, POLLIN, 0}) {}
-UnixIPCHost::~UnixIPCHost() {
+LinuxIPCHost::~LinuxIPCHost() {
close(pfds_[0].fd);
}
-bool UnixIPCHost::EventLoop() {
+bool LinuxIPCHost::EventLoop() {
while (true) {
int status =
TEMP_FAILURE_RETRY(ppoll(pfds_.data(), pfds_.size(), nullptr, nullptr));
return true;
}
-bool UnixIPCHost::OnSetAdapterName(const std::string& name) {
+bool LinuxIPCHost::OnSetAdapterName(const std::string& name) {
std::string decoded_data;
base::Base64Decode(name, &decoded_data);
return adapter_->SetName(decoded_data);
}
-bool UnixIPCHost::OnCreateService(const std::string& service_uuid) {
+bool LinuxIPCHost::OnCreateService(const std::string& service_uuid) {
gatt_servers_[service_uuid] = std::unique_ptr<Server>(new Server);
int gattfd;
return true;
}
-bool UnixIPCHost::OnDestroyService(const std::string& service_uuid) {
+bool LinuxIPCHost::OnDestroyService(const std::string& service_uuid) {
gatt_servers_.erase(service_uuid);
close(pfds_[1].fd);
pfds_.resize(1);
return true;
}
-bool UnixIPCHost::OnAddCharacteristic(const std::string& service_uuid,
+bool LinuxIPCHost::OnAddCharacteristic(const std::string& service_uuid,
const std::string& characteristic_uuid,
const std::string& control_uuid,
const std::string& options) {
return true;
}
-bool UnixIPCHost::OnSetCharacteristicValue(const std::string& service_uuid,
+bool LinuxIPCHost::OnSetCharacteristicValue(const std::string& service_uuid,
const std::string& characteristic_uuid,
const std::string& value) {
std::string decoded_data;
return true;
}
-bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
+bool LinuxIPCHost::OnSetAdvertisement(const std::string& service_uuid,
const std::string& advertise_uuids,
const std::string& advertise_data,
const std::string& manufacturer_data,
return true;
}
-bool UnixIPCHost::OnSetScanResponse(const std::string& service_uuid,
+bool LinuxIPCHost::OnSetScanResponse(const std::string& service_uuid,
const std::string& scan_response_uuids,
const std::string& scan_response_data,
const std::string& manufacturer_data,
return true;
}
-bool UnixIPCHost::OnStartService(const std::string& service_uuid) {
+bool LinuxIPCHost::OnStartService(const std::string& service_uuid) {
return gatt_servers_[service_uuid]->Start();
}
-bool UnixIPCHost::OnStopService(const std::string& service_uuid) {
+bool LinuxIPCHost::OnStopService(const std::string& service_uuid) {
return gatt_servers_[service_uuid]->Stop();
}
-bool UnixIPCHost::OnMessage() {
+bool LinuxIPCHost::OnMessage() {
std::string ipc_msg;
int size = recv(pfds_[kFdIpc].fd, &ipc_msg[0], 0, MSG_PEEK | MSG_TRUNC);
if (-1 == size) {
return false;
}
-bool UnixIPCHost::OnGattWrite() {
+bool LinuxIPCHost::OnGattWrite() {
UUID::UUID128Bit id;
int r = read(pfds_[kFdGatt].fd, id.data(), id.size());
if (r != id.size()) {
// reads from a set of FDs (pfds_) to a set of handlers.
// Reads from the GATT pipe read end will result in a write to
// to the IPC socket, and vise versa.
-class UnixIPCHost {
+class LinuxIPCHost {
public:
- // UnixIPCHost owns the passed sockfd.
- UnixIPCHost(int sockfd, bluetooth::Adapter* adapter);
- ~UnixIPCHost();
+ // LinuxIPCHost owns the passed sockfd.
+ LinuxIPCHost(int sockfd, bluetooth::Adapter* adapter);
+ ~LinuxIPCHost();
// Synchronously handle all events on input FDs.
bool EventLoop();
const char kTestSocketPath[] = "test_socket_path";
-class IPCUnixTest : public ::testing::Test {
+class IPCLinuxTest : public ::testing::Test {
public:
- IPCUnixTest() = default;
- ~IPCUnixTest() override = default;
+ IPCLinuxTest() = default;
+ ~IPCLinuxTest() override = default;
void SetUp() override {
SetUpCommandLine();
std::unique_ptr<ipc::IPCManager> ipc_manager_;
base::ScopedFD client_fd_;
- DISALLOW_COPY_AND_ASSIGN(IPCUnixTest);
+ DISALLOW_COPY_AND_ASSIGN(IPCLinuxTest);
};
-class IPCUnixTestDisabled : public IPCUnixTest {
+class IPCLinuxTestDisabled : public IPCLinuxTest {
public:
- IPCUnixTestDisabled() = default;
- ~IPCUnixTestDisabled() override = default;
+ IPCLinuxTestDisabled() = default;
+ ~IPCLinuxTestDisabled() override = default;
void SetUpCommandLine() override {
// Set up with no --ipc-socket-path
}
private:
- DISALLOW_COPY_AND_ASSIGN(IPCUnixTestDisabled);
+ DISALLOW_COPY_AND_ASSIGN(IPCLinuxTestDisabled);
};
class TestDelegate : public ipc::IPCManager::Delegate,
}
void OnIPCHandlerStarted(ipc::IPCManager::Type type) override {
- ASSERT_EQ(ipc::IPCManager::TYPE_UNIX, type);
+ ASSERT_EQ(ipc::IPCManager::TYPE_LINUX, type);
started_count_++;
base::MessageLoop::current()->Quit();
}
void OnIPCHandlerStopped(ipc::IPCManager::Type type) override {
- ASSERT_EQ(ipc::IPCManager::TYPE_UNIX, type);
+ ASSERT_EQ(ipc::IPCManager::TYPE_LINUX, type);
stopped_count_++;
base::MessageLoop::current()->Quit();
}
DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
-TEST_F(IPCUnixTestDisabled, StartWithNoSocketPath) {
+TEST_F(IPCLinuxTestDisabled, StartWithNoSocketPath) {
TestDelegate delegate;
- EXPECT_FALSE(ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, &delegate));
- EXPECT_FALSE(ipc_manager_->UnixStarted());
+ EXPECT_FALSE(ipc_manager_->Start(ipc::IPCManager::TYPE_LINUX, &delegate));
+ EXPECT_FALSE(ipc_manager_->LinuxStarted());
EXPECT_EQ(0, delegate.started_count());
EXPECT_EQ(0, delegate.stopped_count());
}
-TEST_F(IPCUnixTest, BasicStartAndExit) {
+TEST_F(IPCLinuxTest, BasicStartAndExit) {
TestDelegate delegate;
- EXPECT_TRUE(ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, &delegate));
- EXPECT_TRUE(ipc_manager_->UnixStarted());
+ EXPECT_TRUE(ipc_manager_->Start(ipc::IPCManager::TYPE_LINUX, &delegate));
+ EXPECT_TRUE(ipc_manager_->LinuxStarted());
// Run the message loop. We will stop the loop when we receive a delegate
// event.
EXPECT_EQ(1, delegate.stopped_count());
}
-TEST_F(IPCUnixTest, BasicStartAndConnect) {
+TEST_F(IPCLinuxTest, BasicStartAndConnect) {
TestDelegate delegate;
- EXPECT_TRUE(ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, &delegate));
- EXPECT_TRUE(ipc_manager_->UnixStarted());
+ EXPECT_TRUE(ipc_manager_->Start(ipc::IPCManager::TYPE_LINUX, &delegate));
+ EXPECT_TRUE(ipc_manager_->LinuxStarted());
// Run the message loop. We will stop the loop when we receive a delegate
// event.