aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2016-03-21 17:05:01 -0500
committerCharles Kerr <charles.kerr@canonical.com>2016-03-21 17:05:01 -0500
commit1c4f005f0765f460b28808a624fbec7737324b1a (patch)
tree1515eb80b2c203c3bd0d2b53936ec930f08d863d /src
parent7a25132c125f6e5e413ad26ea950ae22bee982f5 (diff)
downloadayatana-indicator-display-1c4f005f0765f460b28808a624fbec7737324b1a.tar.gz
ayatana-indicator-display-1c4f005f0765f460b28808a624fbec7737324b1a.tar.bz2
ayatana-indicator-display-1c4f005f0765f460b28808a624fbec7737324b1a.zip
in UsbManager, reset AdbdClient on usb disconnect
Diffstat (limited to 'src')
-rw-r--r--src/usb-manager.cpp44
-rw-r--r--src/usb-snap.cpp1
2 files changed, 26 insertions, 19 deletions
diff --git a/src/usb-manager.cpp b/src/usb-manager.cpp
index 840a04b..f5957d9 100644
--- a/src/usb-manager.cpp
+++ b/src/usb-manager.cpp
@@ -39,29 +39,40 @@ public:
const std::string& public_keys_filename,
const std::shared_ptr<UsbMonitor>& usb_monitor
):
- m_adbd_client{std::make_shared<GAdbdClient>(socket_path)},
+ m_socket_path{socket_path},
m_public_keys_filename{public_keys_filename},
m_usb_monitor{usb_monitor}
{
m_usb_monitor->on_usb_disconnected().connect([this](const std::string& /*usb_name*/) {
- m_snap.reset();
+ restart();
});
+ restart();
+ }
+
+ ~Impl() =default;
+
+private:
+
+ void restart()
+ {
+ // clear out old state
+ m_snap_connections.clear();
+ m_snap.reset();
+ m_adbd_client.reset();
+
+ // add a new client
+ m_adbd_client.reset(new GAdbdClient{m_socket_path});
m_adbd_client->on_pk_request().connect(
- [this](const AdbdClient::PKRequest& req){
+ [this](const AdbdClient::PKRequest& req) {
- m_snap.reset(new UsbSnap(req.fingerprint),
- [this](UsbSnap* snap){
- m_snap_connections.clear();
- delete snap;
- }
- );
+ g_debug("%s got pk request", G_STRLOC);
+ m_snap = std::make_shared<UsbSnap>(req.fingerprint);
m_snap_connections.insert((*m_snap).on_user_response().connect(
[this,req](AdbdClient::PKResponse response, bool remember_choice){
- g_message("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice));
+ g_debug("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice));
req.respond(response);
- g_message("%s", G_STRLOC);
if (remember_choice && (response == AdbdClient::PKResponse::ALLOW))
write_public_key(req.public_key);
g_idle_add([](gpointer gself){static_cast<Impl*>(gself)->m_snap.reset(); return G_SOURCE_REMOVE;}, this);
@@ -69,16 +80,11 @@ public:
));
}
);
-
}
- ~Impl() =default;
-
-private:
-
void write_public_key(const std::string& public_key)
{
- g_message("%s writing public key '%s' to '%s'", G_STRLOC, public_key.c_str(), m_public_keys_filename.c_str());
+ g_debug("%s writing public key '%s' to '%s'", G_STRLOC, public_key.c_str(), m_public_keys_filename.c_str());
// confirm the directory exists
auto dirname = g_path_get_dirname(m_public_keys_filename.c_str());
@@ -107,10 +113,12 @@ private:
close(fd);
}
- std::shared_ptr<GAdbdClient> m_adbd_client;
+ const std::string m_socket_path;
const std::string m_public_keys_filename;
+
std::shared_ptr<UsbMonitor> m_usb_monitor;
+ std::shared_ptr<GAdbdClient> m_adbd_client;
std::shared_ptr<UsbSnap> m_snap;
std::set<core::ScopedConnection> m_snap_connections;
};
diff --git a/src/usb-snap.cpp b/src/usb-snap.cpp
index 349d80e..41c78c6 100644
--- a/src/usb-snap.cpp
+++ b/src/usb-snap.cpp
@@ -148,7 +148,6 @@ private:
{
GError* error {};
auto reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION(obus), res, &error);
-g_message("%s got notify response %s", G_STRLOC, g_variant_print(reply, true));
if (error != nullptr) {
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning("UsbSnap: Error calling Notify: %s", error->message);