/* * Copyright (C) 2012 Intel Corporation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ #ifndef SESSION_HELPER_H #define SESSION_HELPER_H #include "session-common.h" #include "dbus-sync.h" #include #include #include #include #include SE_BEGIN_CXX class LogRedirect; class ForkExecChild; /** * Waits for requests via the internal D-Bus connection in run(), sent * by the Session class in syncevo-dbus-server. Then for each request * it remembers what to do in m_operation and returns from the event * loop and executes the requested operation, pretty much like the * traditional syncevo-dbus-server did. */ class SessionHelper : public GDBusCXX::DBusObjectHelper, private boost::noncopyable { GMainLoop *m_loop; GDBusCXX::DBusConnectionPtr m_conn; boost::shared_ptr m_forkexec; boost::function m_operation; boost::shared_ptr m_logger; PushLogger m_pushLogger; /** valid during doSync() */ boost::scoped_ptr m_sync; /** called by main event loop: initiate a sync operation */ void sync(const SessionCommon::SyncParams ¶ms, const boost::shared_ptr< GDBusCXX::Result2 > &result); /** * called by run(): do the sync operation * @return true if the helper is meant to terminate */ bool doSync(const SessionCommon::SyncParams ¶ms, const boost::shared_ptr< GDBusCXX::Result2 > &result); void restore(const std::string &configName, const string &dir, bool before, const std::vector &sources, const boost::shared_ptr< GDBusCXX::Result1 > &result); bool doRestore(const std::string &configName, const string &dir, bool before, const std::vector &sources, const boost::shared_ptr< GDBusCXX::Result1 > &result); void execute(const vector &args, const map &vars, const boost::shared_ptr< GDBusCXX::Result1 > &result); bool doExecute(const vector &args, const map &vars, const boost::shared_ptr< GDBusCXX::Result1 > &result); /** SessionHelper.PasswordResponse */ void passwordResponse(bool timedOut, bool aborted, const std::string &password); public: SessionHelper(GMainLoop *loop, const GDBusCXX::DBusConnectionPtr &conn, const boost::shared_ptr &forkexec, const boost::shared_ptr &parentLogger); ~SessionHelper(); void activate(); void run(); GMainLoop *getLoop() const { return m_loop; } /** Still have connection to parent. Shortcut which asks the ForkExecChild class. */ bool connected(); boost::shared_ptr getForkExecChild() { return m_forkexec; } /** Server.LogOutput for the session D-Bus object */ GDBusCXX::EmitSignal3 emitLogOutput; /** SyncContext::displaySyncProgress */ GDBusCXX::EmitSignal4 emitSyncProgress; /** SyncContext::displaySourceProgress */ GDBusCXX::EmitSignal6 emitSourceProgress; /** SyncContext::m_sourceSyncedSignal */ GDBusCXX::EmitSignal2 emitSourceSynced; /** SyncContext::reportStepCmd -> true/false for "waiting on IO" */ GDBusCXX::EmitSignal1 emitWaiting; /** SyncContext::syncSuccessStart */ GDBusCXX::EmitSignal0Template emitSyncSuccessStart; /** Cmdline::configWasModified() */ GDBusCXX::EmitSignal0Template emitConfigChanged; /** SyncContext::askPassword */ GDBusCXX::EmitSignal2 emitPasswordRequest; /** send message to parent's connection (buffer, type, url) */ GDBusCXX::EmitSignal3, std::string, std::string> emitMessage; /** tell parent's connection to shut down */ GDBusCXX::EmitSignal0Template emitShutdown; /** store the next message received by the session's connection */ void storeMessage(const GDBusCXX::DBusArray &message, const std::string &type) { m_messageSignal(message, type); } typedef boost::signals2::signal &, const std::string &)> MessageSignal_t; MessageSignal_t m_messageSignal; /** store the latest connection state information */ void connectionState(const std::string &error) { m_connectionStateSignal(error); } typedef boost::signals2::signal ConnectionStateSignal_t; ConnectionStateSignal_t m_connectionStateSignal; }; SE_END_CXX #endif // SESSION_HELPER_H