- more porting of OpenSync module to 0.30
[barry.git] / opensync-plugin / src / environment.h
blob87d5fb60be66b391ebd38a788dde5f8d2f389544
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 <opensync/plugin/opensync_plugin_info.h>
27 #include <barry/barry.h>
28 #include <string>
29 #include "idmap.h"
32 class BarryEnvironment;
34 class DatabaseSyncState
36 private:
37 BarryEnvironment *m_pEnv;
39 public:
40 // cache is a map of record ID to bool... the bool doesn't mean
41 // anything... the mere existence of the ID means it belongs
42 // in the cache
43 typedef std::map<uint32_t, bool> cache_type;
45 public:
46 // cache data
47 std::string m_CacheFilename;
48 cache_type m_Cache;
50 // id map data
51 std::string m_MapFilename;
52 idmap m_IdMap;
54 // device data
55 Barry::RecordStateTable m_Table;
57 bool m_Sync;
59 // external OpenSync data
60 OSyncObjFormat *m_pObjFormat;
61 OSyncObjTypeSink *m_pSink;
63 private:
64 std::string m_Desc;
65 const char *m_DBName;
67 public:
68 DatabaseSyncState(BarryEnvironment *pEnv, OSyncPluginInfo *pi,
69 const char *DBName, const char *description);
70 ~DatabaseSyncState();
72 bool LoadCache();
73 bool SaveCache();
75 bool LoadMap();
76 bool SaveMap();
78 void CleanupMap();
79 void ClearDirtyFlags();
81 unsigned long GetMappedRecordId(const std::string &uid);
83 const std::string& GetDesc() const { return m_Desc; }
84 const char* GetDBName() const { return m_DBName; }
88 class BarryEnvironment
90 public:
91 // user config data
92 std::string m_ConfigData;
93 uint32_t m_pin;
95 // device communication
96 Barry::ProbeResult m_ProbeResult;
97 Barry::Controller *m_pCon;
99 // sync data
100 DatabaseSyncState m_CalendarSync, m_ContactsSync;
102 public:
103 BarryEnvironment(OSyncPluginInfo *pi);
104 ~BarryEnvironment();
106 // meta data
107 bool IsConnected() { return m_pCon; }
109 // operations
111 void OpenDesktop(Barry::ProbeResult &result);
112 void Disconnect();
114 DatabaseSyncState* GetSyncObject(OSyncChange *change);
116 void ParseConfig(const char *data);
117 void BuildConfig();
119 void ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname);
120 void ClearCalendarDirtyFlags();
121 void ClearContactsDirtyFlags();
124 #endif