Bumped copyright dates for 2013
[barry.git] / desktop / src / ipc.h
blob30c388f45f7dc53669a36a571c02f04bc355f3a3
1 ///
2 /// \file ipc.h
3 /// Common things needed for both client and server
4 ///
6 /*
7 Copyright (C) 2010-2013, 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 __BARRYDESKTOP_IPC_H__
23 #define __BARRYDESKTOP_IPC_H__
25 #include <wx/ipc.h>
27 #define SERVER_SERVICE_NAME _T("/tmp/bsyncjail.socket")
29 // Connection Topics
30 #define TOPIC_STATUS _T("Status")
31 #define TOPIC_CONFLICT _T("Conflict")
33 // Status items
34 #define STATUS_ITEM_ERROR _T("Error")
35 #define STATUS_ITEM_ENGINE _T("Engine")
36 #define STATUS_ITEM_MAPPING _T("Mapping")
37 #define STATUS_ITEM_ENTRY _T("Entry")
38 #define STATUS_ITEM_MEMBER _T("Member")
40 // Special engine messages
41 #define ENGINE_STATUS_SLOW_SYNC _T("SLOW_SYNC: on")
43 // Conflict items
44 #define CONFLICT_ITEM_START _T("Start")
45 #define CONFLICT_ITEM_CHANGE _T("Change")
46 #define CONFLICT_ITEM_ANSWER _T("Answer")
48 // Used to convert const char* strings into temporary writable
49 // buffers, since wxConnection is not very const correct.
50 class SillyBuffer
52 wxChar *m_buf;
53 int m_size;
54 int m_data_size;
56 public:
57 SillyBuffer()
58 : m_buf( new wxChar[100] )
59 , m_size(100)
60 , m_data_size(0)
64 ~SillyBuffer()
66 delete [] m_buf;
69 int size() const { return m_data_size; }
70 wxChar* buf() { return m_buf; }
72 void resize(int len)
74 if( len+1 > m_size ) {
75 delete [] m_buf;
76 m_buf = 0;
77 m_buf = new wxChar[len+1];
78 m_size = len+1;
79 m_data_size = 0;
83 SillyBuffer& sbuf(const wxString &str) { buf(str); return *this; }
84 SillyBuffer& sbuf(const char *str) { buf(str); return *this; }
85 SillyBuffer& sbuf(const std::string &str) { buf(str); return *this; }
87 wxChar* buf(const wxString &str)
89 resize(str.Len());
90 memcpy(m_buf, str.GetData(), str.Len() * sizeof(wxChar));
91 m_buf[str.Len()] = 0;
92 m_data_size = str.Len();
93 return m_buf;
96 wxChar* buf(const char *str)
98 return buf(wxString(str, wxConvUTF8));
101 wxChar* buf(const std::string &str)
103 return buf(wxString(str.c_str(), wxConvUTF8, str.size()));
107 extern SillyBuffer sb;
109 #endif