Bumped copyright dates for 2013
[barry.git] / opensync-plugin / src / environment.h
blobf799b6917c35a1b0959256ce22bb61cda20c161e
1 //
2 // \file environment.h
3 // Container / environment class for the sync module.
4 //
6 /*
7 Copyright (C) 2006-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_SYNC_ENVIRONMENT_H__
23 #define __BARRY_SYNC_ENVIRONMENT_H__
25 #include <opensync/opensync.h>
26 #include <barry/barry.h>
27 #include <string>
28 #include <memory>
29 #include "idmap.h"
32 struct DatabaseSyncState
34 public:
35 // cache is a map of record ID to bool... the bool doesn't mean
36 // anything... the mere existence of the ID means it belongs
37 // in the cache
38 typedef std::map<uint32_t, bool> cache_type;
40 public:
41 // cache data
42 std::string m_CacheFilename;
43 cache_type m_Cache;
45 // id map data
46 std::string m_MapFilename;
47 idmap m_IdMap;
49 // device data
50 unsigned int m_dbId;
51 std::string m_dbName;
52 Barry::RecordStateTable m_Table;
54 bool m_Sync;
56 private:
57 std::string m_Desc;
59 public:
60 DatabaseSyncState(OSyncMember *pm, const char *description);
61 ~DatabaseSyncState();
63 bool LoadCache();
64 bool SaveCache();
66 bool LoadMap();
67 bool SaveMap();
69 void CleanupMap();
70 void ClearDirtyFlags();
72 std::string Map2Uid(uint32_t recordId) const;
73 unsigned long GetMappedRecordId(const std::string &uid);
77 struct BarryEnvironment
79 private:
80 std::string m_password;
82 public:
83 OSyncMember *member;
85 // user config data
86 std::string m_ConfigData;
87 uint32_t m_pin;
88 bool m_DebugMode;
90 // device communication
91 std::auto_ptr<Barry::DesktopConnector> m_con;
93 // sync data
94 DatabaseSyncState m_CalendarSync, m_ContactsSync;
96 protected:
97 void DoConnect();
99 public:
100 BarryEnvironment(OSyncMember *pm);
101 ~BarryEnvironment();
103 Barry::Mode::Desktop* GetDesktop() { return &m_con->GetDesktop(); }
104 void SetPassword(const std::string &password);
106 void Connect(const Barry::ProbeResult &result);
107 void Reconnect();
108 void Disconnect();
110 DatabaseSyncState* GetSyncObject(OSyncChange *change);
112 void ParseConfig(const char *data, int size);
113 void BuildConfig();
115 void ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname);
116 void ClearCalendarDirtyFlags();
117 void ClearContactsDirtyFlags();
120 #endif