Applied Nicolas Vivien's opensync-plugin-0.4x patch
[barry.git] / opensync-plugin-0.4x / src / environment.h
blob85fc3f9449046c360f9cfe992c85a45b77a7a9ca
1 //
2 // \file environment.h
3 // Container / environment class for the sync module.
4 //
6 /*
7 Copyright (C) 2006-2009, 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 <glib.h>
29 #include "idmap.h"
32 struct DatabaseSyncState
34 public:
35 OSyncObjTypeSink *sink;
37 // cache is a map of record ID to bool... the bool doesn't mean
38 // anything... the mere existence of the ID means it belongs
39 // in the cache
40 typedef std::map<uint32_t, bool> cache_type;
42 public:
43 // cache data
44 std::string m_CacheFilename;
45 cache_type m_Cache;
47 // id map data
48 std::string m_MapFilename;
49 idmap m_IdMap;
51 // device data
52 unsigned int m_dbId;
53 std::string m_dbName;
54 Barry::RecordStateTable m_Table;
56 bool m_Sync;
58 private:
59 std::string m_Desc;
61 public:
62 DatabaseSyncState(OSyncPluginInfo *info, const char *description);
63 ~DatabaseSyncState();
65 bool LoadCache();
66 bool SaveCache();
68 bool LoadMap();
69 bool SaveMap();
71 void CleanupMap();
72 void ClearDirtyFlags();
74 std::string Map2Uid(uint32_t recordId) const;
75 unsigned long GetMappedRecordId(const std::string &uid);
79 struct BarryEnvironment
81 public:
82 OSyncMember *member;
83 OSyncPluginInfo *info;
85 // user config data
86 std::string m_ConfigData;
87 uint32_t m_pin;
88 bool m_DebugMode;
89 std::string m_password;
91 // device communication
92 Barry::IConverter m_IConverter;
93 Barry::ProbeResult m_ProbeResult;
94 Barry::Controller *m_pCon;
95 Barry::Mode::Desktop *m_pDesktop;
97 // sync data
98 DatabaseSyncState m_CalendarSync, m_ContactsSync;
100 protected:
101 void DoConnect();
103 public:
104 // BarryEnvironment(OSyncMember *pm);
105 BarryEnvironment(OSyncPluginInfo *info);
106 ~BarryEnvironment();
108 void Connect(const Barry::ProbeResult &result);
109 void Reconnect();
110 void Disconnect();
112 DatabaseSyncState* GetSyncObject(OSyncChange *change);
114 void BuildConfig();
116 void ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname);
117 void ClearCalendarDirtyFlags();
118 void ClearContactsDirtyFlags();
121 #endif