2 * Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
3 * Copyright (C) 2009 Intel Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) version 3.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <syncevo/TrackingSyncSource.h>
22 #include <syncevo/SafeConfigNode.h>
23 #include <syncevo/PrefixConfigNode.h>
25 #include <boost/bind.hpp>
27 #include <syncevo/declarations.h>
30 TrackingSyncSource::TrackingSyncSource(const SyncSourceParams ¶ms,
31 int granularitySeconds) :
32 TestingSyncSource(params),
33 m_trackingNode(new PrefixConfigNode("item-",
34 boost::shared_ptr<ConfigNode>(new SafeConfigNode(params.m_nodes.getTrackingNode()))))
36 m_operations.m_checkStatus = boost::bind(&TrackingSyncSource::checkStatus, this, _1);
37 m_operations.m_isEmpty = boost::bind(&TrackingSyncSource::isEmpty, this);
38 SyncSourceRevisions::init(this, this, granularitySeconds, m_operations);
41 void TrackingSyncSource::checkStatus(SyncSourceReport &changes)
43 detectChanges(*m_trackingNode);
44 // copy our item counts into the report
45 changes.setItemStat(ITEM_LOCAL, ITEM_ADDED, ITEM_TOTAL, getNewItems().size());
46 changes.setItemStat(ITEM_LOCAL, ITEM_UPDATED, ITEM_TOTAL, getUpdatedItems().size());
47 changes.setItemStat(ITEM_LOCAL, ITEM_REMOVED, ITEM_TOTAL, getDeletedItems().size());
48 changes.setItemStat(ITEM_LOCAL, ITEM_ANY, ITEM_TOTAL, getAllItems().size());
51 void TrackingSyncSource::beginSync(const std::string &lastToken, const std::string &resumeToken)
53 detectChanges(*m_trackingNode);
56 std::string TrackingSyncSource::endSync(bool success)
58 // store changes persistently
62 m_trackingNode->flush();
64 // The Synthesis docs say that we should rollback in case of
65 // failure. Cannot do that for data, so lets at least keep
66 // the revision map unchanged.
69 // no token handling at the moment (not needed for clients)
73 TrackingSyncSource::InsertItemResult TrackingSyncSource::insertItem(const std::string &luid, const std::string &item)
75 InsertItemResult res = insertItem(luid, item, false);
76 updateRevision(*m_trackingNode, luid, res.m_luid, res.m_revision);
80 TrackingSyncSource::InsertItemResult TrackingSyncSource::insertItemRaw(const std::string &luid, const std::string &item)
82 InsertItemResult res = insertItem(luid, item, true);
83 updateRevision(*m_trackingNode, luid, res.m_luid, res.m_revision);
87 void TrackingSyncSource::readItem(const std::string &luid, std::string &item)
89 readItem(luid, item, false);
92 void TrackingSyncSource::readItemRaw(const std::string &luid, std::string &item)
94 readItem(luid, item, true);
97 void TrackingSyncSource::deleteItem(const std::string &luid)
100 deleteRevision(*m_trackingNode, luid);
103 void TrackingSyncSource::enableServerMode()
105 SyncSourceAdmin::init(m_operations, this);
108 bool TrackingSyncSource::serverModeEnabled() const
110 return m_operations.m_loadAdminData;
113 const char *TrackingSyncSource::getPeerMimeType() const
115 return getMimeType();