From c0d56d3161ede267b17662e1d0436dbfeffc01c3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 11 Jun 2010 15:41:31 +0200 Subject: [PATCH] SyncContext:readStdin(): a virtual method for reading input via stdin The new method is needed for importing item data from stdin, a new feature for the command line. The default implementation which is used when executing the command line locally reads from std::cin directly. The syncevo-dbus-server would have to ask its client for the data; this hasn't been implemented yet. To catch the problem and inform the user, an exception is thrown there. --- src/syncevo-dbus-server.cpp | 9 +++++++++ src/syncevo/SyncContext.cpp | 7 +++++++ src/syncevo/SyncContext.h | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/syncevo-dbus-server.cpp b/src/syncevo-dbus-server.cpp index 6c41229a..e0b6bd7d 100644 --- a/src/syncevo-dbus-server.cpp +++ b/src/syncevo-dbus-server.cpp @@ -1451,6 +1451,11 @@ public: bool savePassword(const string &passwordName, const string &password, const ConfigPasswordKey &key); + + /** + * Read stdin via InfoRequest/Response. + */ + void readStdin(string &content); }; /** @@ -2711,6 +2716,10 @@ bool DBusUserInterface::savePassword(const string &passwordName, #endif } +void DBusUserInterface::readStdin(string &content) +{ + throwError("reading stdin in D-Bus server not supported, use --daemon=no in command line"); +} /***************** DBusSync implementation **********************/ diff --git a/src/syncevo/SyncContext.cpp b/src/syncevo/SyncContext.cpp index 1e9a9fbc..95228692 100644 --- a/src/syncevo/SyncContext.cpp +++ b/src/syncevo/SyncContext.cpp @@ -1401,6 +1401,13 @@ string SyncContext::askPassword(const string &passwordName, const string &descr, } } +void SyncContext::readStdin(string &content) +{ + if (!ReadFile(cin, content)) { + throwError("stdin", errno); + } +} + string SyncContext::getUsedSyncURL() { vector urls = getSyncURL(); BOOST_FOREACH (string url, urls) { diff --git a/src/syncevo/SyncContext.h b/src/syncevo/SyncContext.h index a827b124..cb0c034e 100644 --- a/src/syncevo/SyncContext.h +++ b/src/syncevo/SyncContext.h @@ -432,6 +432,14 @@ class SyncContext : public SyncConfig, public ConfigUserInterface { bool getRemoteInitiated() {return m_remoteInitiated;} void setRemoteInitiated(bool remote) {m_remoteInitiated = remote;} + /** + * Read from stdin until end of stream. + * + * Default implementation reads from real stdin, + * D-Bus server implementation must ask client. + */ + virtual void readStdin(string &content); + protected: /** exchange active Synthesis engine */ SharedEngine swapEngine(SharedEngine newengine) {