- opensync compiles again, with 0.30! (not functional yet)
[barry.git] / opensync-plugin / src / environment.h
blobd97b5bc40f1a75870f89216904bcf6638dc4cf14
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 // OpenSync data
60 OSyncObjFormat *m_pObjFormat;
62 private:
63 std::string m_Desc;
64 const char *m_DBName;
66 public:
67 DatabaseSyncState(BarryEnvironment *pEnv, OSyncPluginInfo *pi,
68 const char *DBName, const char *description);
69 ~DatabaseSyncState();
71 bool LoadCache();
72 bool SaveCache();
74 bool LoadMap();
75 bool SaveMap();
77 void CleanupMap();
78 void ClearDirtyFlags();
80 unsigned long GetMappedRecordId(const std::string &uid);
82 const std::string& GetDesc() const { return m_Desc; }
83 const char* GetDBName() const { return m_DBName; }
87 class BarryEnvironment
89 public:
90 // user config data
91 std::string m_ConfigData;
92 uint32_t m_pin;
94 // device communication
95 Barry::ProbeResult m_ProbeResult;
96 Barry::Controller *m_pCon;
98 // sync data
99 DatabaseSyncState m_CalendarSync, m_ContactsSync;
101 public:
102 BarryEnvironment(OSyncPluginInfo *pi);
103 ~BarryEnvironment();
105 // meta data
106 bool IsConnected() { return m_pCon; }
108 // operations
110 void OpenDesktop(Barry::ProbeResult &result);
111 void Disconnect();
113 DatabaseSyncState* GetSyncObject(OSyncChange *change);
115 void ParseConfig(const char *data);
116 void BuildConfig();
118 void ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname);
119 void ClearCalendarDirtyFlags();
120 void ClearContactsDirtyFlags();
123 #endif