]> git.saurik.com Git - wxWidgets.git/blob - samples/ipc/connection.h
Minor corrections to XRC format description.
[wxWidgets.git] / samples / ipc / connection.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: connection.h
3 // Purpose: DDE sample: MyConnection class
4 // Author: Vadim Zeitlin
5 // Created: 2008-02-11 (extracted from client.cpp)
6 // Copyright: (c) 1999 Julian Smart
7 // 2008 Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_SAMPLE_IPC_CONNECTION_H_
12 #define _WX_SAMPLE_IPC_CONNECTION_H_
13
14 // This simple connection class adds logging of all operations
15 class MyConnectionBase : public wxConnection
16 {
17 protected:
18 void Log(const wxString& command,
19 const wxString& topic,
20 const wxString& item,
21 const void *data,
22 size_t size,
23 wxIPCFormat format)
24 {
25 wxString s;
26 if (topic.IsEmpty() && item.IsEmpty())
27 s.Printf("%s(", command.c_str());
28 else if (topic.IsEmpty())
29 s.Printf("%s(item=\"%s\",", command.c_str(), item.c_str());
30 else if (item.IsEmpty())
31 s.Printf("%s(topic=\"%s\",", command.c_str(), topic.c_str());
32 else
33 s.Printf("%s(topic=\"%s\",item=\"%s\",", command.c_str(), topic.c_str(), item.c_str());
34
35 switch (format)
36 {
37 case wxIPC_TEXT:
38 s += wxString(static_cast<const char *>(data), size);
39 break;
40
41 #if wxUSE_UNICODE
42 case wxIPC_UNICODETEXT:
43 s += wxString(static_cast<const wchar_t *>(data), size);
44 break;
45 #endif // wxUSE_UNICODE
46
47 case wxIPC_UTF8TEXT:
48 s += wxString::FromUTF8(static_cast<const char *>(data), size);
49 break;
50
51 case wxIPC_PRIVATE:
52 if ( size == 3 )
53 {
54 const char *bytes = static_cast<const char *>(data);
55 s << '"' << bytes[0] << bytes[1] << bytes[2] << '"';
56 }
57 else
58 {
59 s << "\"???\"";
60 }
61 break;
62
63 case wxIPC_INVALID:
64 s += "[invalid data]";
65 break;
66
67 default:
68 s += "[unknown data]";
69 break;
70 }
71
72 wxLogMessage("%s,%d)", s, size);
73 }
74 };
75
76 #endif // _WX_SAMPLE_IPC_CONNECTION_H_