summaryrefslogtreecommitdiff
path: root/src/syncevo/MultiplexConfigNode.h
blob: 5e4d080121112d4f00f4752626d5b641a7d24b02 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2009 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 INCL_SYNCEVO_MULTIPLEX_CONFIG_NODE
# define INCL_SYNCEVO_MULTIPLEX_CONFIG_NODE

#include <syncevo/declarations.h>
#include <syncevo/ConfigNode.h>
#include <syncevo/SyncConfig.h>
SE_BEGIN_CXX

/**
 * Joins properties from the different nodes that might be used by a
 * SyncConfig or SyncSourceConfig (global/shared/not shared,
 * hidden/user-visible) and presents them as one node. Reading takes
 * the union of all set properties. Writing is directed to the
 * node for which the property was registered.
 */
class MultiplexConfigNode : public FilterConfigNode
{
    const std::string m_name;
    boost::shared_ptr<FilterConfigNode> m_nodes[2][3];
    const ConfigPropertyRegistry &m_registry;
    bool m_havePeerNodes;
    int m_hiddenLower, m_hiddenUpper;

    FilterConfigNode *getNode(const std::string &property,
                              const ConfigProperty **prop = NULL) const;

 public:
    /** join both hidden and user-visible properties */
    MultiplexConfigNode(const std::string &name,
                        const ConfigPropertyRegistry &registry) :
        FilterConfigNode(boost::shared_ptr<ConfigNode>()),
        m_name(name),
        m_registry(registry),
        m_havePeerNodes(true),
        m_hiddenLower(0), m_hiddenUpper(1) {}

    /** only join hidden or user-visible properties */
    MultiplexConfigNode(const std::string &name,
                        const ConfigPropertyRegistry &registry,
                        bool hidden) :
        FilterConfigNode(boost::shared_ptr<ConfigNode>()),
        m_name(name),
        m_registry(registry),
        m_havePeerNodes(true),
        m_hiddenLower(hidden), m_hiddenUpper(hidden) {}

    /** true when peer nodes are used (default), false when they are dummy nodes */
    bool getHavePeerNodes() const { return m_havePeerNodes; }
    void setHavePeerNodes(bool havePeerNodes) { m_havePeerNodes = havePeerNodes; }

    /** configure the nodes to use */
    void setNode(bool hidden, ConfigProperty::Sharing sharing,
                 const boost::shared_ptr<FilterConfigNode> &node) {
        m_nodes[hidden][sharing] = node;
    }
    void setNode(bool hidden, ConfigProperty::Sharing sharing,
                 const boost::shared_ptr<ConfigNode> &node) {
        m_nodes[hidden][sharing].reset(new FilterConfigNode(node));
    }

    virtual void addFilter(const std::string &property,
                           const InitStateString &value);
    virtual void setFilter(const ConfigFilter &filter);

    virtual std::string getName() const { return m_name; }
    virtual void flush();
    virtual InitStateString readProperty(const std::string &property) const;
    virtual void writeProperty(const std::string &property,
                               const InitStateString &value,
                               const std::string &comment = std::string(""));
    virtual void readProperties(PropsType &props) const;

    /*
     * removing or clearing something is not implemented because it is
     * not certain what should be deleted: only properties which are
     * not shared?!
     */
    virtual void removeProperty(const std::string &property);
    virtual void clear();

    /**
     * true if any of the nodes exists
     */
    virtual bool exists() const;
};

SE_END_CXX

#endif // INCL_SYNCEVO_MULTIPLEX_CONFIG_NODE