menu: added new Keywords tag to .desktop files
[barry.git] / opensync-plugin-0.4x / src / tosserror.h
blobfcc4dd4a28d13bc4ca9ccf1634dcc6987e5ede10
1 ///
2 /// \file tosserror.h
3 /// RAII class for OSyncError structs that are wholly
4 /// belonging to the barry plugin.
5 ///
7 /*
8 Copyright (C) 2009-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_SYNC_TOSSERROR_H__
24 #define __BARRY_SYNC_TOSSERROR_H__
26 #include "trace.h"
27 #include <opensync/opensync.h>
30 // TossError
32 /// This is a wrapper class for OSyncError *error pointers.
33 /// For some of the opensync API, these error pointers are passed
34 /// into functions, such as osync_time_*() functions, and filled
35 /// in the event that an error occurs. These kinds of *errors are
36 /// not passed into the framework, and so it is our responsibility
37 /// to free them.
38 ///
39 /// This class makes it easy to do that freeing.
40 ///
41 class TossError
43 OSyncError *m_error;
45 const char *m_func;
46 Trace *m_trace;
48 public:
49 // simple wrapper... unref's the error on destruction
50 TossError()
51 : m_error(0)
52 , m_func(0)
53 , m_trace(0)
57 // log wrapper... logs to given tracer and unref's on destruction
58 TossError(const char *funcname, Trace &trace)
59 : m_error(0)
60 , m_func(funcname)
61 , m_trace(&trace)
65 ~TossError()
67 Clear();
70 /// Returns NULL if no error
71 const char* GetErrorMsg()
73 return osync_error_print(&m_error);
76 bool IsSet()
78 return osync_error_is_set(&m_error);
81 void Log()
83 if( m_error && m_trace )
84 m_trace->logf("%s: %s", m_func, GetErrorMsg());
87 void Clear()
89 if( m_error ) {
90 Log();
91 osync_error_unref(&m_error);
92 m_error = 0;
96 operator OSyncError**()
98 return &m_error;
102 #endif