- added suppot to the Probe class to limit its search for
[barry.git] / opensync-plugin / src / environment.h
blob687e181d22fcb231e963e1d6864144518c9d632b
1 //
2 // \file environment.h
3 // Container / environment class for the sync module.
4 //
6 /*
7 Copyright (C) 2006-2007, 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 "idmap.h"
31 struct DatabaseSyncState
33 public:
34 // cache is a map of record ID to bool... the bool doesn't mean
35 // anything... the mere existence of the ID means it belongs
36 // in the cache
37 typedef std::map<uint32_t, bool> cache_type;
39 public:
40 // cache data
41 std::string m_CacheFilename;
42 cache_type m_Cache;
44 // id map data
45 std::string m_MapFilename;
46 idmap m_IdMap;
48 // device data
49 unsigned int m_dbId;
50 std::string m_dbName;
51 Barry::RecordStateTable m_Table;
53 bool m_Sync;
55 private:
56 std::string m_Desc;
58 public:
59 DatabaseSyncState(OSyncMember *pm, const char *description);
60 ~DatabaseSyncState();
62 bool LoadCache();
63 bool SaveCache();
65 bool LoadMap();
66 bool SaveMap();
68 void CleanupMap();
69 void ClearDirtyFlags();
71 std::string Map2Uid(uint32_t recordId) const;
72 unsigned long GetMappedRecordId(const std::string &uid);
76 struct BarryEnvironment
78 public:
79 OSyncMember *member;
81 // user config data
82 std::string m_ConfigData;
83 uint32_t m_pin;
84 bool m_DebugMode;
86 // device communication
87 Barry::ProbeResult m_ProbeResult;
88 Barry::Controller *m_pCon;
90 // sync data
91 DatabaseSyncState m_CalendarSync, m_ContactsSync;
93 protected:
94 void DoConnect();
96 public:
97 BarryEnvironment(OSyncMember *pm);
98 ~BarryEnvironment();
100 void Connect(const Barry::ProbeResult &result);
101 void Reconnect();
102 void Disconnect();
104 DatabaseSyncState* GetSyncObject(OSyncChange *change);
106 void ParseConfig(const char *data, int size);
107 void BuildConfig();
109 void ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname);
110 void ClearCalendarDirtyFlags();
111 void ClearContactsDirtyFlags();
114 #endif