summaryrefslogtreecommitdiff
path: root/src/dbus/server/dbus-sync.h
blob: 9acde8d3d41601ab31f71ba8b44d19281d1e297b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (C) 2011 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 DBUS_SYNC_H
#define DBUS_SYNC_H

#include "session-common.h"

#include <syncevo/SyncContext.h>
#include <syncevo/UserInterface.h>
#include <syncevo/SuspendFlags.h>

#include <boost/signals2.hpp>

#include <syncevo/declarations.h>
SE_BEGIN_CXX

class SessionHelper;

namespace SessionCommon {
    struct SyncParams;
}

/**
 * Maps sync events to D-Bus signals in SessionHelper.
 * Does password requests by sending out a request for
 * them via SessionHelper and waiting until a reply (positive
 * or negative) is received.
 */
class DBusSync : public SyncContext, private UserInterface
{
    SessionHelper &m_helper;
    SessionCommon::SyncParams m_params;
    bool m_waiting;
    boost::function<void (const std::string &)> m_passwordSuccess;
    boost::function<void ()> m_passwordFailure;
    std::string m_passwordDescr;
    boost::signals2::connection m_parentWatch;
    boost::signals2::connection m_suspendFlagsWatch;

    void suspendFlagsChanged(SuspendFlags &flags);

public:
    DBusSync(const SessionCommon::SyncParams &params,
             SessionHelper &helper);
    ~DBusSync();

    /** to be called by SessionHelper when it gets a response via D-Bus */
    void passwordResponse(bool timedOut, bool aborted, const std::string &password);

protected:
    virtual boost::shared_ptr<TransportAgent> createTransportAgent();
    virtual void displaySyncProgress(sysync::TProgressEventEnum type,
                                     int32_t extra1, int32_t extra2, int32_t extra3);
    virtual void displaySourceProgress(sysync::TProgressEventEnum type,
                                       SyncSource &source,
                                       int32_t extra1, int32_t extra2, int32_t extra3);
    virtual void reportStepCmd(sysync::uInt16 stepCmd);
    virtual void syncSuccessStart();
    string askPassword(const string &passwordName,
                       const string &descr,
                       const ConfigPasswordKey &key);
    virtual void askPasswordAsync(const std::string &passwordName,
                                  const std::string &descr,
                                  const ConfigPasswordKey &key,
                                  const boost::function<void (const std::string &)> &success,
                                  const boost::function<void ()> &failureException);

    virtual bool savePassword(const std::string &passwordName,
                              const std::string &password,
                              const ConfigPasswordKey &key);
    virtual void readStdin(std::string &content);
};

SE_END_CXX

#endif // DBUS_SYNC_H