Bumped copyright dates for 2013
[barry.git] / desktop / src / bsynccl.cc
blob5907ccc4299e3cef88aaefa60e8069bff2eeea22
1 ///
2 /// \file bsyncjail.cc
3 /// Helper program to isolate the actual syncing into its
4 /// own process. Communicates with the main barrydesktop
5 /// via wxWidgets IPC communication. This belongs in its
6 /// own process since the sync can hang, and may need to
7 /// be killed from the GUI.
8 ///
11 Copyright (C) 2010-2013, Net Direct Inc. (http://www.netdirect.ca/)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License in the COPYING file at the
23 root directory of this project for more details.
26 #include <iostream>
27 #include <sstream>
28 #include <stdlib.h>
29 #include "os22.h"
30 #include "os40.h"
31 #include "tempdir.h"
32 #include "ostypes.h"
33 #include "i18n.h"
35 using namespace std;
37 // command line arguments
38 string g_argv_version, g_argv_group_name;
39 OpenSync::Config::pst_type g_sync_types = PST_DO_NOT_SET;
41 class BarrySyncJail : public OpenSync::SyncStatus
43 private:
44 TempDir m_temp;
45 std::auto_ptr<OpenSync::API> m_engine;
47 // communication variables
48 int m_sequenceID;
49 public:
50 BarrySyncJail();
51 ~BarrySyncJail();
54 // overrides
56 virtual bool OnInit();
57 virtual int OnExit();
60 // OpenSync::SyncStatus virtual overrides
62 // virtual void CheckSummary(OpenSync::SyncSummary &summary);
65 //////////////////////////////////////////////////////////////////////////////
66 // BarrySyncJail
68 BarrySyncJail::BarrySyncJail()
69 : m_temp("bsyncjail")
71 OnInit();
74 BarrySyncJail::~BarrySyncJail()
78 bool BarrySyncJail::OnInit()
80 cerr << "OnInit()" << endl;
82 // load opensync engine
83 try {
84 if( g_argv_version == "0.22" )
85 m_engine.reset( new OpenSync::OpenSync22 );
86 else {
87 m_engine.reset( new OpenSync::OpenSync40 );
90 catch( std::exception &e ) {
91 cerr << e.what() << endl;
92 return false;
95 if( !m_engine.get() ) {
96 cerr << "Unknown engine number: " << g_argv_version << endl;
97 return false;
100 // start the sync
101 try {
102 m_engine->Discover(g_argv_group_name);
103 m_engine->Sync(g_argv_group_name, *this, g_sync_types);
105 catch( std::exception &e ) {
106 cerr << e.what() << endl;
107 return true;
110 return true;
113 int BarrySyncJail::OnExit()
115 cerr << "OnExit()" << endl;
117 return 0;
121 // OpenSync::SyncStatus virtual overrides
125 void BarrySyncJail::CheckSummary(OpenSync::SyncSummary &summary)
127 cerr << "CheckSummary" << endl;
128 // FIXME: not currently supported... abort every time
129 // cerr << "FIXME: CheckSummary() not implemented, aborting" << endl;
130 // summary.Abort();
131 summary.Continue();
135 int main(int argc, char *argv[])
137 cerr << "bsyncjail startup" << endl;
139 if( argc != 4 ) {
140 cerr << _C("This is a helper program for barrydesktop, and\n"
141 "is not intended to be called directly.\n") << endl;
142 return 1;
145 g_argv_version = argv[1];
146 g_argv_group_name = argv[2];
147 g_sync_types = atoi(argv[3]);
149 BarrySyncJail app;
150 return app.OnExit();