enable easy switching between 0.22 and svn opensync sources
[barry.git] / opensync-plugin / src / error.cc
blob8a7a2285cd08f0347a413bcfc12fb69432f301df
1 ///
2 /// \file error.cc
3 /// Exception classes used specifically by the plugin.
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 #include "error.h"
23 #include <opensync/opensync.h>
25 //////////////////////////////////////////////////////////////////////////////
26 // osync_error exception class
28 osync_error& osync_error::operator=(const osync_error &other)
30 // unref the existing error
31 if( m_error ) {
32 osync_error_unref(&m_error);
33 m_error = 0;
36 // copy over the new one
37 m_error = other.m_error;
39 // ref it
40 if( m_error )
41 osync_error_ref(&m_error);
43 return *this;
46 osync_error::~osync_error() throw()
48 if( m_error )
49 osync_error_unref(&m_error);
52 std::string osync_error::get_error_msg(OSyncError *error)
54 const char *msg = osync_error_print(&error);
55 if( msg )
56 return msg; // can't pass null into ctor
57 else
58 return "(no error message: osync_error_print() returned NULL)";