2 * Copyright (C) 2012 Intel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef SESSION_HELPER_H
21 #define SESSION_HELPER_H
23 #include "session-common.h"
24 #include "dbus-sync.h"
26 #include <gdbus-cxx-bridge.h>
27 #include <boost/function.hpp>
30 #include <boost/shared_ptr.hpp>
32 #include <syncevo/declarations.h>
37 class SessionHelperLogger;
40 * Waits for requests via the internal D-Bus connection in run(), sent
41 * by the Session class in syncevo-dbus-server. Then for each request
42 * it remembers what to do in m_operation and returns from the event
43 * loop and executes the requested operation, pretty much like the
44 * traditional syncevo-dbus-server did.
46 class SessionHelper : public GDBusCXX::DBusObjectHelper,
47 private boost::noncopyable
50 GDBusCXX::DBusConnectionPtr m_conn;
51 boost::shared_ptr<ForkExecChild> m_forkexec;
52 boost::function<bool ()> m_operation;
53 boost::shared_ptr<SessionHelperLogger> m_logger;
54 PushLogger<Logger> m_pushLogger;
56 /** valid during doSync() */
57 boost::scoped_ptr<DBusSync> m_sync;
59 /** called by main event loop: initiate a sync operation */
60 void sync(const SessionCommon::SyncParams ¶ms,
61 const boost::shared_ptr< GDBusCXX::Result2<bool, SyncReport> > &result);
64 * called by run(): do the sync operation
65 * @return true if the helper is meant to terminate
67 bool doSync(const SessionCommon::SyncParams ¶ms,
68 const boost::shared_ptr< GDBusCXX::Result2<bool, SyncReport> > &result);
70 void restore(const std::string &configName,
71 const string &dir, bool before, const std::vector<std::string> &sources,
72 const boost::shared_ptr< GDBusCXX::Result1<bool> > &result);
73 bool doRestore(const std::string &configName,
74 const string &dir, bool before, const std::vector<std::string> &sources,
75 const boost::shared_ptr< GDBusCXX::Result1<bool> > &result);
77 void execute(const vector<string> &args, const map<string, string> &vars,
78 const boost::shared_ptr< GDBusCXX::Result1<bool> > &result);
79 bool doExecute(const vector<string> &args, const map<string, string> &vars,
80 const boost::shared_ptr< GDBusCXX::Result1<bool> > &result);
82 /** SessionHelper.PasswordResponse */
83 void passwordResponse(bool timedOut, bool aborted, const std::string &password);
86 SessionHelper(GMainLoop *loop,
87 const GDBusCXX::DBusConnectionPtr &conn,
88 const boost::shared_ptr<ForkExecChild> &forkexec);
91 void setDBusLogLevel(Logger::Level level);
92 Logger::Level getDBusLogLevel() const;
96 GMainLoop *getLoop() const { return m_loop; }
98 /** Still have connection to parent. Shortcut which asks the ForkExecChild class. */
101 boost::shared_ptr<ForkExecChild> getForkExecChild() { return m_forkexec; }
103 /** Server.LogOutput for the session D-Bus object */
104 GDBusCXX::EmitSignal3<std::string,
105 std::string, std::string, true> emitLogOutput;
107 /** SyncContext::displaySyncProgress */
108 GDBusCXX::EmitSignal4<sysync::TProgressEventEnum,
109 int32_t, int32_t, int32_t, true> emitSyncProgress;
111 /** SyncContext::displaySourceProgress */
112 GDBusCXX::EmitSignal6<sysync::TProgressEventEnum,
113 std::string, SyncMode,
114 int32_t, int32_t, int32_t, true> emitSourceProgress;
116 /** SyncContext::m_sourceSyncedSignal */
117 GDBusCXX::EmitSignal2<std::string, SyncSourceReport, true> emitSourceSynced;
119 /** SyncContext::reportStepCmd -> true/false for "waiting on IO" */
120 GDBusCXX::EmitSignal1<bool, true> emitWaiting;
122 /** SyncContext::syncSuccessStart */
123 GDBusCXX::EmitSignal0Template<true> emitSyncSuccessStart;
125 /** Cmdline::configWasModified() */
126 GDBusCXX::EmitSignal0Template<true> emitConfigChanged;
128 /** SyncContext::askPassword */
129 GDBusCXX::EmitSignal2<std::string, ConfigPasswordKey> emitPasswordRequest;
131 /** send message to parent's connection (buffer, type, url) */
132 GDBusCXX::EmitSignal3<GDBusCXX::DBusArray<uint8_t>, std::string, std::string> emitMessage;
134 /** tell parent's connection to shut down */
135 GDBusCXX::EmitSignal0Template<false> emitShutdown;
137 /** store the next message received by the session's connection */
138 void storeMessage(const GDBusCXX::DBusArray<uint8_t> &message,
139 const std::string &type) {
140 m_messageSignal(message, type);
142 typedef boost::signals2::signal<void (const GDBusCXX::DBusArray<uint8_t> &,
143 const std::string &)> MessageSignal_t;
144 MessageSignal_t m_messageSignal;
146 /** store the latest connection state information */
147 void connectionState(const std::string &error)
149 m_connectionStateSignal(error);
151 typedef boost::signals2::signal<void (const std::string &)> ConnectionStateSignal_t;
152 ConnectionStateSignal_t m_connectionStateSignal;
157 #endif // SESSION_HELPER_H