]>
git.saurik.com Git - wxWidgets.git/blob - src/common/ipcbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/ipcbase.cpp
3 // Purpose: IPC base classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
21 #include "wx/ipcbase.h"
23 wxIMPLEMENT_ABSTRACT_CLASS(wxServerBase
, wxObject
)
24 wxIMPLEMENT_ABSTRACT_CLASS(wxClientBase
, wxObject
)
25 wxIMPLEMENT_ABSTRACT_CLASS(wxConnectionBase
, wxObject
)
27 wxConnectionBase::wxConnectionBase(void *buffer
, size_t bytes
)
28 : m_buffer((char *)buffer
),
30 m_deletebufferwhendone(false),
34 { // behave like next constructor
36 m_deletebufferwhendone
= true;
40 wxConnectionBase::wxConnectionBase()
43 m_deletebufferwhendone(true),
48 wxConnectionBase::wxConnectionBase(const wxConnectionBase
& copy
)
50 m_buffer(copy
.m_buffer
),
51 m_buffersize(copy
.m_buffersize
),
52 m_deletebufferwhendone(false),
53 m_connected(copy
.m_connected
)
56 // copy constructor would require ref-counted pointer to buffer
57 wxFAIL_MSG( wxT("Copy constructor of wxConnectionBase not implemented") );
61 wxConnectionBase::~wxConnectionBase()
63 if ( m_deletebufferwhendone
)
68 wxString
wxConnectionBase::GetTextFromData(const void* data
,
76 // normally the string should be NUL-terminated and size should
77 // include the total size of the buffer, including NUL -- but don't
78 // crash (by trying to access (size_t)-1 bytes) if it doesn't
82 s
= wxString(static_cast<const char *>(data
), size
);
86 // TODO: we should handle both wxIPC_UTF16TEXT and wxIPC_UTF32TEXT here
87 // for inter-platform IPC
88 case wxIPC_UNICODETEXT
:
89 wxASSERT_MSG( !(size
% sizeof(wchar_t)), "invalid buffer size" );
92 size
/= sizeof(wchar_t);
96 s
= wxString(static_cast<const wchar_t *>(data
), size
);
103 s
= wxString::FromUTF8(static_cast<const char *>(data
), size
);
105 #endif // wxUSE_UNICODE
108 wxFAIL_MSG( "non-string IPC format in GetTextFromData()" );
114 void *wxConnectionBase::GetBufferAtLeast( size_t bytes
)
116 if ( m_buffersize
>= bytes
)
119 { // need to resize buffer
120 if ( m_deletebufferwhendone
)
121 { // we're in charge of buffer, increase it
123 m_buffer
= new char[bytes
];
124 m_buffersize
= bytes
;
126 } // user-supplied buffer, fail