From a20551d82a52749b07ec66fb2bccb082aa7320e2 Mon Sep 17 00:00:00 2001 From: Patrick Gaskin Date: Thu, 23 Apr 2020 05:54:06 -0400 Subject: [PATCH] Implemented action nickel_misc:rescan_books_full --- res/doc | 1 + src/action_cc.cc | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/res/doc b/res/doc index f020edc..2f9d3c7 100644 --- a/res/doc +++ b/res/doc @@ -44,6 +44,7 @@ # misc - one of: # force_usb_connection - forces a usb connection dialog to be shown # rescan_books - forces nickel to rescan books (TODO) +# rescan_books_full - forcez a full usb connect/disconnect cycle (TODO) # cmd_spawn - the command line to pass to /bin/sh -c (started in /) # cmd_output - the timeout in milliseconds (0 < t < 10000), a colon, then the command line to pass to /bin/sh -c (started in /) # diff --git a/src/action_cc.cc b/src/action_cc.cc index 9179155..e33addb 100644 --- a/src/action_cc.cc +++ b/src/action_cc.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include "action_cc.h" #include "util.h" @@ -127,11 +128,16 @@ extern "C" int nm_action_nickelextras(const char *arg, char **err_out) { extern "C" int nm_action_nickelmisc(const char *arg, char **err_out) { #define NM_ERR_RET 1 - if (!strcmp(arg, "rescan_books")) { + if (!strcmp(arg, "rescan_books_full")) { PlugWorkflowManager *(*PlugWorkflowManager_sharedInstance)(); reinterpret_cast(PlugWorkflowManager_sharedInstance) = dlsym(RTLD_DEFAULT, "_ZN19PlugWorkflowManager14sharedInstanceEv"); NM_ASSERT(PlugWorkflowManager_sharedInstance, "could not dlsym PlugWorkflowManager::sharedInstance"); + // this is what is called by PlugWorkflowManager::plugged after confirmation + void (*PlugWorkflowManager_onCancelAndConnect)(PlugWorkflowManager*); + reinterpret_cast(PlugWorkflowManager_onCancelAndConnect) = dlsym(RTLD_DEFAULT, "_ZN19PlugWorkflowManager18onCancelAndConnectEv"); + NM_ASSERT(PlugWorkflowManager_onCancelAndConnect, "could not dlsym PlugWorkflowManager::onCancelAndConnect"); + void (*PlugWorkflowManager_unplugged)(PlugWorkflowManager*); reinterpret_cast(PlugWorkflowManager_unplugged) = dlsym(RTLD_DEFAULT, "_ZN19PlugWorkflowManager9unpluggedEv"); NM_ASSERT(PlugWorkflowManager_unplugged, "could not dlsym PlugWorkflowManager::unplugged"); @@ -139,10 +145,11 @@ extern "C" int nm_action_nickelmisc(const char *arg, char **err_out) { PlugWorkflowManager *wf = PlugWorkflowManager_sharedInstance(); NM_ASSERT(wf, "could not get shared PlugWorkflowManager pointer"); + PlugWorkflowManager_onCancelAndConnect(wf); + sleep(1); PlugWorkflowManager_unplugged(wf); - // TODO: finish this up - NM_RETURN_ERR("not completely implemented yet"); } else if (!strcmp(arg, "force_usb_connection")) { + // we could call libnickel directly, but I prefer not to FILE *nhs; NM_ASSERT((nhs = fopen("/tmp/nickel-hardware-status", "w")), "could not open nickel hardware status pipe: %s", strerror(errno));