debian: made the changelog more verbose as per intrigeri's feedback
[barry.git] / desktop / src / bsynccl.cc
blobd7ddfa52a0e36664a98d61d6a2c71e67fb676a43
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-2012, 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"
34 using namespace std;
36 // command line arguments
37 string g_argv_version, g_argv_group_name;
38 OpenSync::Config::pst_type g_sync_types = PST_DO_NOT_SET;
40 class BarrySyncJail : public OpenSync::SyncStatus
42 private:
43 TempDir m_temp;
44 std::auto_ptr<OpenSync::API> m_engine;
46 // communication variables
47 int m_sequenceID;
48 public:
49 BarrySyncJail();
50 ~BarrySyncJail();
53 // overrides
55 virtual bool OnInit();
56 virtual int OnExit();
59 // OpenSync::SyncStatus virtual overrides
61 // virtual void CheckSummary(OpenSync::SyncSummary &summary);
64 //////////////////////////////////////////////////////////////////////////////
65 // BarrySyncJail
67 BarrySyncJail::BarrySyncJail()
68 : m_temp("bsyncjail")
70 OnInit();
73 BarrySyncJail::~BarrySyncJail()
77 bool BarrySyncJail::OnInit()
79 cerr << "OnInit()" << endl;
81 // load opensync engine
82 try {
83 if( g_argv_version == "0.22" )
84 m_engine.reset( new OpenSync::OpenSync22 );
85 else {
86 m_engine.reset( new OpenSync::OpenSync40 );
89 catch( std::exception &e ) {
90 cerr << e.what() << endl;
91 return false;
94 if( !m_engine.get() ) {
95 cerr << "Unknown engine number: " << g_argv_version << endl;
96 return false;
99 // start the sync
100 try {
101 m_engine->Discover(g_argv_group_name);
102 m_engine->Sync(g_argv_group_name, *this, g_sync_types);
104 catch( std::exception &e ) {
105 cerr << e.what() << endl;
106 return true;
109 return true;
112 int BarrySyncJail::OnExit()
114 cerr << "OnExit()" << endl;
116 return 0;
120 // OpenSync::SyncStatus virtual overrides
124 void BarrySyncJail::CheckSummary(OpenSync::SyncSummary &summary)
126 cerr << "CheckSummary" << endl;
127 // FIXME: not currently supported... abort every time
128 // cerr << "FIXME: CheckSummary() not implemented, aborting" << endl;
129 // summary.Abort();
130 summary.Continue();
134 int main(int argc, char *argv[])
136 cerr << "bsyncjail startup" << endl;
138 if( argc != 4 ) {
139 cerr << "This is a helper program for barrydesktop, and\n"
140 "not intended to be called directly.\n" << endl;
141 return 1;
144 g_argv_version = argv[1];
145 g_argv_group_name = argv[2];
146 g_sync_types = atoi(argv[3]);
148 BarrySyncJail app;
149 return app.OnExit();