-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Composite USB device #15
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
From 9e16a5f8758a44adfd747e3d8be05f78adf70673 Mon Sep 17 00:00:00 2001 | ||
From: Josef Gajdusek <[email protected]> | ||
Date: Mon, 29 May 2017 22:39:21 +0200 | ||
Subject: [PATCH] Remove dbus dependency | ||
|
||
--- | ||
CMakeLists.txt | 9 ++-- | ||
server/server.cpp | 145 +++++++----------------------------------------------- | ||
2 files changed, 23 insertions(+), 131 deletions(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 46bff47..2c2f1a2 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -14,7 +14,6 @@ set(MTP_VERSION_MINOR 0) | ||
set(MTP_VERSION_PATCH 0) | ||
|
||
find_package(Boost REQUIRED COMPONENTS thread system filesystem unit_test_framework) | ||
-pkg_check_modules(DBUSCPP REQUIRED dbus-cpp) | ||
pkg_check_modules(GLOG REQUIRED libglog) | ||
|
||
set( | ||
@@ -61,7 +60,6 @@ include_directories( | ||
include/ | ||
libusbhost/include | ||
${Boost_INCLUDE_DIRS} | ||
- ${DBUSCPP_INCLUDE_DIRS} | ||
) | ||
|
||
add_library( | ||
@@ -73,7 +71,6 @@ target_link_libraries( | ||
mtpserver | ||
android-properties | ||
${GLOG_LIBRARIES} | ||
- ${DBUSCPP_LIBRARIES} | ||
) | ||
|
||
set_target_properties( | ||
@@ -102,3 +99,9 @@ add_subdirectory(libusbhost) | ||
add_subdirectory(server) | ||
add_subdirectory(tests) | ||
add_subdirectory(po) | ||
+ | ||
+target_link_libraries(mtpserver pthread) | ||
+ | ||
+target_link_libraries(mtpserver pthread) | ||
+ | ||
+target_link_libraries(mtpserver pthread) | ||
diff --git a/server/server.cpp b/server/server.cpp | ||
index 0a9a846..62af1bc 100644 | ||
--- a/server/server.cpp | ||
+++ b/server/server.cpp | ||
@@ -35,70 +35,9 @@ | ||
#include <hybris/properties/properties.h> | ||
#include <glog/logging.h> | ||
|
||
-#include <core/dbus/bus.h> | ||
-#include <core/dbus/object.h> | ||
-#include <core/dbus/property.h> | ||
-#include <core/dbus/service.h> | ||
-#include <core/dbus/signal.h> | ||
|
||
-#include <core/dbus/asio/executor.h> | ||
-#include <core/dbus/types/stl/tuple.h> | ||
-#include <core/dbus/types/stl/vector.h> | ||
-#include <core/dbus/types/struct.h> | ||
- | ||
- | ||
-namespace dbus = core::dbus; | ||
using namespace android; | ||
|
||
-namespace core | ||
-{ | ||
-dbus::Bus::Ptr the_session_bus() | ||
-{ | ||
- static dbus::Bus::Ptr session_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::session); | ||
- return session_bus; | ||
-} | ||
- | ||
-struct UnityGreeter | ||
-{ | ||
- struct Properties | ||
- { | ||
- struct IsActive | ||
- { | ||
- inline static std::string name() | ||
- { | ||
- return "IsActive"; | ||
- }; | ||
- typedef UnityGreeter Interface; | ||
- typedef bool ValueType; | ||
- static const bool readable = true; | ||
- static const bool writable = false; | ||
- }; | ||
- }; | ||
-}; | ||
-} | ||
- | ||
-namespace core | ||
-{ | ||
-namespace dbus | ||
-{ | ||
-namespace traits | ||
-{ | ||
-template<> | ||
-struct Service<core::UnityGreeter> | ||
-{ | ||
- inline static const std::string& interface_name() | ||
- { | ||
- static const std::string s | ||
- { | ||
- "com.canonical.UnityGreeter" | ||
- }; | ||
- return s; | ||
- } | ||
-}; | ||
-} | ||
-} | ||
-} | ||
- | ||
namespace | ||
{ | ||
struct FileSystemConfig | ||
@@ -114,8 +53,6 @@ class MtpDaemon | ||
|
||
private: | ||
struct passwd *userdata; | ||
- dbus::Bus::Ptr bus; | ||
- boost::thread dbus_thread; | ||
|
||
// Mtp stuff | ||
MtpServer* server; | ||
@@ -124,8 +61,7 @@ private: | ||
MtpDatabase* mtp_database; | ||
|
||
// Security | ||
- std::shared_ptr<core::dbus::Property<core::UnityGreeter::Properties::IsActive> > is_active; | ||
- bool screen_locked = true; | ||
+ bool screen_locked = false; | ||
|
||
// inotify stuff | ||
boost::thread notifier_thread; | ||
@@ -242,17 +178,6 @@ private: | ||
read_more_notify(); | ||
} | ||
|
||
- void drive_bus() | ||
- { | ||
- try { | ||
- bus->run(); | ||
- } | ||
- catch (...) { | ||
- PLOG(ERROR) << "There was an unexpected error in DBus; terminating."; | ||
- server->stop(); | ||
- } | ||
- } | ||
- | ||
public: | ||
|
||
MtpDaemon(int fd): | ||
@@ -285,15 +210,6 @@ public: | ||
userdata->pw_gid, | ||
FileSystemConfig::file_perm, | ||
FileSystemConfig::directory_perm); | ||
- | ||
- // security / screen locking | ||
- bus = core::the_session_bus(); | ||
- bus->install_executor(core::dbus::asio::make_executor(bus)); | ||
- dbus_thread = boost::thread(&MtpDaemon::drive_bus, this); | ||
- auto greeter_service = dbus::Service::use_service(bus, "com.canonical.UnityGreeter"); | ||
- dbus::Object::Ptr greeter = greeter_service->object_for_path(dbus::types::ObjectPath("/")); | ||
- | ||
- is_active = greeter->get_property<core::UnityGreeter::Properties::IsActive>(); | ||
} | ||
|
||
void initStorage() | ||
@@ -352,7 +268,6 @@ public: | ||
// Cleanup | ||
inotify_rm_watch(inotify_fd, watch_fd); | ||
io_svc.stop(); | ||
- dbus_thread.detach(); | ||
notifier_thread.detach(); | ||
io_service_thread.join(); | ||
close(inotify_fd); | ||
@@ -360,48 +275,22 @@ public: | ||
|
||
void run() | ||
{ | ||
- if (is_active->get()) { | ||
- is_active->changed().connect([this](bool active) | ||
- { | ||
- if (!active) { | ||
- screen_locked = active; | ||
- VLOG(2) << "device was unlocked, adding storage"; | ||
- if (home_storage && !home_storage_added) { | ||
- server->addStorage(home_storage); | ||
- home_storage_added = true; | ||
- } | ||
- BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) { | ||
- auto t = removables.at(name); | ||
- MtpStorage *storage = std::get<0>(t); | ||
- bool added = std::get<1>(t); | ||
- if (!added) { | ||
- mtp_database->addStoragePath(storage->getPath(), | ||
- std::string(), | ||
- storage->getStorageID(), | ||
- true); | ||
- server->addStorage(storage); | ||
- } | ||
- } | ||
- } | ||
- }); | ||
- } else { | ||
- screen_locked = false; | ||
- VLOG(2) << "device is not locked, adding storage"; | ||
- if (home_storage) { | ||
- server->addStorage(home_storage); | ||
- home_storage_added = true; | ||
- } | ||
- BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) { | ||
- auto t = removables.at(name); | ||
- MtpStorage *storage = std::get<0>(t); | ||
- bool added = std::get<1>(t); | ||
- if (!added) { | ||
- mtp_database->addStoragePath(storage->getPath(), | ||
- std::string(), | ||
- storage->getStorageID(), | ||
- true); | ||
- server->addStorage(storage); | ||
- } | ||
+ screen_locked = false; | ||
+ VLOG(2) << "device is not locked, adding storage"; | ||
+ if (home_storage) { | ||
+ server->addStorage(home_storage); | ||
+ home_storage_added = true; | ||
+ } | ||
+ BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) { | ||
+ auto t = removables.at(name); | ||
+ MtpStorage *storage = std::get<0>(t); | ||
+ bool added = std::get<1>(t); | ||
+ if (!added) { | ||
+ mtp_database->addStoragePath(storage->getPath(), | ||
+ std::string(), | ||
+ storage->getStorageID(), | ||
+ true); | ||
+ server->addStorage(storage); | ||
} | ||
} | ||
|
||
-- | ||
2.13.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=mtp-server service | ||
Requires=usb-setup.service dev-mtp_usb.device | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't you forgot "After=usb-setup.service" ? |
||
StartLimitIntervalSec=0 | ||
|
||
[Service] | ||
Type=simple | ||
Environment=GLOG_logtostderr=1 | ||
Restart=always | ||
ExecStart=/usr/bin/mtp-server | ||
User=ceres | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
SUMMARY = "A port of Android's mtp server implementation to Ubuntu." | ||
LICENSE = "GPL-3.0 & Apache-2.0" | ||
LIC_FILES_CHKSUM = " \ | ||
file://COPYING;md5=d32239bcb673463ab874e80d47fae504 \ | ||
file://MODULE_LICENSE_APACHE2;md5=d41d8cd98f00b204e9800998ecf8427e \ | ||
file://NOTICE;md5=9645f39e9db895a4aa6e02cb57294595 \ | ||
" | ||
|
||
SRC_URI = " \ | ||
bzr://code.launchpad.net/~phablet-team/mtp/trunk \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather not have asteroid's build system depend on bzr for this single recipe. I couldn't even make it work... I'd prefer having a mtp-server_0.0.4.bb using: |
||
file://0001-Remove-dbus-dependency.patch \ | ||
file://mtp-server.service \ | ||
" | ||
S = "${WORKDIR}/trunk" | ||
SRCREV = "[email protected]" | ||
|
||
inherit cmake gettext | ||
|
||
DEPENDS += "boost libhybris glog" | ||
|
||
do_configure_prepend() { | ||
echo -e "\ntarget_link_libraries(mtpserver pthread)" >> "${S}/CMakeLists.txt" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering 0001-Remove-dbus-dependency.patch, I don't think we need to insist much more. |
||
} | ||
|
||
do_install_append() { | ||
install -m 644 -D "../mtp-server.service" ${D}/lib/systemd/system/mtp-server.service | ||
install -d ${D}/lib/systemd/system/multi-user.target.wants/ | ||
ln -s ../mtp-server.service ${D}/lib/systemd/system/multi-user.target.wants/mtp-server.service | ||
} | ||
|
||
FILES_${PN} += " /lib/systemd/system " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really want this pthread badly, don't you? :)