]>
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
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/ipcbase.h"
24 IMPLEMENT_CLASS(wxServerBase
, wxObject
)
25 IMPLEMENT_CLASS(wxClientBase
, wxObject
)
26 IMPLEMENT_CLASS(wxConnectionBase
, wxObject
)
28 wxConnectionBase::wxConnectionBase(void *buffer
, size_t bytes
)
29 : m_buffer((char *)buffer
),
31 m_deletebufferwhendone(false),
35 { // behave like next constructor
37 m_deletebufferwhendone
= true;
41 wxConnectionBase::wxConnectionBase()
44 m_deletebufferwhendone(true),
49 wxConnectionBase::wxConnectionBase(const wxConnectionBase
& copy
)
51 m_buffer(copy
.m_buffer
),
52 m_buffersize(copy
.m_buffersize
),
53 m_deletebufferwhendone(false),
54 m_connected(copy
.m_connected
)
57 // copy constructor would require ref-counted pointer to buffer
58 wxFAIL_MSG( wxT("Copy constructor of wxConnectionBase not implemented") );
62 wxConnectionBase::~wxConnectionBase()
64 if ( m_deletebufferwhendone
)
69 wxString
wxConnectionBase::GetTextFromData(const void* data
,
77 // normally the string should be NUL-terminated and size should
78 // include the total size of the buffer, including NUL -- but don't
79 // crash (by trying to access (size_t)-1 bytes) if it doesn't
83 s
= wxString(static_cast<const char *>(data
), size
);
87 // TODO: we should handle both wxIPC_UTF16TEXT and wxIPC_UTF32TEXT here
88 // for inter-platform IPC
89 case wxIPC_UNICODETEXT
:
90 wxASSERT_MSG( !(size
% sizeof(wchar_t)), "invalid buffer size" );
93 size
/= sizeof(wchar_t);
97 s
= wxString(static_cast<const wchar_t *>(data
), size
);
104 s
= wxString::FromUTF8(static_cast<const char *>(data
), size
);
106 #endif // wxUSE_UNICODE
109 wxFAIL_MSG( "non-string IPC format in GetTextFromData()" );
115 void *wxConnectionBase::GetBufferAtLeast( size_t bytes
)
117 if ( m_buffersize
>= bytes
)
120 { // need to resize buffer
121 if ( m_deletebufferwhendone
)
122 { // we're in charge of buffer, increase it
124 m_buffer
= new char[bytes
];
125 m_buffersize
= bytes
;
127 } // user-supplied buffer, fail