Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013 University of California, Los Angeles |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program 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 |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef SYNC_LOG_H |
| 23 | #define SYNC_LOG_H |
| 24 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 25 | #include "db-helper.h" |
Alexander Afanasyev | 6f70a0f | 2013-01-02 20:44:09 -0800 | [diff] [blame] | 26 | #include <sync-state.pb.h> |
| 27 | |
| 28 | typedef boost::shared_ptr<SyncStateMsg> SyncStateMsgPtr; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 30 | class SyncLog : public DbHelper |
| 31 | { |
| 32 | public: |
Alexander Afanasyev | 433ecda | 2013-01-02 22:13:45 -0800 | [diff] [blame] | 33 | SyncLog (const std::string &path, const std::string &localName); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 34 | |
Alexander Afanasyev | 433ecda | 2013-01-02 22:13:45 -0800 | [diff] [blame] | 35 | sqlite3_int64 |
| 36 | GetNextLocalSeqNo (); // side effect: local seq_no will be increased |
| 37 | |
| 38 | void |
| 39 | UpdateDeviceSeqNo (sqlite3_int64 deviceId, sqlite3_int64 seqNo); |
| 40 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 41 | // done |
| 42 | void |
Alexander Afanasyev | 433ecda | 2013-01-02 22:13:45 -0800 | [diff] [blame] | 43 | UpdateDeviceSeqno (const std::string &name, sqlite3_int64 seqNo); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 45 | // std::string |
| 46 | // LookupForwardingAlias (const std::string &deviceName); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 48 | // void |
| 49 | // UpdateForwardingAlias (); |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 51 | // done |
| 52 | /** |
| 53 | * Create an entry in SyncLog and SyncStateNodes corresponding to the current state of SyncNodes |
| 54 | */ |
| 55 | HashPtr |
| 56 | RememberStateInStateLog (); |
| 57 | |
| 58 | // done |
| 59 | sqlite3_int64 |
| 60 | LookupSyncLog (const std::string &stateHash); |
| 61 | |
| 62 | // done |
| 63 | sqlite3_int64 |
| 64 | LookupSyncLog (const Hash &stateHash); |
| 65 | |
| 66 | // How difference is exposed will be determined later by the actual protocol |
Alexander Afanasyev | 6f70a0f | 2013-01-02 20:44:09 -0800 | [diff] [blame] | 67 | SyncStateMsgPtr |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 68 | FindStateDifferences (const std::string &oldHash, const std::string &newHash); |
| 69 | |
Alexander Afanasyev | 6f70a0f | 2013-01-02 20:44:09 -0800 | [diff] [blame] | 70 | SyncStateMsgPtr |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 71 | FindStateDifferences (const Hash &oldHash, const Hash &newHash); |
Alexander Afanasyev | 433ecda | 2013-01-02 22:13:45 -0800 | [diff] [blame] | 72 | |
| 73 | protected: |
| 74 | std::string m_localName; |
| 75 | sqlite3_int64 m_localDeviceId; |
| 76 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 79 | |
| 80 | #endif // SYNC_LOG_H |