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.
This commit is contained in:
Patrick Ohly 2010-06-11 15:41:31 +02:00
parent 3df4855bdd
commit c0d56d3161
3 changed files with 24 additions and 0 deletions

View file

@ -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 **********************/

View file

@ -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<string> urls = getSyncURL();
BOOST_FOREACH (string url, urls) {

View file

@ -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) {